Fix a JPEG2000 decoding regression
When neither the PDF nor the JPEG2000 image provides a colorspace, treat
images with 3 channels as though they are RGB and decode them, instead
of giving up and not decoding at all.
This fixes a regression from CL [1], and also reverts the change to
testing/resources/pixel/bug_304_expected.pdf.0.png from that CL.
Although Acrobat Reader rejects the image in the top-left quadrant and
renders it as white, most other PDF implementations will render is as
red.
[1] https://pdfium-review.googlesource.com/104031
Bug: 430651971
Change-Id: I1bc40492671bd0e2bd39cab063d30157dce92e63
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/134150
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_dib.cpp b/core/fpdfapi/page/cpdf_dib.cpp
index 13bfda2..be46268 100644
--- a/core/fpdfapi/page/cpdf_dib.cpp
+++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -184,6 +184,9 @@
switch (jpx_info.colorspace) {
case OPJ_CLRSPC_UNKNOWN:
case OPJ_CLRSPC_UNSPECIFIED:
+ return jpx_info.channels == 3 ? JpxDecodeAction::kUseRgb
+ : JpxDecodeAction::kDoNothing;
+
case OPJ_CLRSPC_SYCC:
case OPJ_CLRSPC_EYCC:
return JpxDecodeAction::kDoNothing;
@@ -201,11 +204,12 @@
NOTREACHED();
}
-int GetComponentCountFromOpjColorSpace(OPJ_COLOR_SPACE colorspace) {
- switch (colorspace) {
+int GetComponentCountFromJpxImageInfo(
+ const CJPX_Decoder::JpxImageInfo& jpx_info) {
+ switch (jpx_info.colorspace) {
case OPJ_CLRSPC_UNKNOWN:
case OPJ_CLRSPC_UNSPECIFIED:
- return 0;
+ return jpx_info.channels;
case OPJ_CLRSPC_GRAY:
return 1;
@@ -268,7 +272,7 @@
// components count.
if (!pdf_colorspace) {
conversion.jpx_components_count_ =
- GetComponentCountFromOpjColorSpace(jpx_info.colorspace);
+ GetComponentCountFromJpxImageInfo(jpx_info);
}
return conversion;
}
diff --git a/testing/resources/pixel/bug_304_expected.pdf.0.png b/testing/resources/pixel/bug_304_expected.pdf.0.png
index 62de87b..e1b3d43 100644
--- a/testing/resources/pixel/bug_304_expected.pdf.0.png
+++ b/testing/resources/pixel/bug_304_expected.pdf.0.png
Binary files differ