KTX-Software icon indicating copy to clipboard operation
KTX-Software copied to clipboard

[toktx] Do color space transform on JFIF files

Open MarkCallow opened this issue 4 years ago • 3 comments

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?

MarkCallow avatar Jun 19 '20 22:06 MarkCallow

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.

lexaknyazev avatar Jun 23 '20 20:06 lexaknyazev

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.

MarkCallow avatar Jun 23 '20 20:06 MarkCallow

Where can I find documentation of APP2 for JFIF?

See Annex.B, Section B.4 of ICC.1:2010-12.

lexaknyazev avatar Jun 23 '20 20:06 lexaknyazev