Pass span<> to CPDF_ColorSpace::TranslateImageLine().
Then immediately extract .data() from it, to minimize changes.
Change-Id: I9667b8b62f444602705288c38c5ff2b7164948ef
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/85979
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index bdbc335..f91df8f 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -126,8 +126,8 @@
uint32_t v_Load(CPDF_Document* pDoc,
const CPDF_Array* pArray,
std::set<const CPDF_Object*>* pVisited) override;
- void TranslateImageLine(uint8_t* pDestBuf,
- const uint8_t* pSrcBuf,
+ void TranslateImageLine(pdfium::span<uint8_t> dest_span,
+ pdfium::span<const uint8_t> src_span,
int pixels,
int image_width,
int image_height,
@@ -153,8 +153,8 @@
float* R,
float* G,
float* B) const override;
- void TranslateImageLine(uint8_t* pDestBuf,
- const uint8_t* pSrcBuf,
+ void TranslateImageLine(pdfium::span<uint8_t> dest_span,
+ pdfium::span<const uint8_t> src_span,
int pixels,
int image_width,
int image_height,
@@ -191,8 +191,8 @@
float* value,
float* min,
float* max) const override;
- void TranslateImageLine(uint8_t* pDestBuf,
- const uint8_t* pSrcBuf,
+ void TranslateImageLine(pdfium::span<uint8_t> dest_span,
+ pdfium::span<const uint8_t> src_span,
int pixels,
int image_width,
int image_height,
@@ -221,8 +221,8 @@
float* R,
float* G,
float* B) const override;
- void TranslateImageLine(uint8_t* pDestBuf,
- const uint8_t* pSrcBuf,
+ void TranslateImageLine(pdfium::span<uint8_t> dest_span,
+ pdfium::span<const uint8_t> src_span,
int pixels,
int image_width,
int image_height,
@@ -608,12 +608,14 @@
*max = 1.0f;
}
-void CPDF_ColorSpace::TranslateImageLine(uint8_t* dest_buf,
- const uint8_t* src_buf,
+void CPDF_ColorSpace::TranslateImageLine(pdfium::span<uint8_t> dest_span,
+ pdfium::span<const uint8_t> src_span,
int pixels,
int image_width,
int image_height,
bool bTransMask) const {
+ uint8_t* dest_buf = dest_span.data();
+ const uint8_t* src_buf = src_span.data();
std::vector<float> src(m_nComponents);
float R;
float G;
@@ -687,12 +689,14 @@
return true;
}
-void CPDF_CalGray::TranslateImageLine(uint8_t* pDestBuf,
- const uint8_t* pSrcBuf,
+void CPDF_CalGray::TranslateImageLine(pdfium::span<uint8_t> dest_span,
+ pdfium::span<const uint8_t> src_span,
int pixels,
int image_width,
int image_height,
bool bTransMask) const {
+ uint8_t* pDestBuf = dest_span.data();
+ const uint8_t* pSrcBuf = src_span.data();
for (int i = 0; i < pixels; i++) {
*pDestBuf++ = pSrcBuf[i];
*pDestBuf++ = pSrcBuf[i];
@@ -762,12 +766,14 @@
return true;
}
-void CPDF_CalRGB::TranslateImageLine(uint8_t* pDestBuf,
- const uint8_t* pSrcBuf,
+void CPDF_CalRGB::TranslateImageLine(pdfium::span<uint8_t> dest_span,
+ pdfium::span<const uint8_t> src_span,
int pixels,
int image_width,
int image_height,
bool bTransMask) const {
+ uint8_t* pDestBuf = dest_span.data();
+ const uint8_t* pSrcBuf = src_span.data();
if (!bTransMask) {
fxcodec::ReverseRGB(pDestBuf, pSrcBuf, pixels);
return;
@@ -871,12 +877,14 @@
return true;
}
-void CPDF_LabCS::TranslateImageLine(uint8_t* pDestBuf,
- const uint8_t* pSrcBuf,
+void CPDF_LabCS::TranslateImageLine(pdfium::span<uint8_t> dest_span,
+ pdfium::span<const uint8_t> src_span,
int pixels,
int image_width,
int image_height,
bool bTransMask) const {
+ uint8_t* pDestBuf = dest_span.data();
+ const uint8_t* pSrcBuf = src_span.data();
for (int i = 0; i < pixels; i++) {
float lab[3];
lab[0] = pSrcBuf[0] * 100 / 255.0f;
@@ -969,19 +977,21 @@
return true;
}
-void CPDF_ICCBasedCS::TranslateImageLine(uint8_t* pDestBuf,
- const uint8_t* pSrcBuf,
+void CPDF_ICCBasedCS::TranslateImageLine(pdfium::span<uint8_t> dest_span,
+ pdfium::span<const uint8_t> src_span,
int pixels,
int image_width,
int image_height,
bool bTransMask) const {
+ uint8_t* pDestBuf = dest_span.data();
+ const uint8_t* pSrcBuf = src_span.data();
if (m_pProfile->IsSRGB()) {
fxcodec::ReverseRGB(pDestBuf, pSrcBuf, pixels);
return;
}
if (!m_pProfile->transform()) {
if (m_pBaseCS) {
- m_pBaseCS->TranslateImageLine(pDestBuf, pSrcBuf, pixels, image_width,
+ m_pBaseCS->TranslateImageLine(dest_span, src_span, pixels, image_width,
image_height, false);
}
return;
diff --git a/core/fpdfapi/page/cpdf_colorspace.h b/core/fpdfapi/page/cpdf_colorspace.h
index 97341b5..1a14061 100644
--- a/core/fpdfapi/page/cpdf_colorspace.h
+++ b/core/fpdfapi/page/cpdf_colorspace.h
@@ -104,8 +104,9 @@
float* value,
float* min,
float* max) const;
- virtual void TranslateImageLine(uint8_t* dest_buf,
- const uint8_t* src_buf,
+
+ virtual void TranslateImageLine(pdfium::span<uint8_t> dest_span,
+ pdfium::span<const uint8_t> src_span,
int pixels,
int image_width,
int image_height,
diff --git a/core/fpdfapi/page/cpdf_devicecs.cpp b/core/fpdfapi/page/cpdf_devicecs.cpp
index 11152e5..be83369 100644
--- a/core/fpdfapi/page/cpdf_devicecs.cpp
+++ b/core/fpdfapi/page/cpdf_devicecs.cpp
@@ -77,12 +77,14 @@
}
}
-void CPDF_DeviceCS::TranslateImageLine(uint8_t* pDestBuf,
- const uint8_t* pSrcBuf,
+void CPDF_DeviceCS::TranslateImageLine(pdfium::span<uint8_t> dest_span,
+ pdfium::span<const uint8_t> src_span,
int pixels,
int image_width,
int image_height,
bool bTransMask) const {
+ uint8_t* pDestBuf = dest_span.data();
+ const uint8_t* pSrcBuf = src_span.data();
switch (m_Family) {
case Family::kDeviceGray:
for (int i = 0; i < pixels; i++) {
diff --git a/core/fpdfapi/page/cpdf_devicecs.h b/core/fpdfapi/page/cpdf_devicecs.h
index 9848052..9efcadb 100644
--- a/core/fpdfapi/page/cpdf_devicecs.h
+++ b/core/fpdfapi/page/cpdf_devicecs.h
@@ -22,8 +22,8 @@
float* R,
float* G,
float* B) const override;
- void TranslateImageLine(uint8_t* pDestBuf,
- const uint8_t* pSrcBuf,
+ void TranslateImageLine(pdfium::span<uint8_t> dest_span,
+ pdfium::span<const uint8_t> src_span,
int pixels,
int image_width,
int image_height,
diff --git a/core/fpdfapi/page/cpdf_dib.cpp b/core/fpdfapi/page/cpdf_dib.cpp
index 27be60a..dff1d94 100644
--- a/core/fpdfapi/page/cpdf_dib.cpp
+++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -957,8 +957,9 @@
m_bpc = 0;
}
-void CPDF_DIB::TranslateScanline24bpp(uint8_t* dest_scan,
- const uint8_t* src_scan) const {
+void CPDF_DIB::TranslateScanline24bpp(
+ pdfium::span<uint8_t> dest_scan,
+ pdfium::span<const uint8_t> src_scan) const {
if (m_bpc == 0)
return;
@@ -981,7 +982,7 @@
color_values[color] = m_CompData[color].m_DecodeMin +
m_CompData[color].m_DecodeStep * data;
} else {
- unsigned int data = GetBits8(src_scan, src_bit_pos, m_bpc);
+ unsigned int data = GetBits8(src_scan.data(), src_bit_pos, m_bpc);
color_values[color] = m_CompData[color].m_DecodeMin +
m_CompData[color].m_DecodeStep * data;
src_bit_pos += m_bpc;
@@ -1007,8 +1008,8 @@
}
bool CPDF_DIB::TranslateScanline24bppDefaultDecode(
- uint8_t* dest_scan,
- const uint8_t* src_scan) const {
+ pdfium::span<uint8_t> dest_scan,
+ pdfium::span<const uint8_t> src_scan) const {
if (!m_bDefaultDecode)
return false;
@@ -1027,21 +1028,22 @@
if (m_nComponents != 3)
return true;
- const uint8_t* src_pos = src_scan;
+ uint8_t* dest_pos = dest_scan.data();
+ const uint8_t* src_pos = src_scan.data();
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;
+ *dest_pos++ = src_pos[2];
+ *dest_pos++ = src_pos[1];
+ *dest_pos++ = *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;
+ *dest_pos++ = src_pos[4];
+ *dest_pos++ = src_pos[2];
+ *dest_pos++ = *src_pos;
src_pos += 6;
}
break;
@@ -1050,18 +1052,18 @@
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);
+ unsigned int R = GetBits8(src_scan.data(), src_bit_pos, m_bpc);
src_bit_pos += m_bpc;
- unsigned int G = GetBits8(src_scan, src_bit_pos, m_bpc);
+ unsigned int G = GetBits8(src_scan.data(), src_bit_pos, m_bpc);
src_bit_pos += m_bpc;
- unsigned int B = GetBits8(src_scan, src_bit_pos, m_bpc);
+ unsigned int B = GetBits8(src_scan.data(), 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_pos[dest_byte_pos] = B * 255 / max_data;
+ dest_pos[dest_byte_pos + 1] = G * 255 / max_data;
+ dest_pos[dest_byte_pos + 2] = R * 255 / max_data;
dest_byte_pos += 3;
}
break;
@@ -1178,7 +1180,7 @@
}
}
if (m_pColorSpace) {
- TranslateScanline24bpp(m_LineBuf.data(), pSrcLine.data());
+ TranslateScanline24bpp(m_LineBuf, pSrcLine);
src_pitch_value = 3 * m_Width;
pSrcLine = pdfium::make_span(m_LineBuf).first(src_pitch_value);
}
diff --git a/core/fpdfapi/page/cpdf_dib.h b/core/fpdfapi/page/cpdf_dib.h
index ae9e8c3..8be7b3a 100644
--- a/core/fpdfapi/page/cpdf_dib.h
+++ b/core/fpdfapi/page/cpdf_dib.h
@@ -91,10 +91,11 @@
LoadState CreateDecoder();
bool CreateDCTDecoder(pdfium::span<const uint8_t> src_span,
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 TranslateScanline24bpp(pdfium::span<uint8_t> dest_scan,
+ pdfium::span<const uint8_t> src_scan) const;
+ bool TranslateScanline24bppDefaultDecode(
+ pdfium::span<uint8_t> dest_scan,
+ pdfium::span<const uint8_t> src_scan) const;
void ValidateDictParam(const ByteString& filter);
bool TransMask() const;
void SetMaskProperties();