Menu

#768 CMYK JPEG written out as RGB

v1.0_(example)
open
nobody
None
5
1 day ago
1 day ago
No

In the release notes from October, you have:

  • coders/jpeg.c (WriteJPEGImage): Enforce that JPEG is written as RGB unless a different colorspace was specified.

In our case, we load a RGB JPEG file. Then we assign the ICC Colorprofile with CMYK and the image is converted. Then when we write new JPEG file, we have a RGB JPEG file with CMYK profile.

We see in the debug messages:

12:15:28 0:0.341048  0.340u 5499 jpeg.c/WriteJPEGImage/2836/Coder:   Write JPEG Image: image->orientation = 0
12:15:28 0:0.341051  0.340u 5499 jpeg.c/WriteJPEGImage/2867/Coder:   Transforming colorspace from CMYK to RGB
12:15:28 0:0.341053  0.340u 5499 colorspace.c/TransformRGBImage/1450/Transform: Transform colorspace from CMYK to RGB

In noticed that image->colorspace() is CMYK with value 10, but imageinfo->colorspace is still zero for UndefinedColorspace. Seems like RGBTransformImage doesn't update the imageinfo->colorspace.

So this code in the jpeg writer causes conversion to RGB:

  if (((UndefinedColorspace == image_info->colorspace) &&
       (!IsRGBCompatibleColorspace(image->colorspace))) ||
      ((IsRGBCompatibleColorspace(image->colorspace) &&
        !IsRGBColorspace(image->colorspace))))
    {
      if (image->logging)
        (void) LogMagickEvent(CoderEvent,GetMagickModule(),
                              "  Transforming colorspace from %s to RGB",
                              ColorspaceTypeToString(image->colorspace));
      (void) TransformColorspace(image,RGBColorspace);
    }

This may need some update to let both grayscale and CMYK images pass through.

I fix it now by manually setting image_info->colorspace to image->colorspace before saving.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB