KTX-Software
KTX-Software copied to clipboard
[toktx] Do color space transform on JFIF files
toktx should distinguish between JFIF and EXIF files. If JFIF it should transform the required BT.601 space (gamma 2.4) to sRGB. If EXIF it should verify the color space is sRGB and if not, either bail out or transform the space to sRGB or linear depending on the transfer function table. Consider using http://www.littlecms.com/ for this. Need to watch out for YCrCb images and convert those.
How many JFIF files are spec compliant and in BT.601?
JFIF files could have embedded ICC profiles in APP2
section. When such a profile is not provided, they are BT.601 by definition.
In the glTF samples repo, some JPEG textures are vanilla JFIF BT.601, some are JFIF sRGB (with an ICC profile in APP2
), and others also have EXIF. It's worth noting that the glTF spec overrides all color-data to be treated with sRGB primaries and transfer. The glTF spec doesn't specify YCrCb-to-RGB conversion. This means that vanilla JFIF files are treated like: YCrCb-to-RGB as BT.601, and then RGB values are used as if they were encoded as sRGB. The latter is probably sub-optimal but there's no way to verify or manage in-browser JPEG decoding.
To verify embedded ICC profiles (e.g. to avoid extra conversion for sRGB inputs), an implementation has to fully parse the payload and compare specific fields to expected values.
Where can I find documentation of APP2 for JFIF?
Thanks for the information about the samples in the glTF sample repo.
To verify embedded ICC profiles (e.g. to avoid extra conversion for sRGB inputs), an implementation has to fully parse the payload and compare specific fields to expected values.
I think toktx should do this work and convert to sRGB or linear as appropriate. It's already transforming netpbm files. Unfortunately the jpg decoder it is using is completely oblivious to JFIF vs EXIF and whether there is anything in APP2 in the JFIF case. It will need work or I need to find an alternative.