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 "render_int.h" | 7 #include "render_int.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 int clip_width) const { | 1439 int clip_width) const { |
1440 int last_src_x = -1; | 1440 int last_src_x = -1; |
1441 FX_ARGB last_argb = FXARGB_MAKE(0xFF, 0xFF, 0xFF, 0xFF); | 1441 FX_ARGB last_argb = FXARGB_MAKE(0xFF, 0xFF, 0xFF, 0xFF); |
1442 FX_FLOAT unit_To8Bpc = 255.0f / ((1 << m_bpc) - 1); | 1442 FX_FLOAT unit_To8Bpc = 255.0f / ((1 << m_bpc) - 1); |
1443 for (int i = 0; i < clip_width; i++) { | 1443 for (int i = 0; i < clip_width; i++) { |
1444 int dest_x = clip_left + i; | 1444 int dest_x = clip_left + i; |
1445 FX_DWORD src_x = (bFlipX ? (dest_width - dest_x - 1) : dest_x) * | 1445 FX_DWORD src_x = (bFlipX ? (dest_width - dest_x - 1) : dest_x) * |
1446 (int64_t)src_width / dest_width; | 1446 (int64_t)src_width / dest_width; |
1447 src_x %= src_width; | 1447 src_x %= src_width; |
1448 | 1448 |
1449 // No need to check for 32-bit overflow, as |src_x| is bounded by | |
1450 // |src_width| and DownSampleScanline already checked for overflow with the | |
1451 // pitch calculation. | |
1452 const uint8_t* pSrcPixel = nullptr; | |
1453 size_t bit_offset = 0; | |
1454 if (m_bpc % 8 == 0) { | |
1455 pSrcPixel = pSrcLine + src_x * orig_Bpp; | |
1456 } else { | |
1457 size_t num_bits = src_x * m_bpc * m_nComponents; | |
1458 pSrcPixel = pSrcLine + num_bits / 8; | |
1459 bit_offset = num_bits % 8; | |
1460 } | |
1461 | |
1462 uint8_t* pDestPixel = dest_scan + i * dest_Bpp; | 1449 uint8_t* pDestPixel = dest_scan + i * dest_Bpp; |
1463 FX_ARGB argb; | 1450 FX_ARGB argb; |
1464 if (src_x == last_src_x) { | 1451 if (src_x == last_src_x) { |
1465 argb = last_argb; | 1452 argb = last_argb; |
1466 } else { | 1453 } else { |
1467 CFX_FixedBufGrow<uint8_t, 128> extracted_components(m_nComponents); | 1454 CFX_FixedBufGrow<uint8_t, 128> extracted_components(m_nComponents); |
| 1455 const uint8_t* pSrcPixel = nullptr; |
1468 if (m_bpc % 8 != 0) { | 1456 if (m_bpc % 8 != 0) { |
1469 uint64_t src_bit_pos = bit_offset; | 1457 // No need to check for 32-bit overflow, as |src_x| is bounded by |
| 1458 // |src_width| and DownSampleScanline() already checked for overflow |
| 1459 // with the pitch calculation. |
| 1460 size_t num_bits = src_x * m_bpc * m_nComponents; |
| 1461 uint64_t src_bit_pos = num_bits % 8; |
| 1462 pSrcPixel = pSrcLine + num_bits / 8; |
1470 for (FX_DWORD j = 0; j < m_nComponents; ++j) { | 1463 for (FX_DWORD j = 0; j < m_nComponents; ++j) { |
1471 extracted_components[j] = static_cast<uint8_t>( | 1464 extracted_components[j] = static_cast<uint8_t>( |
1472 GetBits8(pSrcPixel, src_bit_pos, m_bpc) * unit_To8Bpc); | 1465 GetBits8(pSrcPixel, src_bit_pos, m_bpc) * unit_To8Bpc); |
1473 src_bit_pos += m_bpc; | 1466 src_bit_pos += m_bpc; |
1474 } | 1467 } |
1475 pSrcPixel = extracted_components; | 1468 pSrcPixel = extracted_components; |
1476 } else if (m_bpc == 16) { | 1469 } else { |
1477 for (FX_DWORD j = 0; j < m_nComponents; ++j) { | 1470 pSrcPixel = pSrcLine + src_x * orig_Bpp; |
1478 extracted_components[j] = pSrcPixel[j * 2]; | 1471 if (m_bpc == 16) { |
| 1472 for (FX_DWORD j = 0; j < m_nComponents; ++j) |
| 1473 extracted_components[j] = pSrcPixel[j * 2]; |
| 1474 pSrcPixel = extracted_components; |
1479 } | 1475 } |
1480 pSrcPixel = extracted_components; | |
1481 } | 1476 } |
1482 | 1477 |
1483 if (m_pColorSpace) { | 1478 if (m_pColorSpace) { |
1484 uint8_t color[4]; | 1479 uint8_t color[4]; |
1485 const FX_BOOL bTransMask = TransMask(); | 1480 const FX_BOOL bTransMask = TransMask(); |
1486 if (m_bDefaultDecode) { | 1481 if (m_bDefaultDecode) { |
1487 m_pColorSpace->TranslateImageLine(color, pSrcPixel, 1, 0, 0, | 1482 m_pColorSpace->TranslateImageLine(color, pSrcPixel, 1, 0, 0, |
1488 bTransMask); | 1483 bTransMask); |
1489 } else { | 1484 } else { |
1490 for (FX_DWORD j = 0; j < m_nComponents; ++j) { | 1485 for (FX_DWORD j = 0; j < m_nComponents; ++j) { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 IFX_Pause* pPause) { | 1641 IFX_Pause* pPause) { |
1647 return LoadHandle->Continue(pPause); | 1642 return LoadHandle->Continue(pPause); |
1648 } | 1643 } |
1649 | 1644 |
1650 CPDF_ImageLoader::~CPDF_ImageLoader() { | 1645 CPDF_ImageLoader::~CPDF_ImageLoader() { |
1651 if (!m_bCached) { | 1646 if (!m_bCached) { |
1652 delete m_pBitmap; | 1647 delete m_pBitmap; |
1653 delete m_pMask; | 1648 delete m_pMask; |
1654 } | 1649 } |
1655 } | 1650 } |
OLD | NEW |