Skip to content
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

Connect to the BC6 decoding from Python #1

Closed
wants to merge 2 commits into from

Conversation

radarhere
Copy link

Helps python-pillow#6449

Two changes here.

  1. Connect to the BC6 decoding from Python

After this PR, with your code as well,

from PIL import Image
im = Image.open("source.dds")
im.save("out.png")

gives

  1. Change bc6_finalize for unsigned data.

As per the comment in the code, the half_to_float function is taken from https://gist.github.com/rygorous/2144712. It is half_to_float_fast5. Except, that code is for converting FP16 into FP32. FP16 has 1 sign bit, 5 exponent bits and then 10 bits for the fraction. Unsigned BC6H has 5 exponent bits and then 11 bits for the fraction. So instead of scaling it down from 65535 to 31743, I'm just scaling it down to 255.

Copy link
Owner

@ShadelessFox ShadelessFox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your image looks faded because of truncation to uint8. I don't think that's the result we want to achieve.

I believe the BC6 decoder should accept an additional parameter, gamma, just like the BC7_UNORM_SRGB variant.

Then, the result of bc6_finalize should be gamma-corrected, normalized to be in the range 0..255 (since it's an HDR container and its values may go beyond 0..1), and only then scaled down to 255.

@ShadelessFox
Copy link
Owner

Fixed in 5087356

radarhere pushed a commit that referenced this pull request Aug 2, 2022
radarhere pushed a commit that referenced this pull request Aug 2, 2022
@radarhere radarhere deleted the bc6 branch October 10, 2022 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants