Page 1 of 1

ImageMagick from 6.9.9-x on returns wrong colorspace information for grayscale JPEG

Posted: 2018-02-19T08:52:33-07:00
by pmhausen
Hi all,

I stumbled into an odd problem with a CMS written in PHP that uses pecl-imagick to scale images. After updating ImageMagick from 6.9.8-9 to 6.9.9-28 I get bogus colorspace values for a particular set of images.

I've come up with some PHP test code:

Code: Select all

$imagick = new \Imagick(__DIR__.'/test.jpg');
echo $imagick->getImageColorspace(), "\n";
With ImageMagick 6.9.8-9 the returned value is "2" for COLORSPACE_GRAY. With 6.9.9-28 I get "35" which is no valid colorspace constant as far as I know. Result is that my CMS rejects to render the image.

Using "identify -verbose" shows mainly this difference:

Code: Select all

<   Background color: gray(255)
<   Border color: gray(223)
<   Matte color: gray(189)
<   Transparent color: gray(0)
---
>   Background color: sgray(255)
>   Border color: sgray(223)
>   Matte color: sgray(189)
>   Transparent color: sgray(0)
Thanks for any hints.
Patrick

Re: ImageMagick from 6.9.9-x on returns wrong colorspace information for grayscale JPEG

Posted: 2018-02-19T09:33:25-07:00
by snibgo

Re: ImageMagick from 6.9.9-x on returns wrong colorspace information for grayscale JPEG

Posted: 2018-02-20T03:37:30-07:00
by pmhausen
OK, so this is a breaking API change, right? What would be the correct course of action, now? Does pecl-imagick need to be adapted to include the new colorspace? Or is that simply a wrapper that exposes everything that is in the C library to PHP? And then Neos CMS needs to learn that COLORSPACE_SGRAY or however that macro will be spelled is a valid value, too ...

Correct?

Thanks,
Patrick

Re: ImageMagick from 6.9.9-x on returns wrong colorspace information for grayscale JPEG

Posted: 2018-02-20T03:53:24-07:00
by Bonzo
Imagick is not written nor maintained by the people who maintain Imagemagick. I suppose it is up to the writers of Imagick; if you can find a way to contact them they may be able to answer your question.

Re: ImageMagick from 6.9.9-x on returns wrong colorspace information for grayscale JPEG

Posted: 2018-02-20T08:12:37-07:00
by pmhausen
Thanks! I found the responsible code.

ImageMagick 6.9.9-28:

Code: Select all

typedef enum
{
  UndefinedColorspace,
  RGBColorspace,            /* Linear RGB colorspace */
  GRAYColorspace,           /* greyscale (linear) image (faked 1 channel) */
  TransparentColorspace,
  [...]
  HCLpColorspace,
  YDbDrColorspace,
  xyYColorspace,
  sGRAYColorspace
} ColorspaceType;
pecl-imagick latest version:

Code: Select all

	IMAGICK_REGISTER_CONST_LONG("COLORSPACE_UNDEFINED", UndefinedColorspace);
	IMAGICK_REGISTER_CONST_LONG("COLORSPACE_RGB", RGBColorspace);
	IMAGICK_REGISTER_CONST_LONG("COLORSPACE_GRAY", GRAYColorspace);
	IMAGICK_REGISTER_CONST_LONG("COLORSPACE_TRANSPARENT", TransparentColorspace);
	[...]
#if MagickLibVersion >= 0x686
	IMAGICK_REGISTER_CONST_LONG("COLORSPACE_LCHAB", LCHabColorspace);
	IMAGICK_REGISTER_CONST_LONG("COLORSPACE_LCHUV", LCHuvColorspace);
	IMAGICK_REGISTER_CONST_LONG("COLORSPACE_SCRGB", scRGBColorspace);
	IMAGICK_REGISTER_CONST_LONG("COLORSPACE_HSI", HSIColorspace);
	IMAGICK_REGISTER_CONST_LONG("COLORSPACE_HSV", HSVColorspace);
	IMAGICK_REGISTER_CONST_LONG("COLORSPACE_HCLP", HCLpColorspace);
	IMAGICK_REGISTER_CONST_LONG("COLORSPACE_YDBDR", YDbDrColorspace);
#endif

	IMAGICK_REGISTER_CONST_LONG("COLORSPACE_REC601YCBCR", Rec601YCbCrColorspace);
	IMAGICK_REGISTER_CONST_LONG("COLORSPACE_REC709YCBCR", Rec709YCbCrColorspace);
#if MagickLibVersion >= 0x690
	IMAGICK_REGISTER_CONST_LONG("COLORSPACE_XYY", xyYColorspace);
#endif
Argh! What an architecture - I mean manually following constants from an upstream project ... there has to be a better way.

Thanks again for your help. Filing bug reports, now ...
Patrick

Re: ImageMagick from 6.9.9-x on returns wrong colorspace information for grayscale JPEG

Posted: 2018-02-20T08:53:28-07:00
by pmhausen
OK, one more question. I'm trying to come up with a patch for pecl-imagick. The feature was introduced in 6.9.9-28 and changed in 6.9.9-30.

6.9.9-28: sGRAYColorspace
6.9.9-30: LinearGRAYColorspace

How can I check the MagickLibVersion for these two versions?

Code: Select all

MagickLibVersion >= 0x699
won't cut it probably.

Thanks,
Patrick

Re: ImageMagick from 6.9.9-x on returns wrong colorspace information for grayscale JPEG

Posted: 2018-02-20T10:57:24-07:00
by magick
The colorspace change was transient. We originally suggested sGRAY / LinearGray so its an analog to sRGB / RGB. However, that change was thought to potentially break too many existing scripts so we settled on Gray / LinearGray to distinguish nonlinear from linear gray. To check for the 6.9.9-29 release, you could check for MagickLibAddendum which is defined as "-29". MagickLibVersion will always be 0x699.