Switch to memcpy()/std::fill()/std::swap() in image processing code. Use optimized library functions in more places. Change-Id: I3a0ecb6d4e8a60b694dc4be58bd7379e5e5837a0 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/73031 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_dib.cpp b/core/fpdfapi/page/cpdf_dib.cpp index d1ab8c8..bf61337 100644 --- a/core/fpdfapi/page/cpdf_dib.cpp +++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -731,9 +731,7 @@ const uint8_t* src = result_bitmap->GetScanline(row); uint8_t* dest = rgb_bitmap->GetWritableScanline(row); for (uint32_t col = 0; col < image_info.width; ++col) { - dest[0] = src[0]; - dest[1] = src[1]; - dest[2] = src[2]; + memcpy(dest, src, 3); src += 4; dest += 3; } @@ -860,9 +858,8 @@ return; } float color_values[3]; - color_values[0] = m_CompData[0].m_DecodeMin; - color_values[1] = color_values[0]; - color_values[2] = color_values[0]; + std::fill(std::begin(color_values), std::end(color_values), + m_CompData[0].m_DecodeMin); float R = 0.0f; float G = 0.0f;
diff --git a/core/fxcodec/fx_codec.cpp b/core/fxcodec/fx_codec.cpp index 300a0a5..84f386a 100644 --- a/core/fxcodec/fx_codec.cpp +++ b/core/fxcodec/fx_codec.cpp
@@ -6,6 +6,8 @@ #include "core/fxcodec/fx_codec.h" +#include <algorithm> + #include "core/fxcrt/fx_memory.h" namespace fxcodec { @@ -22,9 +24,7 @@ void ReverseRGB(uint8_t* pDestBuf, const uint8_t* pSrcBuf, int pixels) { if (pDestBuf == pSrcBuf) { for (int i = 0; i < pixels; i++) { - uint8_t temp = pDestBuf[2]; - pDestBuf[2] = pDestBuf[0]; - pDestBuf[0] = temp; + std::swap(pDestBuf[0], pDestBuf[2]); pDestBuf += 3; } } else {
diff --git a/testing/image_diff/image_diff_png.cpp b/testing/image_diff/image_diff_png.cpp index dcd9d69..e035ec6 100644 --- a/testing/image_diff/image_diff_png.cpp +++ b/testing/image_diff/image_diff_png.cpp
@@ -92,12 +92,12 @@ int pixel_width, uint8_t* rgb, bool* is_opaque) { + const uint8_t* pixel_in = rgba; + uint8_t* pixel_out = rgb; for (int x = 0; x < pixel_width; x++) { - const uint8_t* pixel_in = &rgba[x * 4]; - uint8_t* pixel_out = &rgb[x * 3]; - pixel_out[0] = pixel_in[0]; - pixel_out[1] = pixel_in[1]; - pixel_out[2] = pixel_in[2]; + memcpy(pixel_out, pixel_in, 3); + pixel_in += 4; + pixel_out += 3; } } @@ -148,13 +148,13 @@ int pixel_width, uint8_t* rgba, bool* is_opaque) { + const uint8_t* pixel_in = rgb; + uint8_t* pixel_out = rgba; for (int x = 0; x < pixel_width; x++) { - const uint8_t* pixel_in = &rgb[x * 3]; - uint8_t* pixel_out = &rgba[x * 4]; - pixel_out[0] = pixel_in[0]; - pixel_out[1] = pixel_in[1]; - pixel_out[2] = pixel_in[2]; + memcpy(pixel_out, pixel_in, 3); pixel_out[3] = 0xff; + pixel_in += 3; + pixel_out += 4; } }