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

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

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

Powered by Google App Engine
This is Rietveld 408576698