drewcassidy / quicktex

A project intended to add python bindings to rgbcx that somehow resulted in rewriting it entirely
Apache License 2.0
12 stars 2 forks source link

ATI 1 is decoded incorrectly #22

Open RunDevelopment opened 2 years ago

RunDevelopment commented 2 years ago

ATI 1 is a single channel format.

When using the code dds.read(pathlib.Path(path)).decode().save(target, format="png") to convert an ATI 1 DDS file to PNG, it produces a wrong image. The saved image is of the format RGB = (0,0,0) with the alpha channel containing the channel of the DDS file.

drewcassidy commented 2 years ago

Yes, this is since which channel to decode into is ambiguous, so it defaults to alpha when decoding BC4. the BC4decoder has a channel argument in its constructor to tell it which to use. Again, I'll look into how to make this more convenient when using dds.read

drewcassidy commented 2 years ago

Ah, looks like I did account for this: you can pass constructor arguments to decode(). Try dds.read(path).decode(channel=0, write_alpha=True).save(target, format="png"). I might also make it so that decoders can be passed to decode() instead of always constructing them there

RunDevelopment commented 2 years ago

A very common solution is to output grayscale images for single-channel images. This is also what texconv does.

drewcassidy commented 2 years ago

That's a good solution. I'll consider it. In the meantime you can perform that transformation by extracting the alpha channel from the resulting pillow image.