Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

fix(render): say that an unresolvable /ColorSpace also gets the JP2 palette (#3179)

mtlcl410857fef3b1aea
diff --git a/vendor/README.md b/vendor/README.md
index 95b9418ab..a32c61411 100644
--- a/vendor/README.md
+++ b/vendor/README.md
@@ -44,6 +44,7 @@ horizontal differencing and an 8-bit control) and
JPEG 2000 palettes (#3179): `hayro-syntax::filter::jpx::decode` applies a JP2 palette (`pclr`)
when the image dictionary has no `/ColorSpace`, since the colour then comes from the JP2 header
(ISO 32000-2 §7.4.9). With a `/ColorSpace` the raw indices are kept, as an `/Indexed` space needs.
+A `/ColorSpace` that does not resolve counts as none: the JP2 colours are then the only ones.
Without the patch a palette image with no `/ColorSpace` was drawn as its indices, in gray.
Covered by `filter::jpx::tests::jpx_palette_is_applied_without_a_color_space` and
`filter::jpx::tests::jpx_palette_indices_stay_raw_for_an_indexed_color_space`.
diff --git a/vendor/hayro-syntax/src/filter/jpx.rs b/vendor/hayro-syntax/src/filter/jpx.rs
index f3a631f0c..1f8ebf498 100644
--- a/vendor/hayro-syntax/src/filter/jpx.rs
+++ b/vendor/hayro-syntax/src/filter/jpx.rs
@@ -24,6 +24,9 @@ pub(crate) fn decode(data: &[u8], params: &ImageDecodeParams) -> Option<FilterRe
// PdfCraft patch: (#3179) with no /ColorSpace in the image dictionary the colours come from
// the JP2 header (ISO 32000-2 §7.4.9), so its palette (`pclr`) is applied here; with a
// /ColorSpace the header colour data is ignored, and an /Indexed space takes the raw indices.
+ // A /ColorSpace that does not resolve also leaves `num_components` unset: the header's
+ // colours are then the only ones there are, so the palette is applied too (raw indices
+ // would be drawn as gray).
resolve_palette_indices: params.num_components.is_none(),
strict: false,
target_resolution: params.target_dimension,