ghosta3 / thumbnailator

Automatically exported from code.google.com/p/thumbnailator
Other
0 stars 0 forks source link

Exception reading a CMYK Jpeg #40

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Generate a CMYK JPG, call it selectedFile
1. Run Thumbnails.of(selectedFile).size(500, 500).toFile(thumb500File);

What is the expected output? What do you see instead?

Expected output - thumb500File created normally

Actual output: Exception raised "Incompatible color conversion"

What version of the product are you using? On what operating system? Which
version of Java (Sun/Oracle? OpenJDK?) ?

OpenJDK 7u9, Ubuntu Linux

Please provide any additional information below.

The core Java method ImageIO.read produces exactly the same exception, e.g.

BufferedImage originalImage = ImageIO.read(selectedFile);

so it looks like the issue is with Java, however other people have found 
workarounds - 
http://www.randelshofer.ch/blog/2011/08/reading-cmyk-jpeg-images-with-java-image
io/

Would it be possible to implement a workaround in Thumbnailator too? I think 
the Java issue dates back some time.

A sample JPG exhibiting the problem is attached.

Original issue reported on code.google.com by oliver.k...@gmail.com on 1 Nov 2012 at 12:59

Attachments:

GoogleCodeExporter commented 9 years ago
Thank you for reporting this issue along with a supplemental link.

I have been able to reproduce this issue with Thumbnailator 0.4.2, and it does 
indeed appear to be a problem with the JPEG reader that is being used by Image 
I/O.

I will look into the link in a little more detail at a later time, but I would 
like to see if there are other ways of implementing a workaround rather than 
having to write an alternate JPEG reader to the one that is provided with Java.

(Image I/O does indeed have many outstanding bugs which have not been addressed 
for close to a decade...)

Once again, thank you for the detailed report.

------------------

The following is the stack trace on Ubuntu 12.04 with Oracle JDK 1.7.0_04:

  Exception in thread "main" javax.imageio.IIOException: Unsupported Image Type
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:995)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:966)
    at javax.imageio.ImageReader.read(ImageReader.java:940)
    at net.coobird.thumbnailator.tasks.io.FileImageSource.read(FileImageSource.java:144)
    at net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask.read(SourceSinkThumbnailTask.java:76)
    at net.coobird.thumbnailator.Thumbnailator.createThumbnail(Thumbnailator.java:62)
    at net.coobird.thumbnailator.Thumbnails$Builder.toFile(Thumbnails.java:2409)
    at Issue40.main(Issue40.java:15)

The following is the stacktrace on Ubuntu 12.04 and OpenJDK 1.6.0_24:

  Exception in thread "main" javax.imageio.IIOException: Incompatible color conversion
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.checkColorConversion(JPEGImageReader.java:927)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1028)
    at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:984)
    at javax.imageio.ImageReader.read(ImageReader.java:940)
    at net.coobird.thumbnailator.tasks.io.FileImageSource.read(FileImageSource.java:144)
    at net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask.read(SourceSinkThumbnailTask.java:76)
    at net.coobird.thumbnailator.Thumbnailator.createThumbnail(Thumbnailator.java:62)
    at net.coobird.thumbnailator.Thumbnails$Builder.toFile(Thumbnails.java:2409)
    at Issue40.main(Issue40.java:15)

Original comment by coobird...@gmail.com on 11 Nov 2012 at 12:17

GoogleCodeExporter commented 9 years ago
Yes I guess the ideal would be to submit a patch to the JDK:

http://openjdk.java.net/contribute/

for bug

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5100094

Unfortunately I myself haven't the time to work towards that at the moment.

Original comment by oliver.k...@gmail.com on 11 Nov 2012 at 2:18

GoogleCodeExporter commented 9 years ago
Adding a link to a question on StackOverflow regarding reading CMYK JPEG images 
using Java Image I/O:

http://stackoverflow.com/questions/2408613/problem-reading-jpeg-image-using-imag
eio-readfile-file

Original comment by coobird...@gmail.com on 16 Jul 2013 at 3:38

GoogleCodeExporter commented 9 years ago
FYI: You can workaround this issue by using JPEGImageReader from 

https://github.com/haraldk/TwelveMonkeys

Original comment by marcus.l...@googlemail.com on 24 Oct 2013 at 8:27

GoogleCodeExporter commented 9 years ago
Note
------
Use of "TwelveMonkeys ImageIO" fixes this particular issue.
https://github.com/haraldk/TwelveMonkeys

(Thank you for the tip, marcus!)

Original comment by coobird...@gmail.com on 21 Sep 2014 at 10:41