From 2a1f9736c2e459a9abec00853f0bff21a87e31d4 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 5 Feb 2016 17:37:11 -0800 Subject: Combine two if/else blocks in CPDF_DIBSource::DownSampleScanline32Bit(). R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1671843002 . --- .../fpdfapi/fpdf_render/fpdf_render_loadimage.cpp | 31 +++++++++------------- 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'core') diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp index e62290fdbb..6e4dec3b6a 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp @@ -1446,38 +1446,33 @@ void CPDF_DIBSource::DownSampleScanline32Bit(int orig_Bpp, (int64_t)src_width / dest_width; src_x %= src_width; - // No need to check for 32-bit overflow, as |src_x| is bounded by - // |src_width| and DownSampleScanline already checked for overflow with the - // pitch calculation. - const uint8_t* pSrcPixel = nullptr; - size_t bit_offset = 0; - if (m_bpc % 8 == 0) { - pSrcPixel = pSrcLine + src_x * orig_Bpp; - } else { - size_t num_bits = src_x * m_bpc * m_nComponents; - pSrcPixel = pSrcLine + num_bits / 8; - bit_offset = num_bits % 8; - } - uint8_t* pDestPixel = dest_scan + i * dest_Bpp; FX_ARGB argb; if (src_x == last_src_x) { argb = last_argb; } else { CFX_FixedBufGrow extracted_components(m_nComponents); + const uint8_t* pSrcPixel = nullptr; if (m_bpc % 8 != 0) { - uint64_t src_bit_pos = bit_offset; + // No need to check for 32-bit overflow, as |src_x| is bounded by + // |src_width| and DownSampleScanline() already checked for overflow + // with the pitch calculation. + size_t num_bits = src_x * m_bpc * m_nComponents; + uint64_t src_bit_pos = num_bits % 8; + pSrcPixel = pSrcLine + num_bits / 8; for (FX_DWORD j = 0; j < m_nComponents; ++j) { extracted_components[j] = static_cast( GetBits8(pSrcPixel, src_bit_pos, m_bpc) * unit_To8Bpc); src_bit_pos += m_bpc; } pSrcPixel = extracted_components; - } else if (m_bpc == 16) { - for (FX_DWORD j = 0; j < m_nComponents; ++j) { - extracted_components[j] = pSrcPixel[j * 2]; + } else { + pSrcPixel = pSrcLine + src_x * orig_Bpp; + if (m_bpc == 16) { + for (FX_DWORD j = 0; j < m_nComponents; ++j) + extracted_components[j] = pSrcPixel[j * 2]; + pSrcPixel = extracted_components; } - pSrcPixel = extracted_components; } if (m_pColorSpace) { -- cgit v1.2.3