Skip to content

fix(j2k): preserve declared JP2 color space across decode and recode - #324

Closed
jcwal1516 wants to merge 2 commits into
mainfrom
fix/pr323-bounded-rows
Closed

jcwal1516 wants to merge 2 commits into
mainfrom
fix/pr323-bounded-rows

Conversation

@jcwal1516

Copy link
Copy Markdown
Member

JP2 files with unspecified extra components keep their declared color space and omit the extras from display output. Recoding preserves every codestream component. This branch retains Justin Coyne’s original commit from #323.

Bounded 8-bit and 16-bit row decoding now chooses its output format from the resolved color space and alpha state. Recode validation compares all components, avoiding a false mismatch between filtered JP2 display output and raw codestream output.

Adds regressions for two-component grayscale, four- and five-component sRGB bounded rows, and preservation of all four component samples during recoding. Updates the public and hidden API inventories and their semver review records.

Validation: Rust formatting and diff checks pass. GitHub Actions will validate this branch independently of other development work.

jcoyne and others added 2 commits November 6, 2026 20:05
… components

A JP2 declaring sRGB over four codestream components with no cdef box
failed every Rgb8/Rgba8 decode under the default strict settings with
"backend color space cannot be mapped to requested 8-bit pixel format".
The component-count fallback in resolve_alpha_and_color_space replaced
the declared sRGB with CMYK, which has no 8-bit RGB mapping. Kakadu 7
wrote such files from RGBA TIFFs unless -jp2_alpha was given.

Without a channel definition, ISO/IEC 15444-1 I.5.3.6 leaves the
components after those of the declared color space unspecified. When a
JP2 declares an enumerated or ICC color space, has no cdef or palette,
and has more components than that space (plus alpha), keep the color
space and record the extras as Image::ignored_components. Decoded
output omits them: finish_decoded_image, the native RawBitmap decodes,
streamed region rows and the native planes sink keep only the color
and alpha components. Device plane reuse is disabled for such images.

Lenient decoding still infers alpha for exactly one extra component,
and raw codestreams keep their component-count interpretation. Recode
keeps every component, since it reuses the source JP2 metadata. The
HTJ2K batch direct-plan builder now treats DirectPlanUnsupported as
"not direct" and falls back instead of failing the job.
Choose bounded u8/u16 row layouts from resolved color and alpha metadata.
Compare all codestream components during recode validation and cover row
output and preservation with regression tests. Update the API inventories
and review records for the original JP2 color-space change.
@jcwal1516 jcwal1516 closed this Nov 8, 2026
@jcwal1516
jcwal1516 deleted the fix/pr323-bounded-rows branch November 9, 2026 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants