From cd39a7ca8c97e486aeeba1015667064bc22308e2 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 5 Apr 2018 20:34:11 +0000 Subject: Split CPDF_DIBSource::TranslateScanline24bpp(). Move some code into TranslateScanline24bppDefaultDecode(). Change-Id: I7e985c2abb9b2f9e41214531321f8f3846dd3a94 Reviewed-on: https://pdfium-review.googlesource.com/29857 Reviewed-by: Henrique Nakashima Commit-Queue: Lei Zhang --- core/fpdfapi/render/cpdf_dibsource.cpp | 118 ++++++++++++++++++--------------- core/fpdfapi/render/cpdf_dibsource.h | 2 + 2 files changed, 66 insertions(+), 54 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/render/cpdf_dibsource.cpp b/core/fpdfapi/render/cpdf_dibsource.cpp index d552842756..bb925398a4 100644 --- a/core/fpdfapi/render/cpdf_dibsource.cpp +++ b/core/fpdfapi/render/cpdf_dibsource.cpp @@ -849,60 +849,8 @@ void CPDF_DIBSource::TranslateScanline24bpp(uint8_t* dest_scan, if (m_bpc == 0) return; - unsigned int max_data = (1 << m_bpc) - 1; - if (m_bDefaultDecode) { - if (m_Family == PDFCS_DEVICERGB || m_Family == PDFCS_CALRGB) { - if (m_nComponents != 3) - return; - - const uint8_t* src_pos = src_scan; - switch (m_bpc) { - case 8: - for (int column = 0; column < m_Width; column++) { - *dest_scan++ = src_pos[2]; - *dest_scan++ = src_pos[1]; - *dest_scan++ = *src_pos; - src_pos += 3; - } - break; - case 16: - for (int col = 0; col < m_Width; col++) { - *dest_scan++ = src_pos[4]; - *dest_scan++ = src_pos[2]; - *dest_scan++ = *src_pos; - src_pos += 6; - } - break; - default: - uint64_t src_bit_pos = 0; - size_t dest_byte_pos = 0; - for (int column = 0; column < m_Width; column++) { - unsigned int R = GetBits8(src_scan, src_bit_pos, m_bpc); - src_bit_pos += m_bpc; - unsigned int G = GetBits8(src_scan, src_bit_pos, m_bpc); - src_bit_pos += m_bpc; - unsigned int B = GetBits8(src_scan, src_bit_pos, m_bpc); - src_bit_pos += m_bpc; - R = std::min(R, max_data); - G = std::min(G, max_data); - B = std::min(B, max_data); - dest_scan[dest_byte_pos] = B * 255 / max_data; - dest_scan[dest_byte_pos + 1] = G * 255 / max_data; - dest_scan[dest_byte_pos + 2] = R * 255 / max_data; - dest_byte_pos += 3; - } - break; - } - return; - } - if (m_bpc == 8) { - if (m_nComponents == m_pColorSpace->CountComponents()) { - m_pColorSpace->TranslateImageLine(dest_scan, src_scan, m_Width, m_Width, - m_Height, TransMask()); - } - return; - } - } + if (TranslateScanline24bppDefaultDecode(dest_scan, src_scan)) + return; CFX_FixedBufGrow color_values1(m_nComponents); float* color_values = color_values1; @@ -963,6 +911,68 @@ void CPDF_DIBSource::TranslateScanline24bpp(uint8_t* dest_scan, } } +bool CPDF_DIBSource::TranslateScanline24bppDefaultDecode( + uint8_t* dest_scan, + const uint8_t* src_scan) const { + if (!m_bDefaultDecode) + return false; + + if (m_Family != PDFCS_DEVICERGB && m_Family != PDFCS_CALRGB) { + if (m_bpc != 8) + return false; + + if (m_nComponents == m_pColorSpace->CountComponents()) { + m_pColorSpace->TranslateImageLine(dest_scan, src_scan, m_Width, m_Width, + m_Height, TransMask()); + } + return true; + } + + if (m_nComponents != 3) + return true; + + const uint8_t* src_pos = src_scan; + switch (m_bpc) { + case 8: + for (int column = 0; column < m_Width; column++) { + *dest_scan++ = src_pos[2]; + *dest_scan++ = src_pos[1]; + *dest_scan++ = *src_pos; + src_pos += 3; + } + break; + case 16: + for (int col = 0; col < m_Width; col++) { + *dest_scan++ = src_pos[4]; + *dest_scan++ = src_pos[2]; + *dest_scan++ = *src_pos; + src_pos += 6; + } + break; + default: + const unsigned int max_data = (1 << m_bpc) - 1; + uint64_t src_bit_pos = 0; + size_t dest_byte_pos = 0; + for (int column = 0; column < m_Width; column++) { + unsigned int R = GetBits8(src_scan, src_bit_pos, m_bpc); + src_bit_pos += m_bpc; + unsigned int G = GetBits8(src_scan, src_bit_pos, m_bpc); + src_bit_pos += m_bpc; + unsigned int B = GetBits8(src_scan, src_bit_pos, m_bpc); + src_bit_pos += m_bpc; + R = std::min(R, max_data); + G = std::min(G, max_data); + B = std::min(B, max_data); + dest_scan[dest_byte_pos] = B * 255 / max_data; + dest_scan[dest_byte_pos + 1] = G * 255 / max_data; + dest_scan[dest_byte_pos + 2] = R * 255 / max_data; + dest_byte_pos += 3; + } + break; + } + return true; +} + uint8_t* CPDF_DIBSource::GetBuffer() const { return m_pCachedBitmap ? m_pCachedBitmap->GetBuffer() : nullptr; } diff --git a/core/fpdfapi/render/cpdf_dibsource.h b/core/fpdfapi/render/cpdf_dibsource.h index 534baabf16..4cb79fa57c 100644 --- a/core/fpdfapi/render/cpdf_dibsource.h +++ b/core/fpdfapi/render/cpdf_dibsource.h @@ -96,6 +96,8 @@ class CPDF_DIBSource : public CFX_DIBSource { const CPDF_Dictionary* pParams); void TranslateScanline24bpp(uint8_t* dest_scan, const uint8_t* src_scan) const; + bool TranslateScanline24bppDefaultDecode(uint8_t* dest_scan, + const uint8_t* src_scan) const; void ValidateDictParam(); void DownSampleScanline1Bit(int orig_Bpp, int dest_Bpp, -- cgit v1.2.3