Page 1 of 1

[glennrp fixd IM7 to git] reading linear png (GAMA=1) sets sRGB (nonlinear colorspace) but should set RGB (linear) instd

Posted: 2017-07-29T16:29:22-07:00
by Dabrosny
By request, I'm submitting this simple issue in reading linear png files, separately from another thread (where we were mostly discussing the wisdom of writing linear png files to begin with under certain circumstances).

The problem is that on reading a linear png, i.e. a png file with a GAMA=1 chunk (whether the file was created by IM or not), IM is setting the colorspace incorrectly as sRGB (a nonlinear colorspace) even though it is also marking the image (correctly) as gamma=1. Among other things, this leads to cumulative colorspace transformation errors after round-trip conversions. I've only tested it with linear 16-bit png files, but it's likely that it's the same issue when reading a linear 8-bit png as well.

The correct thing to do when gamma=1 in a png being read into IM would be to mark the image as being in RGB (linear) colorspace, not sRGB.

(I'm using ImageMagick 7.0.6-2 Q16 x64 2017-07-22.)

Re: reading linear png (GAMA=1) sets sRGB (nonlinear colorspace) but it should set RGB (linear) instead

Posted: 2017-07-29T17:40:39-07:00
by glennrp
The png reader is setting gamma to1.0 but neglects to reset the image colorspace. That would be a bug that needs to be fixed.
I'm testing a patch now.

Re: reading linear png (GAMA=1) sets sRGB (nonlinear colorspace) but it should set RGB (linear) instead

Posted: 2017-07-29T18:10:43-07:00
by glennrp
I've pushed a change to the IM7 git repo
The "one" demo works nicely; the pixel values survive the
round-trip PNG->HDR->PNG->HDR:

Code: Select all

0,0: (65535,32896,0)  #FFFF80800000  srgb(255,128,0)
0,0: (65535,32768,0)  #FFFF80000000  rgb(100%,50%,0%)
0,0: (65535,32896,0)  #FF8000  rgb(255,128,0)
0,0: (65535,32767.5,0)  #FFFF80000000  rgb(100%,50%,0%)
0,0: (65535,32896,0)  #FF8000  rgb(255,128,0)
Here's the "one" demo from the other discussion:

Code: Select all


echo one:
im7magick -size 1x1 xc:"#ff8000" txt:- | tail -1

echo one.hdr:
im7magick convert $DEBUG -set colorspace RGB -size 1x1 xc:"#ff8000" one.hdr
im7magick convert one.hdr txt:- | tail -1

echo one.hdr.png:
im7magick convert $DEBUG one.hdr png24:one.hdr.png
im7magick convert one.hdr.png txt:- | tail -1

echo one.hdr.png.hdr:
im7magick convert $DEBUG one.hdr.png one.hdr.png.hdr
im7magick one.hdr.png.hdr txt:- | tail -1

echo one.hdr.png.hdr.png:
im7magick convert $DEBUG one.hdr.png.hdr \
im7magick one.hdr.png.hdr.png txt:- | tail -1