Skip to content

Connect to the BC6 decoding from Python#1

Closed
radarhere wants to merge 2 commits intoShadelessFox:mainfrom
radarhere:bc6
Closed

Connect to the BC6 decoding from Python#1
radarhere wants to merge 2 commits intoShadelessFox:mainfrom
radarhere:bc6

Conversation

@radarhere
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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

Development

Successfully merging this pull request may close these issues.

2 participants