PNG gAMA chunk seems to be inverted
Posted: 2014-10-30T17:45:23-07:00
Hi all,
I found a minor issue with how gamma values are written to PNG files. After a -gamma operation, the PNG encoder takes this into account when writing the gAMA chunk. But the value is inverted; after applying -gamma 2.2 to a linear image it will write 2.2, while it should write .45455.
Some test cases:
The exr image is linear. this command converts it to a PNG image, with linear values, and adds a gAMA chunk set to 1.0 (as expected).
There are however programs out there which ignore the gAMA chunk, so I tried to produce a PNG file with the usual gamma correction (1 / 2.2).
Now the brightness values are encoded with the usual gamma correction of .45455. But the gAMA chunk is set to 2.2. Programs which understand the gAMA chunk (eg. modern browsers) will get confused, and display the image with way too bright colours.
It's possible to work around like this:
Now the PNG file has the usual gamma correction and a correct gAMA chunk.
The colorspace option works as expected:
--
Roeland
I found a minor issue with how gamma values are written to PNG files. After a -gamma operation, the PNG encoder takes this into account when writing the gAMA chunk. But the value is inverted; after applying -gamma 2.2 to a linear image it will write 2.2, while it should write .45455.
Some test cases:
Code: Select all
convert test.exr test.png
There are however programs out there which ignore the gAMA chunk, so I tried to produce a PNG file with the usual gamma correction (1 / 2.2).
Code: Select all
convert test.exr -gamma 2.2 test.png
It's possible to work around like this:
Code: Select all
convert test.exr -gamma 2.2 +gamma .45455 test.png
The colorspace option works as expected:
Code: Select all
convert test.exr -colorspace sRGB test.png
Roeland