Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

Support DXT1, DXT3 and DXT5 DDS encoding

Open SerVB opened this issue 5 years ago • 10 comments

Hi! Currently DDS is a read-only format: https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html?highlight=format#dds. This issue asks to add support for saving DDS images.

SerVB avatar Aug 13 '20 21:08 SerVB

I've created #5402 to add RGB saving at least.

radarhere avatar Apr 13 '21 01:04 radarhere

I've pushed another commit to the PR to add RGBA as well, resolving this issue - unless you have anything further to add.

radarhere avatar Apr 13 '21 10:04 radarhere

Thanks a lot for your efforts. Which DDS formats does writing support? Ideally, it would be great to have all: DXT1, DXT3, and DXT5.

And thank you specially for RGBA, because it's what I've needed.

SerVB avatar Apr 13 '21 11:04 SerVB

Ah, ok. At the moment, it only saves uncompressed data - so not DXT1, DXT3, DXT5 or DX10. That's a level more complex, and not something I'm going to attempt.

We can leave this issue open for those additional formats though if you want.

radarhere avatar Apr 13 '21 11:04 radarhere

Let's leave it open.

SerVB avatar Apr 13 '21 11:04 SerVB

Can someone point me the documentation to the DDS (DXTn) format/spec please? I could try to implement the DXT1 (and therefore DXT3 and 5) compression write support if possible…

jrd avatar Nov 06 '21 11:11 jrd

A while ago, I attempted to implement DXT1 - https://github.com/radarhere/Pillow/tree/dds. Feel free to take that and build on it if you want.

I hit a wall when I realised that it was a lossy encoding, so I wasn't going to be a single perfect solution, and using someone else's logic would probably be better. https://github.com/nothings/stb/blob/master/stb_dxt.h seemed good, but I didn't return to this.

You asked for documentation though. Here are links that I found helpful

  • https://docs.microsoft.com/en-us/windows/win32/direct3d9/opaque-and-1-bit-alpha-textures
  • https://docs.microsoft.com/en-us/windows/win32/directshow/working-with-16-bit-rgb
  • https://docs.microsoft.com/en-us/windows/win32/direct3d10/d3d10-graphics-programming-guide-resources-block-compression#bc1

radarhere avatar Nov 08 '21 11:11 radarhere