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

Encoding DDS images? #2093

Open
JulianKnodt opened this issue Jan 9, 2024 · 4 comments
Open

Encoding DDS images? #2093

JulianKnodt opened this issue Jan 9, 2024 · 4 comments

Comments

@JulianKnodt
Copy link
Contributor

JulianKnodt commented Jan 9, 2024

I would like to be able encode images in the DDS file format. There are few existing implementations that do this, but currently decoding is supported.

My specific use case for this functionality is for downstream use in games.

This is more generally applicable to image processing for use with DirectX(?)

Draft

There is an existing C implementation for encoding/decoding in this repo, under the MIT license.

Microsoft also provides a reference spec of the file format here

The format probably doesn't have much support outside of Windows, so I'm not sure if it's worth supporting or not, but the decoder already exists so maybe for feature parity it's worth adding the encoder?

@fintelia
Copy link
Contributor

I think that would be reasonable.

The uncompressed formats should be relatively straightforward and the texpresso crate supports BC1-BC5, so I it shouldn't be too difficult if you wanted to support those as well. But BC6H or BC7 or anything else would be more complicated

(There's actually also code for DXT compression in this crate, but it is both very slow and produces low quality output, so I'd really like to remove it...)

@JulianKnodt
Copy link
Contributor Author

is DXT compression not deterministic? I haven't actually looked into what it would take to implement.

@fintelia
Copy link
Contributor

fintelia commented Jan 12, 2024

Yep. The process for decompressing DXT is deterministic* but compression is more complex. Each 4x4 block of pixels gets its assigned a shared set of parameters. Different choices of parameters will be better for some pixels in the 4x4 block and worse for others, so you generally want to search through a whole bunch of different options for them to see which is best overall. But searching all 2^32 (or closer to 2^64 for BC7!) options is very expensive, so you need to be smart about which to try

*It turns out different implementations use subtly different deterministic formulas for decoding.

@drewcassidy
Copy link
Contributor

Ive been doodling on a rust library for doing DXT compression (I already made one in C/Python), and there's a number of difficulties in doing it thats vastly different from other image formats.

The containers themselves have things like cube maps, mipmaps, image arrays, 3d textures, etc, which might be adaptable from the animation system here, but there's also things like how to handle alpha (is It premultiplied or not? it matters a lot if you're rescaling!) or the myriad of encoder settings that these block compression formats need. Some formats are 2-channel. some formats have 1-bit alpha. some formats are YUV

I don't think fitting it into image-rs is impossible, but the enum-based image format system kinda gets in the way. The sheer amount of code to make the encoders and decoders work well and quickly is probably better suited to a standalone library

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

No branches or pull requests

3 participants