From 4174b5ab6ac9024acb9b42acbb61d628a2a679e3 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 10 Aug 2018 00:13:37 +0000 Subject: Add CFX_DIBSource::GetWritableScanline(). Remove a bunch of const_cast or equivalent. This will also help when we convert to span<>, since casting spans is a nuisance. Change-Id: I330e5041cbaf33a84425fc4242a3dfacf5ca8011 Reviewed-on: https://pdfium-review.googlesource.com/39831 Commit-Queue: Lei Zhang Reviewed-by: Lei Zhang --- core/fxge/agg/fx_agg_driver.cpp | 20 ++++++++------------ core/fxge/dib/cfx_bitmapcomposer.cpp | 8 +++----- core/fxge/dib/cfx_bitmapstorer.cpp | 4 ++-- core/fxge/dib/cfx_dibitmap.cpp | 16 +++++++--------- core/fxge/dib/cfx_dibsource.cpp | 21 +++++++++++---------- core/fxge/dib/cfx_dibsource.h | 3 +++ core/fxge/dib/cfx_imagetransformer.cpp | 12 ++++++------ core/fxge/skia/fx_skia_device.cpp | 16 ++++++++-------- 8 files changed, 48 insertions(+), 52 deletions(-) (limited to 'core/fxge') diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp index affabba797..3d35e12e45 100644 --- a/core/fxge/agg/fx_agg_driver.cpp +++ b/core/fxge/agg/fx_agg_driver.cpp @@ -164,9 +164,8 @@ void RgbByteOrderTransferBitmap(const RetainPtr& pBitmap, if (dest_format == src_format) { for (int row = 0; row < height; row++) { uint8_t* dest_scan = buffer + (dest_top + row) * pitch + dest_left * Bpp; - uint8_t* src_scan = - const_cast(pSrcBitmap->GetScanline(src_top + row)) + - src_left * Bpp; + const uint8_t* src_scan = + pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; if (Bpp == 4) { for (int col = 0; col < width; col++) { FXARGB_SETDIB(dest_scan, ArgbEncode(src_scan[3], src_scan[0], @@ -191,9 +190,8 @@ void RgbByteOrderTransferBitmap(const RetainPtr& pBitmap, ASSERT(src_format == FXDIB_Rgb32); for (int row = 0; row < height; row++) { uint8_t* dest_scan = dest_buf + row * pitch; - uint8_t* src_scan = - const_cast(pSrcBitmap->GetScanline(src_top + row)) + - src_left * 4; + const uint8_t* src_scan = + pSrcBitmap->GetScanline(src_top + row) + src_left * 4; for (int col = 0; col < width; col++) { *dest_scan++ = src_scan[2]; *dest_scan++ = src_scan[1]; @@ -208,9 +206,8 @@ void RgbByteOrderTransferBitmap(const RetainPtr& pBitmap, if (src_format == FXDIB_Rgb) { for (int row = 0; row < height; row++) { uint8_t* dest_scan = dest_buf + row * pitch; - uint8_t* src_scan = - const_cast(pSrcBitmap->GetScanline(src_top + row)) + - src_left * 3; + const uint8_t* src_scan = + pSrcBitmap->GetScanline(src_top + row) + src_left * 3; for (int col = 0; col < width; col++) { FXARGB_SETDIB(dest_scan, ArgbEncode(0xff, src_scan[0], src_scan[1], src_scan[2])); @@ -225,9 +222,8 @@ void RgbByteOrderTransferBitmap(const RetainPtr& pBitmap, ASSERT(dest_format == FXDIB_Argb); for (int row = 0; row < height; row++) { uint8_t* dest_scan = dest_buf + row * pitch; - uint8_t* src_scan = - const_cast(pSrcBitmap->GetScanline(src_top + row)) + - src_left * 4; + const uint8_t* src_scan = + pSrcBitmap->GetScanline(src_top + row) + src_left * 4; for (int col = 0; col < width; col++) { FXARGB_SETDIB(dest_scan, ArgbEncode(0xff, src_scan[0], src_scan[1], src_scan[2])); diff --git a/core/fxge/dib/cfx_bitmapcomposer.cpp b/core/fxge/dib/cfx_bitmapcomposer.cpp index 3854949207..22e1bc9b65 100644 --- a/core/fxge/dib/cfx_bitmapcomposer.cpp +++ b/core/fxge/dib/cfx_bitmapcomposer.cpp @@ -112,13 +112,11 @@ void CFX_BitmapComposer::ComposeScanline(int line, m_pClipMask->GetPitch() + (m_DestLeft - m_pClipRgn->GetBox().left); } - uint8_t* dest_scan = - const_cast(m_pBitmap->GetScanline(line + m_DestTop)) + - m_DestLeft * m_pBitmap->GetBPP() / 8; + uint8_t* dest_scan = m_pBitmap->GetWritableScanline(line + m_DestTop) + + m_DestLeft * m_pBitmap->GetBPP() / 8; uint8_t* dest_alpha_scan = m_pBitmap->m_pAlphaMask - ? const_cast( - m_pBitmap->m_pAlphaMask->GetScanline(line + m_DestTop)) + + ? m_pBitmap->m_pAlphaMask->GetWritableScanline(line + m_DestTop) + m_DestLeft : nullptr; DoCompose(dest_scan, scanline, m_DestWidth, clip_scan, scan_extra_alpha, diff --git a/core/fxge/dib/cfx_bitmapstorer.cpp b/core/fxge/dib/cfx_bitmapstorer.cpp index f649e0caea..d5b26f28b7 100644 --- a/core/fxge/dib/cfx_bitmapstorer.cpp +++ b/core/fxge/dib/cfx_bitmapstorer.cpp @@ -25,10 +25,10 @@ void CFX_BitmapStorer::Replace(RetainPtr&& pBitmap) { void CFX_BitmapStorer::ComposeScanline(int line, const uint8_t* scanline, const uint8_t* scan_extra_alpha) { - uint8_t* dest_buf = const_cast(m_pBitmap->GetScanline(line)); + uint8_t* dest_buf = m_pBitmap->GetWritableScanline(line); uint8_t* dest_alpha_buf = m_pBitmap->m_pAlphaMask - ? const_cast(m_pBitmap->m_pAlphaMask->GetScanline(line)) + ? m_pBitmap->m_pAlphaMask->GetWritableScanline(line) : nullptr; if (dest_buf) memcpy(dest_buf, scanline, m_pBitmap->GetPitch()); diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp index f17ca52095..3d642c2e76 100644 --- a/core/fxge/dib/cfx_dibitmap.cpp +++ b/core/fxge/dib/cfx_dibitmap.cpp @@ -372,7 +372,7 @@ bool CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int srcBytes = pSrcClone->GetBPP() / 8; int destBytes = pDst->GetBPP() / 8; for (int row = 0; row < m_Height; row++) { - uint8_t* dest_pos = (uint8_t*)pDst->GetScanline(row) + destOffset; + uint8_t* dest_pos = pDst->GetWritableScanline(row) + destOffset; const uint8_t* src_pos = pSrcClone->GetScanline(row) + srcOffset; for (int col = 0; col < m_Width; col++) { *dest_pos = *src_pos; @@ -923,7 +923,7 @@ bool CFX_DIBitmap::CompositeBitmap(int dest_left, : nullptr; uint8_t* dst_scan_extra_alpha = m_pAlphaMask - ? (uint8_t*)m_pAlphaMask->GetScanline(dest_top + row) + dest_left + ? m_pAlphaMask->GetWritableScanline(dest_top + row) + dest_left : nullptr; const uint8_t* clip_scan = nullptr; if (pClipMask) { @@ -995,7 +995,7 @@ bool CFX_DIBitmap::CompositeMask(int dest_left, const uint8_t* src_scan = pMask->GetScanline(src_top + row); uint8_t* dst_scan_extra_alpha = m_pAlphaMask - ? (uint8_t*)m_pAlphaMask->GetScanline(dest_top + row) + dest_left + ? m_pAlphaMask->GetWritableScanline(dest_top + row) + dest_left : nullptr; const uint8_t* clip_scan = nullptr; if (pClipMask) { @@ -1084,10 +1084,8 @@ bool CFX_DIBitmap::CompositeRect(int left, index = (static_cast(color) == 0xff) ? 1 : 0; } for (int row = rect.top; row < rect.bottom; row++) { - uint8_t* dest_scan_top = - const_cast(GetScanline(row)) + rect.left / 8; - uint8_t* dest_scan_top_r = - const_cast(GetScanline(row)) + rect.right / 8; + uint8_t* dest_scan_top = GetWritableScanline(row) + rect.left / 8; + uint8_t* dest_scan_top_r = GetWritableScanline(row) + rect.right / 8; uint8_t left_flag = *dest_scan_top & (255 << (8 - left_shift)); uint8_t right_flag = *dest_scan_top_r & (255 >> right_shift); if (new_width) { @@ -1126,7 +1124,7 @@ bool CFX_DIBitmap::CompositeRect(int left, for (int row = rect.top; row < rect.bottom; row++) { uint8_t* dest_scan = m_pBuffer.Get() + row * m_Pitch + rect.left * Bpp; uint8_t* dest_scan_alpha = - m_pAlphaMask ? (uint8_t*)m_pAlphaMask->GetScanline(row) + rect.left + m_pAlphaMask ? m_pAlphaMask->GetWritableScanline(row) + rect.left : nullptr; if (dest_scan_alpha) { memset(dest_scan_alpha, 0xff, width); @@ -1171,7 +1169,7 @@ bool CFX_DIBitmap::CompositeRect(int left, } } else { uint8_t* dest_scan_alpha = - (uint8_t*)m_pAlphaMask->GetScanline(row) + rect.left; + m_pAlphaMask->GetWritableScanline(row) + rect.left; for (int col = 0; col < width; col++) { uint8_t back_alpha = *dest_scan_alpha; if (back_alpha == 0) { diff --git a/core/fxge/dib/cfx_dibsource.cpp b/core/fxge/dib/cfx_dibsource.cpp index 757547783d..4608b51802 100644 --- a/core/fxge/dib/cfx_dibsource.cpp +++ b/core/fxge/dib/cfx_dibsource.cpp @@ -349,11 +349,10 @@ void ConvertBuffer_Rgb2PltRgb8(uint8_t* dest_buf, } int32_t lut_1 = lut - 1; for (int row = 0; row < height; ++row) { - uint8_t* src_scan = - const_cast(pSrcBitmap->GetScanline(src_top + row)) + src_left; + const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; uint8_t* dest_scan = dest_buf + row * dest_pitch; for (int col = 0; col < width; ++col) { - uint8_t* src_port = src_scan + col * bpp; + const uint8_t* src_port = src_scan + col * bpp; int r = src_port[2] & 0xf0; int g = src_port[1] & 0xf0; int b = src_port[0] & 0xf0; @@ -748,8 +747,10 @@ RetainPtr CFX_DIBSource::Clone(const FX_RECT* pClip) const { int right_shift = 32 - left_shift; int dword_count = pNewBitmap->m_Pitch / 4; for (int row = rect.top; row < rect.bottom; ++row) { - uint32_t* src_scan = (uint32_t*)GetScanline(row) + rect.left / 32; - uint32_t* dest_scan = (uint32_t*)pNewBitmap->GetScanline(row - rect.top); + const uint32_t* src_scan = + reinterpret_cast(GetScanline(row)) + rect.left / 32; + uint32_t* dest_scan = reinterpret_cast( + pNewBitmap->GetWritableScanline(row - rect.top)); for (int i = 0; i < dword_count; ++i) { dest_scan[i] = (src_scan[i] << left_shift) | (src_scan[i + 1] >> right_shift); @@ -762,7 +763,7 @@ RetainPtr CFX_DIBSource::Clone(const FX_RECT* pClip) const { for (int row = rect.top; row < rect.bottom; ++row) { const uint8_t* src_scan = GetScanline(row) + rect.left * m_bpp / 8; - uint8_t* dest_scan = (uint8_t*)pNewBitmap->GetScanline(row - rect.top); + uint8_t* dest_scan = pNewBitmap->GetWritableScanline(row - rect.top); memcpy(dest_scan, src_scan, copy_len); } } @@ -932,8 +933,7 @@ RetainPtr CFX_DIBSource::CloneAlphaMask() const { for (int row = rect.top; row < rect.bottom; ++row) { const uint8_t* src_scan = GetScanline(row) + rect.left * 4 + 3; - uint8_t* dest_scan = - const_cast(pMask->GetScanline(row - rect.top)); + uint8_t* dest_scan = pMask->GetWritableScanline(row - rect.top); for (int col = rect.left; col < rect.right; ++col) { *dest_scan++ = *src_scan; src_scan += 4; @@ -963,7 +963,7 @@ bool CFX_DIBSource::SetAlphaMask(const RetainPtr& pAlphaMask, return false; } for (int row = 0; row < m_Height; ++row) { - memcpy(const_cast(m_pAlphaMask->GetScanline(row)), + memcpy(m_pAlphaMask->GetWritableScanline(row), pAlphaMask->GetScanline(row + rect.top) + rect.left, m_pAlphaMask->m_Pitch); } @@ -1126,7 +1126,8 @@ RetainPtr CFX_DIBSource::SwapXY(bool bXFlip, bool bYFlip) const { if (bYFlip) dest_scan += (result_height - 1) * dest_pitch; if (nBytes == 4) { - uint32_t* src_scan = (uint32_t*)GetScanline(row) + col_start; + const uint32_t* src_scan = + reinterpret_cast(GetScanline(row)) + col_start; for (int col = col_start; col < col_end; ++col) { *(uint32_t*)dest_scan = *src_scan++; dest_scan += dest_step; diff --git a/core/fxge/dib/cfx_dibsource.h b/core/fxge/dib/cfx_dibsource.h index 0e7fb27dde..064dbe2055 100644 --- a/core/fxge/dib/cfx_dibsource.h +++ b/core/fxge/dib/cfx_dibsource.h @@ -44,6 +44,9 @@ class CFX_DIBSource : public Retainable { int clip_left, int clip_width) const = 0; + uint8_t* GetWritableScanline(int line) { + return const_cast(GetScanline(line)); + } int GetWidth() const { return m_Width; } int GetHeight() const { return m_Height; } diff --git a/core/fxge/dib/cfx_imagetransformer.cpp b/core/fxge/dib/cfx_imagetransformer.cpp index 9cd5cea10e..37f56b57dc 100644 --- a/core/fxge/dib/cfx_imagetransformer.cpp +++ b/core/fxge/dib/cfx_imagetransformer.cpp @@ -480,7 +480,7 @@ void CFX_ImageTransformer::DoBilinearLoop( std::function func) { CFX_BilinearMatrix matrix_fix(cdata.matrix); for (int row = 0; row < m_result.Height(); row++) { - uint8_t* dest = const_cast(cdata.bitmap->GetScanline(row)); + const uint8_t* dest = cdata.bitmap->GetScanline(row); for (int col = 0; col < m_result.Width(); col++) { BilinearData d; d.res_x = 0; @@ -496,7 +496,7 @@ void CFX_ImageTransformer::DoBilinearLoop( AdjustCoords(&d.src_col_r, &d.src_row_r); d.row_offset_l = d.src_row_l * cdata.pitch; d.row_offset_r = d.src_row_r * cdata.pitch; - func(d, dest); + func(d, const_cast(dest)); } dest += increment; } @@ -509,7 +509,7 @@ void CFX_ImageTransformer::DoBicubicLoop( std::function func) { CFX_BilinearMatrix matrix_fix(cdata.matrix); for (int row = 0; row < m_result.Height(); row++) { - uint8_t* dest = const_cast(cdata.bitmap->GetScanline(row)); + const uint8_t* dest = cdata.bitmap->GetScanline(row); for (int col = 0; col < m_result.Width(); col++) { BicubicData d; d.res_x = 0; @@ -523,7 +523,7 @@ void CFX_ImageTransformer::DoBicubicLoop( bicubic_get_pos_weight(d.pos_pixel, d.u_w, d.v_w, d.src_col_l, d.src_row_l, d.res_x, d.res_y, stretch_width(), stretch_height()); - func(d, dest); + func(d, const_cast(dest)); } dest += increment; } @@ -536,7 +536,7 @@ void CFX_ImageTransformer::DoDownSampleLoop( std::function func) { CPDF_FixedMatrix matrix_fix(cdata.matrix); for (int row = 0; row < m_result.Height(); row++) { - uint8_t* dest = const_cast(cdata.bitmap->GetScanline(row)); + const uint8_t* dest = cdata.bitmap->GetScanline(row); for (int col = 0; col < m_result.Width(); col++) { DownSampleData d; d.src_col = 0; @@ -544,7 +544,7 @@ void CFX_ImageTransformer::DoDownSampleLoop( matrix_fix.Transform(col, row, &d.src_col, &d.src_row); if (LIKELY(InStretchBounds(d.src_col, d.src_row))) { AdjustCoords(&d.src_col, &d.src_row); - func(d, dest); + func(d, const_cast(dest)); } dest += increment; } diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp index 4fa5a08d09..0b96cdca5f 100644 --- a/core/fxge/skia/fx_skia_device.cpp +++ b/core/fxge/skia/fx_skia_device.cpp @@ -80,8 +80,8 @@ void RgbByteOrderTransferBitmap(const RetainPtr& pBitmap, if (dest_format == src_format) { for (int row = 0; row < height; row++) { uint8_t* dest_scan = buffer + (dest_top + row) * pitch + dest_left * Bpp; - uint8_t* src_scan = - (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; + const uint8_t* src_scan = + pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; if (Bpp == 4) { for (int col = 0; col < width; col++) { FXARGB_SETDIB(dest_scan, ArgbEncode(src_scan[3], src_scan[0], @@ -106,8 +106,8 @@ void RgbByteOrderTransferBitmap(const RetainPtr& pBitmap, if (src_format == FXDIB_Rgb32) { for (int row = 0; row < height; row++) { uint8_t* dest_scan = dest_buf + row * pitch; - uint8_t* src_scan = - (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * 4; + const uint8_t* src_scan = + pSrcBitmap->GetScanline(src_top + row) + src_left * 4; for (int col = 0; col < width; col++) { *dest_scan++ = src_scan[2]; *dest_scan++ = src_scan[1]; @@ -125,8 +125,8 @@ void RgbByteOrderTransferBitmap(const RetainPtr& pBitmap, if (src_format == FXDIB_Rgb) { for (int row = 0; row < height; row++) { uint8_t* dest_scan = (uint8_t*)(dest_buf + row * pitch); - uint8_t* src_scan = - (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left * 3; + const uint8_t* src_scan = + pSrcBitmap->GetScanline(src_top + row) + src_left * 3; for (int col = 0; col < width; col++) { FXARGB_SETDIB(dest_scan, ArgbEncode(0xff, src_scan[0], src_scan[1], src_scan[2])); @@ -138,8 +138,8 @@ void RgbByteOrderTransferBitmap(const RetainPtr& pBitmap, ASSERT(dest_format == FXDIB_Argb); for (int row = 0; row < height; row++) { uint8_t* dest_scan = dest_buf + row * pitch; - uint8_t* src_scan = - (uint8_t*)(pSrcBitmap->GetScanline(src_top + row) + src_left * 4); + const uint8_t* src_scan = + pSrcBitmap->GetScanline(src_top + row) + src_left * 4; for (int col = 0; col < width; col++) { FXARGB_SETDIB(dest_scan, ArgbEncode(0xff, src_scan[0], src_scan[1], src_scan[2])); -- cgit v1.2.3