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

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
Dabrosny
Posts: 111
Joined: 2013-10-02T10:49:39-07:00
Authentication code: 6789
Location: New York, US

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

Post 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.)
Last edited by Dabrosny on 2017-08-10T13:42:33-07:00, edited 1 time in total.
-Dabrosny [Using IM7.0.6 or higher, Q16 HDRI x64 native executable, command line, often invoked from cygwin bash/sh (as of Aug. 2017)]
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

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

Post 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.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

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

Post 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

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

Code: Select all

DEBUG=""

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 \
  png24:one.hdr.png.hdr.png
im7magick one.hdr.png.hdr.png txt:- | tail -1
Post Reply