Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iCCP chunk requirements for GRAY and RGB #478

Open
lvandeve opened this issue Dec 22, 2024 · 0 comments
Open

iCCP chunk requirements for GRAY and RGB #478

lvandeve opened this issue Dec 22, 2024 · 0 comments

Comments

@lvandeve
Copy link

In https://www.w3.org/TR/png-3/#11iCCP, when adding an ICC profile, it's required that images with color type 2 (RGB), 3 (palette) and 6 (RGBA) use an ICC color profile with color space RGB, and images with color types 1 (grayscale) and 4 (grayscale+alpha) use an ICC profile with color space GRAY.

I wonder if it's possible to lighten this restriction:

-allow RGB ICC profiles for all PNG images, including color types 1 and 4. In case of color type 1 and 4 the RGB ICC profile would then mean we've got an RGB image where R=G=B happens to be true for all pixels.

-possibly: allow GRAY ICC profiles for palette PNG images if all palette colors are gray, or to simplify this, allow it for any PNG image that decodes to pixels that have R=G=B

-possibly: completely remove any restrictions in the PNG spec and punt it to the ICC handling library

There are two reasons for this request: compression efficiency, and, not requiring pedantic PNG encoders/decoders to parse the ICC profile for the RGB/GRAY field (since ICC profile parsing is better left up to an ICC library)

For allowing RGB ICC profiles for grayscale PNG images: There is nothing that prevents you from having a color photograph where R=G=B happens to be true for all pixels as stored in the PNG, (e.g. gray environment and white balance that happens to perfectly match up, or screenshot in gray looking section of a game) even if an RGB color profile applies to it. Today you can encode this image with color type 2 (RGB) and add the ICC color profile to it. But since R=G=B for all pixels, it would be more efficient for compression to encode it if you could use color type 1 (grayscale), there's no reason to repeat all the pixel values three times here. But the PNG specification doesn't allow this due to not allowing an RGB ICC profile with color type grayscale. It's true that an RGB color profile can make a grayscale image non-grayscale after application of the color profile, but that doesn't mean that R=G=B is still true at the time it's encoded in the PNG.

For allowing GRAY ICC profiles with a palette with only grayscale pixel values: currently the PNG spec doesn't allow using a GRAY ICC profile with palette. But if the palette happens to have only gray colors, and the set of colors happens to be such that it's more efficient to encode with the palette than 1-bit, 2-bit, 4-bit or 8-bit grayscale, then it would still be more efficient when encoded that way. Example: an image with exactly 2 shades of intermediate gray.

For allowing GRAY ICC profiles with any color type (but still requiring R=G=B if necessary): this would allow a very simple PNG encoder that e.g. only supports color type 2, to still encode valid images with GRAY ICC profile as well when appropriate.

Having no restriction at all would also allow PNG encoders to not have to parse the ICC profile at all, currently to be exactly pedantically correct the encoder (or decoder) has to parse the RGB/GRAY field of the ICC profile to give an error when the color type doesn't match up, instead of allowing a colorimetry library to handle this error instead.

What do you think about this suggestion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant