"-colorspace RGB" broken

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.
mastro
Posts: 5
Joined: 2014-05-05T08:38:37-07:00
Authentication code: 6789

Re: "-colorspace RGB" broken

Post by mastro »

I'm facing this issue now.

Cause Amazon AMI Linux only recently received an update from
ImageMagick-6.5.4.7-6.12.amzn1.x86_64
to
ImageMagick-6.7.8.9-6.14.amzn1.x86_64


I had a service running there that was resizing images.
I need that service to resize ANY image to JPEG and sRGB colorspace

I have no way of query the image. I can just execute a command like you would do in a batch operation with random images on a folder.

This used to be the command (don't get fooled by the fact that this seems a bash script, I just reconstructed it to reproduce the issue, I only specify the options to the software):

Code: Select all

convert "$IN" -quality 90 -intent Perceptual -resize '5120x3200>' -filter Catrom -colorspace RGB -strip "$OUT"
This worked like a charm!

Any image I popped in, PNG, JPEG with colorspace CMYK, GREY or any form of sRGB I obtained an image exactly as the original or only slightly different (for example when the original image was an Adobe sRGB)

After the update with the same command when the original is CMYK or GREY it works. When is an sRGB I obtain an image lot darker.

I cant use the suggested workaround:

Code: Select all

convert "$IN" -set colorspace sRGB -colorspace RGB -quality 90 -intent Perceptual -resize '5120x3200>' -filter Catrom -colorspace sRGB -set colorspace RGB -strip "$OUT"

Cause when the original image is CMYK I can't -set colorspace sRGB, makes no sense.

So, this is a bug to any extent. And it's made worse by the fact that you broken backward compatibility, it doesn't matter if the previous nomenclature was wrong, you did a change that is not backward compatible without anyway to obtain the previous result.

I really love ImageMagick and thank you all that worked on it. But you have to admit you messed up pretty bad here.

Please help me find a workaround for this issue.

Regards,
Daniele
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "-colorspace RGB" broken

Post by fmw42 »

see viewtopic.php?f=4&t=21269

-colorspace RGB was swapped with -colorpace sRGB to more accurately represent that colorspace. sRGB is now non-linear and RGB is linear color.

So just replace RGB with sRGB in your command and see if that works again.
mastro
Posts: 5
Joined: 2014-05-05T08:38:37-07:00
Authentication code: 6789

Re: "-colorspace RGB" broken

Post by mastro »

fmw42 wrote:-colorspace RGB was swapped with -colorpace sRGB to more accurately represent that colorspace. sRGB is now non-linear and RGB is linear color.

So just replace RGB with sRGB in your command and see if that works again.
Hi, thank you

but I already tried that.

using sRGB produce correct colors when the original image is CMYK or GREY.

But it produce lighter images for original images marked as sRGB in the output of the identify -verbose command.

This command:

Code: Select all

-set colorspace sRGB -colorspace RGB -resize '5120x3200>'  -colorspace sRGB -set colorspace RGB
works like it used to work before the update for original sRGB Image. It mess up pretty bad for different colorspace in the original image (for example CMYK images)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "-colorspace RGB" broken

Post by fmw42 »

If you input is CMYK, then try

Code: Select all

-set colorspace CMYK -colorspace RGB -resize '5120x3200>'  -colorspace sRGB -set colorspace RGB
But I suspect you have been doing it oddly for a long time. It looks like you want a doubly converted linear RGB image.

If you want a normal sRGB image then
convert image -colorspace sRGB -resize '5120x3200> result
If you want a linear RGB image and the output format supports it, then
convert image -colorspace RGB -resize '5120x3200> -set colorspace RGB result
If you want a linear RGB but labelled as sRGB, then
convert image -colorspace RGB -resize '5120x3200> -set colorspace sRGB result
mastro
Posts: 5
Joined: 2014-05-05T08:38:37-07:00
Authentication code: 6789

Re: "-colorspace RGB" broken

Post by mastro »

First of all: thank you very much for your response, I really appreciate your effort and time to help me! :)
fmw42 wrote:If you input is CMYK, then try

Code: Select all

-set colorspace CMYK -colorspace RGB -resize '5120x3200>'  -colorspace sRGB -set colorspace RGB
No, can't do that.

I do not have the option of chosing the parameters at runtime.
The software I use do not let me and it should work with any Image.

The Image can be a PNG or JPG with any color profile. It should come in and exit resized in RGB/sRGB with the same parameters.

This just used to work until before the upgrade. And this is why the colorspace option has been broken.

You can't expect me to check every image and see what they are and, in respect to that define the options to resize.
If that was suitable I wouldn't use ImageMagick at all, I'd just fire up Gimp and do it from there.


fmw42 wrote:But I suspect you have been doing it oddly for a long time. It looks like you want a doubly converted linear RGB image.
No, I wasn't doing anything odly.

This is what I was doing before the upgrade:

Code: Select all

-quality 90 -intent Perceptual -resize '5120x3200>' -filter Catrom -colorspace RGB -strip
Did it output RGB or sRGB? I don't know, I don't actually care for the sake of the result, it just worked.

