Rename JpxImageInfo::components to JpxImageInfo::channels
Rename JpxImageInfo::components to JpxImageInfo::channels since the JPX
image's components are referred as "channels" in PDF reference book
(See page 36 in ISO 32000-1:2008), and it might be larger than the
actual component count of a PDF's color space component number.
Renaming will help us distinguish these two concepts and be consistent
with the PDF reference book.
Bug: pdfium:1747
Change-Id: I3ad1f25d0a91cb3a41698fb821a847e3aba37eec
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/105470
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Nigi <nigi@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_dib.cpp b/core/fpdfapi/page/cpdf_dib.cpp
index 9d649c1..37dbe59 100644
--- a/core/fpdfapi/page/cpdf_dib.cpp
+++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -118,12 +118,12 @@
JpxDecodeAction GetJpxDecodeAction(const CJPX_Decoder::JpxImageInfo& jpx_info,
const CPDF_ColorSpace* pdf_colorspace) {
if (pdf_colorspace) {
- // Make sure the JPX image and the PDF colorspace agree on the number of
- // components. In case of a mismatch, try to handle the discrepancy.
- if (jpx_info.components != pdf_colorspace->CountComponents()) {
+ // The channel count of a JPX image can be different from the PDF color
+ // space's component count.
+ if (jpx_info.channels != pdf_colorspace->CountComponents()) {
// Many PDFs generated by iOS meets this condition. See
// https://crbug.com/1012369 for example.
- if (pdf_colorspace->CountComponents() == 3 && jpx_info.components == 4 &&
+ if (pdf_colorspace->CountComponents() == 3 && jpx_info.channels == 4 &&
jpx_info.colorspace == OPJ_CLRSPC_SRGB) {
return JpxDecodeAction::kConvertArgbToRgb;
}
@@ -139,8 +139,8 @@
}
// Cases where the PDF did not provide a colorspace.
- // Choose how to decode based on the number of components in the JPX image.
- switch (jpx_info.components) {
+ // Choose how to decode based on the number of channels in the JPX image.
+ switch (jpx_info.channels) {
case 3:
return JpxDecodeAction::kUseRgb;
@@ -365,7 +365,7 @@
// If the checks above failed to find a colorspace, and the next line to set
// |m_nComponents| does not get reached, then a decoder can try to set
- // |m_nComponents| based on the number of components in the image being
+ // |m_nComponents| based on the number of channels in the image being
// decoded.
m_nComponents = m_pColorSpace->CountComponents();
m_Family = m_pColorSpace->GetFamily();
@@ -603,7 +603,7 @@
break;
case JpxDecodeAction::kUseRgb:
- DCHECK(image_info.components >= 3);
+ DCHECK(image_info.channels >= 3);
swap_rgb = true;
m_pColorSpace = nullptr;
break;
@@ -625,18 +625,18 @@
DCHECK_NE(0, m_nComponents);
} else {
DCHECK_EQ(0, m_nComponents);
- m_nComponents = image_info.components;
+ m_nComponents = image_info.channels;
}
FXDIB_Format format;
- if (image_info.components == 1) {
+ if (image_info.channels == 1) {
format = FXDIB_Format::k8bppRgb;
- } else if (image_info.components <= 3) {
+ } else if (image_info.channels <= 3) {
format = FXDIB_Format::kRgb;
- } else if (image_info.components == 4) {
+ } else if (image_info.channels == 4) {
format = FXDIB_Format::kRgb32;
} else {
- image_info.width = (image_info.width * image_info.components + 2) / 3;
+ image_info.width = (image_info.width * image_info.channels + 2) / 3;
format = FXDIB_Format::kRgb;
}
diff --git a/core/fxcodec/jpx/cjpx_decoder.h b/core/fxcodec/jpx/cjpx_decoder.h
index ee8c9cd..915c57a 100644
--- a/core/fxcodec/jpx/cjpx_decoder.h
+++ b/core/fxcodec/jpx/cjpx_decoder.h
@@ -39,7 +39,7 @@
struct JpxImageInfo {
uint32_t width;
uint32_t height;
- uint32_t components;
+ uint32_t channels;
COLOR_SPACE colorspace;
};
@@ -55,7 +55,7 @@
JpxImageInfo GetInfo() const;
bool StartDecode();
- // |swap_rgb| can only be set for images with 3 or more components.
+ // |swap_rgb| can only be set for images with 3 or more channels.
bool Decode(pdfium::span<uint8_t> dest_buf, uint32_t pitch, bool swap_rgb);
private:
diff --git a/testing/fuzzers/pdf_jpx_fuzzer.cc b/testing/fuzzers/pdf_jpx_fuzzer.cc
index ef88c7f..1a9e8f6 100644
--- a/testing/fuzzers/pdf_jpx_fuzzer.cc
+++ b/testing/fuzzers/pdf_jpx_fuzzer.cc
@@ -19,7 +19,7 @@
static constexpr uint32_t kMemLimitBytes = 1024 * 1024 * 1024; // 1 GB.
FX_SAFE_UINT32 mem = image_info.width;
mem *= image_info.height;
- mem *= image_info.components;
+ mem *= image_info.channels;
return mem.IsValid() && mem.ValueOrDie() <= kMemLimitBytes;
}
@@ -50,14 +50,14 @@
return 0;
FXDIB_Format format;
- if (image_info.components == 1) {
+ if (image_info.channels == 1) {
format = FXDIB_Format::k8bppRgb;
- } else if (image_info.components <= 3) {
+ } else if (image_info.channels <= 3) {
format = FXDIB_Format::kRgb;
- } else if (image_info.components == 4) {
+ } else if (image_info.channels == 4) {
format = FXDIB_Format::kRgb32;
} else {
- image_info.width = (image_info.width * image_info.components + 2) / 3;
+ image_info.width = (image_info.width * image_info.channels + 2) / 3;
format = FXDIB_Format::kRgb;
}
auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();