| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 |
| 7 #include "../../../include/fxge/fx_ge.h" |
| 8 #include "../../../include/fxcodec/fx_codec.h" |
| 9 #include "fx_skia.h" |
| 10 #include "fx_skia_blitter.h" |
| 11 #include "fx_skia_driver.h" |
| 12 #if (_FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_) |
| 13 #include "../apple/apple_int.h" |
| 14 #endif |
| 15 |
| 16 |
| 17 CFX_SkiaDriver::CFX_SkiaDriver(CFX_DIBitmap* pBitmap, int dither_bits, FX_BOOL b
RgbByteOrder, CFX_DIBitmap* pOriDevice, FX_BOOL bGroupKnockout) |
| 18 { |
| 19 m_pBitmap = pBitmap; |
| 20 m_DitherBits = dither_bits; |
| 21 m_pClipRgn = NULL; |
| 22 m_pPlatformBitmap = NULL; |
| 23 m_pPlatformGraphics = NULL; |
| 24 m_pDwRenderTartget = NULL; |
| 25 m_bRgbByteOrder = bRgbByteOrder; |
| 26 m_pOriDevice = pOriDevice; |
| 27 m_bGroupKnockout = bGroupKnockout; |
| 28 m_FillFlags = 0; |
| 29 } |
| 30 |
| 31 CFX_SkiaDriver::~CFX_SkiaDriver() |
| 32 { |
| 33 if (m_pClipRgn) { |
| 34 delete m_pClipRgn; |
| 35 } |
| 36 for (int i = 0; i < m_StateStack.GetSize(); i++) |
| 37 if (m_StateStack[i]) { |
| 38 delete (CFX_ClipRgn*)m_StateStack[i]; |
| 39 } |
| 40 } |
| 41 |
| 42 void CFX_SkiaDriver::InitPlatform() |
| 43 { |
| 44 #if (_FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ && (!defined(_FPDFAPI_MINI_))) |
| 45 CQuartz2D & quartz2d = ((CApplePlatform *)CFX_GEModule::Get()->GetPlatformDa
ta())->_quartz2d; |
| 46 m_pPlatformGraphics = quartz2d.createGraphics(m_pBitmap); |
| 47 #endif |
| 48 } |
| 49 |
| 50 void CFX_SkiaDriver::DestroyPlatform() |
| 51 { |
| 52 #if (_FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ && (!defined(_FPDFAPI_MINI_))) |
| 53 CQuartz2D & quartz2d = ((CApplePlatform *)CFX_GEModule::Get()->GetPlatformDa
ta())->_quartz2d; |
| 54 if (m_pPlatformGraphics) { |
| 55 quartz2d.destroyGraphics(m_pPlatformGraphics); |
| 56 m_pPlatformGraphics = NULL; |
| 57 } |
| 58 #endif |
| 59 } |
| 60 |
| 61 int CFX_SkiaDriver::GetDeviceCaps(int caps_id) |
| 62 { |
| 63 switch (caps_id) { |
| 64 case FXDC_DEVICE_CLASS: |
| 65 return FXDC_DISPLAY; |
| 66 case FXDC_PIXEL_WIDTH: |
| 67 return m_pBitmap->GetWidth(); |
| 68 case FXDC_PIXEL_HEIGHT: |
| 69 return m_pBitmap->GetHeight(); |
| 70 case FXDC_BITS_PIXEL: |
| 71 return m_pBitmap->GetBPP(); |
| 72 case FXDC_HORZ_SIZE: |
| 73 case FXDC_VERT_SIZE: |
| 74 return 0; |
| 75 case FXDC_RENDER_CAPS: { |
| 76 int flags = FXRC_GET_BITS | FXRC_ALPHA_PATH | FXR
C_ALPHA_IMAGE | FXRC_BLEND_MODE | FXRC_SOFT_CLIP; |
| 77 if (m_pBitmap->HasAlpha()) { |
| 78 flags |= FXRC_ALPHA_OUTPUT; |
| 79 } |
| 80 else if (m_pBitmap->IsAlphaMask()) { |
| 81 if (m_pBitmap->GetBPP() == 1) { |
| 82 flags |= FXRC_BITMASK_OUTPUT; |
| 83 } |
| 84 else { |
| 85 flags |= FXRC_BYTEMASK_OUTPUT; |
| 86 } |
| 87 } |
| 88 if (m_pBitmap->IsCmykImage()) { |
| 89 flags |= FXRC_CMYK_OUTPUT; |
| 90 } |
| 91 return flags; |
| 92 } |
| 93 case FXDC_DITHER_BITS: |
| 94 return m_DitherBits; |
| 95 } |
| 96 return 0; |
| 97 } |
| 98 |
| 99 void CFX_SkiaDriver::SaveState() |
| 100 { |
| 101 void* pClip = NULL; |
| 102 if (m_pClipRgn) { |
| 103 pClip = FX_NEW CFX_ClipRgn(*m_pClipRgn); |
| 104 if (!pClip) { |
| 105 return; |
| 106 } |
| 107 } |
| 108 m_StateStack.Add(pClip); |
| 109 } |
| 110 |
| 111 void CFX_SkiaDriver::RestoreState(FX_BOOL bKeepSaved) |
| 112 { |
| 113 if (m_StateStack.GetSize() == 0) { |
| 114 if (m_pClipRgn) { |
| 115 delete m_pClipRgn; |
| 116 m_pClipRgn = NULL; |
| 117 } |
| 118 return; |
| 119 } |
| 120 CFX_ClipRgn* pSavedClip = (CFX_ClipRgn*)m_StateStack[m_StateStack.GetSize()
- 1]; |
| 121 if (m_pClipRgn) { |
| 122 delete m_pClipRgn; |
| 123 m_pClipRgn = NULL; |
| 124 } |
| 125 if (bKeepSaved) { |
| 126 if (pSavedClip) { |
| 127 m_pClipRgn = FX_NEW CFX_ClipRgn(*pSavedClip); |
| 128 } |
| 129 } |
| 130 else { |
| 131 m_StateStack.RemoveAt(m_StateStack.GetSize() - 1); |
| 132 m_pClipRgn = pSavedClip; |
| 133 } |
| 134 } |
| 135 |
| 136 FX_BOOL CFX_SkiaDriver::SetClip_PathFill(const CFX_PathData* pPathData, |
| 137 const CFX_AffineMatrix* pObject2Device, |
| 138 int fill_mode) |
| 139 { |
| 140 if (m_pClipRgn == NULL) { |
| 141 m_pClipRgn = FX_NEW CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDevi
ceCaps(FXDC_PIXEL_HEIGHT)); |
| 142 } |
| 143 if (!m_pClipRgn) { |
| 144 return FALSE; |
| 145 } |
| 146 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { |
| 147 CFX_FloatRect rectf; |
| 148 if (pPathData->IsRect(pObject2Device, &rectf)) { |
| 149 rectf.Intersect(CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIX
EL_WIDTH), (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); |
| 150 FX_RECT rect = rectf.GetOutterRect(); |
| 151 m_pClipRgn->IntersectRect(rect); |
| 152 return TRUE; |
| 153 } |
| 154 } |
| 155 CSkia_PathData path_data; |
| 156 path_data.BuildPath(pPathData, pObject2Device); |
| 157 path_data.m_PathData.close(); |
| 158 path_data.m_PathData.setFillType((fill_mode & 3) == FXFILL_WINDING ? SkPath:
:kWinding_FillType : SkPath::kEvenOdd_FillType); |
| 159 SkPaint spaint; |
| 160 spaint.setColor(0xffffffff); |
| 161 spaint.setAntiAlias(TRUE); |
| 162 spaint.setStyle(SkPaint::kFill_Style); |
| 163 SetClipMask(path_data.m_PathData, &spaint); |
| 164 return TRUE; |
| 165 } |
| 166 |
| 167 FX_BOOL CFX_SkiaDriver::SetClip_PathStroke(const CFX_PathData* pPathData, |
| 168 const CFX_AffineMatrix* pObject2Device, |
| 169 const CFX_GraphStateData* pGraphState) |
| 170 { |
| 171 if (m_pClipRgn == NULL) { |
| 172 m_pClipRgn = FX_NEW CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDevi
ceCaps(FXDC_PIXEL_HEIGHT)); |
| 173 } |
| 174 if (!m_pClipRgn) { |
| 175 return FALSE; |
| 176 } |
| 177 CSkia_PathData path_data; |
| 178 path_data.BuildPath(pPathData, NULL); |
| 179 path_data.m_PathData.setFillType(SkPath::kWinding_FillType); |
| 180 SkPaint spaint; |
| 181 spaint.setColor(0xffffffff); |
| 182 spaint.setStyle(SkPaint::kStroke_Style); |
| 183 spaint.setAntiAlias(TRUE); |
| 184 SkPath dst_path; |
| 185 SkRasterizeStroke(spaint, &dst_path, path_data.m_PathData, pObject2Device, p
GraphState, 1, FALSE, 0); |
| 186 spaint.setStyle(SkPaint::kFill_Style); |
| 187 SetClipMask(dst_path, &spaint); |
| 188 return TRUE; |
| 189 } |
| 190 |
| 191 FX_BOOL CFX_SkiaDriver::DrawPath(const CFX_PathData* pPathData, |
| 192 const CFX_AffineMatrix* pObject2Device, |
| 193 const CFX_GraphStateData* pGraphState, |
| 194 FX_DWORD fill_color, |
| 195 FX_DWORD stroke_color, |
| 196 int fill_mode, |
| 197 int alpha_flag, |
| 198 void* pIccTransform, |
| 199 int blend_type |
| 200 ) |
| 201 { |
| 202 if (blend_type != FXDIB_BLEND_NORMAL) { |
| 203 return FALSE; |
| 204 } |
| 205 if (GetBuffer() == NULL) { |
| 206 return TRUE; |
| 207 } |
| 208 SkIRect rect; |
| 209 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEI
GHT)); |
| 210 if ((fill_mode & 3) && fill_color) { |
| 211 CSkia_PathData path_data; |
| 212 path_data.BuildPath(pPathData, pObject2Device); |
| 213 path_data.m_PathData.setFillType((fill_mode & 3) == FXFILL_WINDING ? SkP
ath::kWinding_FillType : SkPath::kEvenOdd_FillType); |
| 214 SkPaint spaint; |
| 215 spaint.setAntiAlias(TRUE); |
| 216 spaint.setStyle(SkPaint::kFill_Style); |
| 217 spaint.setColor(fill_color); |
| 218 if (!RenderRasterizerSkia(path_data.m_PathData, spaint, rect, fill_color
, fill_mode & FXFILL_FULLCOVER, FALSE, alpha_flag, pIccTransform)) { |
| 219 return FALSE; |
| 220 } |
| 221 } |
| 222 int stroke_alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_STROKE(
alpha_flag) : FXARGB_A(stroke_color); |
| 223 if (pGraphState && stroke_alpha) { |
| 224 CFX_AffineMatrix matrix1, matrix2; |
| 225 if (pObject2Device) { |
| 226 matrix1.a = FXSYS_fabs(pObject2Device->a) > FXSYS_fabs(pObject2Devic
e->b) ? |
| 227 FXSYS_fabs(pObject2Device->a) : FXSYS_fabs(pObject2Devic
e->b); |
| 228 matrix1.d = matrix1.a; |
| 229 matrix2.Set(pObject2Device->a / matrix1.a, pObject2Device->b / matri
x1.a, |
| 230 pObject2Device->c / matrix1.d, pObject2Device->d / matri
x1.d, |
| 231 pObject2Device->e, pObject2Device->f); |
| 232 } |
| 233 CSkia_PathData path_data; |
| 234 path_data.BuildPath(pPathData, &matrix1); |
| 235 path_data.m_PathData.setFillType(SkPath::kWinding_FillType); |
| 236 SkPaint spaint; |
| 237 spaint.setColor(stroke_color); |
| 238 spaint.setStyle(SkPaint::kStroke_Style); |
| 239 spaint.setAntiAlias(TRUE); |
| 240 SkPath dst_path; |
| 241 SkRasterizeStroke(spaint, &dst_path, path_data.m_PathData, &matrix2, pGr
aphState, matrix1.a, FALSE, 0); |
| 242 spaint.setStyle(SkPaint::kFill_Style); |
| 243 int fill_flag = FXGETFLAG_COLORTYPE(alpha_flag) << 8 | FXGETFLAG_ALPHA_S
TROKE(alpha_flag); |
| 244 if (!RenderRasterizerSkia(dst_path, spaint, rect, stroke_color, fill_mod
e & FXFILL_FULLCOVER, FALSE, fill_flag, pIccTransform, FALSE)) { |
| 245 return FALSE; |
| 246 } |
| 247 } |
| 248 return TRUE; |
| 249 } |
| 250 |
| 251 FX_BOOL CFX_SkiaDriver::SetPixel(int x, int y, FX_DWORD color, int alpha_flag, v
oid* pIccTransform) |
| 252 { |
| 253 if (m_pBitmap->GetBuffer() == NULL) { |
| 254 return TRUE; |
| 255 } |
| 256 if (!CFX_GEModule::Get()->GetCodecModule() || !CFX_GEModule::Get()->GetCodec
Module()->GetIccModule()) { |
| 257 pIccTransform = NULL; |
| 258 } |
| 259 if (m_pClipRgn == NULL) { |
| 260 if (m_bRgbByteOrder) { |
| 261 RgbByteOrderSetPixel(m_pBitmap, x, y, color); |
| 262 } |
| 263 else { |
| 264 return _DibSetPixel(m_pBitmap, x, y, color, alpha_flag, pIccTransfor
m); |
| 265 } |
| 266 } |
| 267 else if (m_pClipRgn->GetBox().Contains(x, y)) { |
| 268 if (m_pClipRgn->GetType() == CFX_ClipRgn::RectI) { |
| 269 if (m_bRgbByteOrder) { |
| 270 RgbByteOrderSetPixel(m_pBitmap, x, y, color); |
| 271 } |
| 272 else { |
| 273 return _DibSetPixel(m_pBitmap, x, y, color, alpha_flag, pIccTran
sform); |
| 274 } |
| 275 } |
| 276 else if (m_pClipRgn->GetType() == CFX_ClipRgn::MaskF) { |
| 277 const CFX_DIBitmap* pMask = m_pClipRgn->GetMask(); |
| 278 FX_BOOL bCMYK = FXGETFLAG_COLORTYPE(alpha_flag); |
| 279 int new_alpha = bCMYK ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(
color); |
| 280 new_alpha = new_alpha * pMask->GetScanline(y)[x] / 255; |
| 281 if (m_bRgbByteOrder) { |
| 282 RgbByteOrderSetPixel(m_pBitmap, x, y, (color & 0xffffff) | (new_
alpha << 24)); |
| 283 return TRUE; |
| 284 } |
| 285 if (bCMYK) { |
| 286 FXSETFLAG_ALPHA_FILL(alpha_flag, new_alpha); |
| 287 } |
| 288 else { |
| 289 color = (color & 0xffffff) | (new_alpha << 24); |
| 290 } |
| 291 return _DibSetPixel(m_pBitmap, x, y, color, alpha_flag, pIccTransfor
m); |
| 292 } |
| 293 } |
| 294 return TRUE; |
| 295 } |
| 296 |
| 297 FX_BOOL CFX_SkiaDriver::FillRect(const FX_RECT* pRect, FX_DWORD fill_color, int
alpha_flag, void* pIccTransform, int blend_type) |
| 298 { |
| 299 if (blend_type != FXDIB_BLEND_NORMAL) { |
| 300 return FALSE; |
| 301 } |
| 302 if (m_pBitmap->GetBuffer() == NULL) { |
| 303 return TRUE; |
| 304 } |
| 305 FX_RECT clip_rect; |
| 306 GetClipBox(&clip_rect); |
| 307 FX_RECT draw_rect = clip_rect; |
| 308 if (pRect) { |
| 309 draw_rect.Intersect(*pRect); |
| 310 } |
| 311 if (draw_rect.IsEmpty()) { |
| 312 return TRUE; |
| 313 } |
| 314 if (m_pClipRgn == NULL || m_pClipRgn->GetType() == CFX_ClipRgn::RectI) { |
| 315 if (m_bRgbByteOrder) { |
| 316 RgbByteOrderCompositeRect(m_pBitmap, draw_rect.left, draw_rect.top,
draw_rect.Width(), draw_rect.Height(), fill_color); |
| 317 } |
| 318 else { |
| 319 m_pBitmap->CompositeRect(draw_rect.left, draw_rect.top, draw_rect.Wi
dth(), draw_rect.Height(), fill_color, alpha_flag, pIccTransform); |
| 320 } |
| 321 return TRUE; |
| 322 } |
| 323 m_pBitmap->CompositeMask(draw_rect.left, draw_rect.top, draw_rect.Width(), d
raw_rect.Height(), (const CFX_DIBitmap*)m_pClipRgn->GetMask(), |
| 324 fill_color, draw_rect.left - clip_rect.left, draw_rect.top - clip_rect.t
op, FXDIB_BLEND_NORMAL, NULL, m_bRgbByteOrder, alpha_flag, pIccTransform); |
| 325 return TRUE; |
| 326 } |
| 327 |
| 328 FX_BOOL CFX_SkiaDriver::GetClipBox(FX_RECT* pRect) |
| 329 { |
| 330 if (m_pClipRgn == NULL) { |
| 331 pRect->left = pRect->top = 0; |
| 332 pRect->right = GetDeviceCaps(FXDC_PIXEL_WIDTH); |
| 333 pRect->bottom = GetDeviceCaps(FXDC_PIXEL_HEIGHT); |
| 334 return TRUE; |
| 335 } |
| 336 *pRect = m_pClipRgn->GetBox(); |
| 337 return TRUE; |
| 338 } |
| 339 |
| 340 FX_BOOL CFX_SkiaDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top, void
* pIccTransform, FX_BOOL bDEdge) |
| 341 { |
| 342 if (m_pBitmap->GetBuffer() == NULL) { |
| 343 return TRUE; |
| 344 } |
| 345 if (bDEdge) { |
| 346 if (m_bRgbByteOrder) { |
| 347 RgbByteOrderTransferBitmap(pBitmap, 0, 0, pBitmap->GetWidth(), pBitm
ap->GetHeight(), m_pBitmap, left, top); |
| 348 } |
| 349 else { |
| 350 return pBitmap->TransferBitmap(0, 0, pBitmap->GetWidth(), pBitmap->G
etHeight(), m_pBitmap, left, top, pIccTransform); |
| 351 } |
| 352 return TRUE; |
| 353 } |
| 354 FX_RECT rect(left, top, left + pBitmap->GetWidth(), top + pBitmap->GetHeight
()); |
| 355 CFX_DIBitmap *pBack = NULL; |
| 356 if (m_pOriDevice) { |
| 357 pBack = m_pOriDevice->Clone(&rect); |
| 358 if (!pBack) { |
| 359 return TRUE; |
| 360 } |
| 361 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(), m_pB
itmap, 0, 0); |
| 362 } |
| 363 else { |
| 364 pBack = m_pBitmap->Clone(&rect); |
| 365 } |
| 366 if (!pBack) { |
| 367 return TRUE; |
| 368 } |
| 369 FX_BOOL bRet = TRUE; |
| 370 left = left >= 0 ? 0 : left; |
| 371 top = top >= 0 ? 0 : top; |
| 372 if (m_bRgbByteOrder) { |
| 373 RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(), p
Back, left, top); |
| 374 } |
| 375 else { |
| 376 bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack,
left, top, pIccTransform); |
| 377 } |
| 378 delete pBack; |
| 379 return bRet; |
| 380 } |
| 381 |
| 382 FX_BOOL CFX_SkiaDriver::SetDIBits(const CFX_DIBSource* pBitmap, FX_DWORD argb, c
onst FX_RECT* pSrcRect, int left, int top, int blend_type, |
| 383 int alpha_flag, void* pIccTransform) |
| 384 { |
| 385 if (m_pBitmap->GetBuffer() == NULL) { |
| 386 return TRUE; |
| 387 } |
| 388 if (pBitmap->IsAlphaMask()) |
| 389 return m_pBitmap->CompositeMask(left, top, pSrcRect->Width(), pSrcRect->
Height(), pBitmap, argb, |
| 390 pSrcRect->left, pSrcRect->top, blend_type, m_pClipRgn, m_bRgbByteOrder,
alpha_flag, pIccTransform); |
| 391 return m_pBitmap->CompositeBitmap(left, top, pSrcRect->Width(), pSrcRect->He
ight(), pBitmap, |
| 392 pSrcRect->left, pSrcRect->top, blend_type, m_pClipRgn, m_bRgbByteOrder,
pIccTransform); |
| 393 } |
| 394 |
| 395 FX_BOOL CFX_SkiaDriver::StretchDIBits(const CFX_DIBSource* pSource, FX_DWORD arg
b, int dest_left, int dest_top, |
| 396 int dest_width, int dest_height, const FX_RECT* pClipRect, FX_DWORD flags, |
| 397 int alpha_flag, void* pIccTransform, int blend_type) |
| 398 { |
| 399 if (m_pBitmap->GetBuffer() == NULL) { |
| 400 return TRUE; |
| 401 } |
| 402 if (dest_width == pSource->GetWidth() && dest_height == pSource->GetHeight()
) { |
| 403 FX_RECT rect(0, 0, dest_width, dest_height); |
| 404 return SetDIBits(pSource, argb, &rect, dest_left, dest_top, blend_type,
alpha_flag, pIccTransform); |
| 405 } |
| 406 FX_RECT dest_rect(dest_left, dest_top, dest_left + dest_width, dest_top + de
st_height); |
| 407 dest_rect.Normalize(); |
| 408 FX_RECT dest_clip = dest_rect; |
| 409 dest_clip.Intersect(*pClipRect); |
| 410 CFX_BitmapComposer composer; |
| 411 composer.Compose(m_pBitmap, m_pClipRgn, 255, argb, dest_clip, FALSE, FALSE,
FALSE, m_bRgbByteOrder, alpha_flag, pIccTransform, blend_type); |
| 412 dest_clip.Offset(-dest_rect.left, -dest_rect.top); |
| 413 CFX_ImageStretcher stretcher; |
| 414 if (stretcher.Start(&composer, pSource, dest_width, dest_height, dest_clip,
flags)) { |
| 415 stretcher.Continue(NULL); |
| 416 } |
| 417 return TRUE; |
| 418 } |
| 419 |
| 420 FX_BOOL CFX_SkiaDriver::StartDIBits(const CFX_DIBSource* pSource, int bitmap_alp
ha, FX_DWORD argb, |
| 421 const CFX_AffineMatrix* pMatrix, FX_DWORD render_flags, FX_LPVOID& handle, |
| 422 int alpha_flag, void* pIccTransform, int blend_type) |
| 423 { |
| 424 if (m_pBitmap->GetBuffer() == NULL) { |
| 425 return TRUE; |
| 426 } |
| 427 CFX_ImageRenderer* pRenderer = FX_NEW CFX_ImageRenderer; |
| 428 if (!pRenderer) { |
| 429 return FALSE; |
| 430 } |
| 431 pRenderer->Start(m_pBitmap, m_pClipRgn, pSource, bitmap_alpha, argb, pMatrix
, render_flags, m_bRgbByteOrder, alpha_flag, pIccTransform); |
| 432 handle = pRenderer; |
| 433 return TRUE; |
| 434 } |
| 435 |
| 436 FX_BOOL CFX_SkiaDriver::ContinueDIBits(FX_LPVOID pHandle, IFX_Pause* pPause) |
| 437 { |
| 438 if (m_pBitmap->GetBuffer() == NULL) { |
| 439 return TRUE; |
| 440 } |
| 441 return ((CFX_ImageRenderer*)pHandle)->Continue(pPause); |
| 442 } |
| 443 |
| 444 void CFX_SkiaDriver::CancelDIBits(FX_LPVOID pHandle) |
| 445 { |
| 446 if (m_pBitmap->GetBuffer() == NULL) { |
| 447 return; |
| 448 } |
| 449 delete (CFX_ImageRenderer*)pHandle; |
| 450 } |
| 451 |
| 452 FX_BOOL CFX_SkiaDriver::DrawDeviceText(int nChars, const FXTEXT_CHARPOS* pCharPo
s, CFX_Font* pFont, |
| 453 CFX_FontCache* pCache, const CFX_AffineMatrix* pObject2Device, FX_FLOAT font
_size, FX_DWORD color, |
| 454 int alpha_flag, void* pIccTransform) |
| 455 { |
| 456 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ || _FXM_PLATFORM_ ==
_FXM_PLATFORM_LINUX_ |
| 457 return FALSE; |
| 458 #endif |
| 459 |
| 460 #if (_FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ && (!defined(_FPDFAPI_MINI_))) |
| 461 if (!pFont) { |
| 462 return FALSE; |
| 463 } |
| 464 FX_BOOL bBold = pFont->IsBold(); |
| 465 if (!bBold && pFont->GetSubstFont() && |
| 466 pFont->GetSubstFont()->m_Weight >= 500 && |
| 467 pFont->GetSubstFont()->m_Weight <= 600) { |
| 468 return FALSE; |
| 469 } |
| 470 for (int i = 0; i < nChars; i++) { |
| 471 if (pCharPos[i].m_bGlyphAdjust) { |
| 472 return FALSE; |
| 473 } |
| 474 } |
| 475 CGContextRef ctx = CGContextRef(m_pPlatformGraphics); |
| 476 if (NULL == ctx) { |
| 477 return FALSE; |
| 478 } |
| 479 CGContextSaveGState(ctx); |
| 480 CGContextSetTextDrawingMode(ctx, kCGTextFillClip); |
| 481 CGRect rect_cg; |
| 482 CGImageRef pImageCG = NULL; |
| 483 if (m_pClipRgn) { |
| 484 rect_cg = CGRectMake(m_pClipRgn->GetBox().left, m_pClipRgn->GetBox().top
, m_pClipRgn->GetBox().Width(), m_pClipRgn->GetBox().Height()); |
| 485 const CFX_DIBitmap* pClipMask = m_pClipRgn->GetMask(); |
| 486 if (pClipMask) { |
| 487 CGDataProviderRef pClipMaskDataProvider = CGDataProviderCreateWithDa
ta(NULL, |
| 488 pClipMask->GetBuffer(), |
| 489 pClipMask->GetPitch() * pClipMask->GetHeight(), |
| 490 _DoNothing); |
| 491 CGFloat decode_f[2] = { 255.f, 0.f }; |
| 492 pImageCG = CGImageMaskCreate(pClipMask->GetWidth(), pClipMask->GetHe
ight(), |
| 493 8, 8, pClipMask->GetPitch(), pClipMaskDataProvider, |
| 494 decode_f, FALSE); |
| 495 CGDataProviderRelease(pClipMaskDataProvider); |
| 496 } |
| 497 } |
| 498 else { |
| 499 rect_cg = CGRectMake(0, 0, m_pBitmap->GetWidth(), m_pBitmap->GetHeight()
); |
| 500 } |
| 501 rect_cg = CGContextConvertRectToDeviceSpace(ctx, rect_cg); |
| 502 if (pImageCG) { |
| 503 CGContextClipToMask(ctx, rect_cg, pImageCG); |
| 504 } |
| 505 else { |
| 506 CGContextClipToRect(ctx, rect_cg); |
| 507 } |
| 508 FX_BOOL ret = _CGDrawGlyphRun(ctx, nChars, pCharPos, pFont, pCache, pObject2
Device, font_size, color, alpha_flag, pIccTransform); |
| 509 if (pImageCG) { |
| 510 CGImageRelease(pImageCG); |
| 511 } |
| 512 CGContextRestoreGState(ctx); |
| 513 return ret; |
| 514 #endif |
| 515 |
| 516 } |
| 517 |
| 518 FX_BOOL CFX_SkiaDriver::RenderRasterizerSkia(SkPath& skPath, const SkPaint& orig
Paint, SkIRect& rect, FX_DWORD color, FX_BOOL bFullCover, FX_BOOL bGroupKnockout
, |
| 519 int alpha_flag, void* pIccTransform, FX_BOOL bFill) |
| 520 { |
| 521 CFX_DIBitmap* pt = bGroupKnockout ? this->GetBackDrop() : NULL; |
| 522 CFX_SkiaRenderer render; |
| 523 if (!render.Init(m_pBitmap, pt, m_pClipRgn, color, bFullCover, m_bRgbByteOrd
er, alpha_flag, pIccTransform)) { |
| 524 return FALSE; |
| 525 } |
| 526 SkRasterClip rasterClip(rect); |
| 527 SuperBlitter_skia::DrawPath(skPath, (SkBlitter*)&render, rasterClip, origPa
int); |
| 528 return TRUE; |
| 529 } |
| 530 |
| 531 void CFX_SkiaDriver::SetClipMask(SkPath& skPath, SkPaint* spaint) |
| 532 { |
| 533 SkIRect clip_box; |
| 534 clip_box.set(0, 0, (FX_FLOAT)(GetDeviceCaps(FXDC_PIXEL_WIDTH)), (FX_FLOAT)(G
etDeviceCaps(FXDC_PIXEL_HEIGHT))); |
| 535 clip_box.intersect(m_pClipRgn->GetBox().left, m_pClipRgn->GetBox().top, |
| 536 m_pClipRgn->GetBox().right, m_pClipRgn->GetBox().bottom); |
| 537 SkPath* pathPtr = &skPath; |
| 538 SkRect path_rect = skPath.getBounds(); |
| 539 clip_box.intersect(FXSYS_floor(path_rect.fLeft), FXSYS_floor(path_rect.fTop)
, FXSYS_floor(path_rect.fRight) + 1, FXSYS_floor(path_rect.fBottom) + 1); |
| 540 CFX_DIBitmapRef mask; |
| 541 CFX_DIBitmap* pThisLayer = mask.New(); |
| 542 if (!pThisLayer) { |
| 543 return; |
| 544 } |
| 545 pThisLayer->Create(clip_box.width(), clip_box.height(), FXDIB_8bppMask); |
| 546 pThisLayer->Clear(0); |
| 547 CFX_SkiaA8Renderer render; |
| 548 render.Init(pThisLayer, clip_box.fLeft, clip_box.fTop); |
| 549 SkRasterClip rasterClip(clip_box); |
| 550 SuperBlitter_skia::DrawPath(skPath, (SkBlitter*)&render, rasterClip, *spaint
); |
| 551 m_pClipRgn->IntersectMaskF(clip_box.fLeft, clip_box.fTop, mask); |
| 552 } |
| 553 |
| 554 |
| 555 void SuperBlitter_skia::DrawPath(const SkPath& srcPath, SkBlitter* blitter, cons
t SkRasterClip& rect, const SkPaint& origPaint) |
| 556 { |
| 557 SkPath* pathPtr = (SkPath*)&srcPath; |
| 558 bool doFill = true; |
| 559 SkPath tmpPath; |
| 560 SkTCopyOnFirstWrite<SkPaint> paint(origPaint); |
| 561 { |
| 562 SkScalar coverage; |
| 563 if (FxSkDrawTreatAsHairline(origPaint, &coverage)) { |
| 564 if (FXSYS_fabs(SK_Scalar1 - coverage) < 0.000001f) { |
| 565 paint.writable()->setStrokeWidth(0); |
| 566 } |
| 567 else if (1) { |
| 568 U8CPU newAlpha; |
| 569 int scale = (int)SkScalarMul(coverage, 256); |
| 570 newAlpha = origPaint.getAlpha() * scale >> 8; |
| 571 SkPaint* writablePaint = paint.writable(); |
| 572 writablePaint->setStrokeWidth(0); |
| 573 writablePaint->setAlpha(newAlpha); |
| 574 } |
| 575 } |
| 576 } |
| 577 if (paint->getPathEffect() || paint->getStyle() != SkPaint::kFill_Style) { |
| 578 SkIRect devBounds = rect.getBounds(); |
| 579 devBounds.outset(1, 1); |
| 580 SkRect cullRect = SkRect::Make(devBounds); |
| 581 doFill = paint->getFillPath(*pathPtr, &tmpPath, &cullRect); |
| 582 pathPtr = &tmpPath; |
| 583 } |
| 584 SkPath* devPathPtr = pathPtr; |
| 585 void(*proc)(const SkPath&, const SkRasterClip&, SkBlitter*); |
| 586 if (doFill) { |
| 587 if (paint->isAntiAlias()) { |
| 588 proc = SkScan::AntiFillPath; |
| 589 } |
| 590 else { |
| 591 proc = SkScan::FillPath; |
| 592 } |
| 593 } |
| 594 else { |
| 595 if (paint->isAntiAlias()) { |
| 596 proc = SkScan::AntiHairPath; |
| 597 } |
| 598 else { |
| 599 proc = SkScan::HairPath; |
| 600 } |
| 601 } |
| 602 proc(*devPathPtr, rect, blitter); |
| 603 } |
| 604 |
| 605 void CSkia_PathData::BuildPath(const CFX_PathData* pPathData, const CFX_AffineMa
trix* pObject2Device) |
| 606 { |
| 607 const CFX_PathData* pFPath = pPathData; |
| 608 int nPoints = pFPath->GetPointCount(); |
| 609 FX_PATHPOINT* pPoints = pFPath->GetPoints(); |
| 610 for (int i = 0; i < nPoints; i++) { |
| 611 FX_FLOAT x = pPoints[i].m_PointX, y = pPoints[i].m_PointY; |
| 612 if (pObject2Device) { |
| 613 pObject2Device->Transform(x, y); |
| 614 } |
| 615 int point_type = pPoints[i].m_Flag & FXPT_TYPE; |
| 616 if (point_type == FXPT_MOVETO) { |
| 617 m_PathData.moveTo(x, y); |
| 618 } |
| 619 else if (point_type == FXPT_LINETO) { |
| 620 if (pPoints[i - 1].m_Flag == FXPT_MOVETO && (i == nPoints - 1 || pPo
ints[i + 1].m_Flag == FXPT_MOVETO) && |
| 621 FXSYS_fabs(pPoints[i].m_PointX - pPoints[i - 1].m_PointX) < 0.4f
&& FXSYS_fabs(pPoints[i].m_PointY - pPoints[i - 1].m_PointY) < 0.4f) { |
| 622 x += 0.4f; |
| 623 } |
| 624 m_PathData.lineTo(x, y); |
| 625 } |
| 626 else if (point_type == FXPT_BEZIERTO) { |
| 627 FX_FLOAT x2 = pPoints[i + 1].m_PointX, y2 = pPoints[i + 1].m_PointY; |
| 628 FX_FLOAT x3 = pPoints[i + 2].m_PointX, y3 = pPoints[i + 2].m_PointY; |
| 629 if (pObject2Device) { |
| 630 pObject2Device->Transform(x2, y2); |
| 631 pObject2Device->Transform(x3, y3); |
| 632 } |
| 633 m_PathData.cubicTo(x, y, x2, y2, x3, y3); |
| 634 i += 2; |
| 635 } |
| 636 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE) { |
| 637 m_PathData.close(); |
| 638 } |
| 639 } |
| 640 } |
| 641 |
| 642 FX_BOOL FxSkDrawTreatAsHairline(const SkPaint& paint, SkScalar* coverage) |
| 643 { |
| 644 if (SkPaint::kStroke_Style != paint.getStyle()) { |
| 645 return FALSE; |
| 646 } |
| 647 FXSYS_assert(coverage); |
| 648 SkScalar strokeWidth = paint.getStrokeWidth(); |
| 649 if (strokeWidth < 0.000001f) { |
| 650 *coverage = SK_Scalar1; |
| 651 return TRUE; |
| 652 } |
| 653 if (!paint.isAntiAlias()) { |
| 654 return FALSE; |
| 655 } |
| 656 if (strokeWidth <= SK_Scalar1) { |
| 657 *coverage = strokeWidth; |
| 658 return TRUE; |
| 659 } |
| 660 return FALSE; |
| 661 } |
| 662 |
| 663 static void SkRasterizeStroke(SkPaint& spaint, SkPath* dstPathData, SkPath& path
_data, |
| 664 const CFX_AffineMatrix* pObject2Device, |
| 665 const CFX_GraphStateData* pGraphState, FX_FLOAT scale, |
| 666 FX_BOOL bStrokeAdjust, FX_BOOL bTextMode) |
| 667 { |
| 668 SkPaint::Cap cap; |
| 669 switch (pGraphState->m_LineCap) { |
| 670 case CFX_GraphStateData::LineCapRound: |
| 671 cap = SkPaint::Cap::kRound_Cap; |
| 672 break; |
| 673 case CFX_GraphStateData::LineCapSquare: |
| 674 cap = SkPaint::Cap::kSquare_Cap; |
| 675 break; |
| 676 default: |
| 677 cap = SkPaint::Cap::kButt_Cap; |
| 678 break; |
| 679 } |
| 680 SkPaint::Join join; |
| 681 switch (pGraphState->m_LineJoin) { |
| 682 case CFX_GraphStateData::LineJoinRound: |
| 683 join = SkPaint::Join::kRound_Join; |
| 684 break; |
| 685 case CFX_GraphStateData::LineJoinBevel: |
| 686 join = SkPaint::Join::kBevel_Join; |
| 687 break; |
| 688 default: |
| 689 join = SkPaint::Join::kMiter_Join; |
| 690 break; |
| 691 } |
| 692 FX_FLOAT width = pGraphState->m_LineWidth * scale; |
| 693 FX_FLOAT unit = FXSYS_Div(1.0f, (pObject2Device->GetXUnit() + pObject2Device
->GetYUnit()) / 2); |
| 694 if (width <= unit) { |
| 695 width = unit; |
| 696 } |
| 697 if (pGraphState->m_DashArray == NULL) { |
| 698 SkStroke stroker; |
| 699 stroker.setCap(cap); |
| 700 stroker.setJoin(join); |
| 701 stroker.setMiterLimit(pGraphState->m_MiterLimit); |
| 702 stroker.setWidth(width); |
| 703 stroker.setDoFill(FALSE); |
| 704 stroker.strokePath(path_data, dstPathData); |
| 705 SkMatrix smatrix; |
| 706 smatrix.setAll(pObject2Device->a, pObject2Device->c, pObject2Device->e,
pObject2Device->b, pObject2Device->d, pObject2Device->f, 0, 0, 1); |
| 707 dstPathData->transform(smatrix); |
| 708 } |
| 709 else { |
| 710 int count = (pGraphState->m_DashCount + 1) / 2; |
| 711 SkScalar* intervals = FX_Alloc(SkScalar, count * sizeof (SkScalar)); |
| 712 if (!intervals) { |
| 713 return; |
| 714 } |
| 715 for (int i = 0; i < count; i++) { |
| 716 FX_FLOAT on = pGraphState->m_DashArray[i * 2]; |
| 717 if (on <= 0.000001f) { |
| 718 on = 1.0f / 10; |
| 719 } |
| 720 FX_FLOAT off = i * 2 + 1 == pGraphState->m_DashCount ? on : |
| 721 pGraphState->m_DashArray[i * 2 + 1]; |
| 722 if (off < 0) { |
| 723 off = 0; |
| 724 } |
| 725 intervals[i * 2] = on * scale; |
| 726 intervals[i * 2 + 1] = off * scale; |
| 727 } |
| 728 SkDashPathEffect* pEffect = SkDashPathEffect::Create(intervals, count *
2, pGraphState->m_DashPhase * scale); |
| 729 if (!pEffect) { |
| 730 FX_Free(intervals); |
| 731 return; |
| 732 } |
| 733 spaint.setPathEffect(pEffect)->unref(); |
| 734 spaint.setStrokeWidth(width); |
| 735 spaint.setStrokeMiter(pGraphState->m_MiterLimit); |
| 736 spaint.setStrokeCap(cap); |
| 737 spaint.setStrokeJoin(join); |
| 738 spaint.getFillPath(path_data, dstPathData); |
| 739 SkMatrix smatrix; |
| 740 smatrix.setAll(pObject2Device->a, pObject2Device->c, pObject2Device->e,
pObject2Device->b, pObject2Device->d, pObject2Device->f, 0, 0, 1); |
| 741 dstPathData->transform(smatrix); |
| 742 FX_Free(intervals); |
| 743 } |
| 744 } |
| 745 |
| 746 void RgbByteOrderSetPixel(CFX_DIBitmap* pBitmap, int x, int y, FX_DWORD argb) |
| 747 { |
| 748 if (x < 0 || x >= pBitmap->GetWidth() || y < 0 || y >= pBitmap->GetHeight())
{ |
| 749 return; |
| 750 } |
| 751 FX_LPBYTE pos = (FX_BYTE*)pBitmap->GetBuffer() + y * pBitmap->GetPitch() + x
* pBitmap->GetBPP() / 8; |
| 752 if (pBitmap->GetFormat() == FXDIB_Argb) { |
| 753 FXARGB_SETRGBORDERDIB(pos, ArgbGamma(argb)); |
| 754 } |
| 755 else { |
| 756 int alpha = FXARGB_A(argb); |
| 757 pos[0] = (FXARGB_R(argb) * alpha + pos[0] * (255 - alpha)) / 255; |
| 758 pos[1] = (FXARGB_G(argb) * alpha + pos[1] * (255 - alpha)) / 255; |
| 759 pos[2] = (FXARGB_B(argb) * alpha + pos[2] * (255 - alpha)) / 255; |
| 760 } |
| 761 } |
| 762 |
| 763 FX_ARGB _DefaultCMYK2ARGB(FX_CMYK cmyk, FX_BYTE alpha) |
| 764 { |
| 765 FX_BYTE r, g, b; |
| 766 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValue(cmyk), FXSYS_GetYV
alue(cmyk), FXSYS_GetKValue(cmyk), |
| 767 r, g, b); |
| 768 return ArgbEncode(alpha, r, g, b); |
| 769 } |
| 770 |
| 771 FX_BOOL _DibSetPixel(CFX_DIBitmap* pDevice, int x, int y, FX_DWORD color, int al
pha_flag, void* pIccTransform) |
| 772 { |
| 773 FX_BOOL bObjCMYK = FXGETFLAG_COLORTYPE(alpha_flag); |
| 774 int alpha = bObjCMYK ? FXGETFLAG_ALPHA_FILL(alpha_flag) : FXARGB_A(color); |
| 775 if (pIccTransform) { |
| 776 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge
tIccModule(); |
| 777 color = bObjCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); |
| 778 pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)&color, (FX_LPBY
TE)&color, 1); |
| 779 color = bObjCMYK ? FXCMYK_TODIB(color) : FXARGB_TODIB(color); |
| 780 if (!pDevice->IsCmykImage()) { |
| 781 color = (color & 0xffffff) | (alpha << 24); |
| 782 } |
| 783 } |
| 784 else { |
| 785 if (pDevice->IsCmykImage()) { |
| 786 if (!bObjCMYK) { |
| 787 return FALSE; |
| 788 } |
| 789 } |
| 790 else { |
| 791 if (bObjCMYK) { |
| 792 color = _DefaultCMYK2ARGB(color, alpha); |
| 793 } |
| 794 } |
| 795 } |
| 796 pDevice->SetPixel(x, y, color); |
| 797 if (pDevice->m_pAlphaMask) { |
| 798 pDevice->m_pAlphaMask->SetPixel(x, y, alpha << 24); |
| 799 } |
| 800 return TRUE; |
| 801 } |
| 802 |
| 803 void RgbByteOrderCompositeRect(CFX_DIBitmap* pBitmap, int left, int top, int wid
th, int height, FX_ARGB argb) |
| 804 { |
| 805 int src_alpha = FXARGB_A(argb); |
| 806 if (src_alpha == 0) { |
| 807 return; |
| 808 } |
| 809 FX_RECT rect(left, top, left + width, top + height); |
| 810 rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()); |
| 811 width = rect.Width(); |
| 812 int src_r = FXARGB_R(argb), src_g = FXARGB_G(argb), src_b = FXARGB_B(argb); |
| 813 int Bpp = pBitmap->GetBPP() / 8; |
| 814 FX_BOOL bAlpha = pBitmap->HasAlpha(); |
| 815 int dib_argb = FXARGB_TOBGRORDERDIB(argb); |
| 816 FX_BYTE* pBuffer = pBitmap->GetBuffer(); |
| 817 if (src_alpha == 255) { |
| 818 for (int row = rect.top; row < rect.bottom; row++) { |
| 819 FX_LPBYTE dest_scan = pBuffer + row * pBitmap->GetPitch() + rect.lef
t * Bpp; |
| 820 if (Bpp == 4) { |
| 821 FX_DWORD* scan = (FX_DWORD*)dest_scan; |
| 822 for (int col = 0; col < width; col++) { |
| 823 *scan++ = dib_argb; |
| 824 } |
| 825 } |
| 826 else { |
| 827 for (int col = 0; col < width; col++) { |
| 828 *dest_scan++ = src_r; |
| 829 *dest_scan++ = src_g; |
| 830 *dest_scan++ = src_b; |
| 831 } |
| 832 } |
| 833 } |
| 834 return; |
| 835 } |
| 836 src_r = FX_GAMMA(src_r); |
| 837 src_g = FX_GAMMA(src_g); |
| 838 src_b = FX_GAMMA(src_b); |
| 839 for (int row = rect.top; row < rect.bottom; row++) { |
| 840 FX_LPBYTE dest_scan = pBuffer + row * pBitmap->GetPitch() + rect.left *
Bpp; |
| 841 if (bAlpha) { |
| 842 for (int col = 0; col < width; col++) { |
| 843 FX_BYTE back_alpha = dest_scan[3]; |
| 844 if (back_alpha == 0) { |
| 845 FXARGB_SETRGBORDERDIB(dest_scan, FXARGB_MAKE(src_alpha, src_
r, src_g, src_b)); |
| 846 dest_scan += 4; |
| 847 continue; |
| 848 } |
| 849 FX_BYTE dest_alpha = back_alpha + src_alpha - back_alpha * src_a
lpha / 255; |
| 850 dest_scan[3] = dest_alpha; |
| 851 int alpha_ratio = src_alpha * 255 / dest_alpha; |
| 852 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_r, alpha_ratio); |
| 853 dest_scan++; |
| 854 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_g, alpha_ratio); |
| 855 dest_scan++; |
| 856 *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, src_b, alpha_ratio); |
| 857 dest_scan += 2; |
| 858 } |
| 859 } |
| 860 else { |
| 861 for (int col = 0; col < width; col++) { |
| 862 *dest_scan = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(*dest_s
can), src_r, src_alpha)); |
| 863 dest_scan++; |
| 864 *dest_scan = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(*dest_s
can), src_g, src_alpha)); |
| 865 dest_scan++; |
| 866 *dest_scan = FX_GAMMA_INVERSE(FXDIB_ALPHA_MERGE(FX_GAMMA(*dest_s
can), src_b, src_alpha)); |
| 867 dest_scan++; |
| 868 if (Bpp == 4) { |
| 869 dest_scan++; |
| 870 } |
| 871 } |
| 872 } |
| 873 } |
| 874 } |
| 875 |
| 876 void RgbByteOrderTransferBitmap(CFX_DIBitmap* pBitmap, int dest_left, int dest_t
op, int width, int height, |
| 877 const CFX_DIBSource* pSrcBitmap, int src_left, int src_top) |
| 878 { |
| 879 if (pBitmap == NULL) { |
| 880 return; |
| 881 } |
| 882 pBitmap->GetOverlapRect(dest_left, dest_top, width, height, pSrcBitmap->GetW
idth(), pSrcBitmap->GetHeight(), src_left, src_top, NULL); |
| 883 if (width == 0 || height == 0) { |
| 884 return; |
| 885 } |
| 886 int Bpp = pBitmap->GetBPP() / 8; |
| 887 FXDIB_Format dest_format = pBitmap->GetFormat(); |
| 888 FXDIB_Format src_format = pSrcBitmap->GetFormat(); |
| 889 int pitch = pBitmap->GetPitch(); |
| 890 FX_BYTE* buffer = pBitmap->GetBuffer(); |
| 891 if (dest_format == src_format) { |
| 892 for (int row = 0; row < height; row++) { |
| 893 FX_LPBYTE dest_scan = buffer + (dest_top + row) * pitch + dest_left
* Bpp; |
| 894 FX_LPBYTE src_scan = (FX_LPBYTE)pSrcBitmap->GetScanline(src_top + ro
w) + src_left * Bpp; |
| 895 if (Bpp == 4) { |
| 896 for (int col = 0; col < width; col++) { |
| 897 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(src_scan[3], src_scan[0
], src_scan[1], src_scan[2])); |
| 898 dest_scan += 4; |
| 899 src_scan += 4; |
| 900 } |
| 901 } |
| 902 else { |
| 903 for (int col = 0; col < width; col++) { |
| 904 *dest_scan++ = src_scan[2]; |
| 905 *dest_scan++ = src_scan[1]; |
| 906 *dest_scan++ = src_scan[0]; |
| 907 src_scan += 3; |
| 908 } |
| 909 } |
| 910 } |
| 911 return; |
| 912 } |
| 913 int src_pitch = pSrcBitmap->GetPitch(); |
| 914 FX_ARGB* src_pal = pSrcBitmap->GetPalette(); |
| 915 FX_LPBYTE dest_buf = buffer + dest_top * pitch + dest_left * Bpp; |
| 916 if (dest_format == FXDIB_Rgb) { |
| 917 if (src_format == FXDIB_Rgb32) { |
| 918 for (int row = 0; row < height; row++) { |
| 919 FX_LPBYTE dest_scan = dest_buf + row * pitch; |
| 920 FX_LPBYTE src_scan = (FX_BYTE*)pSrcBitmap->GetScanline(src_top +
row) + src_left * 4; |
| 921 for (int col = 0; col < width; col++) { |
| 922 *dest_scan++ = src_scan[2]; |
| 923 *dest_scan++ = src_scan[1]; |
| 924 *dest_scan++ = src_scan[0]; |
| 925 src_scan += 4; |
| 926 } |
| 927 } |
| 928 } |
| 929 else { |
| 930 ASSERT(FALSE); |
| 931 } |
| 932 } |
| 933 else if (dest_format == FXDIB_Argb || dest_format == FXDIB_Rgb32) { |
| 934 if (src_format == FXDIB_Rgb) { |
| 935 for (int row = 0; row < height; row++) { |
| 936 FX_BYTE* dest_scan = (FX_BYTE*)(dest_buf + row * pitch); |
| 937 FX_LPBYTE src_scan = (FX_BYTE*)pSrcBitmap->GetScanline(src_top +
row) + src_left * 3; |
| 938 if (src_format == FXDIB_Argb) { |
| 939 for (int col = 0; col < width; col++) { |
| 940 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, FX_GAMMA(src_
scan[0]), FX_GAMMA(src_scan[1]), FX_GAMMA(src_scan[2]))); |
| 941 dest_scan += 4; |
| 942 src_scan += 3; |
| 943 } |
| 944 } |
| 945 else { |
| 946 for (int col = 0; col < width; col++) { |
| 947 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[0],
src_scan[1], src_scan[2])); |
| 948 dest_scan += 4; |
| 949 src_scan += 3; |
| 950 } |
| 951 } |
| 952 } |
| 953 } |
| 954 else if (src_format == FXDIB_Rgb32) { |
| 955 ASSERT(dest_format == FXDIB_Argb); |
| 956 for (int row = 0; row < height; row++) { |
| 957 FX_LPBYTE dest_scan = dest_buf + row * pitch; |
| 958 FX_LPBYTE src_scan = (FX_LPBYTE)(pSrcBitmap->GetScanline(src_top
+ row) + src_left * 4); |
| 959 for (int col = 0; col < width; col++) { |
| 960 FXARGB_SETDIB(dest_scan, FXARGB_MAKE(0xff, src_scan[0], src_
scan[1], src_scan[2])); |
| 961 src_scan += 4; |
| 962 dest_scan += 4; |
| 963 } |
| 964 } |
| 965 } |
| 966 } |
| 967 else { |
| 968 ASSERT(FALSE); |
| 969 } |
| 970 } |
| 971 |
| OLD | NEW |