Skip to content

Conversation

@sambvfx
Copy link
Contributor

@sambvfx sambvfx commented Dec 4, 2023

This fixes issues reading BC4 dds files.

The nvidia texture tool exporter generates BC4 dds files that use the DX10 header so that the exact DXGI format can be specified.

@radarhere radarhere changed the title Add support for BC4 dds files Added support for reading BC4 DDS images Dec 4, 2023
DXGI_FORMAT_R8G8B8A8_UNORM = 28
DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29
DXGI_FORMAT_BC4_TYPELESS = 79
DXGI_FORMAT_BC4_UNORM = 80
Copy link
Member

Choose a reason for hiding this comment

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

A note that you may or may not care about - I'm hoping to get #6486 merged before the next release. If it is merged in time, then I would remove these new constants in favour of enums. You've absolutely done the right thing here, no need to change this PR, just letting you know that if you had plans to use these constants externally, things may not play out that way.

Copy link
Member

Choose a reason for hiding this comment

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

#6486 has now been merged

@radarhere radarhere changed the title Added support for reading BC4 DDS images Added support for reading DX10 BC4 DDS images Dec 4, 2023
@radarhere
Copy link
Member

I've created sambvfx#1 to add some more test images - a PNG to compare the image against, and a TYPELESS variation of your test image.

To be certain, this is what your image is supposed to look like, yes?
bc4_unorm

@sambvfx
Copy link
Contributor Author

sambvfx commented Dec 5, 2023

Thanks @radarhere, I've merged your changes.

One odd thing to note is that the original PNG I used was simply the ati1.png from the existing test images. I converted that to the bc4_unorm.dds using nvidia texture tool exporter like this:

nvtt_export.exe ati1.png --format bc4 --output bc4_unorm.dds

Tweaking the tests to compare against the ati1.png instead of the new one you added fails... There's a chance I'm doing something wrong, but I find that a little unexpected.

@radarhere
Copy link
Member

radarhere commented Dec 5, 2023

The compression is lossy format, so it is not unexpected that converting to it created a slightly different file.

Testing, I find that assert_image_similar_tofile(im, TEST_FILE_ATI1.replace(".dds", ".png"), 0.4) passes, but this assert_image_equal_tofile is a stronger test, so the current version is fine to my way of thinking.

@radarhere radarhere merged commit b3f3743 into python-pillow:main Dec 5, 2023
@radarhere
Copy link
Member

With #6486, this change is now mentioned in the release notes - https://pillow.readthedocs.io/en/latest/releasenotes/10.2.0.html#other-changes

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