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

Added DDS BC5 reading #5501

Merged
merged 7 commits into from Jun 11, 2021
Merged

Added DDS BC5 reading #5501

merged 7 commits into from Jun 11, 2021

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented May 16, 2021

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 and a1 in the struct from UINT8 to INT8, and then adjusting it into the UNORM range with

a0 = (b.a0 + 255) / 2;
a1 = (b.a1 + 255) / 2;

The sample image from the issue has a fourcc of "BC5S". I've also added a hexeditted version that uses the DX10 fourcc 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

In a type less resource, the data type is unknown when the resource is first created. The application must choose from the available type less formats

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 -

if dxgi_format in (DXGI_FORMAT_BC7_TYPELESS, DXGI_FORMAT_BC7_UNORM):

elif dxgi_format in (
DXGI_FORMAT_R8G8B8A8_TYPELESS,
DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
):

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 = 82
  • DXGI_FORMAT_BC5_UNORM is 0x00000053 = 83
  • DXGI_FORMAT_BC5_SNORM is 0x00000054 = 84.

@radarhere radarhere marked this pull request as draft May 16, 2021 06:45
@radarhere radarhere force-pushed the dds_bc5 branch 3 times, most recently from 09bc0e1 to c7e7980 Compare May 17, 2021 08:18
@radarhere radarhere marked this pull request as ready for review May 17, 2021 10:13
@radarhere radarhere changed the title Added DDS BC5_UNORM reading Added DDS BC5_UNORM and BC5_SNORM reading May 18, 2021
@radarhere radarhere changed the title Added DDS BC5_UNORM and BC5_SNORM reading Added DDS BC5 reading May 19, 2021
@hugovk
Copy link
Member

hugovk commented Jun 8, 2021

Let's also add this to release notes 👍

@radarhere
Copy link
Member Author

Sure, done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants