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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fxge/agg/fx_agg_driver.h" | 7 #include "core/fxge/agg/fx_agg_driver.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "third_party/agg23/agg_renderer_scanline.h" | 21 #include "third_party/agg23/agg_renderer_scanline.h" |
22 #include "third_party/agg23/agg_scanline_u.h" | 22 #include "third_party/agg23/agg_scanline_u.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 void HardClip(FX_FLOAT& x, FX_FLOAT& y) { | 26 void HardClip(FX_FLOAT& x, FX_FLOAT& y) { |
27 x = std::max(std::min(x, 50000.0f), -50000.0f); | 27 x = std::max(std::min(x, 50000.0f), -50000.0f); |
28 y = std::max(std::min(y, 50000.0f), -50000.0f); | 28 y = std::max(std::min(y, 50000.0f), -50000.0f); |
29 } | 29 } |
30 | 30 |
| 31 void RgbByteOrderSetPixel(CFX_DIBitmap* pBitmap, int x, int y, uint32_t argb) { |
| 32 if (x < 0 || x >= pBitmap->GetWidth() || y < 0 || y >= pBitmap->GetHeight()) |
| 33 return; |
| 34 |
| 35 uint8_t* pos = (uint8_t*)pBitmap->GetBuffer() + y * pBitmap->GetPitch() + |
| 36 x * pBitmap->GetBPP() / 8; |
| 37 if (pBitmap->GetFormat() == FXDIB_Argb) { |
| 38 FXARGB_SETRGBORDERDIB(pos, argb); |
| 39 return; |
| 40 } |
| 41 |
| 42 int alpha = FXARGB_A(argb); |
| 43 pos[0] = (FXARGB_R(argb) * alpha + pos[0] * (255 - alpha)) / 255; |
| 44 pos[1] = (FXARGB_G(argb) * alpha + pos[1] * (255 - alpha)) / 255; |
| 45 pos[2] = (FXARGB_B(argb) * alpha + pos[2] * (255 - alpha)) / 255; |
| 46 } |
| 47 |
| 48 void RgbByteOrderCompositeRect(CFX_DIBitmap* pBitmap, |
| 49 int left, |
| 50 int top, |
| 51 int width, |
| 52 int height, |
| 53 FX_ARGB argb) { |
| 54 int src_alpha = FXARGB_A(argb); |
| 55 if (src_alpha == 0) |
| 56 return; |
| 57 |
| 58 FX_RECT rect(left, top, left + width, top + height); |
| 59 rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()); |
| 60 width = rect.Width(); |
| 61 int src_r = FXARGB_R(argb); |
| 62 int src_g = FXARGB_G(argb); |
| 63 int src_b = FXARGB_B(argb); |
| 64 int Bpp = pBitmap->GetBPP() / 8; |
| 65 FX_BOOL bAlpha = pBitmap->HasAlpha(); |
| 66 int dib_argb = FXARGB_TOBGRORDERDIB(argb); |
| 67 uint8_t* pBuffer = pBitmap->GetBuffer(); |
| 68 if (src_alpha == 255) { |
| 69 for (int row = rect.top; row < rect.bottom; row++) { |
| 70 uint8_t* dest_scan = |
| 71 pBuffer + row * pBitmap->GetPitch() + rect.left * Bpp; |
| 72 if (Bpp == 4) { |
| 73 uint32_t* scan = (uint32_t*)dest_scan; |
| 74 for (int col = 0; col < width; col++) |
| 75 *scan++ = dib_argb; |
| 76 } else { |
| 77 for (int col = 0; col < width; col++) { |
| 78 *dest_scan++ = src_r; |
| 79 *dest_scan++ = src_g; |
| 80 *dest_scan++ = src_b; |
| 81 } |
| 82 } |
| 83 } |
| 84 return; |
| 85 } |
| 86 for (int row = rect.top; row < rect.bottom; row++) { |
| 87 uint8_t* dest_scan = pBuffer + row * pBitmap->GetPitch() + rect.left * Bpp; |
| 88 if (bAlpha) { |
| 89 for (int col = 0; col < width; col++) { |
| 90 uint8_t back_alpha = dest_scan[3]; |
| 91 if (back_alpha == 0) { |
| 92 FXARGB_SETRGBORDERDIB(dest_scan, |
| 93 FXARGB_MAKE(src_alpha, src_r, src_g, src_b)); |
| 94 dest_scan += 4; |
| 95 continue; |
| 96 } |
| 97 uint8_t dest_alpha = |
| 98 back_alpha + src_alpha - back_alpha * src_alpha / 255; |
| 99 dest_scan[3] = dest_alpha; |
| 100 int alpha_ratio = src_alpha * 255 / dest_alpha; |
| 101 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio); |
| 102 dest_scan++; |
| 103 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio); |
| 104 dest_scan++; |
| 105 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio); |
| 106 dest_scan += 2; |
| 107 } |
| 108 } else { |
| 109 for (int col = 0; col < width; col++) { |
| 110 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, src_alpha); |
| 111 dest_scan++; |
| 112 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, src_alpha); |
| 113 dest_scan++; |
| 114 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, src_alpha); |
| 115 dest_scan++; |
| 116 if (Bpp == 4) |
| 117 dest_scan++; |
| 118 } |
| 119 } |
| 120 } |
| 121 } |
| 122 |
| 123 void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap, |
| 124 int dest_left, |
| 125 int dest_top, |
| 126 int width, |
| 127 int height, |
| 128 const CFX_DIBSource* pSrcBitmap, |
| 129 int src_left, |
| 130 int src_top) { |
| 131 if (!pBitmap) |
| 132 return; |
| 133 |
| 134 pBitmap->GetOverlapRect(dest_left, dest_top, width, height, |
| 135 pSrcBitmap->GetWidth(), pSrcBitmap->GetHeight(), |
| 136 src_left, src_top, nullptr); |
| 137 if (width == 0 || height == 0) |
| 138 return; |
| 139 |
| 140 int Bpp = pBitmap->GetBPP() / 8; |
| 141 FXDIB_Format dest_format = pBitmap->GetFormat(); |
| 142 FXDIB_Format src_format = pSrcBitmap->GetFormat(); |
| 143 int pitch = pBitmap->GetPitch(); |
| 144 uint8_t* buffer = pBitmap->GetBuffer(); |
| 145 if (dest_format == src_format) { |
| 146 for (int row = 0; row < height; row++) { |
| 147 uint8_t* dest_scan = buffer + (dest_top + row) * pitch + dest_left * Bpp; |
| 148 uint8_t* src_scan = |
| 149 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; |
| 150 if (Bpp == 4) { |
| 151 for (int col = 0; col < width; col++) { |
| 152 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_scan[3], src_scan[0], |
| 153 src_scan[1], src_scan[2])); |
| 154 dest_scan += 4; |
| 155 src_scan += 4; |
| 156 } |
| 157 } else { |
| 158 for (int col = 0; col < width; col++) { |
| 159 *dest_scan++ = src_scan[2]; |
| 160 *dest_scan++ = src_scan[1]; |
| 161 *dest_scan++ = src_scan[0]; |
| 162 src_scan += 3; |
| 163 } |
| 164 } |
| 165 } |
| 166 return; |
| 167 } |
| 168 |
| 169 uint8_t* dest_buf = buffer + dest_top * pitch + dest_left * Bpp; |
| 170 if (dest_format == FXDIB_Rgb) { |
| 171 if (src_format == FXDIB_Rgb32) { |
| 172 for (int row = 0; row < height; row++) { |
| 173 uint8_t* dest_scan = dest_buf + row * pitch; |
| 174 uint8_t* src_scan = |
| 175 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * 4; |
| 176 for (int col = 0; col < width; col++) { |
| 177 *dest_scan++ = src_scan[2]; |
| 178 *dest_scan++ = src_scan[1]; |
| 179 *dest_scan++ = src_scan[0]; |
| 180 src_scan += 4; |
| 181 } |
| 182 } |
| 183 } else { |
| 184 ASSERT(FALSE); |
| 185 } |
| 186 return; |
| 187 } |
| 188 |
| 189 if (dest_format == FXDIB_Argb || dest_format == FXDIB_Rgb32) { |
| 190 if (src_format == FXDIB_Rgb) { |
| 191 for (int row = 0; row < height; row++) { |
| 192 uint8_t* dest_scan = (uint8_t*)(dest_buf + row * pitch); |
| 193 uint8_t* src_scan = |
| 194 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * 3; |
| 195 for (int col = 0; col < width; col++) { |
| 196 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[0], src_scan[1], |
| 197 src_scan[2])); |
| 198 dest_scan += 4; |
| 199 src_scan += 3; |
| 200 } |
| 201 } |
| 202 } else if (src_format == FXDIB_Rgb32) { |
| 203 ASSERT(dest_format == FXDIB_Argb); |
| 204 for (int row = 0; row < height; row++) { |
| 205 uint8_t* dest_scan = dest_buf + row * pitch; |
| 206 uint8_t* src_scan = |
| 207 (uint8_t*)(pSrcBitmap->GetScanline(src_top + row) + src_left * 4); |
| 208 for (int col = 0; col < width; col++) { |
| 209 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[0], src_scan[1], |
| 210 src_scan[2])); |
| 211 src_scan += 4; |
| 212 dest_scan += 4; |
| 213 } |
| 214 } |
| 215 } |
| 216 return; |
| 217 } |
| 218 |
| 219 ASSERT(FALSE); |
| 220 } |
| 221 |
| 222 FX_ARGB DefaultCMYK2ARGB(FX_CMYK cmyk, uint8_t alpha) { |
| 223 uint8_t r, g, b; |
| 224 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk), |
| 225 FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), r, g, b); |
| 226 return ArgbEncode(alpha, r, g, b); |
| 227 } |
| 228 |
| 229 FX_BOOL DibSetPixel(CFX_DIBitmap* pDevice, |
| 230 int x, |
| 231 int y, |
| 232 uint32_t color, |
| 233 int alpha_flag, |
| 234 void* pIccTransform) { |
| 235 FX_BOOL bObjCMYK = FXGETFLAG_COLORTYPE(alpha_flag); |
| 236 int alpha = bObjCMYK ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(color); |
| 237 if (pIccTransform) { |
| 238 CCodec_IccModule* pIccModule = |
| 239 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
| 240 color = bObjCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); |
| 241 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&color, |
| 242 (uint8_t*)&color, 1); |
| 243 color = bObjCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); |
| 244 if (!pDevice->IsCmykImage()) { |
| 245 color = (color & 0xffffff) | (alpha << 24); |
| 246 } |
| 247 } else { |
| 248 if (pDevice->IsCmykImage()) { |
| 249 if (!bObjCMYK) |
| 250 return FALSE; |
| 251 } else { |
| 252 if (bObjCMYK) |
| 253 color = DefaultCMYK2ARGB(color, alpha); |
| 254 } |
| 255 } |
| 256 pDevice->SetPixel(x, y, color); |
| 257 if (pDevice->m_pAlphaMask) { |
| 258 pDevice->m_pAlphaMask->SetPixel(x, y, alpha << 24); |
| 259 } |
| 260 return TRUE; |
| 261 } |
| 262 |
31 } // namespace | 263 } // namespace |
32 | 264 |
33 void CAgg_PathData::BuildPath(const CFX_PathData* pPathData, | 265 void CAgg_PathData::BuildPath(const CFX_PathData* pPathData, |
34 const CFX_Matrix* pObject2Device) { | 266 const CFX_Matrix* pObject2Device) { |
35 int nPoints = pPathData->GetPointCount(); | 267 int nPoints = pPathData->GetPointCount(); |
36 FX_PATHPOINT* pPoints = pPathData->GetPoints(); | 268 FX_PATHPOINT* pPoints = pPathData->GetPoints(); |
37 for (int i = 0; i < nPoints; i++) { | 269 for (int i = 0; i < nPoints; i++) { |
38 FX_FLOAT x = pPoints[i].m_PointX, y = pPoints[i].m_PointY; | 270 FX_FLOAT x = pPoints[i].m_PointX, y = pPoints[i].m_PointY; |
39 if (pObject2Device) { | 271 if (pObject2Device) { |
40 pObject2Device->Transform(x, y); | 272 pObject2Device->Transform(x, y); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 void CFX_AggDeviceDriver::InitPlatform() {} | 456 void CFX_AggDeviceDriver::InitPlatform() {} |
225 | 457 |
226 void CFX_AggDeviceDriver::DestroyPlatform() {} | 458 void CFX_AggDeviceDriver::DestroyPlatform() {} |
227 | 459 |
228 FX_BOOL CFX_AggDeviceDriver::DrawDeviceText(int nChars, | 460 FX_BOOL CFX_AggDeviceDriver::DrawDeviceText(int nChars, |
229 const FXTEXT_CHARPOS* pCharPos, | 461 const FXTEXT_CHARPOS* pCharPos, |
230 CFX_Font* pFont, | 462 CFX_Font* pFont, |
231 CFX_FontCache* pCache, | 463 CFX_FontCache* pCache, |
232 const CFX_Matrix* pObject2Device, | 464 const CFX_Matrix* pObject2Device, |
233 FX_FLOAT font_size, | 465 FX_FLOAT font_size, |
234 uint32_t color, | 466 uint32_t color) { |
235 int alpha_flag, | |
236 void* pIccTransform) { | |
237 return FALSE; | 467 return FALSE; |
238 } // _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ | 468 } |
239 #endif | 469 #endif // _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ |
240 | 470 |
241 int CFX_AggDeviceDriver::GetDeviceCaps(int caps_id) { | 471 int CFX_AggDeviceDriver::GetDeviceCaps(int caps_id) { |
242 switch (caps_id) { | 472 switch (caps_id) { |
243 case FXDC_DEVICE_CLASS: | 473 case FXDC_DEVICE_CLASS: |
244 return FXDC_DISPLAY; | 474 return FXDC_DISPLAY; |
245 case FXDC_PIXEL_WIDTH: | 475 case FXDC_PIXEL_WIDTH: |
246 return m_pBitmap->GetWidth(); | 476 return m_pBitmap->GetWidth(); |
247 case FXDC_PIXEL_HEIGHT: | 477 case FXDC_PIXEL_HEIGHT: |
248 return m_pBitmap->GetHeight(); | 478 return m_pBitmap->GetHeight(); |
249 case FXDC_BITS_PIXEL: | 479 case FXDC_BITS_PIXEL: |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 (m_FillFlags & FXFILL_NOPATHSMOOTH) != 0); | 1453 (m_FillFlags & FXFILL_NOPATHSMOOTH) != 0); |
1224 return TRUE; | 1454 return TRUE; |
1225 } | 1455 } |
1226 | 1456 |
1227 FX_BOOL CFX_AggDeviceDriver::DrawPath(const CFX_PathData* pPathData, | 1457 FX_BOOL CFX_AggDeviceDriver::DrawPath(const CFX_PathData* pPathData, |
1228 const CFX_Matrix* pObject2Device, | 1458 const CFX_Matrix* pObject2Device, |
1229 const CFX_GraphStateData* pGraphState, | 1459 const CFX_GraphStateData* pGraphState, |
1230 uint32_t fill_color, | 1460 uint32_t fill_color, |
1231 uint32_t stroke_color, | 1461 uint32_t stroke_color, |
1232 int fill_mode, | 1462 int fill_mode, |
1233 int alpha_flag, | |
1234 void* pIccTransform, | |
1235 int blend_type) { | 1463 int blend_type) { |
1236 if (blend_type != FXDIB_BLEND_NORMAL) { | 1464 if (blend_type != FXDIB_BLEND_NORMAL) |
1237 return FALSE; | 1465 return FALSE; |
1238 } | 1466 |
1239 if (!GetBuffer()) { | 1467 if (!GetBuffer()) |
1240 return TRUE; | 1468 return TRUE; |
1241 } | 1469 |
1242 m_FillFlags = fill_mode; | 1470 m_FillFlags = fill_mode; |
1243 if ((fill_mode & 3) && fill_color) { | 1471 if ((fill_mode & 3) && fill_color) { |
1244 CAgg_PathData path_data; | 1472 CAgg_PathData path_data; |
1245 path_data.BuildPath(pPathData, pObject2Device); | 1473 path_data.BuildPath(pPathData, pObject2Device); |
1246 agg::rasterizer_scanline_aa rasterizer; | 1474 agg::rasterizer_scanline_aa rasterizer; |
1247 rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)), | 1475 rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)), |
1248 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT))); | 1476 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT))); |
1249 rasterizer.add_path(path_data.m_PathData); | 1477 rasterizer.add_path(path_data.m_PathData); |
1250 rasterizer.filling_rule((fill_mode & 3) == FXFILL_WINDING | 1478 rasterizer.filling_rule((fill_mode & 3) == FXFILL_WINDING |
1251 ? agg::fill_non_zero | 1479 ? agg::fill_non_zero |
1252 : agg::fill_even_odd); | 1480 : agg::fill_even_odd); |
1253 if (!RenderRasterizer(rasterizer, fill_color, fill_mode & FXFILL_FULLCOVER, | 1481 if (!RenderRasterizer(rasterizer, fill_color, fill_mode & FXFILL_FULLCOVER, |
1254 FALSE, alpha_flag, pIccTransform)) { | 1482 FALSE, 0, nullptr)) { |
1255 return FALSE; | 1483 return FALSE; |
1256 } | 1484 } |
1257 } | 1485 } |
1258 int stroke_alpha = FXGETFLAG_COLORTYPE(alpha_flag) | 1486 int stroke_alpha = FXARGB_A(stroke_color); |
1259 ? FXGETFLAG_ALPHA_STROKE(alpha_flag) | 1487 if (!pGraphState || !stroke_alpha) |
1260 : FXARGB_A(stroke_color); | 1488 return TRUE; |
1261 if (pGraphState && stroke_alpha) { | 1489 |
1262 if (fill_mode & FX_ZEROAREA_FILL) { | 1490 if (fill_mode & FX_ZEROAREA_FILL) { |
1263 CAgg_PathData path_data; | |
1264 path_data.BuildPath(pPathData, pObject2Device); | |
1265 agg::rasterizer_scanline_aa rasterizer; | |
1266 rasterizer.clip_box(0.0f, 0.0f, | |
1267 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)), | |
1268 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT))); | |
1269 RasterizeStroke(rasterizer, path_data.m_PathData, nullptr, pGraphState, 1, | |
1270 FALSE, fill_mode & FX_STROKE_TEXT_MODE); | |
1271 int fill_flag = FXGETFLAG_COLORTYPE(alpha_flag) << 8 | | |
1272 FXGETFLAG_ALPHA_STROKE(alpha_flag); | |
1273 if (!RenderRasterizer(rasterizer, stroke_color, | |
1274 fill_mode & FXFILL_FULLCOVER, m_bGroupKnockout, | |
1275 fill_flag, pIccTransform)) { | |
1276 return FALSE; | |
1277 } | |
1278 return TRUE; | |
1279 } | |
1280 CFX_Matrix matrix1, matrix2; | |
1281 if (pObject2Device) { | |
1282 matrix1.a = std::max(FXSYS_fabs(pObject2Device->a), | |
1283 FXSYS_fabs(pObject2Device->b)); | |
1284 matrix1.d = matrix1.a; | |
1285 matrix2.Set(pObject2Device->a / matrix1.a, pObject2Device->b / matrix1.a, | |
1286 pObject2Device->c / matrix1.d, pObject2Device->d / matrix1.d, | |
1287 0, 0); | |
1288 CFX_Matrix mtRervese; | |
1289 mtRervese.SetReverse(matrix2); | |
1290 matrix1 = *pObject2Device; | |
1291 matrix1.Concat(mtRervese); | |
1292 } | |
1293 CAgg_PathData path_data; | 1491 CAgg_PathData path_data; |
1294 path_data.BuildPath(pPathData, &matrix1); | 1492 path_data.BuildPath(pPathData, pObject2Device); |
1295 agg::rasterizer_scanline_aa rasterizer; | 1493 agg::rasterizer_scanline_aa rasterizer; |
1296 rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)), | 1494 rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)), |
1297 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT))); | 1495 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT))); |
1298 RasterizeStroke(rasterizer, path_data.m_PathData, &matrix2, pGraphState, | 1496 RasterizeStroke(rasterizer, path_data.m_PathData, nullptr, pGraphState, 1, |
1299 matrix1.a, FALSE, fill_mode & FX_STROKE_TEXT_MODE); | 1497 FALSE, fill_mode & FX_STROKE_TEXT_MODE); |
1300 int fill_flag = FXGETFLAG_COLORTYPE(alpha_flag) << 8 | | |
1301 FXGETFLAG_ALPHA_STROKE(alpha_flag); | |
1302 if (!RenderRasterizer(rasterizer, stroke_color, | 1498 if (!RenderRasterizer(rasterizer, stroke_color, |
1303 fill_mode & FXFILL_FULLCOVER, m_bGroupKnockout, | 1499 fill_mode & FXFILL_FULLCOVER, m_bGroupKnockout, 0, |
1304 fill_flag, pIccTransform)) { | 1500 nullptr)) { |
1305 return FALSE; | 1501 return FALSE; |
1306 } | 1502 } |
| 1503 return TRUE; |
| 1504 } |
| 1505 CFX_Matrix matrix1; |
| 1506 CFX_Matrix matrix2; |
| 1507 if (pObject2Device) { |
| 1508 matrix1.a = |
| 1509 std::max(FXSYS_fabs(pObject2Device->a), FXSYS_fabs(pObject2Device->b)); |
| 1510 matrix1.d = matrix1.a; |
| 1511 matrix2.Set(pObject2Device->a / matrix1.a, pObject2Device->b / matrix1.a, |
| 1512 pObject2Device->c / matrix1.d, pObject2Device->d / matrix1.d, 0, |
| 1513 0); |
| 1514 CFX_Matrix mtRervese; |
| 1515 mtRervese.SetReverse(matrix2); |
| 1516 matrix1 = *pObject2Device; |
| 1517 matrix1.Concat(mtRervese); |
| 1518 } |
| 1519 CAgg_PathData path_data; |
| 1520 path_data.BuildPath(pPathData, &matrix1); |
| 1521 agg::rasterizer_scanline_aa rasterizer; |
| 1522 rasterizer.clip_box(0.0f, 0.0f, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)), |
| 1523 (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_HEIGHT))); |
| 1524 RasterizeStroke(rasterizer, path_data.m_PathData, &matrix2, pGraphState, |
| 1525 matrix1.a, FALSE, fill_mode & FX_STROKE_TEXT_MODE); |
| 1526 if (!RenderRasterizer(rasterizer, stroke_color, fill_mode & FXFILL_FULLCOVER, |
| 1527 m_bGroupKnockout, 0, nullptr)) { |
| 1528 return FALSE; |
1307 } | 1529 } |
1308 return TRUE; | 1530 return TRUE; |
1309 } | 1531 } |
1310 | 1532 |
1311 void RgbByteOrderSetPixel(CFX_DIBitmap* pBitmap, int x, int y, uint32_t argb) { | 1533 FX_BOOL CFX_AggDeviceDriver::SetPixel(int x, int y, uint32_t color) { |
1312 if (x < 0 || x >= pBitmap->GetWidth() || y < 0 || y >= pBitmap->GetHeight()) { | 1534 if (!m_pBitmap->GetBuffer()) |
1313 return; | 1535 return TRUE; |
| 1536 |
| 1537 if (!m_pClipRgn) { |
| 1538 if (!m_bRgbByteOrder) |
| 1539 return DibSetPixel(m_pBitmap, x, y, color, 0, nullptr); |
| 1540 RgbByteOrderSetPixel(m_pBitmap, x, y, color); |
| 1541 return TRUE; |
1314 } | 1542 } |
1315 uint8_t* pos = (uint8_t*)pBitmap->GetBuffer() + y * pBitmap->GetPitch() + | 1543 if (!m_pClipRgn->GetBox().Contains(x, y)) |
1316 x * pBitmap->GetBPP() / 8; | 1544 return TRUE; |
1317 if (pBitmap->GetFormat() == FXDIB_Argb) { | 1545 |
1318 FXARGB_SETRGBORDERDIB(pos, argb); | 1546 if (m_pClipRgn->GetType() == CFX_ClipRgn::RectI) { |
1319 } else { | 1547 if (!m_bRgbByteOrder) |
1320 int alpha = FXARGB_A(argb); | 1548 return DibSetPixel(m_pBitmap, x, y, color, 0, nullptr); |
1321 pos[0] = (FXARGB_R(argb) * alpha + pos[0] * (255 - alpha)) / 255; | 1549 RgbByteOrderSetPixel(m_pBitmap, x, y, color); |
1322 pos[1] = (FXARGB_G(argb) * alpha + pos[1] * (255 - alpha)) / 255; | 1550 return TRUE; |
1323 pos[2] = (FXARGB_B(argb) * alpha + pos[2] * (255 - alpha)) / 255; | |
1324 } | 1551 } |
| 1552 if (m_pClipRgn->GetType() != CFX_ClipRgn::MaskF) |
| 1553 return TRUE; |
| 1554 |
| 1555 const CFX_DIBitmap* pMask = m_pClipRgn->GetMask().GetObject(); |
| 1556 int new_alpha = FXARGB_A(color) * pMask->GetScanline(y)[x] / 255; |
| 1557 color = (color & 0xffffff) | (new_alpha << 24); |
| 1558 if (m_bRgbByteOrder) { |
| 1559 RgbByteOrderSetPixel(m_pBitmap, x, y, color); |
| 1560 return TRUE; |
| 1561 } |
| 1562 return DibSetPixel(m_pBitmap, x, y, color, 0, nullptr); |
1325 } | 1563 } |
1326 | 1564 |
1327 void RgbByteOrderCompositeRect(CFX_DIBitmap* pBitmap, | 1565 FX_BOOL CFX_AggDeviceDriver::FillRectWithBlend(const FX_RECT* pRect, |
1328 int left, | 1566 uint32_t fill_color, |
1329 int top, | 1567 int blend_type) { |
1330 int width, | 1568 if (blend_type != FXDIB_BLEND_NORMAL) |
1331 int height, | 1569 return FALSE; |
1332 FX_ARGB argb) { | |
1333 int src_alpha = FXARGB_A(argb); | |
1334 if (src_alpha == 0) { | |
1335 return; | |
1336 } | |
1337 FX_RECT rect(left, top, left + width, top + height); | |
1338 rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()); | |
1339 width = rect.Width(); | |
1340 int src_r = FXARGB_R(argb), src_g = FXARGB_G(argb), src_b = FXARGB_B(argb); | |
1341 int Bpp = pBitmap->GetBPP() / 8; | |
1342 FX_BOOL bAlpha = pBitmap->HasAlpha(); | |
1343 int dib_argb = FXARGB_TOBGRORDERDIB(argb); | |
1344 uint8_t* pBuffer = pBitmap->GetBuffer(); | |
1345 if (src_alpha == 255) { | |
1346 for (int row = rect.top; row < rect.bottom; row++) { | |
1347 uint8_t* dest_scan = | |
1348 pBuffer + row * pBitmap->GetPitch() + rect.left * Bpp; | |
1349 if (Bpp == 4) { | |
1350 uint32_t* scan = (uint32_t*)dest_scan; | |
1351 for (int col = 0; col < width; col++) { | |
1352 *scan++ = dib_argb; | |
1353 } | |
1354 } else { | |
1355 for (int col = 0; col < width; col++) { | |
1356 *dest_scan++ = src_r; | |
1357 *dest_scan++ = src_g; | |
1358 *dest_scan++ = src_b; | |
1359 } | |
1360 } | |
1361 } | |
1362 return; | |
1363 } | |
1364 for (int row = rect.top; row < rect.bottom; row++) { | |
1365 uint8_t* dest_scan = pBuffer + row * pBitmap->GetPitch() + rect.left * Bpp; | |
1366 if (bAlpha) { | |
1367 for (int col = 0; col < width; col++) { | |
1368 uint8_t back_alpha = dest_scan[3]; | |
1369 if (back_alpha == 0) { | |
1370 FXARGB_SETRGBORDERDIB(dest_scan, | |
1371 FXARGB_MAKE(src_alpha, src_r, src_g, src_b)); | |
1372 dest_scan += 4; | |
1373 continue; | |
1374 } | |
1375 uint8_t dest_alpha = | |
1376 back_alpha + src_alpha - back_alpha * src_alpha / 255; | |
1377 dest_scan[3] = dest_alpha; | |
1378 int alpha_ratio = src_alpha * 255 / dest_alpha; | |
1379 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio); | |
1380 dest_scan++; | |
1381 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio); | |
1382 dest_scan++; | |
1383 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio); | |
1384 dest_scan += 2; | |
1385 } | |
1386 } else { | |
1387 for (int col = 0; col < width; col++) { | |
1388 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, src_alpha); | |
1389 dest_scan++; | |
1390 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, src_alpha); | |
1391 dest_scan++; | |
1392 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, src_alpha); | |
1393 dest_scan++; | |
1394 if (Bpp == 4) { | |
1395 dest_scan++; | |
1396 } | |
1397 } | |
1398 } | |
1399 } | |
1400 } | |
1401 | 1570 |
1402 void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap, | 1571 if (!m_pBitmap->GetBuffer()) |
1403 int dest_left, | 1572 return TRUE; |
1404 int dest_top, | |
1405 int width, | |
1406 int height, | |
1407 const CFX_DIBSource* pSrcBitmap, | |
1408 int src_left, | |
1409 int src_top) { | |
1410 if (!pBitmap) { | |
1411 return; | |
1412 } | |
1413 pBitmap->GetOverlapRect(dest_left, dest_top, width, height, | |
1414 pSrcBitmap->GetWidth(), pSrcBitmap->GetHeight(), | |
1415 src_left, src_top, nullptr); | |
1416 if (width == 0 || height == 0) { | |
1417 return; | |
1418 } | |
1419 int Bpp = pBitmap->GetBPP() / 8; | |
1420 FXDIB_Format dest_format = pBitmap->GetFormat(); | |
1421 FXDIB_Format src_format = pSrcBitmap->GetFormat(); | |
1422 int pitch = pBitmap->GetPitch(); | |
1423 uint8_t* buffer = pBitmap->GetBuffer(); | |
1424 if (dest_format == src_format) { | |
1425 for (int row = 0; row < height; row++) { | |
1426 uint8_t* dest_scan = buffer + (dest_top + row) * pitch + dest_left * Bpp; | |
1427 uint8_t* src_scan = | |
1428 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; | |
1429 if (Bpp == 4) { | |
1430 for (int col = 0; col < width; col++) { | |
1431 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_scan[3], src_scan[0], | |
1432 src_scan[1], src_scan[2])); | |
1433 dest_scan += 4; | |
1434 src_scan += 4; | |
1435 } | |
1436 } else { | |
1437 for (int col = 0; col < width; col++) { | |
1438 *dest_scan++ = src_scan[2]; | |
1439 *dest_scan++ = src_scan[1]; | |
1440 *dest_scan++ = src_scan[0]; | |
1441 src_scan += 3; | |
1442 } | |
1443 } | |
1444 } | |
1445 return; | |
1446 } | |
1447 uint8_t* dest_buf = buffer + dest_top * pitch + dest_left * Bpp; | |
1448 if (dest_format == FXDIB_Rgb) { | |
1449 if (src_format == FXDIB_Rgb32) { | |
1450 for (int row = 0; row < height; row++) { | |
1451 uint8_t* dest_scan = dest_buf + row * pitch; | |
1452 uint8_t* src_scan = | |
1453 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * 4; | |
1454 for (int col = 0; col < width; col++) { | |
1455 *dest_scan++ = src_scan[2]; | |
1456 *dest_scan++ = src_scan[1]; | |
1457 *dest_scan++ = src_scan[0]; | |
1458 src_scan += 4; | |
1459 } | |
1460 } | |
1461 } else { | |
1462 ASSERT(FALSE); | |
1463 } | |
1464 } else if (dest_format == FXDIB_Argb || dest_format == FXDIB_Rgb32) { | |
1465 if (src_format == FXDIB_Rgb) { | |
1466 for (int row = 0; row < height; row++) { | |
1467 uint8_t* dest_scan = (uint8_t*)(dest_buf + row * pitch); | |
1468 uint8_t* src_scan = | |
1469 (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * 3; | |
1470 for (int col = 0; col < width; col++) { | |
1471 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[0], src_scan[1], | |
1472 src_scan[2])); | |
1473 dest_scan += 4; | |
1474 src_scan += 3; | |
1475 } | |
1476 } | |
1477 } else if (src_format == FXDIB_Rgb32) { | |
1478 ASSERT(dest_format == FXDIB_Argb); | |
1479 for (int row = 0; row < height; row++) { | |
1480 uint8_t* dest_scan = dest_buf + row * pitch; | |
1481 uint8_t* src_scan = | |
1482 (uint8_t*)(pSrcBitmap->GetScanline(src_top + row) + src_left * 4); | |
1483 for (int col = 0; col < width; col++) { | |
1484 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[0], src_scan[1], | |
1485 src_scan[2])); | |
1486 src_scan += 4; | |
1487 dest_scan += 4; | |
1488 } | |
1489 } | |
1490 } | |
1491 } else { | |
1492 ASSERT(FALSE); | |
1493 } | |
1494 } | |
1495 | 1573 |
1496 FX_ARGB _DefaultCMYK2ARGB(FX_CMYK cmyk, uint8_t alpha) { | |
1497 uint8_t r, g, b; | |
1498 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk), | |
1499 FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), r, g, b); | |
1500 return ArgbEncode(alpha, r, g, b); | |
1501 } | |
1502 | |
1503 FX_BOOL _DibSetPixel(CFX_DIBitmap* pDevice, | |
1504 int x, | |
1505 int y, | |
1506 uint32_t color, | |
1507 int alpha_flag, | |
1508 void* pIccTransform) { | |
1509 FX_BOOL bObjCMYK = FXGETFLAG_COLORTYPE(alpha_flag); | |
1510 int alpha = bObjCMYK ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(color); | |
1511 if (pIccTransform) { | |
1512 CCodec_IccModule* pIccModule = | |
1513 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); | |
1514 color = bObjCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); | |
1515 pIccModule->TranslateScanline(pIccTransform, (uint8_t*)&color, | |
1516 (uint8_t*)&color, 1); | |
1517 color = bObjCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); | |
1518 if (!pDevice->IsCmykImage()) { | |
1519 color = (color & 0xffffff) | (alpha << 24); | |
1520 } | |
1521 } else { | |
1522 if (pDevice->IsCmykImage()) { | |
1523 if (!bObjCMYK) { | |
1524 return FALSE; | |
1525 } | |
1526 } else { | |
1527 if (bObjCMYK) { | |
1528 color = _DefaultCMYK2ARGB(color, alpha); | |
1529 } | |
1530 } | |
1531 } | |
1532 pDevice->SetPixel(x, y, color); | |
1533 if (pDevice->m_pAlphaMask) { | |
1534 pDevice->m_pAlphaMask->SetPixel(x, y, alpha << 24); | |
1535 } | |
1536 return TRUE; | |
1537 } | |
1538 | |
1539 FX_BOOL CFX_AggDeviceDriver::SetPixel(int x, | |
1540 int y, | |
1541 uint32_t color, | |
1542 int alpha_flag, | |
1543 void* pIccTransform) { | |
1544 if (!m_pBitmap->GetBuffer()) { | |
1545 return TRUE; | |
1546 } | |
1547 if (!CFX_GEModule::Get()->GetCodecModule() || | |
1548 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { | |
1549 pIccTransform = nullptr; | |
1550 } | |
1551 if (!m_pClipRgn) { | |
1552 if (m_bRgbByteOrder) { | |
1553 RgbByteOrderSetPixel(m_pBitmap, x, y, color); | |
1554 } else { | |
1555 return _DibSetPixel(m_pBitmap, x, y, color, alpha_flag, pIccTransform); | |
1556 } | |
1557 } else if (m_pClipRgn->GetBox().Contains(x, y)) { | |
1558 if (m_pClipRgn->GetType() == CFX_ClipRgn::RectI) { | |
1559 if (m_bRgbByteOrder) { | |
1560 RgbByteOrderSetPixel(m_pBitmap, x, y, color); | |
1561 } else { | |
1562 return _DibSetPixel(m_pBitmap, x, y, color, alpha_flag, pIccTransform); | |
1563 } | |
1564 } else if (m_pClipRgn->GetType() == CFX_ClipRgn::MaskF) { | |
1565 const CFX_DIBitmap* pMask = m_pClipRgn->GetMask().GetObject(); | |
1566 FX_BOOL bCMYK = FXGETFLAG_COLORTYPE(alpha_flag); | |
1567 int new_alpha = | |
1568 bCMYK ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(color); | |
1569 new_alpha = new_alpha * pMask->GetScanline(y)[x] / 255; | |
1570 if (m_bRgbByteOrder) { | |
1571 RgbByteOrderSetPixel(m_pBitmap, x, y, | |
1572 (color & 0xffffff) | (new_alpha << 24)); | |
1573 return TRUE; | |
1574 } | |
1575 if (bCMYK) { | |
1576 FXSETFLAG_ALPHA_FILL(alpha_flag, new_alpha); | |
1577 } else { | |
1578 color = (color & 0xffffff) | (new_alpha << 24); | |
1579 } | |
1580 return _DibSetPixel(m_pBitmap, x, y, color, alpha_flag, pIccTransform); | |
1581 } | |
1582 } | |
1583 return TRUE; | |
1584 } | |
1585 | |
1586 FX_BOOL CFX_AggDeviceDriver::FillRect(const FX_RECT* pRect, | |
1587 uint32_t fill_color, | |
1588 int alpha_flag, | |
1589 void* pIccTransform, | |
1590 int blend_type) { | |
1591 if (blend_type != FXDIB_BLEND_NORMAL) { | |
1592 return FALSE; | |
1593 } | |
1594 if (!m_pBitmap->GetBuffer()) { | |
1595 return TRUE; | |
1596 } | |
1597 FX_RECT clip_rect; | 1574 FX_RECT clip_rect; |
1598 GetClipBox(&clip_rect); | 1575 GetClipBox(&clip_rect); |
1599 FX_RECT draw_rect = clip_rect; | 1576 FX_RECT draw_rect = clip_rect; |
1600 if (pRect) { | 1577 if (pRect) |
1601 draw_rect.Intersect(*pRect); | 1578 draw_rect.Intersect(*pRect); |
1602 } | 1579 if (draw_rect.IsEmpty()) |
1603 if (draw_rect.IsEmpty()) { | |
1604 return TRUE; | 1580 return TRUE; |
1605 } | 1581 |
1606 if (!m_pClipRgn || m_pClipRgn->GetType() == CFX_ClipRgn::RectI) { | 1582 if (!m_pClipRgn || m_pClipRgn->GetType() == CFX_ClipRgn::RectI) { |
1607 if (m_bRgbByteOrder) { | 1583 if (m_bRgbByteOrder) { |
1608 RgbByteOrderCompositeRect(m_pBitmap, draw_rect.left, draw_rect.top, | 1584 RgbByteOrderCompositeRect(m_pBitmap, draw_rect.left, draw_rect.top, |
1609 draw_rect.Width(), draw_rect.Height(), | 1585 draw_rect.Width(), draw_rect.Height(), |
1610 fill_color); | 1586 fill_color); |
1611 } else { | 1587 } else { |
1612 m_pBitmap->CompositeRect(draw_rect.left, draw_rect.top, draw_rect.Width(), | 1588 m_pBitmap->CompositeRect(draw_rect.left, draw_rect.top, draw_rect.Width(), |
1613 draw_rect.Height(), fill_color, alpha_flag, | 1589 draw_rect.Height(), fill_color, 0, nullptr); |
1614 pIccTransform); | |
1615 } | 1590 } |
1616 return TRUE; | 1591 return TRUE; |
1617 } | 1592 } |
1618 m_pBitmap->CompositeMask( | 1593 m_pBitmap->CompositeMask( |
1619 draw_rect.left, draw_rect.top, draw_rect.Width(), draw_rect.Height(), | 1594 draw_rect.left, draw_rect.top, draw_rect.Width(), draw_rect.Height(), |
1620 m_pClipRgn->GetMask().GetObject(), fill_color, | 1595 m_pClipRgn->GetMask().GetObject(), fill_color, |
1621 draw_rect.left - clip_rect.left, draw_rect.top - clip_rect.top, | 1596 draw_rect.left - clip_rect.left, draw_rect.top - clip_rect.top, |
1622 FXDIB_BLEND_NORMAL, nullptr, m_bRgbByteOrder, alpha_flag, pIccTransform); | 1597 FXDIB_BLEND_NORMAL, nullptr, m_bRgbByteOrder, 0, nullptr); |
1623 return TRUE; | 1598 return TRUE; |
1624 } | 1599 } |
1625 | 1600 |
1626 FX_BOOL CFX_AggDeviceDriver::GetClipBox(FX_RECT* pRect) { | 1601 FX_BOOL CFX_AggDeviceDriver::GetClipBox(FX_RECT* pRect) { |
1627 if (!m_pClipRgn) { | 1602 if (!m_pClipRgn) { |
1628 pRect->left = pRect->top = 0; | 1603 pRect->left = pRect->top = 0; |
1629 pRect->right = GetDeviceCaps(FXDC_PIXEL_WIDTH); | 1604 pRect->right = GetDeviceCaps(FXDC_PIXEL_WIDTH); |
1630 pRect->bottom = GetDeviceCaps(FXDC_PIXEL_HEIGHT); | 1605 pRect->bottom = GetDeviceCaps(FXDC_PIXEL_HEIGHT); |
1631 return TRUE; | 1606 return TRUE; |
1632 } | 1607 } |
1633 *pRect = m_pClipRgn->GetBox(); | 1608 *pRect = m_pClipRgn->GetBox(); |
1634 return TRUE; | 1609 return TRUE; |
1635 } | 1610 } |
1636 | 1611 |
1637 FX_BOOL CFX_AggDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, | 1612 FX_BOOL CFX_AggDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, |
1638 int left, | 1613 int left, |
1639 int top, | 1614 int top) { |
1640 void* pIccTransform, | 1615 if (!m_pBitmap || !m_pBitmap->GetBuffer()) |
1641 FX_BOOL bDEdge) { | |
1642 if (!m_pBitmap->GetBuffer()) { | |
1643 return TRUE; | 1616 return TRUE; |
1644 } | 1617 |
1645 if (bDEdge) { | |
1646 if (m_bRgbByteOrder) { | |
1647 RgbByteOrderTransferBitmap(pBitmap, 0, 0, pBitmap->GetWidth(), | |
1648 pBitmap->GetHeight(), m_pBitmap, left, top); | |
1649 } else { | |
1650 return pBitmap->TransferBitmap(0, 0, pBitmap->GetWidth(), | |
1651 pBitmap->GetHeight(), m_pBitmap, left, top, | |
1652 pIccTransform); | |
1653 } | |
1654 return TRUE; | |
1655 } | |
1656 FX_RECT rect(left, top, left + pBitmap->GetWidth(), | 1618 FX_RECT rect(left, top, left + pBitmap->GetWidth(), |
1657 top + pBitmap->GetHeight()); | 1619 top + pBitmap->GetHeight()); |
1658 CFX_DIBitmap* pBack = nullptr; | 1620 CFX_DIBitmap* pBack = nullptr; |
1659 if (m_pOriDevice) { | 1621 if (m_pOriDevice) { |
1660 pBack = m_pOriDevice->Clone(&rect); | 1622 pBack = m_pOriDevice->Clone(&rect); |
1661 if (!pBack) { | 1623 if (!pBack) |
1662 return TRUE; | 1624 return TRUE; |
1663 } | 1625 |
1664 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(), | 1626 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(), |
1665 m_pBitmap, 0, 0); | 1627 m_pBitmap, 0, 0); |
1666 } else { | 1628 } else { |
1667 pBack = m_pBitmap->Clone(&rect); | 1629 pBack = m_pBitmap->Clone(&rect); |
| 1630 if (!pBack) |
| 1631 return TRUE; |
1668 } | 1632 } |
1669 if (!pBack) { | 1633 |
1670 return TRUE; | |
1671 } | |
1672 FX_BOOL bRet = TRUE; | 1634 FX_BOOL bRet = TRUE; |
1673 left = left >= 0 ? 0 : left; | 1635 left = std::min(left, 0); |
1674 top = top >= 0 ? 0 : top; | 1636 top = std::min(top, 0); |
1675 if (m_bRgbByteOrder) { | 1637 if (m_bRgbByteOrder) { |
1676 RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(), | 1638 RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(), |
1677 pBack, left, top); | 1639 pBack, left, top); |
1678 } else { | 1640 } else { |
1679 bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, | 1641 bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, |
1680 left, top, pIccTransform); | 1642 left, top, nullptr); |
1681 } | 1643 } |
1682 delete pBack; | 1644 delete pBack; |
1683 return bRet; | 1645 return bRet; |
1684 } | 1646 } |
1685 | 1647 |
1686 FX_BOOL CFX_AggDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, | 1648 FX_BOOL CFX_AggDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, |
1687 uint32_t argb, | 1649 uint32_t argb, |
1688 const FX_RECT* pSrcRect, | 1650 const FX_RECT* pSrcRect, |
1689 int left, | 1651 int left, |
1690 int top, | 1652 int top, |
1691 int blend_type, | 1653 int blend_type) { |
1692 int alpha_flag, | 1654 if (!m_pBitmap->GetBuffer()) |
1693 void* pIccTransform) { | |
1694 if (!m_pBitmap->GetBuffer()) { | |
1695 return TRUE; | 1655 return TRUE; |
| 1656 |
| 1657 if (pBitmap->IsAlphaMask()) { |
| 1658 return m_pBitmap->CompositeMask(left, top, pSrcRect->Width(), |
| 1659 pSrcRect->Height(), pBitmap, argb, |
| 1660 pSrcRect->left, pSrcRect->top, blend_type, |
| 1661 m_pClipRgn, m_bRgbByteOrder, 0, nullptr); |
1696 } | 1662 } |
1697 if (pBitmap->IsAlphaMask()) | |
1698 return m_pBitmap->CompositeMask( | |
1699 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, argb, | |
1700 pSrcRect->left, pSrcRect->top, blend_type, m_pClipRgn, m_bRgbByteOrder, | |
1701 alpha_flag, pIccTransform); | |
1702 return m_pBitmap->CompositeBitmap( | 1663 return m_pBitmap->CompositeBitmap( |
1703 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, pSrcRect->left, | 1664 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, pSrcRect->left, |
1704 pSrcRect->top, blend_type, m_pClipRgn, m_bRgbByteOrder, pIccTransform); | 1665 pSrcRect->top, blend_type, m_pClipRgn, m_bRgbByteOrder, nullptr); |
1705 } | 1666 } |
1706 | 1667 |
1707 FX_BOOL CFX_AggDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, | 1668 FX_BOOL CFX_AggDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, |
1708 uint32_t argb, | 1669 uint32_t argb, |
1709 int dest_left, | 1670 int dest_left, |
1710 int dest_top, | 1671 int dest_top, |
1711 int dest_width, | 1672 int dest_width, |
1712 int dest_height, | 1673 int dest_height, |
1713 const FX_RECT* pClipRect, | 1674 const FX_RECT* pClipRect, |
1714 uint32_t flags, | 1675 uint32_t flags, |
1715 int alpha_flag, | |
1716 void* pIccTransform, | |
1717 int blend_type) { | 1676 int blend_type) { |
1718 if (!m_pBitmap->GetBuffer()) { | 1677 if (!m_pBitmap->GetBuffer()) |
1719 return TRUE; | 1678 return TRUE; |
1720 } | 1679 |
1721 if (dest_width == pSource->GetWidth() && | 1680 if (dest_width == pSource->GetWidth() && |
1722 dest_height == pSource->GetHeight()) { | 1681 dest_height == pSource->GetHeight()) { |
1723 FX_RECT rect(0, 0, dest_width, dest_height); | 1682 FX_RECT rect(0, 0, dest_width, dest_height); |
1724 return SetDIBits(pSource, argb, &rect, dest_left, dest_top, blend_type, | 1683 return SetDIBits(pSource, argb, &rect, dest_left, dest_top, blend_type); |
1725 alpha_flag, pIccTransform); | |
1726 } | 1684 } |
1727 FX_RECT dest_rect(dest_left, dest_top, dest_left + dest_width, | 1685 FX_RECT dest_rect(dest_left, dest_top, dest_left + dest_width, |
1728 dest_top + dest_height); | 1686 dest_top + dest_height); |
1729 dest_rect.Normalize(); | 1687 dest_rect.Normalize(); |
1730 FX_RECT dest_clip = dest_rect; | 1688 FX_RECT dest_clip = dest_rect; |
1731 dest_clip.Intersect(*pClipRect); | 1689 dest_clip.Intersect(*pClipRect); |
1732 CFX_BitmapComposer composer; | 1690 CFX_BitmapComposer composer; |
1733 composer.Compose(m_pBitmap, m_pClipRgn, 255, argb, dest_clip, FALSE, FALSE, | 1691 composer.Compose(m_pBitmap, m_pClipRgn, 255, argb, dest_clip, FALSE, FALSE, |
1734 FALSE, m_bRgbByteOrder, alpha_flag, pIccTransform, | 1692 FALSE, m_bRgbByteOrder, 0, nullptr, blend_type); |
1735 blend_type); | |
1736 dest_clip.Offset(-dest_rect.left, -dest_rect.top); | 1693 dest_clip.Offset(-dest_rect.left, -dest_rect.top); |
1737 CFX_ImageStretcher stretcher(&composer, pSource, dest_width, dest_height, | 1694 CFX_ImageStretcher stretcher(&composer, pSource, dest_width, dest_height, |
1738 dest_clip, flags); | 1695 dest_clip, flags); |
1739 if (stretcher.Start()) | 1696 if (stretcher.Start()) |
1740 stretcher.Continue(nullptr); | 1697 stretcher.Continue(nullptr); |
1741 return TRUE; | 1698 return TRUE; |
1742 } | 1699 } |
1743 | 1700 |
1744 FX_BOOL CFX_AggDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, | 1701 FX_BOOL CFX_AggDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, |
1745 int bitmap_alpha, | 1702 int bitmap_alpha, |
1746 uint32_t argb, | 1703 uint32_t argb, |
1747 const CFX_Matrix* pMatrix, | 1704 const CFX_Matrix* pMatrix, |
1748 uint32_t render_flags, | 1705 uint32_t render_flags, |
1749 void*& handle, | 1706 void*& handle, |
1750 int alpha_flag, | |
1751 void* pIccTransform, | |
1752 int blend_type) { | 1707 int blend_type) { |
1753 if (!m_pBitmap->GetBuffer()) { | 1708 if (!m_pBitmap->GetBuffer()) |
1754 return TRUE; | 1709 return TRUE; |
1755 } | 1710 |
1756 CFX_ImageRenderer* pRenderer = new CFX_ImageRenderer; | 1711 CFX_ImageRenderer* pRenderer = new CFX_ImageRenderer; |
1757 pRenderer->Start(m_pBitmap, m_pClipRgn, pSource, bitmap_alpha, argb, pMatrix, | 1712 pRenderer->Start(m_pBitmap, m_pClipRgn, pSource, bitmap_alpha, argb, pMatrix, |
1758 render_flags, m_bRgbByteOrder, alpha_flag, pIccTransform); | 1713 render_flags, m_bRgbByteOrder, 0, nullptr); |
1759 handle = pRenderer; | 1714 handle = pRenderer; |
1760 return TRUE; | 1715 return TRUE; |
1761 } | 1716 } |
1762 | 1717 |
1763 FX_BOOL CFX_AggDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) { | 1718 FX_BOOL CFX_AggDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) { |
1764 if (!m_pBitmap->GetBuffer()) { | 1719 if (!m_pBitmap->GetBuffer()) { |
1765 return TRUE; | 1720 return TRUE; |
1766 } | 1721 } |
1767 return ((CFX_ImageRenderer*)pHandle)->Continue(pPause); | 1722 return ((CFX_ImageRenderer*)pHandle)->Continue(pPause); |
1768 } | 1723 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1809 SetDeviceDriver(pDriver); | 1764 SetDeviceDriver(pDriver); |
1810 return true; | 1765 return true; |
1811 } | 1766 } |
1812 | 1767 |
1813 CFX_FxgeDevice::~CFX_FxgeDevice() { | 1768 CFX_FxgeDevice::~CFX_FxgeDevice() { |
1814 if (m_bOwnedBitmap) { | 1769 if (m_bOwnedBitmap) { |
1815 delete GetBitmap(); | 1770 delete GetBitmap(); |
1816 } | 1771 } |
1817 } | 1772 } |
1818 #endif | 1773 #endif |
OLD | NEW |