Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong colors with CMYK JPEG #837

Closed
THausherr opened this issue Oct 16, 2023 · 1 comment
Closed

Wrong colors with CMYK JPEG #837

THausherr opened this issue Oct 16, 2023 · 1 comment

Comments

@THausherr
Copy link

Describe the bug
CMYK JPEG image shows wrong colors (black is ok)

Version information

  1. The version of the TwelveMonkeys ImageIO library in use.
    For example: 3.9.4

  2. The exact output of java --version (or java -version for older Java releases).

java version "11.0.20" 2023-07-18 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.20+9-LTS-256)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.20+9-LTS-256, mixed mode)

  1. Extra information about OS version, server version, standalone program or web application packaging, executable wrapper, etc. Please state exact version numbers where applicable.

Windows Version 10.0.19045.3570

To Reproduce
Steps to reproduce the behavior:

  1. Compile the below sample code
  2. Download the sample image file

xx

  1. Run the code with the sample file
  2. See error

xx-saved

output:

BufferedImage@12d4bf7e: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace@70be0a2b transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 2551 height = 3697 #numDataElements 3 dataOff[0] = 2
true

Expected behavior

That the saved file would look mostly the same

Example code

        BufferedImage bim = ImageIO.read(new File("xx.jpg"));
        System.out.println(bim);
        boolean b = ImageIO.write(bim, "png", new File("xx-saved.png"));
        System.out.println(b);

Additional context

It happens in PDFBox, so I assume the problem isn't when saving the file.
Etienne-Gautier/pdfbox#1

files as zip:
xx.zip

@haraldk
Copy link
Owner

haraldk commented Oct 16, 2023

Thanks for the sample file!

I'm trying to understand what's going on here, the file has an Adobe marker with YCCK transform, yet it seems it's encoded as plain CMYK... No, wait, the file has TWO Adobe markers. 😮😕🤬

The first has YCCK transform, the second has "unknown" transform (assumed to be CMYK).

I'm not sure if this is intentional by the software that wrote it, but it's really not good for anything but confusing reader software... 😛 I can change the TwelveMonkeys code to use the last occurrence of an Adobe marker instead of the first. Which in 99.99% of the time would be the same (the only one). This is likely what other software does, as it displays the image as intended. But it seems more like an arbitrary decision/coincidence than the "correct" thing to do...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants