You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary Lucas (Jira)" <ji...@apache.org> on 2020/10/02 10:55:00 UTC

[jira] [Commented] (IMAGING-201) Significant change in color of output image of tiff file

    [ https://issues.apache.org/jira/browse/IMAGING-201?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17206093#comment-17206093 ] 

Gary Lucas commented on IMAGING-201:
------------------------------------

I investigated this issue further and it appears that the CMYK to RGB conversions are implemented correctly in the Commons Imaging library. The conversion code takes a round-about approach, but a little algebra shows that they are equivalent to the well-known formulas.  I did find that the conversion maps CMYK to _linear_ RGB, but that the BufferedImage class used by Java wants sRGB. Adding the linear-to-sRGB conversion to the code addressed the incorrect green tone on the model's jacket, but  results in an overall washed out appearance in the image (the poor guy is so pale that he looks like he has a bad case of the flu).

I believe that the key to correctly rendering this image is to use the ICC Color Profile that is bundled with the image using tag 34675 (0x8773: InterColorProfile). There is some support for this in the Commons Imaging color package, but it is not integrated into the TIFF code.  

I'm afraid that I am not especially familiar with color models and profiles and have taken this issue as far as I can for now. I hope these notes might help somebody else get started on a solution.

 

Here's the code I added to my local version of the CMYK photometric interpreter to perform the CMYK to RGB conversion:

int makeRGB(int[] samples) {
   final double c = samples[0] / 255.0;
    final double m = samples[1] / 255.0;
    final double y = samples[2] / 255.0;
    final double k = samples[3] / 255.0;

   int r = (int) (255 * linearToSRGB((1 - c) * (1 - k)) + 0.5);
    int g = (int) (255 * linearToSRGB((1 - m) * (1 - k)) + 0.5);
    int b = (int) (255 * linearToSRGB((1 - y) * (1 - k)) + 0.5);

   return 0xff000000 | (r << 16) | (g << 8) | b;
 }

double linearToSRGB(double a) {
   if (a <= 0.0031308) {
      return a * 12.92;
   } else {
      return 1.055 * Math.pow(a, 1.0 / 2.4) - 0.055;
   }
 }

 

 

 

> Significant change in color of output image of tiff file
> --------------------------------------------------------
>
>                 Key: IMAGING-201
>                 URL: https://issues.apache.org/jira/browse/IMAGING-201
>             Project: Commons Imaging
>          Issue Type: Bug
>          Components: Format: TIFF
>    Affects Versions: 1.0-alpha1
>            Reporter: Praful Vaishnav
>            Priority: Major
>         Attachments: SS_result.png, SS_source.png
>
>
> Hii.. I am reading tiff image file and using this library to convert it to PNG format. Resultant png file has significant change in color wrt its original tiff file. Below is the code :
> {code:java}
> File file = new File("C:\\original.tiff");
> BufferedImage bi = Imaging.getBufferedImage(file);
> File dstFile = new File("C:\\result.png");
> Imaging.writeImage(bi, dstFile, ImageFormats.PNG, null);
> {code}
> Reason could be :
> original image is 32 bit depth and result image is 24 bit depth. Is there any issue with 32 bit depth image file.
> Link for source tiff file - https://www.dropbox.com/s/kgqgdcygelkor8b/original.tiff?dl=0
> Attachements:
> SS_source.png - Screenshot of original tiff file
> SS_result.png - Screenshot of result png file



--
This message was sent by Atlassian Jira
(v8.3.4#803005)