Repository navigation
Accept separate alpha with its own SCALED_FLAG - #30
Merged
Merged
Conversation
SCALED_FLAG is a per-plane field in T.832, and JXRLib applies it per plane. Encoders built on JXRLib, ImageMagick among them, pair a scaled primary plane with an unscaled lossless alpha plane, and the separate alpha compatibility check rejected those files with "separate alpha output depth". Reconstruction and packing already use the alpha plane's own flag on CPU, Metal and CUDA, so drop the comparison. With the check gone, the Metal F16 and F32 output kernels could select the wrong plane's flag: they read the `alpha` selector as an argument of the same call that sets it, and argument evaluation order is unspecified. Take the sample first, as the integer path already does. The regression test decodes a container whose planes differ only in SCALED_FLAG, in both directions, and checks each channel against a standalone decode of its own codestream. The reporter's gradient.jxr now matches the T.835 reference byte for byte on CPU and Metal. Fixes #29.
jcwal1516
force-pushed
the
fix/separate-alpha-scaled-flag
branch
from
November 15, 2026 18:24
8ceeb44 to
e2cf9bb
Compare
jcwal1516
added a commit
that referenced
this pull request
Nov 15, 2026
Publish the separate-alpha SCALED_FLAG fix (#30) with the reference encoder alpha end offsets (#28) and the additional WIC pixel formats (#27). jxr-native and jxr-metal change; jxr, jxr-image and jxr-mpsgraph follow their exact pins to 0.5.1 and 0.6.1. jxr-core, jxr-cuda and jxr-math are unchanged and keep their published versions. Both lockfiles follow. cargo semver-checks reports no semver update required for any of the five packages. docs/releasing.md gives the publish order.
4 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #29. Thanks to @torokati44 for the report, the sample and the diagnosis.
Problem
Separate-alpha images where the alpha plane's SCALED_FLAG differs from the primary plane's were rejected with
InvalidSyntax while separate alpha output depth. JXRLib-based encoders such as ImageMagick produce exactly this (scaled primary, unscaled lossless alpha), and JXRLib decodes those files. SCALED_FLAG is a per-plane field in T.832 and is applied per plane by T.835.Change
jxr-native/src/decode/alpha.rs: stop comparingscaledin the separate-alpha compatibility check. Reconstruction (quantizer steps, DC finalization) and output packing already use the alpha plane's own flag, as do the CUDA and Metal output kernels viaalpha_scaled.jxr-metal/src/kernels/output.metal: the F16 and F32 output kernels read thealphaselector as an argument of the same call that sets it through an out-parameter. Argument evaluation order is unspecified, so the selector could be read uninitialized and choose the wrong plane's flag. The removed check had masked this for separate alpha. Take the sample first, as the integer path already does.jxr/tests/public_parse.rs: regression test that wraps two DC-only luma codestreams differing only in SCALED_FLAG (both directions) and checks each output channel against a standalone decode of its own codestream. The payload is chosen so scaled and unscaled decodes differ; making alpha use the primary's flag fails the test.Checks run
gradient.jxr(100x100 BGRA, separate alpha): byte-identical to the T.835 reference decoder on CPU and Metal.cargo fmt --check,cargo clippy --workspace --all-targets --all-features -D warnings,cargo test --workspace --all-features(277 passed),cargo test -p jxr --no-default-features,cargo doc -D warnings,jxr-mpsgraphignored Metal tests.Not covered
alpha_scaledper sample.