Skip to content

Handle various bits per sample values in JPEG XL files #4738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

1div0
Copy link
Contributor

@1div0 1div0 commented May 4, 2025

I was wondering why the 12 bits per channel images were rejected by the image viewer?

Description

Extend the ranges of bits per sample.

1div0 added 2 commits May 4, 2025 14:04
Signed-off-by: Peter Kovář <peter.kovar@reflexion.tv>
Signed-off-by: Peter Kovář <peter.kovar@reflexion.tv>
@lgritz
Copy link
Collaborator

lgritz commented May 4, 2025

If you get something like 12 bps, are you just leaving those values as they are but storing them in a uint16? So, like, fully bright is 4095?

The design philosophy we adopted is that the app shouldn't need to consider every possible bit depth. On the app side of the interface, we pretend all values are UINT8, UINT16, HALF, etc. So the OIIO reader is expected to "round up" and promote a "non-whole" bit depth to the next bigger whole one -- e.g., 12 bit in the file becomes UINT16. But we want it to look like a proper UINT16, so what we do is scale the values up so that the max brightness is always 65535 for UINT16 data.

Also when we do this scaling, we set in the ImageSpec an attribute "oiio:BitsPerSample" that gives the origin number of bits in the file.

You can see how this works in tiffinput.cpp, for example. Look circa line 1053 (in current main), and 1859 for where the bit depth scaling takes place.

@lgritz
Copy link
Collaborator

lgritz commented May 21, 2025

@1div0 ping on this, I had made some comments/questions

@lgritz
Copy link
Collaborator

lgritz commented May 31, 2025

Hi, @1div0, do you have any comments on the question I had about whether different bit depths in the file were being properly scaled to the full data type range before being handed to the app?

@1div0
Copy link
Contributor Author

1div0 commented Jun 1, 2025

Last two weeks were extremely busy.

The various bit depth in JPEG XL image files in the range from 1 to 31 bits per channel are handled by the decoder in the reference libjxl transparently according to selected data type. That means 8, 16 and 32 bits per channel in output from decoder are scaled properly, so there is not needed to do more.

In other words, 12 bpc images are scaled to next bigger type UINT16.

@jessey-git
Copy link
Contributor

Gentle nudge. How's this PR going?

LG2M, TY

Co-authored-by: Larry Gritz <lg@larrygritz.com>
Signed-off-by: Peter Kovář <software@reflexion.tv>
++

Co-authored-by: Larry Gritz <lg@larrygritz.com>
Signed-off-by: Peter Kovář <software@reflexion.tv>
@1div0
Copy link
Contributor Author

1div0 commented Jul 2, 2025

C001! Finally all checked. Lesson learned. Will do better next time_t.

Good Night. And Good Luck.

@lgritz lgritz merged commit db878e0 into AcademySoftwareFoundation:main Jul 3, 2025
30 checks passed
zachlewis pushed a commit to zachlewis/OpenImageIO that referenced this pull request Aug 1, 2025
…mySoftwareFoundation#4738)

Handle bps other than 8, 16, 32, with appropriate conversion.

---------

Signed-off-by: Peter Kovář <peter.kovar@reflexion.tv>
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.

3 participants