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.
Helps #5499
After declaring BC5_UNORM format to be available in DdsImagePlugin, all that was wrong was that the alpha channel was set to zero. I've fixed that by setting the image mode to RGB instead of RGBA.
As for BC5_SNORM, "the data is encoded in SNORM range", meaning that it is signed rather than unsigned. The key changes to read this data were changing
a0
anda1
in the struct fromUINT8
toINT8
, and then adjusting it into the UNORM range withThe sample image from the issue has a
fourcc
of "BC5S". I've also added a hexeditted version that uses the DX10fourcc
value like the other versions here.For BC5_TYPELESS, https://docs.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-resources-intro#strong-vs-weak-typing
My conclusion is that 'typeless' formats don't actually specify whether they should be UNORM or SNORM. So I have continued our existing tradition of treating TYPELESS as UNORM -
Pillow/src/PIL/DdsImagePlugin.py
Line 158 in 16b9cad
Pillow/src/PIL/DdsImagePlugin.py
Lines 165 to 169 in 16b9cad
See https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpcr2/98e2dbc9-3a1d-4ab2-93e3-152eeebd17a3 for documentation that
DXGI_FORMAT_BC5_TYPELESS
is 0x00000052 = 82DXGI_FORMAT_BC5_UNORM
is 0x00000053 = 83DXGI_FORMAT_BC5_SNORM
is 0x00000054 = 84.