OLD | NEW |
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 #include <algorithm> | 5 #include <algorithm> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "core/fxcodec/fx_codec.h" | 8 #include "core/fxcodec/fx_codec.h" |
9 #include "core/fxcrt/fx_memory.h" | 9 #include "core/fxcrt/fx_memory.h" |
10 | 10 |
11 #include "core/fpdfapi/page/cpdf_shadingpattern.h" | 11 #include "core/fpdfapi/page/cpdf_shadingpattern.h" |
12 #include "core/fpdfapi/page/pageint.h" | 12 #include "core/fpdfapi/page/pageint.h" |
13 #include "core/fpdfapi/parser/cpdf_array.h" | 13 #include "core/fpdfapi/parser/cpdf_array.h" |
14 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 14 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
15 #include "core/fpdfapi/parser/cpdf_stream_acc.h" | 15 #include "core/fpdfapi/parser/cpdf_stream_acc.h" |
16 #include "core/fxge/cfx_fxgedevice.h" | 16 #include "core/fxge/cfx_fxgedevice.h" |
17 #include "core/fxge/cfx_gemodule.h" | 17 #include "core/fxge/cfx_gemodule.h" |
18 #include "core/fxge/cfx_graphstatedata.h" | 18 #include "core/fxge/cfx_graphstatedata.h" |
19 #include "core/fxge/cfx_pathdata.h" | 19 #include "core/fxge/cfx_pathdata.h" |
20 #include "core/fxge/cfx_renderdevice.h" | 20 #include "core/fxge/cfx_renderdevice.h" |
21 #include "core/fxge/skia/fx_skia_device.h" | 21 #include "core/fxge/skia/fx_skia_device.h" |
22 | |
23 #ifndef _SKIA_SUPPORT_ | |
24 #include "core/fxge/ge/cfx_cliprgn.h" | |
25 #endif | |
26 | |
27 #include "third_party/base/ptr_util.h" | 22 #include "third_party/base/ptr_util.h" |
28 | |
29 #include "third_party/skia/include/core/SkCanvas.h" | 23 #include "third_party/skia/include/core/SkCanvas.h" |
30 #include "third_party/skia/include/core/SkPaint.h" | |
31 #include "third_party/skia/include/core/SkPath.h" | |
32 #include "third_party/skia/include/effects/SkDashPathEffect.h" | |
33 #include "third_party/skia/include/pathops/SkPathOps.h" | |
34 | |
35 #ifdef _SKIA_SUPPORT_ | |
36 #include "third_party/skia/include/core/SkColorFilter.h" | 24 #include "third_party/skia/include/core/SkColorFilter.h" |
37 #include "third_party/skia/include/core/SkColorPriv.h" | 25 #include "third_party/skia/include/core/SkColorPriv.h" |
38 #include "third_party/skia/include/core/SkMaskFilter.h" | 26 #include "third_party/skia/include/core/SkMaskFilter.h" |
| 27 #include "third_party/skia/include/core/SkPaint.h" |
| 28 #include "third_party/skia/include/core/SkPath.h" |
39 #include "third_party/skia/include/core/SkPictureRecorder.h" | 29 #include "third_party/skia/include/core/SkPictureRecorder.h" |
40 #include "third_party/skia/include/core/SkShader.h" | 30 #include "third_party/skia/include/core/SkShader.h" |
41 #include "third_party/skia/include/core/SkStream.h" | 31 #include "third_party/skia/include/core/SkStream.h" |
42 #include "third_party/skia/include/core/SkTypeface.h" | 32 #include "third_party/skia/include/core/SkTypeface.h" |
| 33 #include "third_party/skia/include/effects/SkDashPathEffect.h" |
43 #include "third_party/skia/include/effects/SkGradientShader.h" | 34 #include "third_party/skia/include/effects/SkGradientShader.h" |
44 #endif | 35 #include "third_party/skia/include/pathops/SkPathOps.h" |
45 | 36 |
46 #ifdef SK_DEBUG | 37 #ifdef SK_DEBUG |
47 #include "third_party/skia/include/core/SkClipStack.h" | 38 #include "third_party/skia/include/core/SkClipStack.h" |
48 #endif | 39 #endif |
49 | 40 |
50 namespace { | 41 namespace { |
51 | 42 |
52 #ifndef _SKIA_SUPPORT_ | |
53 void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap, | |
54 int dest_left, | |
55 int dest_top, | |
56 int width, | |
57 int height, | |
58 const CFX_DIBSource* pSrcBitmap, | |
59 int src_left, | |
60 int src_top) { | |
61 if (!pBitmap) | |
62 return; | |
63 | |
64 pBitmap->GetOverlapRect(dest_left, dest_top, width, height, | |
65 pSrcBitmap->GetWidth(), pSrcBitmap->GetHeight(), | |
66 src_left, src_top, nullptr); | |
67 if (width == 0 || height == 0) | |
68 return; | |
69 | |
70 int Bpp = pBitmap->GetBPP() / 8; | |
71 FXDIB_Format dest_format = pBitmap->GetFormat(); | |
72 FXDIB_Format src_format = pSrcBitmap->GetFormat(); | |
73 int pitch = pBitmap->GetPitch(); | |
74 uint8_t* buffer = pBitmap->GetBuffer(); | |
75 if (dest_format == src_format) { | |
76 for (int row = 0; row < height; row++) { | |
77 uint8_t* dest_scan = buffer + (dest_top + row) * pitch + dest_left * Bpp; | |
78 uint8_t* src_scan = | |
79 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; | |
80 if (Bpp == 4) { | |
81 for (int col = 0; col < width; col++) { | |
82 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_scan[3], src_scan[0], | |
83 src_scan[1], src_scan[2])); | |
84 dest_scan += 4; | |
85 src_scan += 4; | |
86 } | |
87 } else { | |
88 for (int col = 0; col < width; col++) { | |
89 *dest_scan++ = src_scan[2]; | |
90 *dest_scan++ = src_scan[1]; | |
91 *dest_scan++ = src_scan[0]; | |
92 src_scan += 3; | |
93 } | |
94 } | |
95 } | |
96 return; | |
97 } | |
98 | |
99 uint8_t* dest_buf = buffer + dest_top * pitch + dest_left * Bpp; | |
100 if (dest_format == FXDIB_Rgb) { | |
101 if (src_format == FXDIB_Rgb32) { | |
102 for (int row = 0; row < height; row++) { | |
103 uint8_t* dest_scan = dest_buf + row * pitch; | |
104 uint8_t* src_scan = | |
105 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * 4; | |
106 for (int col = 0; col < width; col++) { | |
107 *dest_scan++ = src_scan[2]; | |
108 *dest_scan++ = src_scan[1]; | |
109 *dest_scan++ = src_scan[0]; | |
110 src_scan += 4; | |
111 } | |
112 } | |
113 } else { | |
114 ASSERT(false); | |
115 } | |
116 return; | |
117 } | |
118 | |
119 if (dest_format == FXDIB_Argb || dest_format == FXDIB_Rgb32) { | |
120 if (src_format == FXDIB_Rgb) { | |
121 for (int row = 0; row < height; row++) { | |
122 uint8_t* dest_scan = (uint8_t*)(dest_buf + row * pitch); | |
123 uint8_t* src_scan = | |
124 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * 3; | |
125 for (int col = 0; col < width; col++) { | |
126 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[0], src_scan[1], | |
127 src_scan[2])); | |
128 dest_scan += 4; | |
129 src_scan += 3; | |
130 } | |
131 } | |
132 } else if (src_format == FXDIB_Rgb32) { | |
133 ASSERT(dest_format == FXDIB_Argb); | |
134 for (int row = 0; row < height; row++) { | |
135 uint8_t* dest_scan = dest_buf + row * pitch; | |
136 uint8_t* src_scan = | |
137 (uint8_t*)(pSrcBitmap->GetScanline(src_top + row) + src_left * 4); | |
138 for (int col = 0; col < width; col++) { | |
139 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[0], src_scan[1], | |
140 src_scan[2])); | |
141 src_scan += 4; | |
142 dest_scan += 4; | |
143 } | |
144 } | |
145 } | |
146 return; | |
147 } | |
148 | |
149 ASSERT(false); | |
150 } | |
151 | |
152 #endif | |
153 | |
154 #define SHOW_SKIA_PATH 0 // set to 1 to print the path contents | 43 #define SHOW_SKIA_PATH 0 // set to 1 to print the path contents |
155 #define DRAW_SKIA_CLIP 0 // set to 1 to draw a green rectangle around the clip | 44 #define DRAW_SKIA_CLIP 0 // set to 1 to draw a green rectangle around the clip |
156 | 45 |
157 void DebugShowSkiaPath(const SkPath& path) { | 46 void DebugShowSkiaPath(const SkPath& path) { |
158 #if SHOW_SKIA_PATH | 47 #if SHOW_SKIA_PATH |
159 char buffer[4096]; | 48 char buffer[4096]; |
160 sk_bzero(buffer, sizeof(buffer)); | 49 sk_bzero(buffer, sizeof(buffer)); |
161 SkMemoryWStream stream(buffer, sizeof(buffer)); | 50 SkMemoryWStream stream(buffer, sizeof(buffer)); |
162 path.dump(&stream, false, false); | 51 path.dump(&stream, false, false); |
163 printf("%s\n", buffer); | 52 printf("%s\n", buffer); |
(...skipping 13 matching lines...) Expand all Loading... |
177 #if DRAW_SKIA_CLIP | 66 #if DRAW_SKIA_CLIP |
178 | 67 |
179 SkPaint DebugClipPaint() { | 68 SkPaint DebugClipPaint() { |
180 SkPaint paint; | 69 SkPaint paint; |
181 paint.setAntiAlias(true); | 70 paint.setAntiAlias(true); |
182 paint.setColor(SK_ColorGREEN); | 71 paint.setColor(SK_ColorGREEN); |
183 paint.setStyle(SkPaint::kStroke_Style); | 72 paint.setStyle(SkPaint::kStroke_Style); |
184 return paint; | 73 return paint; |
185 } | 74 } |
186 | 75 |
187 #ifdef _SKIA_SUPPORT_ | |
188 void DebugDrawSkiaClipRect(SkCanvas* canvas, const SkRect& rect) { | 76 void DebugDrawSkiaClipRect(SkCanvas* canvas, const SkRect& rect) { |
189 SkPaint paint = DebugClipPaint(); | 77 SkPaint paint = DebugClipPaint(); |
190 canvas->drawRect(rect, paint); | 78 canvas->drawRect(rect, paint); |
191 } | 79 } |
192 #endif | |
193 | 80 |
194 void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) { | 81 void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) { |
195 SkPaint paint = DebugClipPaint(); | 82 SkPaint paint = DebugClipPaint(); |
196 canvas->drawPath(path, paint); | 83 canvas->drawPath(path, paint); |
197 } | 84 } |
198 | 85 |
199 #else // DRAW_SKIA_CLIP | 86 #else // DRAW_SKIA_CLIP |
200 | 87 |
201 #ifdef _SKIA_SUPPORT_ | |
202 void DebugDrawSkiaClipRect(SkCanvas* canvas, const SkRect& rect) {} | 88 void DebugDrawSkiaClipRect(SkCanvas* canvas, const SkRect& rect) {} |
203 #endif | |
204 | |
205 void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) {} | 89 void DebugDrawSkiaClipPath(SkCanvas* canvas, const SkPath& path) {} |
206 | 90 |
207 #endif // DRAW_SKIA_CLIP | 91 #endif // DRAW_SKIA_CLIP |
208 | 92 |
209 #undef SHOW_SKIA_PATH | 93 #undef SHOW_SKIA_PATH |
210 #undef DRAW_SKIA_CLIP | 94 #undef DRAW_SKIA_CLIP |
211 | 95 |
212 #ifdef _SKIA_SUPPORT_ | |
213 static void DebugValidate(const CFX_DIBitmap* bitmap, | 96 static void DebugValidate(const CFX_DIBitmap* bitmap, |
214 const CFX_DIBitmap* device) { | 97 const CFX_DIBitmap* device) { |
215 if (bitmap) { | 98 if (bitmap) { |
216 SkASSERT(bitmap->GetBPP() == 8 || bitmap->GetBPP() == 32); | 99 SkASSERT(bitmap->GetBPP() == 8 || bitmap->GetBPP() == 32); |
217 if (bitmap->GetBPP() == 32) { | 100 if (bitmap->GetBPP() == 32) { |
218 bitmap->DebugVerifyBitmapIsPreMultiplied(); | 101 bitmap->DebugVerifyBitmapIsPreMultiplied(); |
219 } | 102 } |
220 } | 103 } |
221 if (device) { | 104 if (device) { |
222 SkASSERT(device->GetBPP() == 8 || device->GetBPP() == 32); | 105 SkASSERT(device->GetBPP() == 8 || device->GetBPP() == 32); |
223 if (device->GetBPP() == 32) { | 106 if (device->GetBPP() == 32) { |
224 device->DebugVerifyBitmapIsPreMultiplied(); | 107 device->DebugVerifyBitmapIsPreMultiplied(); |
225 } | 108 } |
226 } | 109 } |
227 } | 110 } |
228 #endif | |
229 | 111 |
230 SkPath BuildPath(const CFX_PathData* pPathData) { | 112 SkPath BuildPath(const CFX_PathData* pPathData) { |
231 SkPath skPath; | 113 SkPath skPath; |
232 const CFX_PathData* pFPath = pPathData; | 114 const CFX_PathData* pFPath = pPathData; |
233 int nPoints = pFPath->GetPointCount(); | 115 int nPoints = pFPath->GetPointCount(); |
234 FX_PATHPOINT* pPoints = pFPath->GetPoints(); | 116 FX_PATHPOINT* pPoints = pFPath->GetPoints(); |
235 for (int i = 0; i < nPoints; i++) { | 117 for (int i = 0; i < nPoints; i++) { |
236 FX_FLOAT x = pPoints[i].m_PointX; | 118 FX_FLOAT x = pPoints[i].m_PointX; |
237 FX_FLOAT y = pPoints[i].m_PointY; | 119 FX_FLOAT y = pPoints[i].m_PointY; |
238 int point_type = pPoints[i].m_Flag & FXPT_TYPE; | 120 int point_type = pPoints[i].m_Flag & FXPT_TYPE; |
(...skipping 12 matching lines...) Expand all Loading... |
251 } | 133 } |
252 return skPath; | 134 return skPath; |
253 } | 135 } |
254 | 136 |
255 SkMatrix ToSkMatrix(const CFX_Matrix& m) { | 137 SkMatrix ToSkMatrix(const CFX_Matrix& m) { |
256 SkMatrix skMatrix; | 138 SkMatrix skMatrix; |
257 skMatrix.setAll(m.a, m.b, m.e, m.c, m.d, m.f, 0, 0, 1); | 139 skMatrix.setAll(m.a, m.b, m.e, m.c, m.d, m.f, 0, 0, 1); |
258 return skMatrix; | 140 return skMatrix; |
259 } | 141 } |
260 | 142 |
261 #ifdef _SKIA_SUPPORT_ | |
262 // use when pdf's y-axis points up insead of down | 143 // use when pdf's y-axis points up insead of down |
263 SkMatrix ToFlippedSkMatrix(const CFX_Matrix& m, SkScalar flip) { | 144 SkMatrix ToFlippedSkMatrix(const CFX_Matrix& m, SkScalar flip) { |
264 SkMatrix skMatrix; | 145 SkMatrix skMatrix; |
265 skMatrix.setAll(m.a * flip, -m.c * flip, m.e, m.b * flip, -m.d * flip, m.f, 0, | 146 skMatrix.setAll(m.a * flip, -m.c * flip, m.e, m.b * flip, -m.d * flip, m.f, 0, |
266 0, 1); | 147 0, 1); |
267 return skMatrix; | 148 return skMatrix; |
268 } | 149 } |
269 #endif | |
270 | 150 |
271 SkBlendMode GetSkiaBlendMode(int blend_type) { | 151 SkBlendMode GetSkiaBlendMode(int blend_type) { |
272 switch (blend_type) { | 152 switch (blend_type) { |
273 case FXDIB_BLEND_MULTIPLY: | 153 case FXDIB_BLEND_MULTIPLY: |
274 return SkBlendMode::kMultiply; | 154 return SkBlendMode::kMultiply; |
275 case FXDIB_BLEND_SCREEN: | 155 case FXDIB_BLEND_SCREEN: |
276 return SkBlendMode::kScreen; | 156 return SkBlendMode::kScreen; |
277 case FXDIB_BLEND_OVERLAY: | 157 case FXDIB_BLEND_OVERLAY: |
278 return SkBlendMode::kOverlay; | 158 return SkBlendMode::kOverlay; |
279 case FXDIB_BLEND_DARKEN: | 159 case FXDIB_BLEND_DARKEN: |
(...skipping 19 matching lines...) Expand all Loading... |
299 case FXDIB_BLEND_COLOR: | 179 case FXDIB_BLEND_COLOR: |
300 return SkBlendMode::kColor; | 180 return SkBlendMode::kColor; |
301 case FXDIB_BLEND_LUMINOSITY: | 181 case FXDIB_BLEND_LUMINOSITY: |
302 return SkBlendMode::kLuminosity; | 182 return SkBlendMode::kLuminosity; |
303 case FXDIB_BLEND_NORMAL: | 183 case FXDIB_BLEND_NORMAL: |
304 default: | 184 default: |
305 return SkBlendMode::kSrcOver; | 185 return SkBlendMode::kSrcOver; |
306 } | 186 } |
307 } | 187 } |
308 | 188 |
309 #ifdef _SKIA_SUPPORT_ | |
310 bool AddColors(const CPDF_ExpIntFunc* pFunc, SkTDArray<SkColor>* skColors) { | 189 bool AddColors(const CPDF_ExpIntFunc* pFunc, SkTDArray<SkColor>* skColors) { |
311 if (pFunc->CountInputs() != 1) | 190 if (pFunc->CountInputs() != 1) |
312 return false; | 191 return false; |
313 if (pFunc->m_Exponent != 1) | 192 if (pFunc->m_Exponent != 1) |
314 return false; | 193 return false; |
315 if (pFunc->m_nOrigOutputs != 3) | 194 if (pFunc->m_nOrigOutputs != 3) |
316 return false; | 195 return false; |
317 skColors->push( | 196 skColors->push( |
318 SkColorSetARGB(0xFF, SkUnitScalarClampToByte(pFunc->m_pBeginValues[0]), | 197 SkColorSetARGB(0xFF, SkUnitScalarClampToByte(pFunc->m_pBeginValues[0]), |
319 SkUnitScalarClampToByte(pFunc->m_pBeginValues[1]), | 198 SkUnitScalarClampToByte(pFunc->m_pBeginValues[1]), |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 colorType = SkColorType::kUnknown_SkColorType; | 462 colorType = SkColorType::kUnknown_SkColorType; |
584 } | 463 } |
585 SkImageInfo imageInfo = | 464 SkImageInfo imageInfo = |
586 SkImageInfo::Make(width, height, colorType, alphaType); | 465 SkImageInfo::Make(width, height, colorType, alphaType); |
587 skBitmap->installPixels(imageInfo, buffer, rowBytes, *ctPtr, nullptr, | 466 skBitmap->installPixels(imageInfo, buffer, rowBytes, *ctPtr, nullptr, |
588 nullptr); | 467 nullptr); |
589 *widthPtr = width; | 468 *widthPtr = width; |
590 *heightPtr = height; | 469 *heightPtr = height; |
591 return true; | 470 return true; |
592 } | 471 } |
593 #endif | |
594 | 472 |
595 } // namespace | 473 } // namespace |
596 | 474 |
597 // Encapsulate the state used for successive text and path draws so that | 475 // Encapsulate the state used for successive text and path draws so that |
598 // they can be combined. | 476 // they can be combined. |
599 class SkiaState { | 477 class SkiaState { |
600 public: | 478 public: |
601 enum class Clip { | 479 enum class Clip { |
602 kSave, | 480 kSave, |
603 kPath, | 481 kPath, |
604 }; | 482 }; |
605 | 483 |
606 // mark all cached state as uninitialized | 484 // mark all cached state as uninitialized |
607 SkiaState() | 485 SkiaState() |
608 : m_pFont(nullptr), | 486 : m_pFont(nullptr), |
609 m_fontSize(0), | 487 m_fontSize(0), |
610 m_fillColor(0), | 488 m_fillColor(0), |
611 m_strokeColor(0), | 489 m_strokeColor(0), |
612 m_blendType(0), | 490 m_blendType(0), |
613 m_commandIndex(0), | 491 m_commandIndex(0), |
614 #if _SKIA_SUPPORT_ | |
615 m_drawText(false), | 492 m_drawText(false), |
616 #endif | |
617 m_drawPath(false), | 493 m_drawPath(false), |
618 m_fillPath(false), | 494 m_fillPath(false), |
619 m_debugDisable(true) { | 495 m_debugDisable(false) {} |
620 } | |
621 | 496 |
622 bool DrawPath(const CFX_PathData* pPathData, | 497 bool DrawPath(const CFX_PathData* pPathData, |
623 const CFX_Matrix* pMatrix, | 498 const CFX_Matrix* pMatrix, |
624 const CFX_GraphStateData* pDrawState, | 499 const CFX_GraphStateData* pDrawState, |
625 uint32_t fill_color, | 500 uint32_t fill_color, |
626 uint32_t stroke_color, | 501 uint32_t stroke_color, |
627 int fill_mode, | 502 int fill_mode, |
628 int blend_type, | 503 int blend_type, |
629 CFX_SkiaDeviceDriver* pDriver) { | 504 CFX_SkiaDeviceDriver* pDriver) { |
630 if (m_debugDisable) | 505 if (m_debugDisable) |
631 return false; | 506 return false; |
632 if (m_commandIndex < m_commands.count()) | 507 if (m_commandIndex < m_commands.count()) |
633 FlushCommands(pDriver); | 508 FlushCommands(pDriver); |
634 #if _SKIA_SUPPORT_ | |
635 if (m_drawText) | 509 if (m_drawText) |
636 FlushText(pDriver); | 510 FlushText(pDriver); |
637 #endif | |
638 if (m_drawPath && DrawChanged(pMatrix, pDrawState, fill_color, stroke_color, | 511 if (m_drawPath && DrawChanged(pMatrix, pDrawState, fill_color, stroke_color, |
639 fill_mode, blend_type)) { | 512 fill_mode, blend_type)) { |
640 FlushPath(pDriver); | 513 FlushPath(pDriver); |
641 } | 514 } |
642 if (!m_drawPath) { | 515 if (!m_drawPath) { |
643 m_skPath.reset(); | 516 m_skPath.reset(); |
644 m_fillPath = (fill_mode & 3) && fill_color; | 517 m_fillPath = (fill_mode & 3) && fill_color; |
645 m_skPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE | 518 m_skPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE |
646 ? SkPath::kEvenOdd_FillType | 519 ? SkPath::kEvenOdd_FillType |
647 : SkPath::kWinding_FillType); | 520 : SkPath::kWinding_FillType); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 DebugShowSkiaPath(m_skPath); | 567 DebugShowSkiaPath(m_skPath); |
695 DebugShowCanvasMatrix(skCanvas); | 568 DebugShowCanvasMatrix(skCanvas); |
696 skPaint.setStyle(SkPaint::kStroke_Style); | 569 skPaint.setStyle(SkPaint::kStroke_Style); |
697 skPaint.setColor(m_strokeColor); | 570 skPaint.setColor(m_strokeColor); |
698 skCanvas->drawPath(m_skPath, skPaint); | 571 skCanvas->drawPath(m_skPath, skPaint); |
699 } | 572 } |
700 skCanvas->restore(); | 573 skCanvas->restore(); |
701 m_drawPath = false; | 574 m_drawPath = false; |
702 } | 575 } |
703 | 576 |
704 #ifdef _SKIA_SUPPORT_ | |
705 bool DrawText(int nChars, | 577 bool DrawText(int nChars, |
706 const FXTEXT_CHARPOS* pCharPos, | 578 const FXTEXT_CHARPOS* pCharPos, |
707 CFX_Font* pFont, | 579 CFX_Font* pFont, |
708 const CFX_Matrix* pMatrix, | 580 const CFX_Matrix* pMatrix, |
709 FX_FLOAT font_size, | 581 FX_FLOAT font_size, |
710 uint32_t color, | 582 uint32_t color, |
711 CFX_SkiaDeviceDriver* pDriver) { | 583 CFX_SkiaDeviceDriver* pDriver) { |
712 if (m_debugDisable) | 584 if (m_debugDisable) |
713 return false; | 585 return false; |
714 if (m_commandIndex < m_commands.count()) | 586 if (m_commandIndex < m_commands.count()) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 skPaint.setSubpixelText(true); | 630 skPaint.setSubpixelText(true); |
759 skPaint.setHinting(SkPaint::kNo_Hinting); | 631 skPaint.setHinting(SkPaint::kNo_Hinting); |
760 SkCanvas* skCanvas = pDriver->SkiaCanvas(); | 632 SkCanvas* skCanvas = pDriver->SkiaCanvas(); |
761 skCanvas->save(); | 633 skCanvas->save(); |
762 skCanvas->concat(skMatrix); | 634 skCanvas->concat(skMatrix); |
763 skCanvas->drawPosText(m_glyphs.begin(), m_glyphs.count() * 2, | 635 skCanvas->drawPosText(m_glyphs.begin(), m_glyphs.count() * 2, |
764 m_positions.begin(), skPaint); | 636 m_positions.begin(), skPaint); |
765 skCanvas->restore(); | 637 skCanvas->restore(); |
766 m_drawText = false; | 638 m_drawText = false; |
767 } | 639 } |
768 #endif | |
769 | 640 |
770 bool SetClipFill(const CFX_PathData* pPathData, | 641 bool SetClipFill(const CFX_PathData* pPathData, |
771 const CFX_Matrix* pMatrix, | 642 const CFX_Matrix* pMatrix, |
772 int fill_mode, | 643 int fill_mode, |
773 CFX_SkiaDeviceDriver* pDriver) { | 644 CFX_SkiaDeviceDriver* pDriver) { |
774 if (m_debugDisable) | 645 if (m_debugDisable) |
775 return false; | 646 return false; |
776 SkPath skClipPath = BuildPath(pPathData); | 647 SkPath skClipPath = BuildPath(pPathData); |
777 skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE | 648 skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE |
778 ? SkPath::kEvenOdd_FillType | 649 ? SkPath::kEvenOdd_FillType |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 for (int index = 0; index < pState->m_DashCount; ++index) { | 819 for (int index = 0; index < pState->m_DashCount; ++index) { |
949 if (pState->m_DashArray[index] != refState.m_DashArray[index]) | 820 if (pState->m_DashArray[index] != refState.m_DashArray[index]) |
950 return false; | 821 return false; |
951 } | 822 } |
952 return true; | 823 return true; |
953 } | 824 } |
954 | 825 |
955 void Flush(CFX_SkiaDeviceDriver* pDriver) { | 826 void Flush(CFX_SkiaDeviceDriver* pDriver) { |
956 if (m_drawPath) | 827 if (m_drawPath) |
957 FlushPath(pDriver); | 828 FlushPath(pDriver); |
958 #ifdef _SKIA_SUPPORT_ | |
959 if (m_drawText) | 829 if (m_drawText) |
960 FlushText(pDriver); | 830 FlushText(pDriver); |
961 #endif | |
962 } | 831 } |
963 | 832 |
964 #ifdef SK_DEBUG | 833 #ifdef SK_DEBUG |
965 void Dump(const CFX_SkiaDeviceDriver* pDriver) const { | 834 void Dump(const CFX_SkiaDeviceDriver* pDriver) const { |
966 SkDebugf("\n\nSkia Save Count %d:\n", pDriver->m_pCanvas->getSaveCount()); | 835 SkDebugf("\n\nSkia Save Count %d:\n", pDriver->m_pCanvas->getSaveCount()); |
967 pDriver->m_pCanvas->getClipStack()->dump(); | 836 pDriver->m_pCanvas->getClipStack()->dump(); |
968 SkDebugf("Cache:\n"); | 837 SkDebugf("Cache:\n"); |
969 for (int index = 0; index < m_commands.count(); ++index) { | 838 for (int index = 0; index < m_commands.count(); ++index) { |
970 SkDebugf("%s ", m_commandIndex == index ? "-->" : " "); | 839 SkDebugf("%s ", m_commandIndex == index ? "-->" : " "); |
971 switch (m_commands[index]) { | 840 switch (m_commands[index]) { |
(...skipping 22 matching lines...) Expand all Loading... |
994 CFX_Matrix m_drawMatrix; | 863 CFX_Matrix m_drawMatrix; |
995 CFX_GraphStateData m_clipState; | 864 CFX_GraphStateData m_clipState; |
996 CFX_GraphStateData m_drawState; | 865 CFX_GraphStateData m_drawState; |
997 CFX_Matrix m_clipMatrix; | 866 CFX_Matrix m_clipMatrix; |
998 CFX_Font* m_pFont; | 867 CFX_Font* m_pFont; |
999 FX_FLOAT m_fontSize; | 868 FX_FLOAT m_fontSize; |
1000 uint32_t m_fillColor; | 869 uint32_t m_fillColor; |
1001 uint32_t m_strokeColor; | 870 uint32_t m_strokeColor; |
1002 int m_blendType; | 871 int m_blendType; |
1003 int m_commandIndex; // active position in clip command stack | 872 int m_commandIndex; // active position in clip command stack |
1004 #ifdef _SKIA_SUPPORT_ | |
1005 bool m_drawText; | 873 bool m_drawText; |
1006 #endif | |
1007 bool m_drawPath; | 874 bool m_drawPath; |
1008 bool m_fillPath; | 875 bool m_fillPath; |
1009 bool m_debugDisable; // turn off cache for debugging | 876 bool m_debugDisable; // turn off cache for debugging |
1010 }; | 877 }; |
1011 | 878 |
1012 // convert a stroking path to scanlines | 879 // convert a stroking path to scanlines |
1013 void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint, | 880 void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint, |
1014 const CFX_GraphStateData* pGraphState, | 881 const CFX_GraphStateData* pGraphState, |
1015 const SkMatrix& matrix) { | 882 const SkMatrix& matrix) { |
1016 SkPaint::Cap cap; | 883 SkPaint::Cap cap; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 } | 942 } |
1076 | 943 |
1077 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, | 944 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, |
1078 bool bRgbByteOrder, | 945 bool bRgbByteOrder, |
1079 CFX_DIBitmap* pOriDevice, | 946 CFX_DIBitmap* pOriDevice, |
1080 bool bGroupKnockout) | 947 bool bGroupKnockout) |
1081 : m_pBitmap(pBitmap), | 948 : m_pBitmap(pBitmap), |
1082 m_pOriDevice(pOriDevice), | 949 m_pOriDevice(pOriDevice), |
1083 m_pRecorder(nullptr), | 950 m_pRecorder(nullptr), |
1084 m_pCache(new SkiaState), | 951 m_pCache(new SkiaState), |
1085 #ifndef _SKIA_SUPPORT_ | |
1086 m_pClipRgn(nullptr), | |
1087 m_FillFlags(0), | |
1088 m_bRgbByteOrder(bRgbByteOrder), | |
1089 #endif | |
1090 m_bGroupKnockout(bGroupKnockout) { | 952 m_bGroupKnockout(bGroupKnockout) { |
1091 SkBitmap skBitmap; | 953 SkBitmap skBitmap; |
1092 SkASSERT(pBitmap->GetBPP() == 8 || pBitmap->GetBPP() == 32); | 954 SkASSERT(pBitmap->GetBPP() == 8 || pBitmap->GetBPP() == 32); |
1093 SkImageInfo imageInfo = SkImageInfo::Make( | 955 SkImageInfo imageInfo = SkImageInfo::Make( |
1094 pBitmap->GetWidth(), pBitmap->GetHeight(), | 956 pBitmap->GetWidth(), pBitmap->GetHeight(), |
1095 pBitmap->GetBPP() == 8 ? kAlpha_8_SkColorType : kN32_SkColorType, | 957 pBitmap->GetBPP() == 8 ? kAlpha_8_SkColorType : kN32_SkColorType, |
1096 kOpaque_SkAlphaType); | 958 kOpaque_SkAlphaType); |
1097 skBitmap.installPixels(imageInfo, pBitmap->GetBuffer(), pBitmap->GetPitch(), | 959 skBitmap.installPixels(imageInfo, pBitmap->GetBuffer(), pBitmap->GetPitch(), |
1098 nullptr, // FIXME(caryclark) set color table | 960 nullptr, /* to do : set color table */ |
1099 nullptr, nullptr); | 961 nullptr, nullptr); |
1100 m_pCanvas = new SkCanvas(skBitmap); | 962 m_pCanvas = new SkCanvas(skBitmap); |
| 963 if (m_bGroupKnockout) |
| 964 SkDebugf(""); // FIXME(caryclark) suppress 'm_bGroupKnockout is unused' |
1101 } | 965 } |
1102 | 966 |
1103 #ifdef _SKIA_SUPPORT_ | |
1104 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(int size_x, int size_y) | 967 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(int size_x, int size_y) |
1105 : m_pBitmap(nullptr), | 968 : m_pBitmap(nullptr), |
1106 m_pOriDevice(nullptr), | 969 m_pOriDevice(nullptr), |
1107 m_pRecorder(new SkPictureRecorder), | 970 m_pRecorder(new SkPictureRecorder), |
1108 m_pCache(new SkiaState), | 971 m_pCache(new SkiaState), |
1109 m_bGroupKnockout(false) { | 972 m_bGroupKnockout(false) { |
1110 m_pRecorder->beginRecording(SkIntToScalar(size_x), SkIntToScalar(size_y)); | 973 m_pRecorder->beginRecording(SkIntToScalar(size_x), SkIntToScalar(size_y)); |
1111 m_pCanvas = m_pRecorder->getRecordingCanvas(); | 974 m_pCanvas = m_pRecorder->getRecordingCanvas(); |
1112 } | 975 } |
1113 | 976 |
1114 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(SkPictureRecorder* recorder) | 977 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(SkPictureRecorder* recorder) |
1115 : m_pBitmap(nullptr), | 978 : m_pBitmap(nullptr), |
1116 m_pOriDevice(nullptr), | 979 m_pOriDevice(nullptr), |
1117 m_pRecorder(recorder), | 980 m_pRecorder(recorder), |
1118 m_pCache(new SkiaState), | 981 m_pCache(new SkiaState), |
1119 m_bGroupKnockout(false) { | 982 m_bGroupKnockout(false) { |
1120 m_pCanvas = m_pRecorder->getRecordingCanvas(); | 983 m_pCanvas = m_pRecorder->getRecordingCanvas(); |
1121 } | 984 } |
1122 #endif | |
1123 | 985 |
1124 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { | 986 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { |
1125 Flush(); | 987 Flush(); |
1126 if (!m_pRecorder) | 988 if (!m_pRecorder) |
1127 delete m_pCanvas; | 989 delete m_pCanvas; |
1128 } | 990 } |
1129 | 991 |
1130 void CFX_SkiaDeviceDriver::Flush() { | 992 void CFX_SkiaDeviceDriver::Flush() { |
1131 m_pCache->Flush(this); | 993 m_pCache->Flush(this); |
1132 m_pCache->FlushCommands(this); | 994 m_pCache->FlushCommands(this); |
1133 } | 995 } |
1134 | 996 |
1135 bool CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, | 997 bool CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, |
1136 const FXTEXT_CHARPOS* pCharPos, | 998 const FXTEXT_CHARPOS* pCharPos, |
1137 CFX_Font* pFont, | 999 CFX_Font* pFont, |
1138 const CFX_Matrix* pObject2Device, | 1000 const CFX_Matrix* pObject2Device, |
1139 FX_FLOAT font_size, | 1001 FX_FLOAT font_size, |
1140 uint32_t color) { | 1002 uint32_t color) { |
1141 #ifdef _SKIA_SUPPORT_ | |
1142 if (m_pCache->DrawText(nChars, pCharPos, pFont, pObject2Device, font_size, | 1003 if (m_pCache->DrawText(nChars, pCharPos, pFont, pObject2Device, font_size, |
1143 color, this)) { | 1004 color, this)) { |
1144 return true; | 1005 return true; |
1145 } | 1006 } |
1146 sk_sp<SkTypeface> typeface(SkSafeRef(pFont->GetDeviceCache())); | 1007 sk_sp<SkTypeface> typeface(SkSafeRef(pFont->GetDeviceCache())); |
1147 SkPaint paint; | 1008 SkPaint paint; |
1148 paint.setAntiAlias(true); | 1009 paint.setAntiAlias(true); |
1149 paint.setColor(color); | 1010 paint.setColor(color); |
1150 paint.setTypeface(typeface); | 1011 paint.setTypeface(typeface); |
1151 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 1012 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
1152 paint.setHinting(SkPaint::kNo_Hinting); | 1013 paint.setHinting(SkPaint::kNo_Hinting); |
1153 paint.setTextSize(font_size); | 1014 paint.setTextSize(font_size); |
1154 paint.setSubpixelText(true); | 1015 paint.setSubpixelText(true); |
1155 m_pCanvas->save(); | 1016 m_pCanvas->save(); |
1156 SkScalar flip = font_size < 0 ? -1 : 1; | 1017 SkScalar flip = font_size < 0 ? -1 : 1; |
1157 SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device, flip); | 1018 SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device, flip); |
1158 m_pCanvas->concat(skMatrix); | 1019 m_pCanvas->concat(skMatrix); |
1159 SkTDArray<SkPoint> positions; | 1020 SkTDArray<SkPoint> positions; |
1160 positions.setCount(nChars); | 1021 positions.setCount(nChars); |
1161 SkTDArray<uint16_t> glyphs; | 1022 SkTDArray<uint16_t> glyphs; |
1162 glyphs.setCount(nChars); | 1023 glyphs.setCount(nChars); |
1163 for (int index = 0; index < nChars; ++index) { | 1024 for (int index = 0; index < nChars; ++index) { |
1164 const FXTEXT_CHARPOS& cp = pCharPos[index]; | 1025 const FXTEXT_CHARPOS& cp = pCharPos[index]; |
1165 positions[index] = {cp.m_OriginX * flip, cp.m_OriginY * flip}; | 1026 positions[index] = {cp.m_OriginX * flip, cp.m_OriginY * flip}; |
1166 glyphs[index] = (uint16_t)cp.m_GlyphIndex; | 1027 glyphs[index] = (uint16_t)cp.m_GlyphIndex; |
1167 } | 1028 } |
1168 m_pCanvas->drawPosText(glyphs.begin(), nChars * 2, positions.begin(), paint); | 1029 m_pCanvas->drawPosText(glyphs.begin(), nChars * 2, positions.begin(), paint); |
1169 m_pCanvas->restore(); | 1030 m_pCanvas->restore(); |
1170 return true; | 1031 return true; |
1171 #else | |
1172 return false; | |
1173 #endif | |
1174 } | 1032 } |
1175 | 1033 |
1176 int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) const { | 1034 int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) const { |
1177 switch (caps_id) { | 1035 switch (caps_id) { |
1178 case FXDC_DEVICE_CLASS: | 1036 case FXDC_DEVICE_CLASS: |
1179 return FXDC_DISPLAY; | 1037 return FXDC_DISPLAY; |
1180 #ifdef _SKIA_SUPPORT_ | |
1181 case FXDC_PIXEL_WIDTH: | 1038 case FXDC_PIXEL_WIDTH: |
1182 return m_pCanvas->imageInfo().width(); | 1039 return m_pCanvas->imageInfo().width(); |
1183 case FXDC_PIXEL_HEIGHT: | 1040 case FXDC_PIXEL_HEIGHT: |
1184 return m_pCanvas->imageInfo().height(); | 1041 return m_pCanvas->imageInfo().height(); |
1185 case FXDC_BITS_PIXEL: | 1042 case FXDC_BITS_PIXEL: |
1186 return 32; | 1043 return 32; |
1187 case FXDC_HORZ_SIZE: | 1044 case FXDC_HORZ_SIZE: |
1188 case FXDC_VERT_SIZE: | 1045 case FXDC_VERT_SIZE: |
1189 return 0; | 1046 return 0; |
1190 case FXDC_RENDER_CAPS: | 1047 case FXDC_RENDER_CAPS: |
1191 return FXRC_GET_BITS | FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE | | 1048 return FXRC_GET_BITS | FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE | |
1192 FXRC_BLEND_MODE | FXRC_SOFT_CLIP | FXRC_ALPHA_OUTPUT | | 1049 FXRC_BLEND_MODE | FXRC_SOFT_CLIP | FXRC_ALPHA_OUTPUT | |
1193 FXRC_FILLSTROKE_PATH | FXRC_SHADING; | 1050 FXRC_FILLSTROKE_PATH | FXRC_SHADING; |
1194 #else | |
1195 case FXDC_PIXEL_WIDTH: | |
1196 return m_pBitmap->GetWidth(); | |
1197 case FXDC_PIXEL_HEIGHT: | |
1198 return m_pBitmap->GetHeight(); | |
1199 case FXDC_BITS_PIXEL: | |
1200 return m_pBitmap->GetBPP(); | |
1201 case FXDC_HORZ_SIZE: | |
1202 case FXDC_VERT_SIZE: | |
1203 return 0; | |
1204 case FXDC_RENDER_CAPS: { | |
1205 int flags = FXRC_GET_BITS | FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE | | |
1206 FXRC_BLEND_MODE | FXRC_SOFT_CLIP; | |
1207 if (m_pBitmap->HasAlpha()) { | |
1208 flags |= FXRC_ALPHA_OUTPUT; | |
1209 } else if (m_pBitmap->IsAlphaMask()) { | |
1210 if (m_pBitmap->GetBPP() == 1) { | |
1211 flags |= FXRC_BITMASK_OUTPUT; | |
1212 } else { | |
1213 flags |= FXRC_BYTEMASK_OUTPUT; | |
1214 } | |
1215 } | |
1216 if (m_pBitmap->IsCmykImage()) { | |
1217 flags |= FXRC_CMYK_OUTPUT; | |
1218 } | |
1219 return flags; | |
1220 } | |
1221 #endif | |
1222 } | 1051 } |
1223 return 0; | 1052 return 0; |
1224 } | 1053 } |
1225 | 1054 |
1226 void CFX_SkiaDeviceDriver::SaveState() { | 1055 void CFX_SkiaDeviceDriver::SaveState() { |
1227 #ifdef _SKIA_SUPPORT_ | |
1228 if (!m_pCache->ClipSave(this)) | 1056 if (!m_pCache->ClipSave(this)) |
1229 m_pCanvas->save(); | 1057 m_pCanvas->save(); |
1230 #else | |
1231 std::unique_ptr<CFX_ClipRgn> pClip; | |
1232 if (m_pClipRgn) | |
1233 pClip = pdfium::MakeUnique<CFX_ClipRgn>(*m_pClipRgn); | |
1234 m_StateStack.push_back(std::move(pClip)); | |
1235 #endif | |
1236 } | 1058 } |
1237 | 1059 |
1238 void CFX_SkiaDeviceDriver::RestoreState(bool bKeepSaved) { | 1060 void CFX_SkiaDeviceDriver::RestoreState(bool bKeepSaved) { |
1239 #ifdef _SKIA_SUPPORT_ | |
1240 if (!m_pCache->ClipRestore(this)) | 1061 if (!m_pCache->ClipRestore(this)) |
1241 m_pCanvas->restore(); | 1062 m_pCanvas->restore(); |
1242 if (bKeepSaved) | 1063 if (bKeepSaved) |
1243 SaveState(); | 1064 SaveState(); |
1244 #else | |
1245 m_pClipRgn.reset(); | |
1246 | |
1247 if (m_StateStack.empty()) | |
1248 return; | |
1249 | |
1250 if (bKeepSaved) { | |
1251 if (m_StateStack.back()) | |
1252 m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>(*m_StateStack.back()); | |
1253 } else { | |
1254 m_pClipRgn = std::move(m_StateStack.back()); | |
1255 m_StateStack.pop_back(); | |
1256 } | |
1257 #endif | |
1258 } | 1065 } |
1259 | 1066 |
1260 #ifndef _SKIA_SUPPORT_ | |
1261 void CFX_SkiaDeviceDriver::SetClipMask(const FX_RECT& clipBox, | |
1262 const SkPath& path) { | |
1263 FX_RECT path_rect(clipBox.left, clipBox.top, clipBox.right + 1, | |
1264 clipBox.bottom + 1); | |
1265 path_rect.Intersect(m_pClipRgn->GetBox()); | |
1266 CFX_DIBitmapRef mask; | |
1267 CFX_DIBitmap* pThisLayer = mask.Emplace(); | |
1268 pThisLayer->Create(path_rect.Width(), path_rect.Height(), FXDIB_8bppMask); | |
1269 pThisLayer->Clear(0); | |
1270 | |
1271 SkImageInfo imageInfo = | |
1272 SkImageInfo::Make(pThisLayer->GetWidth(), pThisLayer->GetHeight(), | |
1273 SkColorType::kAlpha_8_SkColorType, kOpaque_SkAlphaType); | |
1274 SkBitmap bitmap; | |
1275 bitmap.installPixels(imageInfo, pThisLayer->GetBuffer(), | |
1276 pThisLayer->GetPitch(), nullptr, nullptr, nullptr); | |
1277 SkCanvas* canvas = new SkCanvas(bitmap); | |
1278 canvas->translate( | |
1279 clipBox.left, | |
1280 clipBox.top); // FIXME(caryclark) wrong sign(s)? upside down? | |
1281 SkPaint paint; | |
1282 paint.setAntiAlias((m_FillFlags & FXFILL_NOPATHSMOOTH) == 0); | |
1283 canvas->drawPath(path, paint); | |
1284 std::unique_ptr<uint8_t, FxFreeDeleter> raw_buf; | |
1285 raw_buf.reset( | |
1286 FX_Alloc2D(uint8_t, pThisLayer->GetWidth(), pThisLayer->GetHeight())); | |
1287 m_pClipRgn->IntersectMaskF(path_rect.left, path_rect.top, mask); | |
1288 delete canvas; | |
1289 } | |
1290 #endif | |
1291 | |
1292 bool CFX_SkiaDeviceDriver::SetClip_PathFill( | 1067 bool CFX_SkiaDeviceDriver::SetClip_PathFill( |
1293 const CFX_PathData* pPathData, // path info | 1068 const CFX_PathData* pPathData, // path info |
1294 const CFX_Matrix* pObject2Device, // flips object's y-axis | 1069 const CFX_Matrix* pObject2Device, // flips object's y-axis |
1295 int fill_mode // fill mode, WINDING or ALTERNATE | 1070 int fill_mode // fill mode, WINDING or ALTERNATE |
1296 ) { | 1071 ) { |
1297 CFX_Matrix identity; | 1072 CFX_Matrix identity; |
1298 const CFX_Matrix* deviceMatrix = pObject2Device ? pObject2Device : &identity; | 1073 const CFX_Matrix* deviceMatrix = pObject2Device ? pObject2Device : &identity; |
1299 #ifdef _SKIA_SUPPORT_ | |
1300 if (m_pCache->SetClipFill(pPathData, deviceMatrix, fill_mode, this)) | 1074 if (m_pCache->SetClipFill(pPathData, deviceMatrix, fill_mode, this)) |
1301 return true; | 1075 return true; |
1302 #else | |
1303 m_FillFlags = fill_mode; | |
1304 if (!m_pClipRgn) { | |
1305 m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>( | |
1306 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | |
1307 } | |
1308 #endif | |
1309 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { | 1076 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { |
1310 CFX_FloatRect rectf; | 1077 CFX_FloatRect rectf; |
1311 if (pPathData->IsRect(deviceMatrix, &rectf)) { | 1078 if (pPathData->IsRect(deviceMatrix, &rectf)) { |
1312 rectf.Intersect( | 1079 rectf.Intersect( |
1313 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), | 1080 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), |
1314 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); | 1081 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); |
1315 #ifdef _SKIA_SUPPORT_ | |
1316 // note that PDF's y-axis goes up; Skia's y-axis goes down | 1082 // note that PDF's y-axis goes up; Skia's y-axis goes down |
1317 SkRect skClipRect = | 1083 SkRect skClipRect = |
1318 SkRect::MakeLTRB(rectf.left, rectf.bottom, rectf.right, rectf.top); | 1084 SkRect::MakeLTRB(rectf.left, rectf.bottom, rectf.right, rectf.top); |
1319 DebugDrawSkiaClipRect(m_pCanvas, skClipRect); | 1085 DebugDrawSkiaClipRect(m_pCanvas, skClipRect); |
1320 m_pCanvas->clipRect(skClipRect, SkCanvas::kIntersect_Op, true); | 1086 m_pCanvas->clipRect(skClipRect, SkCanvas::kIntersect_Op, true); |
1321 #else | |
1322 FX_RECT rect = rectf.GetOuterRect(); | |
1323 m_pClipRgn->IntersectRect(rect); | |
1324 #endif | |
1325 return true; | 1087 return true; |
1326 } | 1088 } |
1327 } | 1089 } |
1328 SkPath skClipPath = BuildPath(pPathData); | 1090 SkPath skClipPath = BuildPath(pPathData); |
1329 skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE | 1091 skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE |
1330 ? SkPath::kEvenOdd_FillType | 1092 ? SkPath::kEvenOdd_FillType |
1331 : SkPath::kWinding_FillType); | 1093 : SkPath::kWinding_FillType); |
1332 SkMatrix skMatrix = ToSkMatrix(*deviceMatrix); | 1094 SkMatrix skMatrix = ToSkMatrix(*deviceMatrix); |
1333 skClipPath.transform(skMatrix); | 1095 skClipPath.transform(skMatrix); |
1334 DebugShowSkiaPath(skClipPath); | 1096 DebugShowSkiaPath(skClipPath); |
1335 DebugDrawSkiaClipPath(m_pCanvas, skClipPath); | 1097 DebugDrawSkiaClipPath(m_pCanvas, skClipPath); |
1336 m_pCanvas->clipPath(skClipPath, SkCanvas::kIntersect_Op, true); | 1098 m_pCanvas->clipPath(skClipPath, SkCanvas::kIntersect_Op, true); |
1337 #ifndef _SKIA_SUPPORT_ | 1099 |
1338 FX_RECT clipBox(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), | |
1339 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | |
1340 SetClipMask(clipBox, skClipPath); | |
1341 #endif | |
1342 return true; | 1100 return true; |
1343 } | 1101 } |
1344 | 1102 |
1345 bool CFX_SkiaDeviceDriver::SetClip_PathStroke( | 1103 bool CFX_SkiaDeviceDriver::SetClip_PathStroke( |
1346 const CFX_PathData* pPathData, // path info | 1104 const CFX_PathData* pPathData, // path info |
1347 const CFX_Matrix* pObject2Device, // optional transformation | 1105 const CFX_Matrix* pObject2Device, // optional transformation |
1348 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes | 1106 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes |
1349 ) { | 1107 ) { |
1350 #ifdef _SKIA_SUPPORT_ | |
1351 if (m_pCache->SetClipStroke(pPathData, pObject2Device, pGraphState, this)) | 1108 if (m_pCache->SetClipStroke(pPathData, pObject2Device, pGraphState, this)) |
1352 return true; | 1109 return true; |
1353 #else | |
1354 if (!m_pClipRgn) { | |
1355 m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>( | |
1356 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | |
1357 } | |
1358 #endif | |
1359 // build path data | 1110 // build path data |
1360 SkPath skPath = BuildPath(pPathData); | 1111 SkPath skPath = BuildPath(pPathData); |
1361 SkMatrix skMatrix = ToSkMatrix(*pObject2Device); | 1112 SkMatrix skMatrix = ToSkMatrix(*pObject2Device); |
1362 SkPaint skPaint; | 1113 SkPaint skPaint; |
1363 PaintStroke(&skPaint, pGraphState, skMatrix); | 1114 PaintStroke(&skPaint, pGraphState, skMatrix); |
1364 SkPath dst_path; | 1115 SkPath dst_path; |
1365 skPaint.getFillPath(skPath, &dst_path); | 1116 skPaint.getFillPath(skPath, &dst_path); |
1366 dst_path.transform(skMatrix); | 1117 dst_path.transform(skMatrix); |
1367 DebugDrawSkiaClipPath(m_pCanvas, dst_path); | 1118 DebugDrawSkiaClipPath(m_pCanvas, dst_path); |
1368 #ifdef _SKIA_SUPPORT_ | |
1369 m_pCanvas->clipPath(dst_path, SkCanvas::kIntersect_Op, true); | 1119 m_pCanvas->clipPath(dst_path, SkCanvas::kIntersect_Op, true); |
1370 #else | |
1371 FX_RECT clipBox(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), | |
1372 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | |
1373 SetClipMask(clipBox, dst_path); | |
1374 #endif | |
1375 return true; | 1120 return true; |
1376 } | 1121 } |
1377 | 1122 |
1378 bool CFX_SkiaDeviceDriver::DrawPath( | 1123 bool CFX_SkiaDeviceDriver::DrawPath( |
1379 const CFX_PathData* pPathData, // path info | 1124 const CFX_PathData* pPathData, // path info |
1380 const CFX_Matrix* pObject2Device, // optional transformation | 1125 const CFX_Matrix* pObject2Device, // optional transformation |
1381 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes | 1126 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes |
1382 uint32_t fill_color, // fill color | 1127 uint32_t fill_color, // fill color |
1383 uint32_t stroke_color, // stroke color | 1128 uint32_t stroke_color, // stroke color |
1384 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled | 1129 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled |
1385 int blend_type) { | 1130 int blend_type) { |
1386 if (m_pCache->DrawPath(pPathData, pObject2Device, pGraphState, fill_color, | 1131 if (m_pCache->DrawPath(pPathData, pObject2Device, pGraphState, fill_color, |
1387 stroke_color, fill_mode, blend_type, this)) { | 1132 stroke_color, fill_mode, blend_type, this)) { |
1388 return true; | 1133 return true; |
1389 } | 1134 } |
1390 SkIRect rect; | 1135 SkIRect rect; |
1391 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), | 1136 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), |
1392 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); | 1137 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); |
1393 SkMatrix skMatrix; | 1138 SkMatrix skMatrix; |
1394 if (pObject2Device) | 1139 if (pObject2Device) |
1395 skMatrix = ToSkMatrix(*pObject2Device); | 1140 skMatrix = ToSkMatrix(*pObject2Device); |
1396 else | 1141 else |
1397 skMatrix.setIdentity(); | 1142 skMatrix.setIdentity(); |
1398 SkPaint skPaint; | 1143 SkPaint skPaint; |
1399 skPaint.setAntiAlias(true); | 1144 skPaint.setAntiAlias(true); |
1400 if (fill_mode & FXFILL_FULLCOVER) | |
1401 skPaint.setBlendMode(SkBlendMode::kPlus); | |
1402 int stroke_alpha = FXARGB_A(stroke_color); | 1145 int stroke_alpha = FXARGB_A(stroke_color); |
1403 if (pGraphState && stroke_alpha) | 1146 if (pGraphState && stroke_alpha) |
1404 PaintStroke(&skPaint, pGraphState, skMatrix); | 1147 PaintStroke(&skPaint, pGraphState, skMatrix); |
1405 SkPath skPath = BuildPath(pPathData); | 1148 SkPath skPath = BuildPath(pPathData); |
1406 m_pCanvas->save(); | 1149 m_pCanvas->save(); |
1407 m_pCanvas->concat(skMatrix); | 1150 m_pCanvas->concat(skMatrix); |
1408 if ((fill_mode & 3) && fill_color) { | 1151 if ((fill_mode & 3) && fill_color) { |
1409 skPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE | 1152 skPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE |
1410 ? SkPath::kEvenOdd_FillType | 1153 ? SkPath::kEvenOdd_FillType |
1411 : SkPath::kWinding_FillType); | 1154 : SkPath::kWinding_FillType); |
1412 SkPath strokePath; | 1155 SkPath strokePath; |
1413 const SkPath* fillPath = &skPath; | 1156 const SkPath* fillPath = &skPath; |
1414 if (pGraphState && stroke_alpha) { | 1157 if (pGraphState && stroke_alpha) { |
1415 if (m_bGroupKnockout) { | 1158 SkAlpha fillA = SkColorGetA(fill_color); |
| 1159 SkAlpha strokeA = SkColorGetA(stroke_color); |
| 1160 if (fillA && fillA < 0xFF && strokeA && strokeA < 0xFF) { |
1416 skPaint.getFillPath(skPath, &strokePath); | 1161 skPaint.getFillPath(skPath, &strokePath); |
1417 if (Op(skPath, strokePath, SkPathOp::kDifference_SkPathOp, | 1162 if (Op(skPath, strokePath, SkPathOp::kDifference_SkPathOp, |
1418 &strokePath)) { | 1163 &strokePath)) { |
1419 fillPath = &strokePath; | 1164 fillPath = &strokePath; |
1420 } | 1165 } |
1421 } | 1166 } |
1422 } | 1167 } |
1423 skPaint.setStyle(SkPaint::kFill_Style); | 1168 skPaint.setStyle(SkPaint::kFill_Style); |
1424 skPaint.setColor(fill_color); | 1169 skPaint.setColor(fill_color); |
1425 m_pCanvas->drawPath(*fillPath, skPaint); | 1170 m_pCanvas->drawPath(*fillPath, skPaint); |
(...skipping 25 matching lines...) Expand all Loading... |
1451 spaint.setAntiAlias(true); | 1196 spaint.setAntiAlias(true); |
1452 spaint.setColor(fill_color); | 1197 spaint.setColor(fill_color); |
1453 spaint.setBlendMode(GetSkiaBlendMode(blend_type)); | 1198 spaint.setBlendMode(GetSkiaBlendMode(blend_type)); |
1454 | 1199 |
1455 m_pCanvas->drawRect( | 1200 m_pCanvas->drawRect( |
1456 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), | 1201 SkRect::MakeLTRB(pRect->left, pRect->top, pRect->right, pRect->bottom), |
1457 spaint); | 1202 spaint); |
1458 return true; | 1203 return true; |
1459 } | 1204 } |
1460 | 1205 |
1461 #ifdef _SKIA_SUPPORT_ | |
1462 bool CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern, | 1206 bool CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern, |
1463 const CFX_Matrix* pMatrix, | 1207 const CFX_Matrix* pMatrix, |
1464 const FX_RECT& clip_rect, | 1208 const FX_RECT& clip_rect, |
1465 int alpha, | 1209 int alpha, |
1466 bool bAlphaMode) { | 1210 bool bAlphaMode) { |
1467 if (kAxialShading != pPattern->GetShadingType() && | 1211 if (kAxialShading != pPattern->GetShadingType() && |
1468 kRadialShading != pPattern->GetShadingType()) { | 1212 kRadialShading != pPattern->GetShadingType()) { |
1469 // TODO(caryclark) more types | 1213 // TODO(caryclark) more types |
1470 return false; | 1214 return false; |
1471 } | 1215 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1585 skPath.transform(inverse); | 1329 skPath.transform(inverse); |
1586 } | 1330 } |
1587 m_pCanvas->save(); | 1331 m_pCanvas->save(); |
1588 if (!skClip.isEmpty()) | 1332 if (!skClip.isEmpty()) |
1589 m_pCanvas->clipPath(skClip, SkCanvas::kIntersect_Op, true); | 1333 m_pCanvas->clipPath(skClip, SkCanvas::kIntersect_Op, true); |
1590 m_pCanvas->concat(skMatrix); | 1334 m_pCanvas->concat(skMatrix); |
1591 m_pCanvas->drawPath(skPath, paint); | 1335 m_pCanvas->drawPath(skPath, paint); |
1592 m_pCanvas->restore(); | 1336 m_pCanvas->restore(); |
1593 return true; | 1337 return true; |
1594 } | 1338 } |
1595 #endif | |
1596 | 1339 |
1597 uint8_t* CFX_SkiaDeviceDriver::GetBuffer() const { | 1340 uint8_t* CFX_SkiaDeviceDriver::GetBuffer() const { |
1598 return m_pBitmap->GetBuffer(); | 1341 return m_pBitmap->GetBuffer(); |
1599 } | 1342 } |
1600 | 1343 |
1601 bool CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { | 1344 bool CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect) { |
1602 // TODO(caryclark) call m_canvas->getClipDeviceBounds() instead | 1345 // TODO(caryclark) call m_canvas->getClipDeviceBounds() instead |
1603 pRect->left = 0; | 1346 pRect->left = 0; |
1604 pRect->top = 0; | 1347 pRect->top = 0; |
1605 const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); | 1348 const SkImageInfo& canvasSize = m_pCanvas->imageInfo(); |
1606 pRect->right = canvasSize.width(); | 1349 pRect->right = canvasSize.width(); |
1607 pRect->bottom = canvasSize.height(); | 1350 pRect->bottom = canvasSize.height(); |
1608 return true; | 1351 return true; |
1609 } | 1352 } |
1610 | 1353 |
1611 bool CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) { | 1354 bool CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) { |
1612 if (!m_pBitmap) | 1355 if (!m_pBitmap) |
1613 return true; | 1356 return true; |
1614 uint8_t* srcBuffer = m_pBitmap->GetBuffer(); | 1357 uint8_t* srcBuffer = m_pBitmap->GetBuffer(); |
1615 if (!srcBuffer) | 1358 if (!srcBuffer) |
1616 return true; | 1359 return true; |
1617 #ifdef _SKIA_SUPPORT_ | |
1618 int srcWidth = m_pBitmap->GetWidth(); | 1360 int srcWidth = m_pBitmap->GetWidth(); |
1619 int srcHeight = m_pBitmap->GetHeight(); | 1361 int srcHeight = m_pBitmap->GetHeight(); |
1620 int srcRowBytes = srcWidth * sizeof(uint32_t); | 1362 int srcRowBytes = srcWidth * sizeof(uint32_t); |
1621 SkImageInfo srcImageInfo = SkImageInfo::Make( | 1363 SkImageInfo srcImageInfo = SkImageInfo::Make( |
1622 srcWidth, srcHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); | 1364 srcWidth, srcHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); |
1623 SkBitmap skSrcBitmap; | 1365 SkBitmap skSrcBitmap; |
1624 skSrcBitmap.installPixels(srcImageInfo, srcBuffer, srcRowBytes, nullptr, | 1366 skSrcBitmap.installPixels(srcImageInfo, srcBuffer, srcRowBytes, nullptr, |
1625 nullptr, nullptr); | 1367 nullptr, nullptr); |
1626 SkASSERT(pBitmap); | 1368 SkASSERT(pBitmap); |
1627 uint8_t* dstBuffer = pBitmap->GetBuffer(); | 1369 uint8_t* dstBuffer = pBitmap->GetBuffer(); |
1628 SkASSERT(dstBuffer); | 1370 SkASSERT(dstBuffer); |
1629 int dstWidth = pBitmap->GetWidth(); | 1371 int dstWidth = pBitmap->GetWidth(); |
1630 int dstHeight = pBitmap->GetHeight(); | 1372 int dstHeight = pBitmap->GetHeight(); |
1631 int dstRowBytes = dstWidth * sizeof(uint32_t); | 1373 int dstRowBytes = dstWidth * sizeof(uint32_t); |
1632 SkImageInfo dstImageInfo = SkImageInfo::Make( | 1374 SkImageInfo dstImageInfo = SkImageInfo::Make( |
1633 dstWidth, dstHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); | 1375 dstWidth, dstHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); |
1634 SkBitmap skDstBitmap; | 1376 SkBitmap skDstBitmap; |
1635 skDstBitmap.installPixels(dstImageInfo, dstBuffer, dstRowBytes, nullptr, | 1377 skDstBitmap.installPixels(dstImageInfo, dstBuffer, dstRowBytes, nullptr, |
1636 nullptr, nullptr); | 1378 nullptr, nullptr); |
1637 SkCanvas canvas(skDstBitmap); | 1379 SkCanvas canvas(skDstBitmap); |
1638 canvas.drawBitmap(skSrcBitmap, left, top, nullptr); | 1380 canvas.drawBitmap(skSrcBitmap, left, top, nullptr); |
1639 return true; | 1381 return true; |
1640 #else | |
1641 FX_RECT rect(left, top, left + pBitmap->GetWidth(), | |
1642 top + pBitmap->GetHeight()); | |
1643 CFX_DIBitmap* pBack = nullptr; | |
1644 if (m_pOriDevice) { | |
1645 pBack = m_pOriDevice->Clone(&rect); | |
1646 if (!pBack) | |
1647 return true; | |
1648 | |
1649 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(), | |
1650 m_pBitmap, 0, 0); | |
1651 } else { | |
1652 pBack = m_pBitmap->Clone(&rect); | |
1653 if (!pBack) | |
1654 return true; | |
1655 } | |
1656 | |
1657 bool bRet = true; | |
1658 left = std::min(left, 0); | |
1659 top = std::min(top, 0); | |
1660 if (m_bRgbByteOrder) { | |
1661 RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(), | |
1662 pBack, left, top); | |
1663 } else { | |
1664 bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, | |
1665 left, top); | |
1666 } | |
1667 delete pBack; | |
1668 return bRet; | |
1669 #endif | |
1670 } | 1382 } |
1671 | 1383 |
1672 CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() { | 1384 CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() { |
1673 return m_pOriDevice; | 1385 return m_pOriDevice; |
1674 } | 1386 } |
1675 | 1387 |
1676 bool CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, | 1388 bool CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, |
1677 uint32_t argb, | 1389 uint32_t argb, |
1678 const FX_RECT* pSrcRect, | 1390 const FX_RECT* pSrcRect, |
1679 int left, | 1391 int left, |
1680 int top, | 1392 int top, |
1681 int blend_type) { | 1393 int blend_type) { |
1682 if (!m_pBitmap || !m_pBitmap->GetBuffer()) | 1394 if (!m_pBitmap || !m_pBitmap->GetBuffer()) |
1683 return true; | 1395 return true; |
1684 | 1396 |
1685 #ifdef _SKIA_SUPPORT_ | |
1686 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), left, | 1397 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), left, |
1687 top + pBitmap->GetHeight()); | 1398 top + pBitmap->GetHeight()); |
1688 void* dummy; | 1399 void* dummy; |
1689 return StartDIBits(pBitmap, 0xFF, argb, &m, 0, dummy, blend_type); | 1400 return StartDIBits(pBitmap, 0xFF, argb, &m, 0, dummy, blend_type); |
1690 #else | |
1691 if (pBitmap->IsAlphaMask()) { | |
1692 return m_pBitmap->CompositeMask( | |
1693 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, argb, | |
1694 pSrcRect->left, pSrcRect->top, blend_type, m_pClipRgn.get(), | |
1695 m_bRgbByteOrder, 0, nullptr); | |
1696 } | |
1697 return m_pBitmap->CompositeBitmap( | |
1698 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, pSrcRect->left, | |
1699 pSrcRect->top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder, nullptr); | |
1700 #endif | |
1701 } | 1401 } |
1702 | 1402 |
1703 bool CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, | 1403 bool CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, |
1704 uint32_t argb, | 1404 uint32_t argb, |
1705 int dest_left, | 1405 int dest_left, |
1706 int dest_top, | 1406 int dest_top, |
1707 int dest_width, | 1407 int dest_width, |
1708 int dest_height, | 1408 int dest_height, |
1709 const FX_RECT* pClipRect, | 1409 const FX_RECT* pClipRect, |
1710 uint32_t flags, | 1410 uint32_t flags, |
1711 int blend_type) { | 1411 int blend_type) { |
1712 #ifdef _SKIA_SUPPORT_ | |
1713 if (!m_pBitmap->GetBuffer()) | 1412 if (!m_pBitmap->GetBuffer()) |
1714 return true; | 1413 return true; |
1715 CFX_Matrix m(dest_width, 0, 0, -dest_height, dest_left, | 1414 CFX_Matrix m(dest_width, 0, 0, -dest_height, dest_left, |
1716 dest_top + dest_height); | 1415 dest_top + dest_height); |
1717 | 1416 |
1718 m_pCanvas->save(); | 1417 m_pCanvas->save(); |
1719 SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom, | 1418 SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom, |
1720 pClipRect->right, pClipRect->top); | 1419 pClipRect->right, pClipRect->top); |
1721 m_pCanvas->clipRect(skClipRect, SkCanvas::kIntersect_Op, true); | 1420 m_pCanvas->clipRect(skClipRect, SkCanvas::kIntersect_Op, true); |
1722 void* dummy; | 1421 void* dummy; |
1723 bool result = StartDIBits(pSource, 0xFF, argb, &m, 0, dummy, blend_type); | 1422 bool result = StartDIBits(pSource, 0xFF, argb, &m, 0, dummy, blend_type); |
1724 m_pCanvas->restore(); | 1423 m_pCanvas->restore(); |
1725 | 1424 |
1726 return result; | 1425 return result; |
1727 #else | |
1728 if (dest_width == pSource->GetWidth() && | |
1729 dest_height == pSource->GetHeight()) { | |
1730 FX_RECT rect(0, 0, dest_width, dest_height); | |
1731 return SetDIBits(pSource, argb, &rect, dest_left, dest_top, blend_type); | |
1732 } | |
1733 FX_RECT dest_rect(dest_left, dest_top, dest_left + dest_width, | |
1734 dest_top + dest_height); | |
1735 dest_rect.Normalize(); | |
1736 FX_RECT dest_clip = dest_rect; | |
1737 dest_clip.Intersect(*pClipRect); | |
1738 CFX_BitmapComposer composer; | |
1739 composer.Compose(m_pBitmap, m_pClipRgn.get(), 255, argb, dest_clip, false, | |
1740 false, false, m_bRgbByteOrder, 0, nullptr, blend_type); | |
1741 dest_clip.Offset(-dest_rect.left, -dest_rect.top); | |
1742 CFX_ImageStretcher stretcher(&composer, pSource, dest_width, dest_height, | |
1743 dest_clip, flags); | |
1744 if (stretcher.Start()) | |
1745 stretcher.Continue(nullptr); | |
1746 return true; | |
1747 #endif | |
1748 } | 1426 } |
1749 | 1427 |
1750 bool CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, | 1428 bool CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, |
1751 int bitmap_alpha, | 1429 int bitmap_alpha, |
1752 uint32_t argb, | 1430 uint32_t argb, |
1753 const CFX_Matrix* pMatrix, | 1431 const CFX_Matrix* pMatrix, |
1754 uint32_t render_flags, | 1432 uint32_t render_flags, |
1755 void*& handle, | 1433 void*& handle, |
1756 int blend_type) { | 1434 int blend_type) { |
1757 #ifdef _SKIA_SUPPORT_ | |
1758 DebugValidate(m_pBitmap, m_pOriDevice); | 1435 DebugValidate(m_pBitmap, m_pOriDevice); |
1759 SkColorTable* ct = nullptr; | 1436 SkColorTable* ct = nullptr; |
1760 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; | 1437 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; |
1761 std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage; | 1438 std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage; |
1762 SkBitmap skBitmap; | 1439 SkBitmap skBitmap; |
1763 int width, height; | 1440 int width, height; |
1764 if (!Upsample(pSource, dst8Storage, dst32Storage, &ct, &skBitmap, &width, | 1441 if (!Upsample(pSource, dst8Storage, dst32Storage, &ct, &skBitmap, &width, |
1765 &height, false)) { | 1442 &height, false)) { |
1766 return false; | 1443 return false; |
1767 } | 1444 } |
(...skipping 18 matching lines...) Expand all Loading... |
1786 m_pBitmap->SetPixel(x, y, skBitmap.getColor(src.fX, src.fY)); | 1463 m_pBitmap->SetPixel(x, y, skBitmap.getColor(src.fX, src.fY)); |
1787 } | 1464 } |
1788 } | 1465 } |
1789 } else { | 1466 } else { |
1790 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); | 1467 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); |
1791 } | 1468 } |
1792 m_pCanvas->restore(); | 1469 m_pCanvas->restore(); |
1793 if (ct) | 1470 if (ct) |
1794 ct->unref(); | 1471 ct->unref(); |
1795 DebugValidate(m_pBitmap, m_pOriDevice); | 1472 DebugValidate(m_pBitmap, m_pOriDevice); |
1796 #else | |
1797 if (!m_pBitmap->GetBuffer()) | |
1798 return true; | |
1799 | |
1800 CFX_ImageRenderer* pRenderer = new CFX_ImageRenderer; | |
1801 pRenderer->Start(m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb, | |
1802 pMatrix, render_flags, m_bRgbByteOrder, 0, nullptr); | |
1803 handle = pRenderer; | |
1804 #endif | |
1805 return true; | 1473 return true; |
1806 } | 1474 } |
1807 | 1475 |
1808 bool CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { | 1476 bool CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { |
1809 #ifdef _SKIA_SUPPORT_ | |
1810 return false; | 1477 return false; |
1811 #else | |
1812 if (!m_pBitmap->GetBuffer()) { | |
1813 return true; | |
1814 } | |
1815 return static_cast<CFX_ImageRenderer*>(handle)->Continue(pPause); | |
1816 #endif | |
1817 } | 1478 } |
1818 | 1479 |
1819 #ifdef _SKIA_SUPPORT_ | |
1820 void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) { | 1480 void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) { |
1821 void* buffer = pDIBitmap->GetBuffer(); | 1481 void* buffer = pDIBitmap->GetBuffer(); |
1822 if (!buffer) | 1482 if (!buffer) |
1823 return; | 1483 return; |
1824 if (pDIBitmap->GetBPP() != 32) { | 1484 if (pDIBitmap->GetBPP() != 32) { |
1825 return; | 1485 return; |
1826 } | 1486 } |
1827 int height = pDIBitmap->GetHeight(); | 1487 int height = pDIBitmap->GetHeight(); |
1828 int width = pDIBitmap->GetWidth(); | 1488 int width = pDIBitmap->GetWidth(); |
1829 int rowBytes = pDIBitmap->GetPitch(); | 1489 int rowBytes = pDIBitmap->GetPitch(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 if (!m_pBitmap || !m_pBitmap->GetBuffer()) | 1550 if (!m_pBitmap || !m_pBitmap->GetBuffer()) |
1891 return true; | 1551 return true; |
1892 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), dest_left, | 1552 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), dest_left, |
1893 dest_top + pBitmap->GetHeight()); | 1553 dest_top + pBitmap->GetHeight()); |
1894 return DrawBitsWithMask(pBitmap, pMask, bitmap_alpha, &m, blend_type); | 1554 return DrawBitsWithMask(pBitmap, pMask, bitmap_alpha, &m, blend_type); |
1895 } | 1555 } |
1896 | 1556 |
1897 void CFX_SkiaDeviceDriver::Clear(uint32_t color) { | 1557 void CFX_SkiaDeviceDriver::Clear(uint32_t color) { |
1898 m_pCanvas->clear(color); | 1558 m_pCanvas->clear(color); |
1899 } | 1559 } |
1900 #endif | |
1901 | 1560 |
1902 void CFX_SkiaDeviceDriver::Dump() const { | 1561 void CFX_SkiaDeviceDriver::Dump() const { |
1903 #ifdef SK_DEBUG | 1562 #ifdef SK_DEBUG |
1904 if (m_pCache) | 1563 if (m_pCache) |
1905 m_pCache->Dump(this); | 1564 m_pCache->Dump(this); |
1906 #endif | 1565 #endif |
1907 } | 1566 } |
1908 | 1567 |
1909 #ifdef _SKIA_SUPPORT_ | |
1910 void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const { | 1568 void CFX_SkiaDeviceDriver::DebugVerifyBitmapIsPreMultiplied() const { |
1911 if (m_pOriDevice) | 1569 if (m_pOriDevice) |
1912 m_pOriDevice->DebugVerifyBitmapIsPreMultiplied(); | 1570 m_pOriDevice->DebugVerifyBitmapIsPreMultiplied(); |
1913 } | 1571 } |
1914 #endif | |
1915 | 1572 |
1916 CFX_FxgeDevice::CFX_FxgeDevice() { | 1573 CFX_FxgeDevice::CFX_FxgeDevice() { |
1917 #ifdef _SKIA_SUPPORT_ | |
1918 m_bOwnedBitmap = false; | 1574 m_bOwnedBitmap = false; |
1919 #endif | |
1920 } | 1575 } |
1921 | 1576 |
1922 #ifdef _SKIA_SUPPORT_ | |
1923 void CFX_FxgeDevice::Clear(uint32_t color) { | 1577 void CFX_FxgeDevice::Clear(uint32_t color) { |
1924 CFX_SkiaDeviceDriver* skDriver = | 1578 CFX_SkiaDeviceDriver* skDriver = |
1925 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); | 1579 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); |
1926 skDriver->Clear(color); | 1580 skDriver->Clear(color); |
1927 } | 1581 } |
1928 | 1582 |
1929 SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) { | 1583 SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) { |
1930 CFX_SkiaDeviceDriver* skDriver = new CFX_SkiaDeviceDriver(size_x, size_y); | 1584 CFX_SkiaDeviceDriver* skDriver = new CFX_SkiaDeviceDriver(size_x, size_y); |
1931 SetDeviceDriver(pdfium::WrapUnique(skDriver)); | 1585 SetDeviceDriver(pdfium::WrapUnique(skDriver)); |
1932 return skDriver->GetRecorder(); | 1586 return skDriver->GetRecorder(); |
1933 } | 1587 } |
1934 #endif | |
1935 | 1588 |
1936 bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, | 1589 bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, |
1937 bool bRgbByteOrder, | 1590 bool bRgbByteOrder, |
1938 CFX_DIBitmap* pOriDevice, | 1591 CFX_DIBitmap* pOriDevice, |
1939 bool bGroupKnockout) { | 1592 bool bGroupKnockout) { |
1940 if (!pBitmap) | 1593 if (!pBitmap) |
1941 return false; | 1594 return false; |
1942 SetBitmap(pBitmap); | 1595 SetBitmap(pBitmap); |
1943 SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>( | 1596 SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>( |
1944 pBitmap, bRgbByteOrder, pOriDevice, bGroupKnockout)); | 1597 pBitmap, bRgbByteOrder, pOriDevice, bGroupKnockout)); |
1945 return true; | 1598 return true; |
1946 } | 1599 } |
1947 | 1600 |
1948 #ifdef _SKIA_SUPPORT_ | |
1949 bool CFX_FxgeDevice::AttachRecorder(SkPictureRecorder* recorder) { | 1601 bool CFX_FxgeDevice::AttachRecorder(SkPictureRecorder* recorder) { |
1950 if (!recorder) | 1602 if (!recorder) |
1951 return false; | 1603 return false; |
1952 SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>(recorder)); | 1604 SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>(recorder)); |
1953 return true; | 1605 return true; |
1954 } | 1606 } |
1955 #endif | |
1956 | 1607 |
1957 bool CFX_FxgeDevice::Create(int width, | 1608 bool CFX_FxgeDevice::Create(int width, |
1958 int height, | 1609 int height, |
1959 FXDIB_Format format, | 1610 FXDIB_Format format, |
1960 CFX_DIBitmap* pOriDevice) { | 1611 CFX_DIBitmap* pOriDevice) { |
1961 m_bOwnedBitmap = true; | 1612 m_bOwnedBitmap = true; |
1962 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; | 1613 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; |
1963 if (!pBitmap->Create(width, height, format)) { | 1614 if (!pBitmap->Create(width, height, format)) { |
1964 delete pBitmap; | 1615 delete pBitmap; |
1965 return false; | 1616 return false; |
1966 } | 1617 } |
1967 SetBitmap(pBitmap); | 1618 SetBitmap(pBitmap); |
1968 SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>(pBitmap, false, | 1619 SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>(pBitmap, false, |
1969 pOriDevice, false)); | 1620 pOriDevice, false)); |
1970 return true; | 1621 return true; |
1971 } | 1622 } |
1972 | 1623 |
1973 CFX_FxgeDevice::~CFX_FxgeDevice() { | 1624 CFX_FxgeDevice::~CFX_FxgeDevice() { |
1974 #ifdef _SKIA_SUPPORT_ | |
1975 Flush(); | 1625 Flush(); |
1976 // call destructor of CFX_RenderDevice / CFX_SkiaDeviceDriver immediately | 1626 // call destructor of CFX_RenderDevice / CFX_SkiaDeviceDriver immediately |
1977 if (m_bOwnedBitmap && GetBitmap()) | 1627 if (m_bOwnedBitmap && GetBitmap()) |
1978 delete GetBitmap(); | 1628 delete GetBitmap(); |
1979 #endif | |
1980 } | 1629 } |
1981 | 1630 |
1982 #ifdef _SKIA_SUPPORT_ | |
1983 void CFX_FxgeDevice::DebugVerifyBitmapIsPreMultiplied() const { | 1631 void CFX_FxgeDevice::DebugVerifyBitmapIsPreMultiplied() const { |
1984 #ifdef SK_DEBUG | 1632 #ifdef SK_DEBUG |
1985 CFX_SkiaDeviceDriver* skDriver = | 1633 CFX_SkiaDeviceDriver* skDriver = |
1986 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); | 1634 static_cast<CFX_SkiaDeviceDriver*>(GetDeviceDriver()); |
1987 if (skDriver) | 1635 if (skDriver) |
1988 skDriver->DebugVerifyBitmapIsPreMultiplied(); | 1636 skDriver->DebugVerifyBitmapIsPreMultiplied(); |
1989 #endif | 1637 #endif |
1990 } | 1638 } |
1991 | 1639 |
1992 bool CFX_FxgeDevice::SetBitsWithMask(const CFX_DIBSource* pBitmap, | 1640 bool CFX_FxgeDevice::SetBitsWithMask(const CFX_DIBSource* pBitmap, |
(...skipping 25 matching lines...) Expand all Loading... |
2018 uint8_t g = SkGetPackedG32(srcRow[x]); | 1666 uint8_t g = SkGetPackedG32(srcRow[x]); |
2019 uint8_t b = SkGetPackedB32(srcRow[x]); | 1667 uint8_t b = SkGetPackedB32(srcRow[x]); |
2020 SkA32Assert(a); | 1668 SkA32Assert(a); |
2021 SkASSERT(r <= a); | 1669 SkASSERT(r <= a); |
2022 SkASSERT(g <= a); | 1670 SkASSERT(g <= a); |
2023 SkASSERT(b <= a); | 1671 SkASSERT(b <= a); |
2024 } | 1672 } |
2025 } | 1673 } |
2026 #endif | 1674 #endif |
2027 } | 1675 } |
2028 #endif | |
2029 | |
2030 #ifndef _SKIA_SUPPORT_ | |
2031 class CFX_Renderer { | |
2032 private: | |
2033 int m_Alpha, m_Red, m_Green, m_Blue, m_Gray; | |
2034 uint32_t m_Color; | |
2035 bool m_bFullCover; | |
2036 bool m_bRgbByteOrder; | |
2037 CFX_DIBitmap* m_pOriDevice; | |
2038 FX_RECT m_ClipBox; | |
2039 const CFX_DIBitmap* m_pClipMask; | |
2040 CFX_DIBitmap* m_pDevice; | |
2041 const CFX_ClipRgn* m_pClipRgn; | |
2042 void (CFX_Renderer::*composite_span)(uint8_t*, | |
2043 int, | |
2044 int, | |
2045 int, | |
2046 uint8_t*, | |
2047 int, | |
2048 int, | |
2049 uint8_t*, | |
2050 uint8_t*); | |
2051 | |
2052 public: | |
2053 void prepare(unsigned) {} | |
2054 | |
2055 void CompositeSpan(uint8_t* dest_scan, | |
2056 uint8_t* ori_scan, | |
2057 int Bpp, | |
2058 bool bDestAlpha, | |
2059 int span_left, | |
2060 int span_len, | |
2061 uint8_t* cover_scan, | |
2062 int clip_left, | |
2063 int clip_right, | |
2064 uint8_t* clip_scan) { | |
2065 ASSERT(!m_pDevice->IsCmykImage()); | |
2066 int col_start = span_left < clip_left ? clip_left - span_left : 0; | |
2067 int col_end = (span_left + span_len) < clip_right | |
2068 ? span_len | |
2069 : (clip_right - span_left); | |
2070 if (Bpp) { | |
2071 dest_scan += col_start * Bpp; | |
2072 ori_scan += col_start * Bpp; | |
2073 } else { | |
2074 dest_scan += col_start / 8; | |
2075 ori_scan += col_start / 8; | |
2076 } | |
2077 if (m_bRgbByteOrder) { | |
2078 if (Bpp == 4 && bDestAlpha) { | |
2079 for (int col = col_start; col < col_end; col++) { | |
2080 int src_alpha; | |
2081 if (clip_scan) { | |
2082 src_alpha = m_Alpha * clip_scan[col] / 255; | |
2083 } else { | |
2084 src_alpha = m_Alpha; | |
2085 } | |
2086 uint8_t dest_alpha = | |
2087 ori_scan[3] + src_alpha - ori_scan[3] * src_alpha / 255; | |
2088 dest_scan[3] = dest_alpha; | |
2089 int alpha_ratio = src_alpha * 255 / dest_alpha; | |
2090 if (m_bFullCover) { | |
2091 *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Red, alpha_ratio); | |
2092 *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, alpha_ratio); | |
2093 *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, alpha_ratio); | |
2094 dest_scan++; | |
2095 ori_scan++; | |
2096 } else { | |
2097 int r = FXDIB_ALPHA_MERGE(*ori_scan++, m_Red, alpha_ratio); | |
2098 int g = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, alpha_ratio); | |
2099 int b = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, alpha_ratio); | |
2100 ori_scan++; | |
2101 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, r, cover_scan[col]); | |
2102 dest_scan++; | |
2103 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, g, cover_scan[col]); | |
2104 dest_scan++; | |
2105 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, b, cover_scan[col]); | |
2106 dest_scan += 2; | |
2107 } | |
2108 } | |
2109 return; | |
2110 } | |
2111 if (Bpp == 3 || Bpp == 4) { | |
2112 for (int col = col_start; col < col_end; col++) { | |
2113 int src_alpha; | |
2114 if (clip_scan) { | |
2115 src_alpha = m_Alpha * clip_scan[col] / 255; | |
2116 } else { | |
2117 src_alpha = m_Alpha; | |
2118 } | |
2119 int r = FXDIB_ALPHA_MERGE(*ori_scan++, m_Red, src_alpha); | |
2120 int g = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, src_alpha); | |
2121 int b = FXDIB_ALPHA_MERGE(*ori_scan, m_Blue, src_alpha); | |
2122 ori_scan += Bpp - 2; | |
2123 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, r, cover_scan[col]); | |
2124 dest_scan++; | |
2125 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, g, cover_scan[col]); | |
2126 dest_scan++; | |
2127 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, b, cover_scan[col]); | |
2128 dest_scan += Bpp - 2; | |
2129 } | |
2130 } | |
2131 return; | |
2132 } | |
2133 if (Bpp == 4 && bDestAlpha) { | |
2134 for (int col = col_start; col < col_end; col++) { | |
2135 int src_alpha; | |
2136 if (clip_scan) { | |
2137 src_alpha = m_Alpha * clip_scan[col] / 255; | |
2138 } else { | |
2139 src_alpha = m_Alpha; | |
2140 } | |
2141 int src_alpha_covered = src_alpha * cover_scan[col] / 255; | |
2142 if (src_alpha_covered == 0) { | |
2143 dest_scan += 4; | |
2144 continue; | |
2145 } | |
2146 if (cover_scan[col] == 255) { | |
2147 dest_scan[3] = src_alpha_covered; | |
2148 *dest_scan++ = m_Blue; | |
2149 *dest_scan++ = m_Green; | |
2150 *dest_scan = m_Red; | |
2151 dest_scan += 2; | |
2152 continue; | |
2153 } else { | |
2154 if (dest_scan[3] == 0) { | |
2155 dest_scan[3] = src_alpha_covered; | |
2156 *dest_scan++ = m_Blue; | |
2157 *dest_scan++ = m_Green; | |
2158 *dest_scan = m_Red; | |
2159 dest_scan += 2; | |
2160 continue; | |
2161 } | |
2162 uint8_t cover = cover_scan[col]; | |
2163 dest_scan[3] = FXDIB_ALPHA_MERGE(dest_scan[3], src_alpha, cover); | |
2164 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, cover); | |
2165 dest_scan++; | |
2166 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, cover); | |
2167 dest_scan++; | |
2168 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, cover); | |
2169 dest_scan += 2; | |
2170 } | |
2171 } | |
2172 return; | |
2173 } | |
2174 if (Bpp == 3 || Bpp == 4) { | |
2175 for (int col = col_start; col < col_end; col++) { | |
2176 int src_alpha; | |
2177 if (clip_scan) { | |
2178 src_alpha = m_Alpha * clip_scan[col] / 255; | |
2179 } else { | |
2180 src_alpha = m_Alpha; | |
2181 } | |
2182 if (m_bFullCover) { | |
2183 *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, src_alpha); | |
2184 *dest_scan++ = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, src_alpha); | |
2185 *dest_scan = FXDIB_ALPHA_MERGE(*ori_scan, m_Red, src_alpha); | |
2186 dest_scan += Bpp - 2; | |
2187 ori_scan += Bpp - 2; | |
2188 continue; | |
2189 } | |
2190 int b = FXDIB_ALPHA_MERGE(*ori_scan++, m_Blue, src_alpha); | |
2191 int g = FXDIB_ALPHA_MERGE(*ori_scan++, m_Green, src_alpha); | |
2192 int r = FXDIB_ALPHA_MERGE(*ori_scan, m_Red, src_alpha); | |
2193 ori_scan += Bpp - 2; | |
2194 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, b, cover_scan[col]); | |
2195 dest_scan++; | |
2196 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, g, cover_scan[col]); | |
2197 dest_scan++; | |
2198 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, r, cover_scan[col]); | |
2199 dest_scan += Bpp - 2; | |
2200 continue; | |
2201 } | |
2202 return; | |
2203 } | |
2204 if (Bpp == 1) { | |
2205 for (int col = col_start; col < col_end; col++) { | |
2206 int src_alpha; | |
2207 if (clip_scan) { | |
2208 src_alpha = m_Alpha * clip_scan[col] / 255; | |
2209 } else { | |
2210 src_alpha = m_Alpha; | |
2211 } | |
2212 if (m_bFullCover) { | |
2213 *dest_scan = FXDIB_ALPHA_MERGE(*ori_scan++, m_Gray, src_alpha); | |
2214 } else { | |
2215 int gray = FXDIB_ALPHA_MERGE(*ori_scan++, m_Gray, src_alpha); | |
2216 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, gray, cover_scan[col]); | |
2217 dest_scan++; | |
2218 } | |
2219 } | |
2220 } else { | |
2221 int index = 0; | |
2222 if (m_pDevice->GetPalette()) { | |
2223 for (int i = 0; i < 2; i++) { | |
2224 if (FXARGB_TODIB(m_pDevice->GetPalette()[i]) == m_Color) { | |
2225 index = i; | |
2226 } | |
2227 } | |
2228 } else { | |
2229 index = ((uint8_t)m_Color == 0xff) ? 1 : 0; | |
2230 } | |
2231 uint8_t* dest_scan1 = dest_scan; | |
2232 for (int col = col_start; col < col_end; col++) { | |
2233 int src_alpha; | |
2234 if (clip_scan) { | |
2235 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; | |
2236 } else { | |
2237 src_alpha = m_Alpha * cover_scan[col] / 255; | |
2238 } | |
2239 if (src_alpha) { | |
2240 if (!index) { | |
2241 *dest_scan1 &= ~(1 << (7 - (col + span_left) % 8)); | |
2242 } else { | |
2243 *dest_scan1 |= 1 << (7 - (col + span_left) % 8); | |
2244 } | |
2245 } | |
2246 dest_scan1 = dest_scan + (span_left % 8 + col - col_start + 1) / 8; | |
2247 } | |
2248 } | |
2249 } | |
2250 | |
2251 void CompositeSpan1bpp(uint8_t* dest_scan, | |
2252 int Bpp, | |
2253 int span_left, | |
2254 int span_len, | |
2255 uint8_t* cover_scan, | |
2256 int clip_left, | |
2257 int clip_right, | |
2258 uint8_t* clip_scan, | |
2259 uint8_t* dest_extra_alpha_scan) { | |
2260 ASSERT(!m_bRgbByteOrder); | |
2261 ASSERT(!m_pDevice->IsCmykImage()); | |
2262 int col_start = span_left < clip_left ? clip_left - span_left : 0; | |
2263 int col_end = (span_left + span_len) < clip_right | |
2264 ? span_len | |
2265 : (clip_right - span_left); | |
2266 dest_scan += col_start / 8; | |
2267 int index = 0; | |
2268 if (m_pDevice->GetPalette()) { | |
2269 for (int i = 0; i < 2; i++) { | |
2270 if (FXARGB_TODIB(m_pDevice->GetPalette()[i]) == m_Color) { | |
2271 index = i; | |
2272 } | |
2273 } | |
2274 } else { | |
2275 index = ((uint8_t)m_Color == 0xff) ? 1 : 0; | |
2276 } | |
2277 uint8_t* dest_scan1 = dest_scan; | |
2278 for (int col = col_start; col < col_end; col++) { | |
2279 int src_alpha; | |
2280 if (clip_scan) { | |
2281 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; | |
2282 } else { | |
2283 src_alpha = m_Alpha * cover_scan[col] / 255; | |
2284 } | |
2285 if (src_alpha) { | |
2286 if (!index) { | |
2287 *dest_scan1 &= ~(1 << (7 - (col + span_left) % 8)); | |
2288 } else { | |
2289 *dest_scan1 |= 1 << (7 - (col + span_left) % 8); | |
2290 } | |
2291 } | |
2292 dest_scan1 = dest_scan + (span_left % 8 + col - col_start + 1) / 8; | |
2293 } | |
2294 } | |
2295 | |
2296 void CompositeSpanGray(uint8_t* dest_scan, | |
2297 int Bpp, | |
2298 int span_left, | |
2299 int span_len, | |
2300 uint8_t* cover_scan, | |
2301 int clip_left, | |
2302 int clip_right, | |
2303 uint8_t* clip_scan, | |
2304 uint8_t* dest_extra_alpha_scan) { | |
2305 ASSERT(!m_bRgbByteOrder); | |
2306 int col_start = span_left < clip_left ? clip_left - span_left : 0; | |
2307 int col_end = (span_left + span_len) < clip_right | |
2308 ? span_len | |
2309 : (clip_right - span_left); | |
2310 dest_scan += col_start; | |
2311 if (dest_extra_alpha_scan) { | |
2312 for (int col = col_start; col < col_end; col++) { | |
2313 int src_alpha; | |
2314 if (m_bFullCover) { | |
2315 if (clip_scan) { | |
2316 src_alpha = m_Alpha * clip_scan[col] / 255; | |
2317 } else { | |
2318 src_alpha = m_Alpha; | |
2319 } | |
2320 } else { | |
2321 if (clip_scan) { | |
2322 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; | |
2323 } else { | |
2324 src_alpha = m_Alpha * cover_scan[col] / 255; | |
2325 } | |
2326 } | |
2327 if (src_alpha) { | |
2328 if (src_alpha == 255) { | |
2329 *dest_scan = m_Gray; | |
2330 *dest_extra_alpha_scan = m_Alpha; | |
2331 } else { | |
2332 uint8_t dest_alpha = (*dest_extra_alpha_scan) + src_alpha - | |
2333 (*dest_extra_alpha_scan) * src_alpha / 255; | |
2334 *dest_extra_alpha_scan++ = dest_alpha; | |
2335 int alpha_ratio = src_alpha * 255 / dest_alpha; | |
2336 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, alpha_ratio); | |
2337 dest_scan++; | |
2338 continue; | |
2339 } | |
2340 } | |
2341 dest_extra_alpha_scan++; | |
2342 dest_scan++; | |
2343 } | |
2344 } else { | |
2345 for (int col = col_start; col < col_end; col++) { | |
2346 int src_alpha; | |
2347 if (clip_scan) { | |
2348 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; | |
2349 } else { | |
2350 src_alpha = m_Alpha * cover_scan[col] / 255; | |
2351 } | |
2352 if (src_alpha) { | |
2353 if (src_alpha == 255) { | |
2354 *dest_scan = m_Gray; | |
2355 } else { | |
2356 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, src_alpha); | |
2357 } | |
2358 } | |
2359 dest_scan++; | |
2360 } | |
2361 } | |
2362 } | |
2363 | |
2364 void CompositeSpanARGB(uint8_t* dest_scan, | |
2365 int Bpp, | |
2366 int span_left, | |
2367 int span_len, | |
2368 uint8_t* cover_scan, | |
2369 int clip_left, | |
2370 int clip_right, | |
2371 uint8_t* clip_scan, | |
2372 uint8_t* dest_extra_alpha_scan) { | |
2373 int col_start = span_left < clip_left ? clip_left - span_left : 0; | |
2374 int col_end = (span_left + span_len) < clip_right | |
2375 ? span_len | |
2376 : (clip_right - span_left); | |
2377 dest_scan += col_start * Bpp; | |
2378 if (m_bRgbByteOrder) { | |
2379 for (int col = col_start; col < col_end; col++) { | |
2380 int src_alpha; | |
2381 if (m_bFullCover) { | |
2382 if (clip_scan) { | |
2383 src_alpha = m_Alpha * clip_scan[col] / 255; | |
2384 } else { | |
2385 src_alpha = m_Alpha; | |
2386 } | |
2387 } else { | |
2388 if (clip_scan) { | |
2389 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; | |
2390 } else { | |
2391 src_alpha = m_Alpha * cover_scan[col] / 255; | |
2392 } | |
2393 } | |
2394 if (src_alpha) { | |
2395 if (src_alpha == 255) { | |
2396 *(uint32_t*)dest_scan = m_Color; | |
2397 } else { | |
2398 uint8_t dest_alpha = | |
2399 dest_scan[3] + src_alpha - dest_scan[3] * src_alpha / 255; | |
2400 dest_scan[3] = dest_alpha; | |
2401 int alpha_ratio = src_alpha * 255 / dest_alpha; | |
2402 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio); | |
2403 dest_scan++; | |
2404 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio); | |
2405 dest_scan++; | |
2406 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio); | |
2407 dest_scan += 2; | |
2408 continue; | |
2409 } | |
2410 } | |
2411 dest_scan += 4; | |
2412 } | |
2413 return; | |
2414 } | |
2415 for (int col = col_start; col < col_end; col++) { | |
2416 int src_alpha; | |
2417 if (m_bFullCover) { | |
2418 if (clip_scan) { | |
2419 src_alpha = m_Alpha * clip_scan[col] / 255; | |
2420 } else { | |
2421 src_alpha = m_Alpha; | |
2422 } | |
2423 } else { | |
2424 if (clip_scan) { | |
2425 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; | |
2426 } else { | |
2427 src_alpha = m_Alpha * cover_scan[col] / 255; | |
2428 } | |
2429 } | |
2430 if (src_alpha) { | |
2431 if (src_alpha == 255) { | |
2432 *(uint32_t*)dest_scan = m_Color; | |
2433 } else { | |
2434 if (dest_scan[3] == 0) { | |
2435 dest_scan[3] = src_alpha; | |
2436 *dest_scan++ = m_Blue; | |
2437 *dest_scan++ = m_Green; | |
2438 *dest_scan = m_Red; | |
2439 dest_scan += 2; | |
2440 continue; | |
2441 } | |
2442 uint8_t dest_alpha = | |
2443 dest_scan[3] + src_alpha - dest_scan[3] * src_alpha / 255; | |
2444 dest_scan[3] = dest_alpha; | |
2445 int alpha_ratio = src_alpha * 255 / dest_alpha; | |
2446 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio); | |
2447 dest_scan++; | |
2448 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio); | |
2449 dest_scan++; | |
2450 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio); | |
2451 dest_scan += 2; | |
2452 continue; | |
2453 } | |
2454 } | |
2455 dest_scan += Bpp; | |
2456 } | |
2457 } | |
2458 | |
2459 void CompositeSpanRGB(uint8_t* dest_scan, | |
2460 int Bpp, | |
2461 int span_left, | |
2462 int span_len, | |
2463 uint8_t* cover_scan, | |
2464 int clip_left, | |
2465 int clip_right, | |
2466 uint8_t* clip_scan, | |
2467 uint8_t* dest_extra_alpha_scan) { | |
2468 int col_start = span_left < clip_left ? clip_left - span_left : 0; | |
2469 int col_end = (span_left + span_len) < clip_right | |
2470 ? span_len | |
2471 : (clip_right - span_left); | |
2472 dest_scan += col_start * Bpp; | |
2473 if (m_bRgbByteOrder) { | |
2474 for (int col = col_start; col < col_end; col++) { | |
2475 int src_alpha; | |
2476 if (clip_scan) { | |
2477 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; | |
2478 } else { | |
2479 src_alpha = m_Alpha * cover_scan[col] / 255; | |
2480 } | |
2481 if (src_alpha) { | |
2482 if (src_alpha == 255) { | |
2483 if (Bpp == 4) { | |
2484 *(uint32_t*)dest_scan = m_Color; | |
2485 } else if (Bpp == 3) { | |
2486 *dest_scan++ = m_Red; | |
2487 *dest_scan++ = m_Green; | |
2488 *dest_scan++ = m_Blue; | |
2489 continue; | |
2490 } | |
2491 } else { | |
2492 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, src_alpha); | |
2493 dest_scan++; | |
2494 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, src_alpha); | |
2495 dest_scan++; | |
2496 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, src_alpha); | |
2497 dest_scan += Bpp - 2; | |
2498 continue; | |
2499 } | |
2500 } | |
2501 dest_scan += Bpp; | |
2502 } | |
2503 return; | |
2504 } | |
2505 if (Bpp == 3 && dest_extra_alpha_scan) { | |
2506 for (int col = col_start; col < col_end; col++) { | |
2507 int src_alpha; | |
2508 if (m_bFullCover) { | |
2509 if (clip_scan) { | |
2510 src_alpha = m_Alpha * clip_scan[col] / 255; | |
2511 } else { | |
2512 src_alpha = m_Alpha; | |
2513 } | |
2514 } else { | |
2515 if (clip_scan) { | |
2516 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; | |
2517 } else { | |
2518 src_alpha = m_Alpha * cover_scan[col] / 255; | |
2519 } | |
2520 } | |
2521 if (src_alpha) { | |
2522 if (src_alpha == 255) { | |
2523 *dest_scan++ = (uint8_t)m_Blue; | |
2524 *dest_scan++ = (uint8_t)m_Green; | |
2525 *dest_scan++ = (uint8_t)m_Red; | |
2526 *dest_extra_alpha_scan++ = (uint8_t)m_Alpha; | |
2527 continue; | |
2528 } else { | |
2529 uint8_t dest_alpha = (*dest_extra_alpha_scan) + src_alpha - | |
2530 (*dest_extra_alpha_scan) * src_alpha / 255; | |
2531 *dest_extra_alpha_scan++ = dest_alpha; | |
2532 int alpha_ratio = src_alpha * 255 / dest_alpha; | |
2533 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio); | |
2534 dest_scan++; | |
2535 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio); | |
2536 dest_scan++; | |
2537 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio); | |
2538 dest_scan++; | |
2539 continue; | |
2540 } | |
2541 } | |
2542 dest_extra_alpha_scan++; | |
2543 dest_scan += Bpp; | |
2544 } | |
2545 } else { | |
2546 for (int col = col_start; col < col_end; col++) { | |
2547 int src_alpha; | |
2548 if (m_bFullCover) { | |
2549 if (clip_scan) { | |
2550 src_alpha = m_Alpha * clip_scan[col] / 255; | |
2551 } else { | |
2552 src_alpha = m_Alpha; | |
2553 } | |
2554 } else { | |
2555 if (clip_scan) { | |
2556 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; | |
2557 } else { | |
2558 src_alpha = m_Alpha * cover_scan[col] / 255; | |
2559 } | |
2560 } | |
2561 if (src_alpha) { | |
2562 if (src_alpha == 255) { | |
2563 if (Bpp == 4) { | |
2564 *(uint32_t*)dest_scan = m_Color; | |
2565 } else if (Bpp == 3) { | |
2566 *dest_scan++ = m_Blue; | |
2567 *dest_scan++ = m_Green; | |
2568 *dest_scan++ = m_Red; | |
2569 continue; | |
2570 } | |
2571 } else { | |
2572 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, src_alpha); | |
2573 dest_scan++; | |
2574 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, src_alpha); | |
2575 dest_scan++; | |
2576 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, src_alpha); | |
2577 dest_scan += Bpp - 2; | |
2578 continue; | |
2579 } | |
2580 } | |
2581 dest_scan += Bpp; | |
2582 } | |
2583 } | |
2584 } | |
2585 | |
2586 void CompositeSpanCMYK(uint8_t* dest_scan, | |
2587 int Bpp, | |
2588 int span_left, | |
2589 int span_len, | |
2590 uint8_t* cover_scan, | |
2591 int clip_left, | |
2592 int clip_right, | |
2593 uint8_t* clip_scan, | |
2594 uint8_t* dest_extra_alpha_scan) { | |
2595 ASSERT(!m_bRgbByteOrder); | |
2596 int col_start = span_left < clip_left ? clip_left - span_left : 0; | |
2597 int col_end = (span_left + span_len) < clip_right | |
2598 ? span_len | |
2599 : (clip_right - span_left); | |
2600 dest_scan += col_start * 4; | |
2601 if (dest_extra_alpha_scan) { | |
2602 for (int col = col_start; col < col_end; col++) { | |
2603 int src_alpha; | |
2604 if (m_bFullCover) { | |
2605 if (clip_scan) { | |
2606 src_alpha = m_Alpha * clip_scan[col] / 255; | |
2607 } else { | |
2608 src_alpha = m_Alpha; | |
2609 } | |
2610 } else { | |
2611 if (clip_scan) { | |
2612 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; | |
2613 } else { | |
2614 src_alpha = m_Alpha * cover_scan[col] / 255; | |
2615 } | |
2616 } | |
2617 if (src_alpha) { | |
2618 if (src_alpha == 255) { | |
2619 *(FX_CMYK*)dest_scan = m_Color; | |
2620 *dest_extra_alpha_scan = (uint8_t)m_Alpha; | |
2621 } else { | |
2622 uint8_t dest_alpha = (*dest_extra_alpha_scan) + src_alpha - | |
2623 (*dest_extra_alpha_scan) * src_alpha / 255; | |
2624 *dest_extra_alpha_scan++ = dest_alpha; | |
2625 int alpha_ratio = src_alpha * 255 / dest_alpha; | |
2626 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, alpha_ratio); | |
2627 dest_scan++; | |
2628 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, alpha_ratio); | |
2629 dest_scan++; | |
2630 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, alpha_ratio); | |
2631 dest_scan++; | |
2632 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, alpha_ratio); | |
2633 dest_scan++; | |
2634 continue; | |
2635 } | |
2636 } | |
2637 dest_extra_alpha_scan++; | |
2638 dest_scan += 4; | |
2639 } | |
2640 } else { | |
2641 for (int col = col_start; col < col_end; col++) { | |
2642 int src_alpha; | |
2643 if (clip_scan) { | |
2644 src_alpha = m_Alpha * cover_scan[col] * clip_scan[col] / 255 / 255; | |
2645 } else { | |
2646 src_alpha = m_Alpha * cover_scan[col] / 255; | |
2647 } | |
2648 if (src_alpha) { | |
2649 if (src_alpha == 255) { | |
2650 *(FX_CMYK*)dest_scan = m_Color; | |
2651 } else { | |
2652 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Red, src_alpha); | |
2653 dest_scan++; | |
2654 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Green, src_alpha); | |
2655 dest_scan++; | |
2656 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Blue, src_alpha); | |
2657 dest_scan++; | |
2658 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, m_Gray, src_alpha); | |
2659 dest_scan++; | |
2660 continue; | |
2661 } | |
2662 } | |
2663 dest_scan += 4; | |
2664 } | |
2665 } | |
2666 } | |
2667 | |
2668 template <class Scanline> | |
2669 void render(const Scanline& sl) { | |
2670 if (!m_pOriDevice && !composite_span) { | |
2671 return; | |
2672 } | |
2673 int y = sl.y(); | |
2674 if (y < m_ClipBox.top || y >= m_ClipBox.bottom) { | |
2675 return; | |
2676 } | |
2677 uint8_t* dest_scan = m_pDevice->GetBuffer() + m_pDevice->GetPitch() * y; | |
2678 uint8_t* dest_scan_extra_alpha = nullptr; | |
2679 CFX_DIBitmap* pAlphaMask = m_pDevice->m_pAlphaMask; | |
2680 if (pAlphaMask) { | |
2681 dest_scan_extra_alpha = | |
2682 pAlphaMask->GetBuffer() + pAlphaMask->GetPitch() * y; | |
2683 } | |
2684 uint8_t* ori_scan = nullptr; | |
2685 if (m_pOriDevice) { | |
2686 ori_scan = m_pOriDevice->GetBuffer() + m_pOriDevice->GetPitch() * y; | |
2687 } | |
2688 int Bpp = m_pDevice->GetBPP() / 8; | |
2689 bool bDestAlpha = m_pDevice->HasAlpha() || m_pDevice->IsAlphaMask(); | |
2690 unsigned num_spans = sl.num_spans(); | |
2691 typename Scanline::const_iterator span = sl.begin(); | |
2692 while (1) { | |
2693 int x = span->x; | |
2694 ASSERT(span->len > 0); | |
2695 uint8_t* dest_pos = nullptr; | |
2696 uint8_t* dest_extra_alpha_pos = nullptr; | |
2697 uint8_t* ori_pos = nullptr; | |
2698 if (Bpp) { | |
2699 ori_pos = ori_scan ? ori_scan + x * Bpp : nullptr; | |
2700 dest_pos = dest_scan + x * Bpp; | |
2701 dest_extra_alpha_pos = | |
2702 dest_scan_extra_alpha ? dest_scan_extra_alpha + x : nullptr; | |
2703 } else { | |
2704 dest_pos = dest_scan + x / 8; | |
2705 ori_pos = ori_scan ? ori_scan + x / 8 : nullptr; | |
2706 } | |
2707 uint8_t* clip_pos = nullptr; | |
2708 if (m_pClipMask) { | |
2709 clip_pos = m_pClipMask->GetBuffer() + | |
2710 (y - m_ClipBox.top) * m_pClipMask->GetPitch() + x - | |
2711 m_ClipBox.left; | |
2712 } | |
2713 if (ori_pos) { | |
2714 CompositeSpan(dest_pos, ori_pos, Bpp, bDestAlpha, x, span->len, | |
2715 span->covers, m_ClipBox.left, m_ClipBox.right, clip_pos); | |
2716 } else { | |
2717 (this->*composite_span)(dest_pos, Bpp, x, span->len, span->covers, | |
2718 m_ClipBox.left, m_ClipBox.right, clip_pos, | |
2719 dest_extra_alpha_pos); | |
2720 } | |
2721 if (--num_spans == 0) { | |
2722 break; | |
2723 } | |
2724 ++span; | |
2725 } | |
2726 } | |
2727 | |
2728 bool Init(CFX_DIBitmap* pDevice, | |
2729 CFX_DIBitmap* pOriDevice, | |
2730 const CFX_ClipRgn* pClipRgn, | |
2731 uint32_t color, | |
2732 bool bFullCover, | |
2733 bool bRgbByteOrder, | |
2734 int alpha_flag = 0, | |
2735 void* pIccTransform = nullptr) { | |
2736 m_pDevice = pDevice; | |
2737 m_pClipRgn = pClipRgn; | |
2738 composite_span = nullptr; | |
2739 m_bRgbByteOrder = bRgbByteOrder; | |
2740 m_pOriDevice = pOriDevice; | |
2741 if (m_pClipRgn) { | |
2742 m_ClipBox = m_pClipRgn->GetBox(); | |
2743 } else { | |
2744 m_ClipBox.left = m_ClipBox.top = 0; | |
2745 m_ClipBox.right = m_pDevice->GetWidth(); | |
2746 m_ClipBox.bottom = m_pDevice->GetHeight(); | |
2747 } | |
2748 m_pClipMask = nullptr; | |
2749 if (m_pClipRgn && m_pClipRgn->GetType() == CFX_ClipRgn::MaskF) { | |
2750 m_pClipMask = m_pClipRgn->GetMask().GetObject(); | |
2751 } | |
2752 m_bFullCover = bFullCover; | |
2753 bool bObjectCMYK = !!FXGETFLAG_COLORTYPE(alpha_flag); | |
2754 bool bDeviceCMYK = pDevice->IsCmykImage(); | |
2755 m_Alpha = bObjectCMYK ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(color); | |
2756 CCodec_IccModule* pIccModule = nullptr; | |
2757 if (!CFX_GEModule::Get()->GetCodecModule() || | |
2758 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { | |
2759 pIccTransform = nullptr; | |
2760 } else { | |
2761 pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); | |
2762 } | |
2763 if (m_pDevice->GetBPP() == 8) { | |
2764 ASSERT(!m_bRgbByteOrder); | |
2765 composite_span = &CFX_Renderer::CompositeSpanGray; | |
2766 if (m_pDevice->IsAlphaMask()) { | |
2767 m_Gray = 255; | |
2768 } else { | |
2769 if (pIccTransform) { | |
2770 uint8_t gray; | |
2771 color = bObjectCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); | |
2772 pIccModule->TranslateScanline(pIccTransform, &gray, | |
2773 (const uint8_t*)&color, 1); | |
2774 m_Gray = gray; | |
2775 } else { | |
2776 if (bObjectCMYK) { | |
2777 uint8_t r, g, b; | |
2778 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color), | |
2779 FXSYS_GetYValue(color), FXSYS_GetKValue(color), | |
2780 r, g, b); | |
2781 m_Gray = FXRGB2GRAY(r, g, b); | |
2782 } else { | |
2783 m_Gray = | |
2784 FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B(color)); | |
2785 } | |
2786 } | |
2787 } | |
2788 return true; | |
2789 } | |
2790 if (bDeviceCMYK) { | |
2791 ASSERT(!m_bRgbByteOrder); | |
2792 composite_span = &CFX_Renderer::CompositeSpanCMYK; | |
2793 if (bObjectCMYK) { | |
2794 m_Color = FXCMYK_TODIB(color); | |
2795 if (pIccTransform) { | |
2796 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&m_Color, | |
2797 (const uint8_t*)&m_Color, 1); | |
2798 } | |
2799 } else { | |
2800 if (!pIccTransform) { | |
2801 return false; | |
2802 } | |
2803 color = FXARGB_TODIB(color); | |
2804 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&m_Color, | |
2805 (const uint8_t*)&color, 1); | |
2806 } | |
2807 m_Red = ((uint8_t*)&m_Color)[0]; | |
2808 m_Green = ((uint8_t*)&m_Color)[1]; | |
2809 m_Blue = ((uint8_t*)&m_Color)[2]; | |
2810 m_Gray = ((uint8_t*)&m_Color)[3]; | |
2811 } else { | |
2812 composite_span = (pDevice->GetFormat() == FXDIB_Argb) | |
2813 ? &CFX_Renderer::CompositeSpanARGB | |
2814 : &CFX_Renderer::CompositeSpanRGB; | |
2815 if (pIccTransform) { | |
2816 color = bObjectCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); | |
2817 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&m_Color, | |
2818 (const uint8_t*)&color, 1); | |
2819 ((uint8_t*)&m_Color)[3] = m_Alpha; | |
2820 m_Red = ((uint8_t*)&m_Color)[2]; | |
2821 m_Green = ((uint8_t*)&m_Color)[1]; | |
2822 m_Blue = ((uint8_t*)&m_Color)[0]; | |
2823 if (m_bRgbByteOrder) { | |
2824 m_Color = FXARGB_TODIB(m_Color); | |
2825 m_Color = FXARGB_TOBGRORDERDIB(m_Color); | |
2826 } | |
2827 } else { | |
2828 if (bObjectCMYK) { | |
2829 uint8_t r, g, b; | |
2830 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(color), FXSYS_GetMValue(color), | |
2831 FXSYS_GetYValue(color), FXSYS_GetKValue(color), r, | |
2832 g, b); | |
2833 m_Color = FXARGB_MAKE(m_Alpha, r, g, b); | |
2834 if (m_bRgbByteOrder) { | |
2835 m_Color = FXARGB_TOBGRORDERDIB(m_Color); | |
2836 } else { | |
2837 m_Color = FXARGB_TODIB(m_Color); | |
2838 } | |
2839 m_Red = r; | |
2840 m_Green = g; | |
2841 m_Blue = b; | |
2842 } else { | |
2843 if (m_bRgbByteOrder) { | |
2844 m_Color = FXARGB_TOBGRORDERDIB(color); | |
2845 } else { | |
2846 m_Color = FXARGB_TODIB(color); | |
2847 } | |
2848 ArgbDecode(color, m_Alpha, m_Red, m_Green, m_Blue); | |
2849 } | |
2850 } | |
2851 } | |
2852 if (m_pDevice->GetBPP() == 1) { | |
2853 composite_span = &CFX_Renderer::CompositeSpan1bpp; | |
2854 } | |
2855 return true; | |
2856 } | |
2857 }; | |
2858 | |
2859 #endif | |
OLD | NEW |