| 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/include/fx_dib.h" | 7 #include "core/fxge/include/fx_dib.h" |
| 8 | 8 |
| 9 #include <limits.h> | 9 #include <limits.h> |
| 10 | 10 |
| 11 #include "core/fxcodec/include/fx_codec.h" | 11 #include "core/fxcodec/include/fx_codec.h" |
| 12 #include "core/fxge/dib/dib_int.h" | 12 #include "core/fxge/dib/dib_int.h" |
| 13 #include "core/fxge/include/fx_ge.h" | 13 #include "core/fxge/include/fx_ge.h" |
| 14 | 14 |
| 15 FX_BOOL ConvertBuffer(FXDIB_Format dest_format, | |
| 16 uint8_t* dest_buf, | |
| 17 int dest_pitch, | |
| 18 int width, | |
| 19 int height, | |
| 20 const CFX_DIBSource* pSrcBitmap, | |
| 21 int src_left, | |
| 22 int src_top, | |
| 23 uint32_t*& pal, | |
| 24 void* pIccTransform); | |
| 25 void CmykDecode(uint32_t cmyk, int& c, int& m, int& y, int& k) { | 15 void CmykDecode(uint32_t cmyk, int& c, int& m, int& y, int& k) { |
| 26 c = FXSYS_GetCValue(cmyk); | 16 c = FXSYS_GetCValue(cmyk); |
| 27 m = FXSYS_GetMValue(cmyk); | 17 m = FXSYS_GetMValue(cmyk); |
| 28 y = FXSYS_GetYValue(cmyk); | 18 y = FXSYS_GetYValue(cmyk); |
| 29 k = FXSYS_GetKValue(cmyk); | 19 k = FXSYS_GetKValue(cmyk); |
| 30 } | 20 } |
| 31 void ArgbDecode(uint32_t argb, int& a, int& r, int& g, int& b) { | 21 void ArgbDecode(uint32_t argb, int& a, int& r, int& g, int& b) { |
| 32 a = FXARGB_A(argb); | 22 a = FXARGB_A(argb); |
| 33 r = FXARGB_R(argb); | 23 r = FXARGB_R(argb); |
| 34 g = FXARGB_G(argb); | 24 g = FXARGB_G(argb); |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 if (pClipRgn) { | 381 if (pClipRgn) { |
| 392 dest_rect.Intersect(pClipRgn->GetBox()); | 382 dest_rect.Intersect(pClipRgn->GetBox()); |
| 393 } | 383 } |
| 394 dest_left = dest_rect.left; | 384 dest_left = dest_rect.left; |
| 395 dest_top = dest_rect.top; | 385 dest_top = dest_rect.top; |
| 396 src_left = dest_left - x_offset; | 386 src_left = dest_left - x_offset; |
| 397 src_top = dest_top - y_offset; | 387 src_top = dest_top - y_offset; |
| 398 width = dest_rect.right - dest_rect.left; | 388 width = dest_rect.right - dest_rect.left; |
| 399 height = dest_rect.bottom - dest_rect.top; | 389 height = dest_rect.bottom - dest_rect.top; |
| 400 } | 390 } |
| 391 |
| 401 FX_BOOL CFX_DIBitmap::TransferBitmap(int dest_left, | 392 FX_BOOL CFX_DIBitmap::TransferBitmap(int dest_left, |
| 402 int dest_top, | 393 int dest_top, |
| 403 int width, | 394 int width, |
| 404 int height, | 395 int height, |
| 405 const CFX_DIBSource* pSrcBitmap, | 396 const CFX_DIBSource* pSrcBitmap, |
| 406 int src_left, | 397 int src_left, |
| 407 int src_top, | 398 int src_top) { |
| 408 void* pIccTransform) { | 399 if (!m_pBuffer) |
| 409 if (!m_pBuffer) { | |
| 410 return FALSE; | 400 return FALSE; |
| 411 } | 401 |
| 412 GetOverlapRect(dest_left, dest_top, width, height, pSrcBitmap->GetWidth(), | 402 GetOverlapRect(dest_left, dest_top, width, height, pSrcBitmap->GetWidth(), |
| 413 pSrcBitmap->GetHeight(), src_left, src_top, nullptr); | 403 pSrcBitmap->GetHeight(), src_left, src_top, nullptr); |
| 414 if (width == 0 || height == 0) { | 404 if (width == 0 || height == 0) |
| 415 return TRUE; | 405 return TRUE; |
| 416 } | 406 |
| 417 FXDIB_Format dest_format = GetFormat(); | 407 FXDIB_Format dest_format = GetFormat(); |
| 418 FXDIB_Format src_format = pSrcBitmap->GetFormat(); | 408 FXDIB_Format src_format = pSrcBitmap->GetFormat(); |
| 419 if (dest_format == src_format && !pIccTransform) { | 409 if (dest_format == src_format) { |
| 420 if (GetBPP() == 1) { | 410 if (GetBPP() == 1) { |
| 421 for (int row = 0; row < height; row++) { | 411 for (int row = 0; row < height; row++) { |
| 422 uint8_t* dest_scan = m_pBuffer + (dest_top + row) * m_Pitch; | 412 uint8_t* dest_scan = m_pBuffer + (dest_top + row) * m_Pitch; |
| 423 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row); | 413 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row); |
| 424 for (int col = 0; col < width; col++) { | 414 for (int col = 0; col < width; col++) { |
| 425 if (src_scan[(src_left + col) / 8] & | 415 if (src_scan[(src_left + col) / 8] & |
| 426 (1 << (7 - (src_left + col) % 8))) { | 416 (1 << (7 - (src_left + col) % 8))) { |
| 427 dest_scan[(dest_left + col) / 8] |= 1 | 417 dest_scan[(dest_left + col) / 8] |= 1 |
| 428 << (7 - (dest_left + col) % 8); | 418 << (7 - (dest_left + col) % 8); |
| 429 } else { | 419 } else { |
| 430 dest_scan[(dest_left + col) / 8] &= | 420 dest_scan[(dest_left + col) / 8] &= |
| 431 ~(1 << (7 - (dest_left + col) % 8)); | 421 ~(1 << (7 - (dest_left + col) % 8)); |
| 432 } | 422 } |
| 433 } | 423 } |
| 434 } | 424 } |
| 435 } else { | 425 } else { |
| 436 int Bpp = GetBPP() / 8; | 426 int Bpp = GetBPP() / 8; |
| 437 for (int row = 0; row < height; row++) { | 427 for (int row = 0; row < height; row++) { |
| 438 uint8_t* dest_scan = | 428 uint8_t* dest_scan = |
| 439 m_pBuffer + (dest_top + row) * m_Pitch + dest_left * Bpp; | 429 m_pBuffer + (dest_top + row) * m_Pitch + dest_left * Bpp; |
| 440 const uint8_t* src_scan = | 430 const uint8_t* src_scan = |
| 441 pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; | 431 pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; |
| 442 FXSYS_memcpy(dest_scan, src_scan, width * Bpp); | 432 FXSYS_memcpy(dest_scan, src_scan, width * Bpp); |
| 443 } | 433 } |
| 444 } | 434 } |
| 445 } else { | 435 } else { |
| 446 if (m_pPalette) { | 436 if (m_pPalette) |
| 447 return FALSE; | 437 return FALSE; |
| 448 } | 438 |
| 449 if (m_bpp == 8) { | 439 if (m_bpp == 8) |
| 450 dest_format = FXDIB_8bppMask; | 440 dest_format = FXDIB_8bppMask; |
| 451 } | 441 |
| 452 uint8_t* dest_buf = | 442 uint8_t* dest_buf = |
| 453 m_pBuffer + dest_top * m_Pitch + dest_left * GetBPP() / 8; | 443 m_pBuffer + dest_top * m_Pitch + dest_left * GetBPP() / 8; |
| 454 uint32_t* d_plt = nullptr; | 444 uint32_t* d_plt = nullptr; |
| 455 if (!ConvertBuffer(dest_format, dest_buf, m_Pitch, width, height, | 445 if (!ConvertBuffer(dest_format, dest_buf, m_Pitch, width, height, |
| 456 pSrcBitmap, src_left, src_top, d_plt, pIccTransform)) { | 446 pSrcBitmap, src_left, src_top, d_plt)) { |
| 457 return FALSE; | 447 return FALSE; |
| 458 } | 448 } |
| 459 } | 449 } |
| 460 return TRUE; | 450 return TRUE; |
| 461 } | 451 } |
| 452 |
| 462 FX_BOOL CFX_DIBitmap::TransferMask(int dest_left, | 453 FX_BOOL CFX_DIBitmap::TransferMask(int dest_left, |
| 463 int dest_top, | 454 int dest_top, |
| 464 int width, | 455 int width, |
| 465 int height, | 456 int height, |
| 466 const CFX_DIBSource* pMask, | 457 const CFX_DIBSource* pMask, |
| 467 uint32_t color, | 458 uint32_t color, |
| 468 int src_left, | 459 int src_left, |
| 469 int src_top, | 460 int src_top, |
| 470 int alpha_flag, | 461 int alpha_flag, |
| 471 void* pIccTransform) { | 462 void* pIccTransform) { |
| (...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1673 uint32_t* pSrcPalette) { | 1664 uint32_t* pSrcPalette) { |
| 1674 m_pBitmap.reset(new CFX_DIBitmap); | 1665 m_pBitmap.reset(new CFX_DIBitmap); |
| 1675 if (!m_pBitmap->Create(width, height, src_format)) { | 1666 if (!m_pBitmap->Create(width, height, src_format)) { |
| 1676 m_pBitmap.reset(); | 1667 m_pBitmap.reset(); |
| 1677 return FALSE; | 1668 return FALSE; |
| 1678 } | 1669 } |
| 1679 if (pSrcPalette) | 1670 if (pSrcPalette) |
| 1680 m_pBitmap->CopyPalette(pSrcPalette); | 1671 m_pBitmap->CopyPalette(pSrcPalette); |
| 1681 return TRUE; | 1672 return TRUE; |
| 1682 } | 1673 } |
| OLD | NEW |