donmccurdy / KTX-Parse

KTX 2.0 (.ktx2) parser and serializer.
MIT License
48 stars 7 forks source link

Can I read a specific pixel value? #52

Closed abogartz closed 1 year ago

abogartz commented 1 year ago

I'm having trouble finding info on this, so forgive me for the newbie question. But can you suggest how I can use this to parse the pixel values of an image? For instance, if I wanted to see if the pixel at [0,0] in your example file, test_uastc.ktx2 were solid white, or had an alpha value of 0, can I do this with the parsed data?

Thanks for a cool tool!

donmccurdy commented 1 year ago

Hi @abogartz! KTX Parse will parse the .ktx2 container / wrapper, and let you identify the compression used, image dimensions, mipmaps, 3D or array textures, etc.. The image data within that could be in a number of compression formats. In the simplest case the data could already be uncompressed RGBA, and that's pretty easy to read. But more commonly people use Basis Universal compression in KTX2 files, and that isn't as trivial to decode.

I'd recommend THREE.KTX2Loader as an example for transcoding Basis Universal textures to RGBA data. It uses ktx-parse to read the container, then uses the official Basis WASM transcoders to decompress to RGBA or transcode to an appropriate GPU compression format.