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

Tif image throws "Destination type from ImageReadParam does not match legal imageTypes from reader: javax.imageio.ImageTypeSpecifier" #651

Closed
KoenDG opened this issue Dec 23, 2021 · 4 comments

Comments

@KoenDG
Copy link
Contributor

KoenDG commented Dec 23, 2021

I'm not sure if this is because of a bug, or if the image just actually isn't "a correct tif file" so to speak.

I've created a branch to test this, against the 3.8.0 release commit.

I've also tested it against the current latest commit, the behavior is identical.

Describe the bug
A Tiff image seemingly cannot be parsed

Version information

  1. The version of the TwelveMonkeys ImageIO library in use.

3.8.0

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

For example:

$ java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment Corretto-8.222.10.1 (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM Corretto-8.222.10.1 (build 25.222-b10, 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.

To Reproduce

Expected behavior
A branch has been created, running the unit tests displays the behavior.

Example code
I created a branch here and simply added a file to the test: https://github.com/KoenDG/TwelveMonkeys/blob/3c3c76b428924f0db6795b6eb8cb7ccb5b7576f0/imageio/imageio-tiff/src/test/java/com/twelvemonkeys/imageio/plugins/tiff/TIFFImageReaderTest.java

Sample file(s)
Added here on the local branch: https://github.com/KoenDG/TwelveMonkeys/blob/3c3c76b428924f0db6795b6eb8cb7ccb5b7576f0/imageio/imageio-tiff/src/test/resources/new/27d40bc5f25d8382b890766accb28cf7.tif

Stak trace
The error one gets when running mvn clean package

[ERROR] Tests run: 107, Failures: 2, Errors: 1, Skipped: 2, Time elapsed: 4.062 s <<< FAILURE! - in com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReaderTest
[ERROR] com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReaderTest.testGetTypeSpecifiers  Time elapsed: 0.004 s  <<< FAILURE!
java.lang.AssertionError: ImageTypeSpecifier from getRawImageType should be in the iterator from getImageTypes

[ERROR] com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReaderTest.testNotBadCaching  Time elapsed: 0.15 s  <<< ERROR!
java.lang.ArrayIndexOutOfBoundsException: 4

[ERROR] com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReaderTest.testSetDestinationType  Time elapsed: 0.002 s  <<< FAILURE!
java.lang.AssertionError: Could not read file:TwelveMonkeys/imageio/imageio-tiff/target/test-classes/new/27d40bc5f25d8382b890766accb28cf7.tif with explicit destination type javax.imageio.ImageTypeSpecifier@460e5a6f
Caused by: javax.imageio.IIOException: Destination type from ImageReadParam does not match legal imageTypes from reader: javax.imageio.ImageTypeSpecifier@460e5a6f
@haraldk
Copy link
Owner

haraldk commented Dec 23, 2021

Thanks! Will look into it.

@haraldk
Copy link
Owner

haraldk commented Dec 24, 2021

Okay,

My finding so far is that this TIFF file uses CMYK + 1 extra sample.

The ExtraSamples tag contains the value 999, which is not as specified by the TIFF standard... Legal values are 0 (unspecified), 1 (associated/aka premultiplied), and 2 (unassociated).

However, I think the reader should just treat this value as 0. But there's no standard way in Java2D to express this kind of pixel layout, so I had to create my own ExtraSamplesColorModel for this situation. Unfortunately, it seems that there is a problem using setRGB with this color model, and causing an ArrayIndexOutOfBoundsException (from the caching test).

Not sure about the other two test fails yet, but I think they are related.

PS: The image is also displayed weird in MacOS Preview, where the extra channel is treated as alpha (but the alpha channel isn't aligned with the color data).

haraldk added a commit that referenced this issue Dec 24, 2021
haraldk added a commit that referenced this issue Dec 24, 2021
haraldk added a commit that referenced this issue Dec 24, 2021
…ith ImageTypeSpecifier comparison.

(cherry picked from commit 98e4b76)
@haraldk
Copy link
Owner

haraldk commented Dec 24, 2021

Pushed some fixes now! Just in time to prepare the turkey.. 😉

I didn't add your sample file to the tests as it's quite large, and I could verify I fixed the problems in the ExtraSamplesColorModel unit test, but I verified that your test would also pass with the current code locally.

Merry Christmas! 🎄

@KoenDG
Copy link
Contributor Author

KoenDG commented Dec 25, 2021

Merry Christmas to you too.

@haraldk haraldk closed this as completed Dec 27, 2021
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