Fix EXR encoder to write scaled values - #3195
Open
JimBobSquarePants wants to merge 1 commit into
Open
JimBobSquarePants wants to merge 1 commit into
JimBobSquarePants wants to merge 1 commit into
Conversation
The EXR decoder maps file values to scaled values, but the encoder read native values. Pixel formats whose native range is not [0, 1], such as HalfVector4, wrote wrong color and alpha values to the file.
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.
Prerequisites
Description
Related to #3194
The EXR decoder and encoder did not agree. The decoder writes scaled values into the pixel format with
FromAssociatedScaledVector4. The encoder read native values withToAssociatedVector4().For a pixel format whose native range is
[0, 1], both values are equal, so the output was correct. For a pixel format with a different native range, the encoder wrote wrong values. For example,HalfVector4maps the scaled range[0, 1]to the native range[-65504, 65504]. A scaled red value of0.25went to the file as-32752, and an opaque alpha went to the file as65504.The encoder now reads
ToAssociatedScaledVector4()in the floating-point path and in the unsigned integer path.Rgba128.FromVector4in the unsigned integer path also expects components in[0, 1].I added a test that saves an
Image<HalfVector4>asHalf,Float, andUnsignedInt, loads the result asRgbaVector, and compares the scaled values. The test uses an alpha of0.5, so the clamp in the decoder cannot hide a wrong alpha value.This change does not add HDR support. Values outside
[0, 1]still clamp in 4.x. I track that work in #3194 for v5.