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

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
pmhausen
Posts: 4
Joined: 2018-02-19T08:43:25-07:00
Authentication code: 1152

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

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

snibgo's IM pages: im.snibgo.com
pmhausen
Posts: 4
Joined: 2018-02-19T08:43:25-07:00
Authentication code: 1152

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

Post 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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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.
pmhausen
Posts: 4
Joined: 2018-02-19T08:43:25-07:00
Authentication code: 1152

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

Post 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
pmhausen
Posts: 4
Joined: 2018-02-19T08:43:25-07:00
Authentication code: 1152

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

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post 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.
Post Reply