microsoft / DirectXTex

DirectXTex texture processing library
https://walbourn.github.io/directxtex/
MIT License
1.82k stars 448 forks source link

Support for working with unexpanded P8/A8P8 images #520

Open walbourn opened 1 month ago

walbourn commented 1 month ago

Currently the DDS, TGA, and WIC readers always expand P8 and A8P8 format images to RGBA32. This is the primary workflow, and makes sense as the default behavior. Most of the operations/functions in the library do not support paletted data by design. Direct3D 11 and Direct3D 12 do not support palette texture formats, although in theory you could implement them with a programmable shader.

I could make use of the DXGI enumerations DXGI_FORMAT_P8 and DXGI_FORMAT_A8P8 which were added for video support to return the data in the original paletted form.

This would also require some way to retrieve the palette data as well (like adding a palette member to Image).

Requesting this behavior on read rather than the current behavior to always expand the data would require some specific behavior flag (DDS_FLAGS_ALLOW_P8, TGA_FLAGS_ALLOW_P8, WIC_FLAGS_ALLOW_P8).

Writing would be indicated by giving an input image with DXGI_FORMAT_P8 or DXGI_FORMAT_A8P8.

If there was some reason to support this palette workflow, then it would be worth considering adding a codec for the PCX which is a classic paletted format.

"palette workflow" would also imply the need for explicit functions to convert P8/A8P8 to RGBA32, and a function for converting RGBA32 to a P8/A8P8 image using something like "median cut" (see this article).

karurung commented 1 month ago

Trying to create new flag constants such as 'DDS_FLAGS_ALLOW_P8', 'TGA_FLAGS_ALLOW_P8', and 'WIC_FLAGS_ALLOW_P8'. These flags should be clearly defined in your library to indicate that the reder should allow for paletted formats.

Also, considering the addition of a codec for classic paletted formats like PCX seems like a great step as well. PCX would be suport various image formats.