Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(718)

Side by Side Diff: core/src/fxge/agg/fx_agg_driver.cpp

Issue 1800523005: Move core/src/ up to core/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxge/agg/fx_agg_driver.h ('k') | core/src/fxge/android/fpf_skiafont.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "core/src/fxge/agg/fx_agg_driver.h"
8
9 #include <algorithm>
10
11 #include "core/include/fxcodec/fx_codec.h"
12 #include "core/include/fxge/fx_ge.h"
13 #include "core/src/fxge/dib/dib_int.h"
14 #include "core/src/fxge/ge/fx_text_int.h"
15 #include "third_party/agg23/agg_conv_dash.h"
16 #include "third_party/agg23/agg_conv_stroke.h"
17 #include "third_party/agg23/agg_curves.h"
18 #include "third_party/agg23/agg_path_storage.h"
19 #include "third_party/agg23/agg_pixfmt_gray.h"
20 #include "third_party/agg23/agg_rasterizer_scanline_aa.h"
21 #include "third_party/agg23/agg_renderer_scanline.h"
22 #include "third_party/agg23/agg_scanline_u.h"
23
24 namespace {
25
26 void HardClip(FX_FLOAT& x, FX_FLOAT& y) {
27 x = std::max(std::min(x, 50000.0f), -50000.0f);
28 y = std::max(std::min(y, 50000.0f), -50000.0f);
29 }
30
31 } // namespace
32
33 void CAgg_PathData::BuildPath(const CFX_PathData* pPathData,
34 const CFX_Matrix* pObject2Device) {
35 int nPoints = pPathData->GetPointCount();
36 FX_PATHPOINT* pPoints = pPathData->GetPoints();
37 for (int i = 0; i < nPoints; i++) {
38 FX_FLOAT x = pPoints[i].m_PointX, y = pPoints[i].m_PointY;
39 if (pObject2Device) {
40 pObject2Device->Transform(x, y);
41 }
42 HardClip(x, y);
43 int point_type = pPoints[i].m_Flag & FXPT_TYPE;
44 if (point_type == FXPT_MOVETO) {
45 m_PathData.move_to(x, y);
46 } else if (point_type == FXPT_LINETO) {
47 if (pPoints[i - 1].m_Flag == FXPT_MOVETO &&
48 (i == nPoints - 1 || pPoints[i + 1].m_Flag == FXPT_MOVETO) &&
49 pPoints[i].m_PointX == pPoints[i - 1].m_PointX &&
50 pPoints[i].m_PointY == pPoints[i - 1].m_PointY) {
51 x += 1;
52 }
53 m_PathData.line_to(x, y);
54 } else if (point_type == FXPT_BEZIERTO) {
55 FX_FLOAT x0 = pPoints[i - 1].m_PointX, y0 = pPoints[i - 1].m_PointY;
56 FX_FLOAT x2 = pPoints[i + 1].m_PointX, y2 = pPoints[i + 1].m_PointY;
57 FX_FLOAT x3 = pPoints[i + 2].m_PointX, y3 = pPoints[i + 2].m_PointY;
58 if (pObject2Device) {
59 pObject2Device->Transform(x0, y0);
60 pObject2Device->Transform(x2, y2);
61 pObject2Device->Transform(x3, y3);
62 }
63 agg::curve4 curve(x0, y0, x, y, x2, y2, x3, y3);
64 i += 2;
65 m_PathData.add_path_curve(curve);
66 }
67 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE) {
68 m_PathData.end_poly();
69 }
70 }
71 }
72 namespace agg {
73
74 template <class BaseRenderer>
75 class renderer_scanline_aa_offset {
76 public:
77 typedef BaseRenderer base_ren_type;
78 typedef typename base_ren_type::color_type color_type;
79 renderer_scanline_aa_offset(base_ren_type& ren, unsigned left, unsigned top)
80 : m_ren(&ren), m_left(left), m_top(top) {}
81 void color(const color_type& c) { m_color = c; }
82 const color_type& color() const { return m_color; }
83 void prepare(unsigned) {}
84 template <class Scanline>
85 void render(const Scanline& sl) {
86 int y = sl.y();
87 unsigned num_spans = sl.num_spans();
88 typename Scanline::const_iterator span = sl.begin();
89 for (;;) {
90 int x = span->x;
91 if (span->len > 0) {
92 m_ren->blend_solid_hspan(x - m_left, y - m_top, (unsigned)span->len,
93 m_color, span->covers);
94 } else {
95 m_ren->blend_hline(x - m_left, y - m_top, (unsigned)(x - span->len - 1),
96 m_color, *(span->covers));
97 }
98 if (--num_spans == 0) {
99 break;
100 }
101 ++span;
102 }
103 }
104
105 private:
106 base_ren_type* m_ren;
107 color_type m_color;
108 unsigned m_left, m_top;
109 };
110
111 } // namespace agg
112
113 static void RasterizeStroke(agg::rasterizer_scanline_aa& rasterizer,
114 agg::path_storage& path_data,
115 const CFX_Matrix* pObject2Device,
116 const CFX_GraphStateData* pGraphState,
117 FX_FLOAT scale = 1.0f,
118 FX_BOOL bStrokeAdjust = FALSE,
119 FX_BOOL bTextMode = FALSE) {
120 agg::line_cap_e cap;
121 switch (pGraphState->m_LineCap) {
122 case CFX_GraphStateData::LineCapRound:
123 cap = agg::round_cap;
124 break;
125 case CFX_GraphStateData::LineCapSquare:
126 cap = agg::square_cap;
127 break;
128 default:
129 cap = agg::butt_cap;
130 break;
131 }
132 agg::line_join_e join;
133 switch (pGraphState->m_LineJoin) {
134 case CFX_GraphStateData::LineJoinRound:
135 join = agg::round_join;
136 break;
137 case CFX_GraphStateData::LineJoinBevel:
138 join = agg::bevel_join;
139 break;
140 default:
141 join = agg::miter_join_revert;
142 break;
143 }
144 FX_FLOAT width = pGraphState->m_LineWidth * scale;
145 FX_FLOAT unit = 1.f;
146 if (pObject2Device) {
147 unit =
148 1.0f / ((pObject2Device->GetXUnit() + pObject2Device->GetYUnit()) / 2);
149 }
150 if (width < unit) {
151 width = unit;
152 }
153 if (pGraphState->m_DashArray) {
154 typedef agg::conv_dash<agg::path_storage> dash_converter;
155 dash_converter dash(path_data);
156 for (int i = 0; i < (pGraphState->m_DashCount + 1) / 2; i++) {
157 FX_FLOAT on = pGraphState->m_DashArray[i * 2];
158 if (on <= 0.000001f) {
159 on = 1.0f / 10;
160 }
161 FX_FLOAT off = i * 2 + 1 == pGraphState->m_DashCount
162 ? on
163 : pGraphState->m_DashArray[i * 2 + 1];
164 if (off < 0) {
165 off = 0;
166 }
167 dash.add_dash(on * scale, off * scale);
168 }
169 dash.dash_start(pGraphState->m_DashPhase * scale);
170 typedef agg::conv_stroke<dash_converter> dash_stroke;
171 dash_stroke stroke(dash);
172 stroke.line_join(join);
173 stroke.line_cap(cap);
174 stroke.miter_limit(pGraphState->m_MiterLimit);
175 stroke.width(width);
176 rasterizer.add_path_transformed(stroke, pObject2Device);
177 } else {
178 agg::conv_stroke<agg::path_storage> stroke(path_data);
179 stroke.line_join(join);
180 stroke.line_cap(cap);
181 stroke.miter_limit(pGraphState->m_MiterLimit);
182 stroke.width(width);
183 rasterizer.add_path_transformed(stroke, pObject2Device);
184 }
185 }
186
187 IFX_RenderDeviceDriver* IFX_RenderDeviceDriver::CreateFxgeDriver(
188 CFX_DIBitmap* pBitmap,
189 FX_BOOL bRgbByteOrder,
190 CFX_DIBitmap* pOriDevice,
191 FX_BOOL bGroupKnockout) {
192 return new CFX_AggDeviceDriver(pBitmap, 0, bRgbByteOrder, pOriDevice,
193 bGroupKnockout);
194 }
195
196 CFX_AggDeviceDriver::CFX_AggDeviceDriver(CFX_DIBitmap* pBitmap,
197 int dither_bits,
198 FX_BOOL bRgbByteOrder,
199 CFX_DIBitmap* pOriDevice,
200 FX_BOOL bGroupKnockout) {
201 m_pBitmap = pBitmap;
202 m_DitherBits = dither_bits;
203 m_pClipRgn = NULL;
204 m_pPlatformBitmap = NULL;
205 m_pPlatformGraphics = NULL;
206 m_pDwRenderTartget = NULL;
207 m_bRgbByteOrder = bRgbByteOrder;
208 m_pOriDevice = pOriDevice;
209 m_bGroupKnockout = bGroupKnockout;
210 m_FillFlags = 0;
211 InitPlatform();
212 }
213
214 CFX_AggDeviceDriver::~CFX_AggDeviceDriver() {
215 delete m_pClipRgn;
216 for (int i = 0; i < m_StateStack.GetSize(); i++)
217 delete m_StateStack[i];
218 DestroyPlatform();
219 }
220
221 uint8_t* CFX_AggDeviceDriver::GetBuffer() const {
222 return m_pBitmap->GetBuffer();
223 }
224
225 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_
226 void CFX_AggDeviceDriver::InitPlatform() {}
227
228 void CFX_AggDeviceDriver::DestroyPlatform() {}
229
230 FX_BOOL CFX_AggDeviceDriver::DrawDeviceText(int nChars,
231 const FXTEXT_CHARPOS* pCharPos,
232 CFX_Font* pFont,
233 CFX_FontCache* pCache,
234 const CFX_Matrix* pObject2Device,
235 FX_FLOAT font_size,
236 FX_DWORD color,
237 int alpha_flag,
238 void* pIccTransform) {
239 return FALSE;
240 } // _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_
241 #endif
242
243 int CFX_AggDeviceDriver::GetDeviceCaps(int caps_id) {
244 switch (caps_id) {
245 case FXDC_DEVICE_CLASS:
246 return FXDC_DISPLAY;
247 case FXDC_PIXEL_WIDTH:
248 return m_pBitmap->GetWidth();
249 case FXDC_PIXEL_HEIGHT:
250 return m_pBitmap->GetHeight();
251 case FXDC_BITS_PIXEL:
252 return m_pBitmap->GetBPP();
253 case FXDC_HORZ_SIZE:
254 case FXDC_VERT_SIZE:
255 return 0;
256 case FXDC_RENDER_CAPS: {
257 int flags = FXRC_GET_BITS | FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE |
258 FXRC_BLEND_MODE | FXRC_SOFT_CLIP;
259 if (m_pBitmap->HasAlpha()) {
260 flags |= FXRC_ALPHA_OUTPUT;
261 } else if (m_pBitmap->IsAlphaMask()) {
262 if (m_pBitmap->GetBPP() == 1) {
263 flags |= FXRC_BITMASK_OUTPUT;
264 } else {
265 flags |= FXRC_BYTEMASK_OUTPUT;
266 }
267 }
268 if (m_pBitmap->IsCmykImage()) {
269 flags |= FXRC_CMYK_OUTPUT;
270 }
271 return flags;
272 }
273 case FXDC_DITHER_BITS:
274 return m_DitherBits;
275 }
276 return 0;
277 }
278
279 void CFX_AggDeviceDriver::SaveState() {
280 CFX_ClipRgn* pClip = NULL;
281 if (m_pClipRgn) {
282 pClip = new CFX_ClipRgn(*m_pClipRgn);
283 }
284 m_StateStack.Add(pClip);
285 }
286
287 void CFX_AggDeviceDriver::RestoreState(FX_BOOL bKeepSaved) {
288 if (m_StateStack.GetSize() == 0) {
289 delete m_pClipRgn;
290 m_pClipRgn = NULL;
291 return;
292 }
293 CFX_ClipRgn* pSavedClip = m_StateStack[m_StateStack.GetSize() - 1];
294 delete m_pClipRgn;
295 m_pClipRgn = NULL;
296 if (bKeepSaved) {
297 if (pSavedClip) {
298 m_pClipRgn = new CFX_ClipRgn(*pSavedClip);
299 }
300 } else {
301 m_StateStack.RemoveAt(m_StateStack.GetSize() - 1);
302 m_pClipRgn = pSavedClip;
303 }
304 }
305
306 void CFX_AggDeviceDriver::SetClipMask(agg::rasterizer_scanline_aa& rasterizer) {
307 FX_RECT path_rect(rasterizer.min_x(), rasterizer.min_y(),
308 rasterizer.max_x() + 1, rasterizer.max_y() + 1);
309 path_rect.Intersect(m_pClipRgn->GetBox());
310 CFX_DIBitmapRef mask;
311 CFX_DIBitmap* pThisLayer = mask.New();
312 if (!pThisLayer) {
313 return;
314 }
315 pThisLayer->Create(path_rect.Width(), path_rect.Height(), FXDIB_8bppMask);
316 pThisLayer->Clear(0);
317 agg::rendering_buffer raw_buf(pThisLayer->GetBuffer(), pThisLayer->GetWidth(),
318 pThisLayer->GetHeight(),
319 pThisLayer->GetPitch());
320 agg::pixfmt_gray8 pixel_buf(raw_buf);
321 agg::renderer_base<agg::pixfmt_gray8> base_buf(pixel_buf);
322 agg::renderer_scanline_aa_offset<agg::renderer_base<agg::pixfmt_gray8> >
323 final_render(base_buf, path_rect.left, path_rect.top);
324 final_render.color(agg::gray8(255));
325 agg::scanline_u8 scanline;
326 agg::render_scanlines(rasterizer, scanline, final_render,
327 (m_FillFlags & FXFILL_NOPATHSMOOTH) != 0);
328 m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, mask);
329 }
330
331 FX_BOOL CFX_AggDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData,
332 const CFX_Matrix* pObject2Device,
333 int fill_mode) {
334 m_FillFlags = fill_mode;
335 if (!m_pClipRgn) {
336 m_pClipRgn = new CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH),
337 GetDeviceCaps(FXDC_PIXEL_HEIGHT));
338 }
339 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) {
340 CFX_FloatRect rectf;
341 if (pPathData->IsRect(pObject2Device, &rectf)) {
342 rectf.Intersect(
343 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH),
344 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
345 FX_RECT rect = rectf.GetOutterRect();
346 m_pClipRgn->IntersectRect(rect);
347 return TRUE;
348 }
349 }
350 CAgg_PathData path_data;
351 path_data.BuildPath(pPathData, pObject2Device);
352 path_data.m_PathData.end_poly();
353 agg::rasterizer_scanline_aa rasterizer;
354 rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
355 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
356 rasterizer.add_path(path_data.m_PathData);
357 rasterizer.filling_rule((fill_mode & 3) == FXFILL_WINDING
358 ? agg::fill_non_zero
359 : agg::fill_even_odd);
360 SetClipMask(rasterizer);
361 return TRUE;
362 }
363
364 FX_BOOL CFX_AggDeviceDriver::SetClip_PathStroke(
365 const CFX_PathData* pPathData,
366 const CFX_Matrix* pObject2Device,
367 const CFX_GraphStateData* pGraphState) {
368 if (!m_pClipRgn) {
369 m_pClipRgn = new CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH),
370 GetDeviceCaps(FXDC_PIXEL_HEIGHT));
371 }
372 CAgg_PathData path_data;
373 path_data.BuildPath(pPathData, NULL);
374 agg::rasterizer_scanline_aa rasterizer;
375 rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
376 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
377 RasterizeStroke(rasterizer, path_data.m_PathData, pObject2Device,
378 pGraphState);
379 rasterizer.filling_rule(agg::fill_non_zero);
380 SetClipMask(rasterizer);
381 return TRUE;
382 }
383
384 class CFX_Renderer {
385 private:
386 int m_Alpha, m_Red, m_Green, m_Blue, m_Gray;
387 FX_DWORD m_Color;
388 FX_BOOL m_bFullCover;
389 FX_BOOL m_bRgbByteOrder;
390 CFX_DIBitmap* m_pOriDevice;
391 FX_RECT m_ClipBox;
392 const CFX_DIBitmap* m_pClipMask;
393 CFX_DIBitmap* m_pDevice;
394 const CFX_ClipRgn* m_pClipRgn;
395 void (CFX_Renderer::*composite_span)(uint8_t*,
396 int,
397 int,
398 int,
399 uint8_t*,
400 int,
401 int,
402 uint8_t*,
403 uint8_t*);
404
405 public:
406 void prepare(unsigned) {}
407
408 void CompositeSpan(uint8_t* dest_scan,
409 uint8_t* ori_scan,
410 int Bpp,
411 FX_BOOL bDestAlpha,
412 int span_left,
413 int span_len,
414 uint8_t* cover_scan,
415 int clip_left,
416 int clip_right,
417 uint8_t* clip_scan) {
418 ASSERT(!m_pDevice->IsCmykImage());
419 int col_start = span_left < clip_left ? clip_left - span_left : 0;
420 int col_end = (span_left + span_len) < clip_right
421 ? span_len
422 : (clip_right - span_left);
423 if (Bpp) {
424 dest_scan += col_start * Bpp;
425 ori_scan += col_start * Bpp;
426 } else {
427 dest_scan += col_start / 8;
428 ori_scan += col_start / 8;
429 }
430 if (m_bRgbByteOrder) {
431 if (Bpp == 4 && bDestAlpha) {
432 for (int col = col_start; col < col_end; col++) {
433 int src_alpha;
434 if (clip_scan) {
435 src_alpha = m_Alpha * clip_scan[col] / 255;
436 } else {
437 src_alpha = m_Alpha;
438 }
439 uint8_t dest_alpha =
440 ori_scan[3] + src_alpha - ori_scan[3] * src_alpha / 255;
441 dest_scan[3] = dest_alpha;
442 int alpha_ratio = src_alpha * 255 / dest_alpha;
443 if (m_bFullCover) {
444 *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Red, alpha_ratio);
445 *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, alpha_ratio);
446 *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, alpha_ratio);
447 dest_scan++;
448 ori_scan++;
449 } else {
450 int r = FXDIB_ALPHA_MERGE(*ori_scan++, m_Red, alpha_ratio);
451 int g = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, alpha_ratio);
452 int b = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, alpha_ratio);
453 ori_scan++;
454 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, r, cover_scan[col]);
455 dest_scan++;
456 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, g, cover_scan[col]);
457 dest_scan++;
458 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, b, cover_scan[col]);
459 dest_scan += 2;
460 }
461 }
462 return;
463 }
464 if (Bpp == 3 || Bpp == 4) {
465 for (int col = col_start; col < col_end; col++) {
466 int src_alpha;
467 if (clip_scan) {
468 src_alpha = m_Alpha * clip_scan[col] / 255;
469 } else {
470 src_alpha = m_Alpha;
471 }
472 int r = FXDIB_ALPHA_MERGE(*ori_scan++, m_Red, src_alpha);
473 int g = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, src_alpha);
474 int b = FXDIB_ALPHA_MERGE(*ori_scan, m_Blue, src_alpha);
475 ori_scan += Bpp - 2;
476 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, r, cover_scan[col]);
477 dest_scan++;
478 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, g, cover_scan[col]);
479 dest_scan++;
480 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, b, cover_scan[col]);
481 dest_scan += Bpp - 2;
482 }
483 }
484 return;
485 }
486 if (Bpp == 4 && bDestAlpha) {
487 for (int col = col_start; col < col_end; col++) {
488 int src_alpha;
489 if (clip_scan) {
490 src_alpha = m_Alpha * clip_scan[col] / 255;
491 } else {
492 src_alpha = m_Alpha;
493 }
494 int src_alpha_covered = src_alpha * cover_scan[col] / 255;
495 if (src_alpha_covered == 0) {
496 dest_scan += 4;
497 continue;
498 }
499 if (cover_scan[col] == 255) {
500 dest_scan[3] = src_alpha_covered;
501 *dest_scan++ = m_Blue;
502 *dest_scan++ = m_Green;
503 *dest_scan = m_Red;
504 dest_scan += 2;
505 continue;
506 } else {
507 if (dest_scan[3] == 0) {
508 dest_scan[3] = src_alpha_covered;
509 *dest_scan++ = m_Blue;
510 *dest_scan++ = m_Green;
511 *dest_scan = m_Red;
512 dest_scan += 2;
513 continue;
514 }
515 uint8_t cover = cover_scan[col];
516 dest_scan[3] = FXDIB_ALPHA_MERGE(dest_scan[3], src_alpha, cover);
517 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, cover);
518 dest_scan++;
519 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, cover);
520 dest_scan++;
521 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, cover);
522 dest_scan += 2;
523 }
524 }
525 return;
526 }
527 if (Bpp == 3 || Bpp == 4) {
528 for (int col = col_start; col < col_end; col++) {
529 int src_alpha;
530 if (clip_scan) {
531 src_alpha = m_Alpha * clip_scan[col] / 255;
532 } else {
533 src_alpha = m_Alpha;
534 }
535 if (m_bFullCover) {
536 *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, src_alpha);
537 *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, src_alpha);
538 *dest_scan = FXDIB_ALPHA_MERGE(*ori_scan, m_Red, src_alpha);
539 dest_scan += Bpp - 2;
540 ori_scan += Bpp - 2;
541 continue;
542 }
543 int b = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, src_alpha);
544 int g = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, src_alpha);
545 int r = FXDIB_ALPHA_MERGE(*ori_scan, m_Red, src_alpha);
546 ori_scan += Bpp - 2;
547 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, b, cover_scan[col]);
548 dest_scan++;
549 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, g, cover_scan[col]);
550 dest_scan++;
551 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, r, cover_scan[col]);
552 dest_scan += Bpp - 2;
553 continue;
554 }
555 return;
556 }
557 if (Bpp == 1) {
558 for (int col = col_start; col < col_end; col++) {
559 int src_alpha;
560 if (clip_scan) {
561 src_alpha = m_Alpha * clip_scan[col] / 255;
562 } else {
563 src_alpha = m_Alpha;
564 }
565 if (m_bFullCover) {
566 *dest_scan = FXDIB_ALPHA_MERGE(*ori_scan++, m_Gray, src_alpha);
567 } else {
568 int gray = FXDIB_ALPHA_MERGE(*ori_scan++, m_Gray, src_alpha);
569 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, cover_scan[col]);
570 dest_scan++;
571 }
572 }
573 } else {
574 int index = 0;
575 if (m_pDevice->GetPalette()) {
576 for (int i = 0; i < 2; i++) {
577 if (FXARGB_TODIB(m_pDevice->GetPalette()[i]) == m_Color) {
578 index = i;
579 }
580 }
581 } else {
582 index = ((uint8_t)m_Color == 0xff) ? 1 : 0;
583 }
584 uint8_t* dest_scan1 = dest_scan;
585 for (int col = col_start; col < col_end; col++) {
586 int src_alpha;
587 if (clip_scan) {
588 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
589 } else {
590 src_alpha = m_Alpha * cover_scan[col] / 255;
591 }
592 if (src_alpha) {
593 if (!index) {
594 *dest_scan1 &= ~(1 << (7 - (col + span_left) % 8));
595 } else {
596 *dest_scan1 |= 1 << (7 - (col + span_left) % 8);
597 }
598 }
599 dest_scan1 = dest_scan + (span_left % 8 + col - col_start + 1) / 8;
600 }
601 }
602 }
603
604 void CompositeSpan1bpp(uint8_t* dest_scan,
605 int Bpp,
606 int span_left,
607 int span_len,
608 uint8_t* cover_scan,
609 int clip_left,
610 int clip_right,
611 uint8_t* clip_scan,
612 uint8_t* dest_extra_alpha_scan) {
613 ASSERT(!m_bRgbByteOrder);
614 ASSERT(!m_pDevice->IsCmykImage());
615 int col_start = span_left < clip_left ? clip_left - span_left : 0;
616 int col_end = (span_left + span_len) < clip_right
617 ? span_len
618 : (clip_right - span_left);
619 dest_scan += col_start / 8;
620 int index = 0;
621 if (m_pDevice->GetPalette()) {
622 for (int i = 0; i < 2; i++) {
623 if (FXARGB_TODIB(m_pDevice->GetPalette()[i]) == m_Color) {
624 index = i;
625 }
626 }
627 } else {
628 index = ((uint8_t)m_Color == 0xff) ? 1 : 0;
629 }
630 uint8_t* dest_scan1 = dest_scan;
631 for (int col = col_start; col < col_end; col++) {
632 int src_alpha;
633 if (clip_scan) {
634 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
635 } else {
636 src_alpha = m_Alpha * cover_scan[col] / 255;
637 }
638 if (src_alpha) {
639 if (!index) {
640 *dest_scan1 &= ~(1 << (7 - (col + span_left) % 8));
641 } else {
642 *dest_scan1 |= 1 << (7 - (col + span_left) % 8);
643 }
644 }
645 dest_scan1 = dest_scan + (span_left % 8 + col - col_start + 1) / 8;
646 }
647 }
648
649 void CompositeSpanGray(uint8_t* dest_scan,
650 int Bpp,
651 int span_left,
652 int span_len,
653 uint8_t* cover_scan,
654 int clip_left,
655 int clip_right,
656 uint8_t* clip_scan,
657 uint8_t* dest_extra_alpha_scan) {
658 ASSERT(!m_bRgbByteOrder);
659 int col_start = span_left < clip_left ? clip_left - span_left : 0;
660 int col_end = (span_left + span_len) < clip_right
661 ? span_len
662 : (clip_right - span_left);
663 dest_scan += col_start;
664 if (dest_extra_alpha_scan) {
665 for (int col = col_start; col < col_end; col++) {
666 int src_alpha;
667 if (m_bFullCover) {
668 if (clip_scan) {
669 src_alpha = m_Alpha * clip_scan[col] / 255;
670 } else {
671 src_alpha = m_Alpha;
672 }
673 } else {
674 if (clip_scan) {
675 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
676 } else {
677 src_alpha = m_Alpha * cover_scan[col] / 255;
678 }
679 }
680 if (src_alpha) {
681 if (src_alpha == 255) {
682 *dest_scan = m_Gray;
683 *dest_extra_alpha_scan = m_Alpha;
684 } else {
685 uint8_t dest_alpha = (*dest_extra_alpha_scan) + src_alpha -
686 (*dest_extra_alpha_scan) * src_alpha / 255;
687 *dest_extra_alpha_scan++ = dest_alpha;
688 int alpha_ratio = src_alpha * 255 / dest_alpha;
689 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, alpha_ratio);
690 dest_scan++;
691 continue;
692 }
693 }
694 dest_extra_alpha_scan++;
695 dest_scan++;
696 }
697 } else {
698 for (int col = col_start; col < col_end; col++) {
699 int src_alpha;
700 if (clip_scan) {
701 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
702 } else {
703 src_alpha = m_Alpha * cover_scan[col] / 255;
704 }
705 if (src_alpha) {
706 if (src_alpha == 255) {
707 *dest_scan = m_Gray;
708 } else {
709 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, src_alpha);
710 }
711 }
712 dest_scan++;
713 }
714 }
715 }
716
717 void CompositeSpanARGB(uint8_t* dest_scan,
718 int Bpp,
719 int span_left,
720 int span_len,
721 uint8_t* cover_scan,
722 int clip_left,
723 int clip_right,
724 uint8_t* clip_scan,
725 uint8_t* dest_extra_alpha_scan) {
726 int col_start = span_left < clip_left ? clip_left - span_left : 0;
727 int col_end = (span_left + span_len) < clip_right
728 ? span_len
729 : (clip_right - span_left);
730 dest_scan += col_start * Bpp;
731 if (m_bRgbByteOrder) {
732 for (int col = col_start; col < col_end; col++) {
733 int src_alpha;
734 if (m_bFullCover) {
735 if (clip_scan) {
736 src_alpha = m_Alpha * clip_scan[col] / 255;
737 } else {
738 src_alpha = m_Alpha;
739 }
740 } else {
741 if (clip_scan) {
742 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
743 } else {
744 src_alpha = m_Alpha * cover_scan[col] / 255;
745 }
746 }
747 if (src_alpha) {
748 if (src_alpha == 255) {
749 *(FX_DWORD*)dest_scan = m_Color;
750 } else {
751 uint8_t dest_alpha =
752 dest_scan[3] + src_alpha - dest_scan[3] * src_alpha / 255;
753 dest_scan[3] = dest_alpha;
754 int alpha_ratio = src_alpha * 255 / dest_alpha;
755 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio);
756 dest_scan++;
757 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio);
758 dest_scan++;
759 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio);
760 dest_scan += 2;
761 continue;
762 }
763 }
764 dest_scan += 4;
765 }
766 return;
767 }
768 for (int col = col_start; col < col_end; col++) {
769 int src_alpha;
770 if (m_bFullCover) {
771 if (clip_scan) {
772 src_alpha = m_Alpha * clip_scan[col] / 255;
773 } else {
774 src_alpha = m_Alpha;
775 }
776 } else {
777 if (clip_scan) {
778 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
779 } else {
780 src_alpha = m_Alpha * cover_scan[col] / 255;
781 }
782 }
783 if (src_alpha) {
784 if (src_alpha == 255) {
785 *(FX_DWORD*)dest_scan = m_Color;
786 } else {
787 if (dest_scan[3] == 0) {
788 dest_scan[3] = src_alpha;
789 *dest_scan++ = m_Blue;
790 *dest_scan++ = m_Green;
791 *dest_scan = m_Red;
792 dest_scan += 2;
793 continue;
794 }
795 uint8_t dest_alpha =
796 dest_scan[3] + src_alpha - dest_scan[3] * src_alpha / 255;
797 dest_scan[3] = dest_alpha;
798 int alpha_ratio = src_alpha * 255 / dest_alpha;
799 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio);
800 dest_scan++;
801 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio);
802 dest_scan++;
803 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio);
804 dest_scan += 2;
805 continue;
806 }
807 }
808 dest_scan += Bpp;
809 }
810 }
811
812 void CompositeSpanRGB(uint8_t* dest_scan,
813 int Bpp,
814 int span_left,
815 int span_len,
816 uint8_t* cover_scan,
817 int clip_left,
818 int clip_right,
819 uint8_t* clip_scan,
820 uint8_t* dest_extra_alpha_scan) {
821 int col_start = span_left < clip_left ? clip_left - span_left : 0;
822 int col_end = (span_left + span_len) < clip_right
823 ? span_len
824 : (clip_right - span_left);
825 dest_scan += col_start * Bpp;
826 if (m_bRgbByteOrder) {
827 for (int col = col_start; col < col_end; col++) {
828 int src_alpha;
829 if (clip_scan) {
830 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
831 } else {
832 src_alpha = m_Alpha * cover_scan[col] / 255;
833 }
834 if (src_alpha) {
835 if (src_alpha == 255) {
836 if (Bpp == 4) {
837 *(FX_DWORD*)dest_scan = m_Color;
838 } else if (Bpp == 3) {
839 *dest_scan++ = m_Red;
840 *dest_scan++ = m_Green;
841 *dest_scan++ = m_Blue;
842 continue;
843 }
844 } else {
845 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, src_alpha);
846 dest_scan++;
847 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, src_alpha);
848 dest_scan++;
849 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, src_alpha);
850 dest_scan += Bpp - 2;
851 continue;
852 }
853 }
854 dest_scan += Bpp;
855 }
856 return;
857 }
858 if (Bpp == 3 && dest_extra_alpha_scan) {
859 for (int col = col_start; col < col_end; col++) {
860 int src_alpha;
861 if (m_bFullCover) {
862 if (clip_scan) {
863 src_alpha = m_Alpha * clip_scan[col] / 255;
864 } else {
865 src_alpha = m_Alpha;
866 }
867 } else {
868 if (clip_scan) {
869 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
870 } else {
871 src_alpha = m_Alpha * cover_scan[col] / 255;
872 }
873 }
874 if (src_alpha) {
875 if (src_alpha == 255) {
876 *dest_scan++ = (uint8_t)m_Blue;
877 *dest_scan++ = (uint8_t)m_Green;
878 *dest_scan++ = (uint8_t)m_Red;
879 *dest_extra_alpha_scan++ = (uint8_t)m_Alpha;
880 continue;
881 } else {
882 uint8_t dest_alpha = (*dest_extra_alpha_scan) + src_alpha -
883 (*dest_extra_alpha_scan) * src_alpha / 255;
884 *dest_extra_alpha_scan++ = dest_alpha;
885 int alpha_ratio = src_alpha * 255 / dest_alpha;
886 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio);
887 dest_scan++;
888 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio);
889 dest_scan++;
890 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio);
891 dest_scan++;
892 continue;
893 }
894 }
895 dest_extra_alpha_scan++;
896 dest_scan += Bpp;
897 }
898 } else {
899 for (int col = col_start; col < col_end; col++) {
900 int src_alpha;
901 if (m_bFullCover) {
902 if (clip_scan) {
903 src_alpha = m_Alpha * clip_scan[col] / 255;
904 } else {
905 src_alpha = m_Alpha;
906 }
907 } else {
908 if (clip_scan) {
909 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
910 } else {
911 src_alpha = m_Alpha * cover_scan[col] / 255;
912 }
913 }
914 if (src_alpha) {
915 if (src_alpha == 255) {
916 if (Bpp == 4) {
917 *(FX_DWORD*)dest_scan = m_Color;
918 } else if (Bpp == 3) {
919 *dest_scan++ = m_Blue;
920 *dest_scan++ = m_Green;
921 *dest_scan++ = m_Red;
922 continue;
923 }
924 } else {
925 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, src_alpha);
926 dest_scan++;
927 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, src_alpha);
928 dest_scan++;
929 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, src_alpha);
930 dest_scan += Bpp - 2;
931 continue;
932 }
933 }
934 dest_scan += Bpp;
935 }
936 }
937 }
938
939 void CompositeSpanCMYK(uint8_t* dest_scan,
940 int Bpp,
941 int span_left,
942 int span_len,
943 uint8_t* cover_scan,
944 int clip_left,
945 int clip_right,
946 uint8_t* clip_scan,
947 uint8_t* dest_extra_alpha_scan) {
948 ASSERT(!m_bRgbByteOrder);
949 int col_start = span_left < clip_left ? clip_left - span_left : 0;
950 int col_end = (span_left + span_len) < clip_right
951 ? span_len
952 : (clip_right - span_left);
953 dest_scan += col_start * 4;
954 if (dest_extra_alpha_scan) {
955 for (int col = col_start; col < col_end; col++) {
956 int src_alpha;
957 if (m_bFullCover) {
958 if (clip_scan) {
959 src_alpha = m_Alpha * clip_scan[col] / 255;
960 } else {
961 src_alpha = m_Alpha;
962 }
963 } else {
964 if (clip_scan) {
965 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
966 } else {
967 src_alpha = m_Alpha * cover_scan[col] / 255;
968 }
969 }
970 if (src_alpha) {
971 if (src_alpha == 255) {
972 *(FX_CMYK*)dest_scan = m_Color;
973 *dest_extra_alpha_scan = (uint8_t)m_Alpha;
974 } else {
975 uint8_t dest_alpha = (*dest_extra_alpha_scan) + src_alpha -
976 (*dest_extra_alpha_scan) * src_alpha / 255;
977 *dest_extra_alpha_scan++ = dest_alpha;
978 int alpha_ratio = src_alpha * 255 / dest_alpha;
979 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio);
980 dest_scan++;
981 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio);
982 dest_scan++;
983 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio);
984 dest_scan++;
985 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, alpha_ratio);
986 dest_scan++;
987 continue;
988 }
989 }
990 dest_extra_alpha_scan++;
991 dest_scan += 4;
992 }
993 } else {
994 for (int col = col_start; col < col_end; col++) {
995 int src_alpha;
996 if (clip_scan) {
997 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255;
998 } else {
999 src_alpha = m_Alpha * cover_scan[col] / 255;
1000 }
1001 if (src_alpha) {
1002 if (src_alpha == 255) {
1003 *(FX_CMYK*)dest_scan = m_Color;
1004 } else {
1005 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, src_alpha);
1006 dest_scan++;
1007 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, src_alpha);
1008 dest_scan++;
1009 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, src_alpha);
1010 dest_scan++;
1011 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, src_alpha);
1012 dest_scan++;
1013 continue;
1014 }
1015 }
1016 dest_scan += 4;
1017 }
1018 }
1019 }
1020
1021 template <class Scanline>
1022 void render(const Scanline& sl) {
1023 if (!m_pOriDevice && !composite_span) {
1024 return;
1025 }
1026 int y = sl.y();
1027 if (y < m_ClipBox.top || y >= m_ClipBox.bottom) {
1028 return;
1029 }
1030 uint8_t* dest_scan = m_pDevice->GetBuffer() + m_pDevice->GetPitch() * y;
1031 uint8_t* dest_scan_extra_alpha = NULL;
1032 CFX_DIBitmap* pAlphaMask = m_pDevice->m_pAlphaMask;
1033 if (pAlphaMask) {
1034 dest_scan_extra_alpha =
1035 pAlphaMask->GetBuffer() + pAlphaMask->GetPitch() * y;
1036 }
1037 uint8_t* ori_scan = NULL;
1038 if (m_pOriDevice) {
1039 ori_scan = m_pOriDevice->GetBuffer() + m_pOriDevice->GetPitch() * y;
1040 }
1041 int Bpp = m_pDevice->GetBPP() / 8;
1042 FX_BOOL bDestAlpha = m_pDevice->HasAlpha() || m_pDevice->IsAlphaMask();
1043 unsigned num_spans = sl.num_spans();
1044 typename Scanline::const_iterator span = sl.begin();
1045 while (1) {
1046 int x = span->x;
1047 ASSERT(span->len > 0);
1048 uint8_t* dest_pos = NULL;
1049 uint8_t* dest_extra_alpha_pos = NULL;
1050 uint8_t* ori_pos = NULL;
1051 if (Bpp) {
1052 ori_pos = ori_scan ? ori_scan + x * Bpp : NULL;
1053 dest_pos = dest_scan + x * Bpp;
1054 dest_extra_alpha_pos =
1055 dest_scan_extra_alpha ? dest_scan_extra_alpha + x : NULL;
1056 } else {
1057 dest_pos = dest_scan + x / 8;
1058 ori_pos = ori_scan ? ori_scan + x / 8 : NULL;
1059 }
1060 uint8_t* clip_pos = NULL;
1061 if (m_pClipMask) {
1062 clip_pos = m_pClipMask->GetBuffer() +
1063 (y - m_ClipBox.top) * m_pClipMask->GetPitch() + x -
1064 m_ClipBox.left;
1065 }
1066 if (ori_pos) {
1067 CompositeSpan(dest_pos, ori_pos, Bpp, bDestAlpha, x, span->len,
1068 span->covers, m_ClipBox.left, m_ClipBox.right, clip_pos);
1069 } else {
1070 (this->*composite_span)(dest_pos, Bpp, x, span->len, span->covers,
1071 m_ClipBox.left, m_ClipBox.right, clip_pos,
1072 dest_extra_alpha_pos);
1073 }
1074 if (--num_spans == 0) {
1075 break;
1076 }
1077 ++span;
1078 }
1079 }
1080
1081 FX_BOOL Init(CFX_DIBitmap* pDevice,
1082 CFX_DIBitmap* pOriDevice,
1083 const CFX_ClipRgn* pClipRgn,
1084 FX_DWORD color,
1085 FX_BOOL bFullCover,
1086 FX_BOOL bRgbByteOrder,
1087 int alpha_flag = 0,
1088 void* pIccTransform = NULL) {
1089 m_pDevice = pDevice;
1090 m_pClipRgn = pClipRgn;
1091 composite_span = NULL;
1092 m_bRgbByteOrder = bRgbByteOrder;
1093 m_pOriDevice = pOriDevice;
1094 if (m_pClipRgn) {
1095 m_ClipBox = m_pClipRgn->GetBox();
1096 } else {
1097 m_ClipBox.left = m_ClipBox.top = 0;
1098 m_ClipBox.right = m_pDevice->GetWidth();
1099 m_ClipBox.bottom = m_pDevice->GetHeight();
1100 }
1101 m_pClipMask = NULL;
1102 if (m_pClipRgn && m_pClipRgn->GetType() == CFX_ClipRgn::MaskF) {
1103 m_pClipMask = m_pClipRgn->GetMask();
1104 }
1105 m_bFullCover = bFullCover;
1106 FX_BOOL bObjectCMYK = FXGETFLAG_COLORTYPE(alpha_flag);
1107 FX_BOOL bDeviceCMYK = pDevice->IsCmykImage();
1108 m_Alpha = bObjectCMYK ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(color);
1109 ICodec_IccModule* pIccModule = NULL;
1110 if (!CFX_GEModule::Get()->GetCodecModule() ||
1111 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {
1112 pIccTransform = NULL;
1113 } else {
1114 pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
1115 }
1116 if (m_pDevice->GetBPP() == 8) {
1117 ASSERT(!m_bRgbByteOrder);
1118 composite_span = &CFX_Renderer::CompositeSpanGray;
1119 if (m_pDevice->IsAlphaMask()) {
1120 m_Gray = 255;
1121 } else {
1122 if (pIccTransform) {
1123 uint8_t gray;
1124 color = bObjectCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
1125 pIccModule->TranslateScanline(pIccTransform, &gray,
1126 (const uint8_t*)&color, 1);
1127 m_Gray = gray;
1128 } else {
1129 if (bObjectCMYK) {
1130 uint8_t r, g, b;
1131 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color),
1132 FXSYS_GetYValue(color), FXSYS_GetKValue(color),
1133 r, g, b);
1134 m_Gray = FXRGB2GRAY(r, g, b);
1135 } else {
1136 m_Gray =
1137 FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B(color));
1138 }
1139 }
1140 }
1141 return TRUE;
1142 }
1143 if (bDeviceCMYK) {
1144 ASSERT(!m_bRgbByteOrder);
1145 composite_span = &CFX_Renderer::CompositeSpanCMYK;
1146 if (bObjectCMYK) {
1147 m_Color = FXCMYK_TODIB(color);
1148 if (pIccTransform) {
1149 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&m_Color,
1150 (const uint8_t*)&m_Color, 1);
1151 }
1152 } else {
1153 if (!pIccTransform) {
1154 return FALSE;
1155 }
1156 color = FXARGB_TODIB(color);
1157 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&m_Color,
1158 (const uint8_t*)&color, 1);
1159 }
1160 m_Red = ((uint8_t*)&m_Color)[0];
1161 m_Green = ((uint8_t*)&m_Color)[1];
1162 m_Blue = ((uint8_t*)&m_Color)[2];
1163 m_Gray = ((uint8_t*)&m_Color)[3];
1164 } else {
1165 composite_span = (pDevice->GetFormat() == FXDIB_Argb)
1166 ? &CFX_Renderer::CompositeSpanARGB
1167 : &CFX_Renderer::CompositeSpanRGB;
1168 if (pIccTransform) {
1169 color = bObjectCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
1170 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&m_Color,
1171 (const uint8_t*)&color, 1);
1172 ((uint8_t*)&m_Color)[3] = m_Alpha;
1173 m_Red = ((uint8_t*)&m_Color)[2];
1174 m_Green = ((uint8_t*)&m_Color)[1];
1175 m_Blue = ((uint8_t*)&m_Color)[0];
1176 if (m_bRgbByteOrder) {
1177 m_Color = FXARGB_TODIB(m_Color);
1178 m_Color = FXARGB_TOBGRORDERDIB(m_Color);
1179 }
1180 } else {
1181 if (bObjectCMYK) {
1182 uint8_t r, g, b;
1183 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color),
1184 FXSYS_GetYValue(color), FXSYS_GetKValue(color), r,
1185 g, b);
1186 m_Color = FXARGB_MAKE(m_Alpha, r, g, b);
1187 if (m_bRgbByteOrder) {
1188 m_Color = FXARGB_TOBGRORDERDIB(m_Color);
1189 } else {
1190 m_Color = FXARGB_TODIB(m_Color);
1191 }
1192 m_Red = r;
1193 m_Green = g;
1194 m_Blue = b;
1195 } else {
1196 if (m_bRgbByteOrder) {
1197 m_Color = FXARGB_TOBGRORDERDIB(color);
1198 } else {
1199 m_Color = FXARGB_TODIB(color);
1200 }
1201 ArgbDecode(color, m_Alpha, m_Red, m_Green, m_Blue);
1202 }
1203 }
1204 }
1205 if (m_pDevice->GetBPP() == 1) {
1206 composite_span = &CFX_Renderer::CompositeSpan1bpp;
1207 }
1208 return TRUE;
1209 }
1210 };
1211
1212 FX_BOOL CFX_AggDeviceDriver::RenderRasterizer(
1213 agg::rasterizer_scanline_aa& rasterizer,
1214 FX_DWORD color,
1215 FX_BOOL bFullCover,
1216 FX_BOOL bGroupKnockout,
1217 int alpha_flag,
1218 void* pIccTransform) {
1219 CFX_DIBitmap* pt = bGroupKnockout ? m_pOriDevice : NULL;
1220 CFX_Renderer render;
1221 if (!render.Init(m_pBitmap, pt, m_pClipRgn, color, bFullCover,
1222 m_bRgbByteOrder, alpha_flag, pIccTransform)) {
1223 return FALSE;
1224 }
1225 agg::scanline_u8 scanline;
1226 agg::render_scanlines(rasterizer, scanline, render,
1227 (m_FillFlags & FXFILL_NOPATHSMOOTH) != 0);
1228 return TRUE;
1229 }
1230
1231 FX_BOOL CFX_AggDeviceDriver::DrawPath(const CFX_PathData* pPathData,
1232 const CFX_Matrix* pObject2Device,
1233 const CFX_GraphStateData* pGraphState,
1234 FX_DWORD fill_color,
1235 FX_DWORD stroke_color,
1236 int fill_mode,
1237 int alpha_flag,
1238 void* pIccTransform,
1239 int blend_type) {
1240 if (blend_type != FXDIB_BLEND_NORMAL) {
1241 return FALSE;
1242 }
1243 if (!GetBuffer()) {
1244 return TRUE;
1245 }
1246 m_FillFlags = fill_mode;
1247 if ((fill_mode & 3) && fill_color) {
1248 CAgg_PathData path_data;
1249 path_data.BuildPath(pPathData, pObject2Device);
1250 agg::rasterizer_scanline_aa rasterizer;
1251 rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
1252 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
1253 rasterizer.add_path(path_data.m_PathData);
1254 rasterizer.filling_rule((fill_mode & 3) == FXFILL_WINDING
1255 ? agg::fill_non_zero
1256 : agg::fill_even_odd);
1257 if (!RenderRasterizer(rasterizer, fill_color, fill_mode & FXFILL_FULLCOVER,
1258 FALSE, alpha_flag, pIccTransform)) {
1259 return FALSE;
1260 }
1261 }
1262 int stroke_alpha = FXGETFLAG_COLORTYPE(alpha_flag)
1263 ? FXGETFLAG_ALPHA_STROKE(alpha_flag)
1264 : FXARGB_A(stroke_color);
1265 if (pGraphState && stroke_alpha) {
1266 if (fill_mode & FX_ZEROAREA_FILL) {
1267 CAgg_PathData path_data;
1268 path_data.BuildPath(pPathData, pObject2Device);
1269 agg::rasterizer_scanline_aa rasterizer;
1270 rasterizer.clip_box(0.0f, 0.0f,
1271 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
1272 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
1273 RasterizeStroke(rasterizer, path_data.m_PathData, NULL, pGraphState, 1,
1274 FALSE, fill_mode & FX_STROKE_TEXT_MODE);
1275 int fill_flag = FXGETFLAG_COLORTYPE(alpha_flag) << 8 |
1276 FXGETFLAG_ALPHA_STROKE(alpha_flag);
1277 if (!RenderRasterizer(rasterizer, stroke_color,
1278 fill_mode & FXFILL_FULLCOVER, m_bGroupKnockout,
1279 fill_flag, pIccTransform)) {
1280 return FALSE;
1281 }
1282 return TRUE;
1283 }
1284 CFX_Matrix matrix1, matrix2;
1285 if (pObject2Device) {
1286 matrix1.a = std::max(FXSYS_fabs(pObject2Device->a),
1287 FXSYS_fabs(pObject2Device->b));
1288 matrix1.d = matrix1.a;
1289 matrix2.Set(pObject2Device->a / matrix1.a, pObject2Device->b / matrix1.a,
1290 pObject2Device->c / matrix1.d, pObject2Device->d / matrix1.d,
1291 0, 0);
1292 CFX_Matrix mtRervese;
1293 mtRervese.SetReverse(matrix2);
1294 matrix1 = *pObject2Device;
1295 matrix1.Concat(mtRervese);
1296 }
1297 CAgg_PathData path_data;
1298 path_data.BuildPath(pPathData, &matrix1);
1299 agg::rasterizer_scanline_aa rasterizer;
1300 rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
1301 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
1302 RasterizeStroke(rasterizer, path_data.m_PathData, &matrix2, pGraphState,
1303 matrix1.a, FALSE, fill_mode & FX_STROKE_TEXT_MODE);
1304 int fill_flag = FXGETFLAG_COLORTYPE(alpha_flag) << 8 |
1305 FXGETFLAG_ALPHA_STROKE(alpha_flag);
1306 if (!RenderRasterizer(rasterizer, stroke_color,
1307 fill_mode & FXFILL_FULLCOVER, m_bGroupKnockout,
1308 fill_flag, pIccTransform)) {
1309 return FALSE;
1310 }
1311 }
1312 return TRUE;
1313 }
1314
1315 void RgbByteOrderSetPixel(CFX_DIBitmap* pBitmap, int x, int y, FX_DWORD argb) {
1316 if (x < 0 || x >= pBitmap->GetWidth() || y < 0 || y >= pBitmap->GetHeight()) {
1317 return;
1318 }
1319 uint8_t* pos = (uint8_t*)pBitmap->GetBuffer() + y * pBitmap->GetPitch() +
1320 x * pBitmap->GetBPP() / 8;
1321 if (pBitmap->GetFormat() == FXDIB_Argb) {
1322 FXARGB_SETRGBORDERDIB(pos, ArgbGamma(argb));
1323 } else {
1324 int alpha = FXARGB_A(argb);
1325 pos[0] = (FXARGB_R(argb) * alpha + pos[0] * (255 - alpha)) / 255;
1326 pos[1] = (FXARGB_G(argb) * alpha + pos[1] * (255 - alpha)) / 255;
1327 pos[2] = (FXARGB_B(argb) * alpha + pos[2] * (255 - alpha)) / 255;
1328 }
1329 }
1330
1331 void RgbByteOrderCompositeRect(CFX_DIBitmap* pBitmap,
1332 int left,
1333 int top,
1334 int width,
1335 int height,
1336 FX_ARGB argb) {
1337 int src_alpha = FXARGB_A(argb);
1338 if (src_alpha == 0) {
1339 return;
1340 }
1341 FX_RECT rect(left, top, left + width, top + height);
1342 rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight());
1343 width = rect.Width();
1344 int src_r = FXARGB_R(argb), src_g = FXARGB_G(argb), src_b = FXARGB_B(argb);
1345 int Bpp = pBitmap->GetBPP() / 8;
1346 FX_BOOL bAlpha = pBitmap->HasAlpha();
1347 int dib_argb = FXARGB_TOBGRORDERDIB(argb);
1348 uint8_t* pBuffer = pBitmap->GetBuffer();
1349 if (src_alpha == 255) {
1350 for (int row = rect.top; row < rect.bottom; row++) {
1351 uint8_t* dest_scan =
1352 pBuffer + row * pBitmap->GetPitch() + rect.left * Bpp;
1353 if (Bpp == 4) {
1354 FX_DWORD* scan = (FX_DWORD*)dest_scan;
1355 for (int col = 0; col < width; col++) {
1356 *scan++ = dib_argb;
1357 }
1358 } else {
1359 for (int col = 0; col < width; col++) {
1360 *dest_scan++ = src_r;
1361 *dest_scan++ = src_g;
1362 *dest_scan++ = src_b;
1363 }
1364 }
1365 }
1366 return;
1367 }
1368 src_r = FX_GAMMA(src_r);
1369 src_g = FX_GAMMA(src_g);
1370 src_b = FX_GAMMA(src_b);
1371 for (int row = rect.top; row < rect.bottom; row++) {
1372 uint8_t* dest_scan = pBuffer + row * pBitmap->GetPitch() + rect.left * Bpp;
1373 if (bAlpha) {
1374 for (int col = 0; col < width; col++) {
1375 uint8_t back_alpha = dest_scan[3];
1376 if (back_alpha == 0) {
1377 FXARGB_SETRGBORDERDIB(dest_scan,
1378 FXARGB_MAKE(src_alpha, src_r, src_g, src_b));
1379 dest_scan += 4;
1380 continue;
1381 }
1382 uint8_t dest_alpha =
1383 back_alpha + src_alpha - back_alpha * src_alpha / 255;
1384 dest_scan[3] = dest_alpha;
1385 int alpha_ratio = src_alpha * 255 / dest_alpha;
1386 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio);
1387 dest_scan++;
1388 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio);
1389 dest_scan++;
1390 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio);
1391 dest_scan += 2;
1392 }
1393 } else {
1394 for (int col = 0; col < width; col++) {
1395 *dest_scan = FX_GAMMA_INVERSE(
1396 FXDIB_ALPHA_MERGE(FX_GAMMA(*dest_scan), src_r, src_alpha));
1397 dest_scan++;
1398 *dest_scan = FX_GAMMA_INVERSE(
1399 FXDIB_ALPHA_MERGE(FX_GAMMA(*dest_scan), src_g, src_alpha));
1400 dest_scan++;
1401 *dest_scan = FX_GAMMA_INVERSE(
1402 FXDIB_ALPHA_MERGE(FX_GAMMA(*dest_scan), src_b, src_alpha));
1403 dest_scan++;
1404 if (Bpp == 4) {
1405 dest_scan++;
1406 }
1407 }
1408 }
1409 }
1410 }
1411
1412 void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap,
1413 int dest_left,
1414 int dest_top,
1415 int width,
1416 int height,
1417 const CFX_DIBSource* pSrcBitmap,
1418 int src_left,
1419 int src_top) {
1420 if (!pBitmap) {
1421 return;
1422 }
1423 pBitmap->GetOverlapRect(dest_left, dest_top, width, height,
1424 pSrcBitmap->GetWidth(), pSrcBitmap->GetHeight(),
1425 src_left, src_top, NULL);
1426 if (width == 0 || height == 0) {
1427 return;
1428 }
1429 int Bpp = pBitmap->GetBPP() / 8;
1430 FXDIB_Format dest_format = pBitmap->GetFormat();
1431 FXDIB_Format src_format = pSrcBitmap->GetFormat();
1432 int pitch = pBitmap->GetPitch();
1433 uint8_t* buffer = pBitmap->GetBuffer();
1434 if (dest_format == src_format) {
1435 for (int row = 0; row < height; row++) {
1436 uint8_t* dest_scan = buffer + (dest_top + row) * pitch + dest_left * Bpp;
1437 uint8_t* src_scan =
1438 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp;
1439 if (Bpp == 4) {
1440 for (int col = 0; col < width; col++) {
1441 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_scan[3], src_scan[0],
1442 src_scan[1], src_scan[2]));
1443 dest_scan += 4;
1444 src_scan += 4;
1445 }
1446 } else {
1447 for (int col = 0; col < width; col++) {
1448 *dest_scan++ = src_scan[2];
1449 *dest_scan++ = src_scan[1];
1450 *dest_scan++ = src_scan[0];
1451 src_scan += 3;
1452 }
1453 }
1454 }
1455 return;
1456 }
1457 uint8_t* dest_buf = buffer + dest_top * pitch + dest_left * Bpp;
1458 if (dest_format == FXDIB_Rgb) {
1459 if (src_format == FXDIB_Rgb32) {
1460 for (int row = 0; row < height; row++) {
1461 uint8_t* dest_scan = dest_buf + row * pitch;
1462 uint8_t* src_scan =
1463 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
1464 for (int col = 0; col < width; col++) {
1465 *dest_scan++ = src_scan[2];
1466 *dest_scan++ = src_scan[1];
1467 *dest_scan++ = src_scan[0];
1468 src_scan += 4;
1469 }
1470 }
1471 } else {
1472 ASSERT(FALSE);
1473 }
1474 } else if (dest_format == FXDIB_Argb || dest_format == FXDIB_Rgb32) {
1475 if (src_format == FXDIB_Rgb) {
1476 for (int row = 0; row < height; row++) {
1477 uint8_t* dest_scan = (uint8_t*)(dest_buf + row * pitch);
1478 uint8_t* src_scan =
1479 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * 3;
1480 if (src_format == FXDIB_Argb) {
1481 for (int col = 0; col < width; col++) {
1482 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, FX_GAMMA(src_scan[0]),
1483 FX_GAMMA(src_scan[1]),
1484 FX_GAMMA(src_scan[2])));
1485 dest_scan += 4;
1486 src_scan += 3;
1487 }
1488 } else {
1489 for (int col = 0; col < width; col++) {
1490 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[0], src_scan[1],
1491 src_scan[2]));
1492 dest_scan += 4;
1493 src_scan += 3;
1494 }
1495 }
1496 }
1497 } else if (src_format == FXDIB_Rgb32) {
1498 ASSERT(dest_format == FXDIB_Argb);
1499 for (int row = 0; row < height; row++) {
1500 uint8_t* dest_scan = dest_buf + row * pitch;
1501 uint8_t* src_scan =
1502 (uint8_t*)(pSrcBitmap->GetScanline(src_top + row) + src_left * 4);
1503 for (int col = 0; col < width; col++) {
1504 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[0], src_scan[1],
1505 src_scan[2]));
1506 src_scan += 4;
1507 dest_scan += 4;
1508 }
1509 }
1510 }
1511 } else {
1512 ASSERT(FALSE);
1513 }
1514 }
1515
1516 FX_ARGB _DefaultCMYK2ARGB(FX_CMYK cmyk, uint8_t alpha) {
1517 uint8_t r, g, b;
1518 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk),
1519 FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), r, g, b);
1520 return ArgbEncode(alpha, r, g, b);
1521 }
1522
1523 FX_BOOL _DibSetPixel(CFX_DIBitmap* pDevice,
1524 int x,
1525 int y,
1526 FX_DWORD color,
1527 int alpha_flag,
1528 void* pIccTransform) {
1529 FX_BOOL bObjCMYK = FXGETFLAG_COLORTYPE(alpha_flag);
1530 int alpha = bObjCMYK ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(color);
1531 if (pIccTransform) {
1532 ICodec_IccModule* pIccModule =
1533 CFX_GEModule::Get()->GetCodecModule()->GetIccModule();
1534 color = bObjCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
1535 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&color,
1536 (uint8_t*)&color, 1);
1537 color = bObjCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color);
1538 if (!pDevice->IsCmykImage()) {
1539 color = (color & 0xffffff) | (alpha << 24);
1540 }
1541 } else {
1542 if (pDevice->IsCmykImage()) {
1543 if (!bObjCMYK) {
1544 return FALSE;
1545 }
1546 } else {
1547 if (bObjCMYK) {
1548 color = _DefaultCMYK2ARGB(color, alpha);
1549 }
1550 }
1551 }
1552 pDevice->SetPixel(x, y, color);
1553 if (pDevice->m_pAlphaMask) {
1554 pDevice->m_pAlphaMask->SetPixel(x, y, alpha << 24);
1555 }
1556 return TRUE;
1557 }
1558
1559 FX_BOOL CFX_AggDeviceDriver::SetPixel(int x,
1560 int y,
1561 FX_DWORD color,
1562 int alpha_flag,
1563 void* pIccTransform) {
1564 if (!m_pBitmap->GetBuffer()) {
1565 return TRUE;
1566 }
1567 if (!CFX_GEModule::Get()->GetCodecModule() ||
1568 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {
1569 pIccTransform = NULL;
1570 }
1571 if (!m_pClipRgn) {
1572 if (m_bRgbByteOrder) {
1573 RgbByteOrderSetPixel(m_pBitmap, x, y, color);
1574 } else {
1575 return _DibSetPixel(m_pBitmap, x, y, color, alpha_flag, pIccTransform);
1576 }
1577 } else if (m_pClipRgn->GetBox().Contains(x, y)) {
1578 if (m_pClipRgn->GetType() == CFX_ClipRgn::RectI) {
1579 if (m_bRgbByteOrder) {
1580 RgbByteOrderSetPixel(m_pBitmap, x, y, color);
1581 } else {
1582 return _DibSetPixel(m_pBitmap, x, y, color, alpha_flag, pIccTransform);
1583 }
1584 } else if (m_pClipRgn->GetType() == CFX_ClipRgn::MaskF) {
1585 const CFX_DIBitmap* pMask = m_pClipRgn->GetMask();
1586 FX_BOOL bCMYK = FXGETFLAG_COLORTYPE(alpha_flag);
1587 int new_alpha =
1588 bCMYK ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(color);
1589 new_alpha = new_alpha * pMask->GetScanline(y)[x] / 255;
1590 if (m_bRgbByteOrder) {
1591 RgbByteOrderSetPixel(m_pBitmap, x, y,
1592 (color & 0xffffff) | (new_alpha << 24));
1593 return TRUE;
1594 }
1595 if (bCMYK) {
1596 FXSETFLAG_ALPHA_FILL(alpha_flag, new_alpha);
1597 } else {
1598 color = (color & 0xffffff) | (new_alpha << 24);
1599 }
1600 return _DibSetPixel(m_pBitmap, x, y, color, alpha_flag, pIccTransform);
1601 }
1602 }
1603 return TRUE;
1604 }
1605
1606 FX_BOOL CFX_AggDeviceDriver::FillRect(const FX_RECT* pRect,
1607 FX_DWORD fill_color,
1608 int alpha_flag,
1609 void* pIccTransform,
1610 int blend_type) {
1611 if (blend_type != FXDIB_BLEND_NORMAL) {
1612 return FALSE;
1613 }
1614 if (!m_pBitmap->GetBuffer()) {
1615 return TRUE;
1616 }
1617 FX_RECT clip_rect;
1618 GetClipBox(&clip_rect);
1619 FX_RECT draw_rect = clip_rect;
1620 if (pRect) {
1621 draw_rect.Intersect(*pRect);
1622 }
1623 if (draw_rect.IsEmpty()) {
1624 return TRUE;
1625 }
1626 if (!m_pClipRgn || m_pClipRgn->GetType() == CFX_ClipRgn::RectI) {
1627 if (m_bRgbByteOrder) {
1628 RgbByteOrderCompositeRect(m_pBitmap, draw_rect.left, draw_rect.top,
1629 draw_rect.Width(), draw_rect.Height(),
1630 fill_color);
1631 } else {
1632 m_pBitmap->CompositeRect(draw_rect.left, draw_rect.top, draw_rect.Width(),
1633 draw_rect.Height(), fill_color, alpha_flag,
1634 pIccTransform);
1635 }
1636 return TRUE;
1637 }
1638 m_pBitmap->CompositeMask(
1639 draw_rect.left, draw_rect.top, draw_rect.Width(), draw_rect.Height(),
1640 (const CFX_DIBitmap*)m_pClipRgn->GetMask(), fill_color,
1641 draw_rect.left - clip_rect.left, draw_rect.top - clip_rect.top,
1642 FXDIB_BLEND_NORMAL, NULL, m_bRgbByteOrder, alpha_flag, pIccTransform);
1643 return TRUE;
1644 }
1645
1646 FX_BOOL CFX_AggDeviceDriver::GetClipBox(FX_RECT* pRect) {
1647 if (!m_pClipRgn) {
1648 pRect->left = pRect->top = 0;
1649 pRect->right = GetDeviceCaps(FXDC_PIXEL_WIDTH);
1650 pRect->bottom = GetDeviceCaps(FXDC_PIXEL_HEIGHT);
1651 return TRUE;
1652 }
1653 *pRect = m_pClipRgn->GetBox();
1654 return TRUE;
1655 }
1656
1657 FX_BOOL CFX_AggDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap,
1658 int left,
1659 int top,
1660 void* pIccTransform,
1661 FX_BOOL bDEdge) {
1662 if (!m_pBitmap->GetBuffer()) {
1663 return TRUE;
1664 }
1665 if (bDEdge) {
1666 if (m_bRgbByteOrder) {
1667 RgbByteOrderTransferBitmap(pBitmap, 0, 0, pBitmap->GetWidth(),
1668 pBitmap->GetHeight(), m_pBitmap, left, top);
1669 } else {
1670 return pBitmap->TransferBitmap(0, 0, pBitmap->GetWidth(),
1671 pBitmap->GetHeight(), m_pBitmap, left, top,
1672 pIccTransform);
1673 }
1674 return TRUE;
1675 }
1676 FX_RECT rect(left, top, left + pBitmap->GetWidth(),
1677 top + pBitmap->GetHeight());
1678 CFX_DIBitmap* pBack = NULL;
1679 if (m_pOriDevice) {
1680 pBack = m_pOriDevice->Clone(&rect);
1681 if (!pBack) {
1682 return TRUE;
1683 }
1684 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(),
1685 m_pBitmap, 0, 0);
1686 } else {
1687 pBack = m_pBitmap->Clone(&rect);
1688 }
1689 if (!pBack) {
1690 return TRUE;
1691 }
1692 FX_BOOL bRet = TRUE;
1693 left = left >= 0 ? 0 : left;
1694 top = top >= 0 ? 0 : top;
1695 if (m_bRgbByteOrder) {
1696 RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(),
1697 pBack, left, top);
1698 } else {
1699 bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack,
1700 left, top, pIccTransform);
1701 }
1702 delete pBack;
1703 return bRet;
1704 }
1705
1706 FX_BOOL CFX_AggDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap,
1707 FX_DWORD argb,
1708 const FX_RECT* pSrcRect,
1709 int left,
1710 int top,
1711 int blend_type,
1712 int alpha_flag,
1713 void* pIccTransform) {
1714 if (!m_pBitmap->GetBuffer()) {
1715 return TRUE;
1716 }
1717 if (pBitmap->IsAlphaMask())
1718 return m_pBitmap->CompositeMask(
1719 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, argb,
1720 pSrcRect->left, pSrcRect->top, blend_type, m_pClipRgn, m_bRgbByteOrder,
1721 alpha_flag, pIccTransform);
1722 return m_pBitmap->CompositeBitmap(
1723 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, pSrcRect->left,
1724 pSrcRect->top, blend_type, m_pClipRgn, m_bRgbByteOrder, pIccTransform);
1725 }
1726
1727 FX_BOOL CFX_AggDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource,
1728 FX_DWORD argb,
1729 int dest_left,
1730 int dest_top,
1731 int dest_width,
1732 int dest_height,
1733 const FX_RECT* pClipRect,
1734 FX_DWORD flags,
1735 int alpha_flag,
1736 void* pIccTransform,
1737 int blend_type) {
1738 if (!m_pBitmap->GetBuffer()) {
1739 return TRUE;
1740 }
1741 if (dest_width == pSource->GetWidth() &&
1742 dest_height == pSource->GetHeight()) {
1743 FX_RECT rect(0, 0, dest_width, dest_height);
1744 return SetDIBits(pSource, argb, &rect, dest_left, dest_top, blend_type,
1745 alpha_flag, pIccTransform);
1746 }
1747 FX_RECT dest_rect(dest_left, dest_top, dest_left + dest_width,
1748 dest_top + dest_height);
1749 dest_rect.Normalize();
1750 FX_RECT dest_clip = dest_rect;
1751 dest_clip.Intersect(*pClipRect);
1752 CFX_BitmapComposer composer;
1753 composer.Compose(m_pBitmap, m_pClipRgn, 255, argb, dest_clip, FALSE, FALSE,
1754 FALSE, m_bRgbByteOrder, alpha_flag, pIccTransform,
1755 blend_type);
1756 dest_clip.Offset(-dest_rect.left, -dest_rect.top);
1757 CFX_ImageStretcher stretcher;
1758 if (stretcher.Start(&composer, pSource, dest_width, dest_height, dest_clip,
1759 flags)) {
1760 stretcher.Continue(NULL);
1761 }
1762 return TRUE;
1763 }
1764
1765 FX_BOOL CFX_AggDeviceDriver::StartDIBits(const CFX_DIBSource* pSource,
1766 int bitmap_alpha,
1767 FX_DWORD argb,
1768 const CFX_Matrix* pMatrix,
1769 FX_DWORD render_flags,
1770 void*& handle,
1771 int alpha_flag,
1772 void* pIccTransform,
1773 int blend_type) {
1774 if (!m_pBitmap->GetBuffer()) {
1775 return TRUE;
1776 }
1777 CFX_ImageRenderer* pRenderer = new CFX_ImageRenderer;
1778 pRenderer->Start(m_pBitmap, m_pClipRgn, pSource, bitmap_alpha, argb, pMatrix,
1779 render_flags, m_bRgbByteOrder, alpha_flag, pIccTransform);
1780 handle = pRenderer;
1781 return TRUE;
1782 }
1783
1784 FX_BOOL CFX_AggDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) {
1785 if (!m_pBitmap->GetBuffer()) {
1786 return TRUE;
1787 }
1788 return ((CFX_ImageRenderer*)pHandle)->Continue(pPause);
1789 }
1790
1791 void CFX_AggDeviceDriver::CancelDIBits(void* pHandle) {
1792 if (!m_pBitmap->GetBuffer()) {
1793 return;
1794 }
1795 delete (CFX_ImageRenderer*)pHandle;
1796 }
1797
1798 CFX_FxgeDevice::CFX_FxgeDevice() {
1799 m_bOwnedBitmap = FALSE;
1800 }
1801
1802 bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap,
1803 int dither_bits,
1804 bool bRgbByteOrder,
1805 CFX_DIBitmap* pOriDevice,
1806 bool bGroupKnockout) {
1807 if (!pBitmap) {
1808 return false;
1809 }
1810 SetBitmap(pBitmap);
1811 IFX_RenderDeviceDriver* pDriver = new CFX_AggDeviceDriver(
1812 pBitmap, dither_bits, bRgbByteOrder, pOriDevice, bGroupKnockout);
1813 SetDeviceDriver(pDriver);
1814 return true;
1815 }
1816
1817 bool CFX_FxgeDevice::Create(int width,
1818 int height,
1819 FXDIB_Format format,
1820 int dither_bits,
1821 CFX_DIBitmap* pOriDevice) {
1822 m_bOwnedBitmap = true;
1823 CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
1824 if (!pBitmap->Create(width, height, format)) {
1825 delete pBitmap;
1826 return false;
1827 }
1828 SetBitmap(pBitmap);
1829 IFX_RenderDeviceDriver* pDriver =
1830 new CFX_AggDeviceDriver(pBitmap, dither_bits, FALSE, pOriDevice, FALSE);
1831 SetDeviceDriver(pDriver);
1832 return true;
1833 }
1834
1835 CFX_FxgeDevice::~CFX_FxgeDevice() {
1836 if (m_bOwnedBitmap) {
1837 delete GetBitmap();
1838 }
1839 }
OLDNEW
« no previous file with comments | « core/src/fxge/agg/fx_agg_driver.h ('k') | core/src/fxge/android/fpf_skiafont.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698