And for "just worked" I mean that it correctly guessed which color profile to parse and always produced the same color profile as output with same visual appearance, regardless of the original image profile.

After the upgrade that seems not to be the case anymore and you actually have to know what's the original profile in order to resize the image to RGB/sRGB with the same visual appearance as the original one.
fmw42 wrote:If you want a normal sRGB image then
convert image -colorspace sRGB -resize '5120x3200> result
If you want a linear RGB image and the output format supports it, then
convert image -colorspace RGB -resize '5120x3200> -set colorspace RGB result
If you want a linear RGB but labelled as sRGB, then
convert image -colorspace RGB -resize '5120x3200> -set colorspace sRGB result
I want what the command was doing before the upgrade.
Was it a normal sRGB? A linear RGB? a linear RGB labeled sRGB? I don't know what it was.

But those command you suggested simply doesn't work for all the cases.

My test case is this:

- CMYK JPEG
- Grey JPEG
- sRGB JPEG (don't know if linear, normal or what, sRGB is what identify -verbose say in Colorspace)
- sRGB with Adobe profile

Before the upgrade the same very command produced a JPEG in RGB (sRGB.. whatever) visually equal to the original one (with the exception of the Adobe profile which was slightly different after conversion)
After the upgrade I end up with a much darker image for the sRGB (Adobe or not) images.

Changing the option from -colorspace RGB to -colorspace sRGB reverse the issue: it gives a correct image for sRGB images and produce a much lighter image for CMYK images.

What's happening under the cover? I don't know I'm no expert in colorspaces. I'm just pointing out that before it worked, now it doesn't: and I'm asking for a way to obtain the exact same result with a SINGLE command (I know how to obtain it with different command for different original color profile, but that's not what I need), is this even possible anymore?

PS: I said "I don't care if it is RGB or sRGB or RGB marked as sRGB", what I meant is that I do not care for the sake of the result: as long as it obtain a *RGB that has the same visual appearance of the original image I'm fine with it. I actually care and am interested to know what was/is going on to better understand the issue.

PPS: some context may be in order; I'm a developer and I use ImageMagick in a customization of a third party open source software that, among other features, provide a manner to automatically resize images using ImageMagick. The customer upload Images to the software, gets a bunch of resizes on different sizes which are then shipped to different platforms (web, Android, iOS, ...). Android do not support color profiles in Images and do not support CMYK, which means I have to resize the images and convert them to RGB/sRGB. I do the same for all the platforms involved for consistency and because some color profile may not be supported in iOS or future platform as well while RGB should always be supported. After an operating system software update the customer started to complain images was randomly becoming very darker. The reason is this change in ImageMagick and I need to find a way to make the software work as used to work with the new ImageMagick.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "-colorspace RGB" broken

Post by fmw42 »

IM colorspace was in a state of flux at that time. There is no way to determine if it was even doing colorspace correctly at that time. But assuming it was doing it the old way, then on a current system, the following should be the equivalent

Code: Select all

-quality 90 -intent Perceptual -resize '5120x3200>' -filter Catrom -colorspace sRGB -strip
However, in my opinion, you should be stripping the color profiles and other data right after reading the input and not waiting to the end.

Likewise, you need to set the filter before the resize. The way you have it, it may not being using Catrom at all. But IM 6, may pick it up. But I always put settings before the corresponding operators.
mastro
Posts: 5
Joined: 2014-05-05T08:38:37-07:00
Authentication code: 6789

Re: "-colorspace RGB" broken

Post by mastro »

fmw42 wrote:IM colorspace was in a state of flux at that time. There is no way to determine if it was even doing colorspace correctly at that time. But assuming it was doing it the old way, then on a current system, the following should be the equivalent

Code: Select all

-quality 90 -intent Perceptual -resize '5120x3200>' -filter Catrom -colorspace sRGB -strip
However, in my opinion, you should be stripping the color profiles and other data right after reading the input and not waiting to the end.

Likewise, you need to set the filter before the resize. The way you have it, it may not being using Catrom at all. But IM 6, may pick it up. But I always put settings before the corresponding operators.
Thanks for the suggestion, -strip was actually at the very beginning at first, I moved it at the end as a test.
Catrom has always been there and I remember trying various filter so it should be picked up :) anyway I'll move it before resize...

Anything else about the issue with colorspace?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: "-colorspace RGB" broken

Post by fmw42 »

what is your output format? if not jpg, then -quality 90 may not be an appropriate value. see http://www.imagemagick.org/script/comma ... hp#quality
mastro
Posts: 5
Joined: 2014-05-05T08:38:37-07:00
Authentication code: 6789

Re: "-colorspace RGB" broken

Post by mastro »

fmw42 wrote:what is your output format? if not jpg, then -quality 90 may not be an appropriate value. see http://www.imagemagick.org/script/comma ... hp#quality
I need to output JPEG images with (s)RGB colorspace without custom profiles regardless of the input image format / colorspace/profile
Post Reply