Resolve output scaling and pixel layout once per image - #7
Merged
Merged
Conversation
The generic CPU packers interpreted the output format per sample: every sample re-derived its bias, rounding, and postscaling from the request, every pixel re-converted the crop origin and re-matched the channel layout, and every pixel copied its primaries with a variable-length memmove. The packed RGB555/RGB565/RGB101010/RGBE path repeated the same per-sample scale resolution. scale_integer_component is now "resolve a ChannelScale, then apply it", and the ordered and packed-color packers resolve each channel's scale once per image through that same implementation, so the fast path and the reference cannot diverge. Resolution failures are kept and reported by the first sample that uses the channel, preserving the previous error behavior. Crop conversion and layout decisions are hoisted out of the pixel loops, and primaries are copied with fixed-size moves.
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.
The generic CPU packers interpreted the output format per sample:
memmove;scale_integer_componentis now "resolve aChannelScale, then apply it". The ordered and packed-color packers resolve each channel's scale once per image through that same implementation, so the fast path and the reference cannot diverge. Resolution failures are stored and reported by the first sample that uses the channel, which preserves the previous error behavior. Crop conversion and layout decisions are hoisted out of the pixel loops, and primaries are copied with fixed-size moves.This covers every non-Luma-U8 CPU output, including the common RGB8/RGBA8 targets. Luma U8 already had its own SIMD path.
Performance. Measured with
jxr-load-bench(in-memory parse + entropy + reconstruction + packing/readback, 3 warmups, 20 iterations) on an M4 Pro, interleaved withmainin the same session. Each value is the lower of two rounds' medians. CPU decode:Metal decodes don't use this path and are unchanged.
Validation on an M4 Pro:
cargo fmt --all -- --check;cargo clippy --workspace --all-targets --all-features -- -D warnings;cargo test --workspace --all-features(255 passed); T.834/T.835 conformance CPU 517/517, Annex-A rewrap 517/517, and Metal 517/517. An earlier revision regressed RGBE by about 3.5%, because the packed-color path still resolved scales per sample. That's fixed here: RGBE, F16 (Maui-64bppRGBHalf), and F32 (P19d-128bppPRGBAFloat) CPU decodes matchmainwithin noise in same-session A/B runs.