Skip to content

Accept separate alpha with its own SCALED_FLAG - #30

Merged
jcwal1516 merged 1 commit into
mainfrom
fix/separate-alpha-scaled-flag
Nov 15, 2026
Merged

jcwal1516 merged 1 commit into
mainfrom
fix/separate-alpha-scaled-flag

Conversation

@jcwal1516

Copy link
Copy Markdown
Member

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 comparing scaled in 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 via alpha_scaled.
  • jxr-metal/src/kernels/output.metal: the F16 and F32 output kernels read the alpha selector 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

  • Reporter's gradient.jxr (100x100 BGRA, separate alpha): byte-identical to the T.835 reference decoder on CPU and Metal.
  • Metal F16 output with mixed flags, both directions: identical to CPU (one-off check, not committed).
  • T.834 conformance, CPU and Metal: 517 passed, 179 skipped, 0 failed. The CPU report is identical per file to a run without this change.
  • 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-mpsgraph ignored Metal tests.

Not covered

  • CUDA hardware is untested here; the CUDA output kernel already selects alpha_scaled per sample.
  • The check still requires SHIFT_BITS, LEN_MANTISSA and EXP_BIAS to match between planes. Those are also per-plane fields and may be stricter than needed, but no sample needs it, so that is left for a follow-up.

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
jcwal1516 force-pushed the fix/separate-alpha-scaled-flag branch from 8ceeb44 to e2cf9bb Compare November 15, 2026 18:24
@jcwal1516
jcwal1516 merged commit 2ad449a into main Nov 15, 2026
4 checks passed
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.
@jcwal1516
jcwal1516 deleted the fix/separate-alpha-scaled-flag branch November 15, 2026 19:44
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.

Separate-alpha images rejected when alpha plane's SCALED_FLAG differs from the primary plane's

1 participant