haraldk / TwelveMonkeys

TwelveMonkeys ImageIO: Additional plug-ins and extensions for Java's ImageIO
https://haraldk.github.io/TwelveMonkeys/
BSD 3-Clause "New" or "Revised" License
1.84k stars 308 forks source link

TIFF PhotometricInterpretation 8 (CIE L*a*b*) #173

Closed cosenary closed 8 years ago

cosenary commented 8 years ago

Hi,

first of all: thanks a lot for your fantastic library!

Sometimes I come across TIFF images, that I try to read with ImageIO.read(file);, but can't because of the following exception: javax.imageio.IIOException: Unknown TIFF PhotometricInterpretation value: 8. Is this a specific issue of image like an invalid structure or not following the specifications (the image can be opened e.g. by IrfanView)? Is there anything I can do in order to read these types of images?

Stacktrace

Caused by: javax.imageio.IIOException: Unknown TIFF PhotometricInterpretation value: 8
    at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader.getRawImageType(Unknown Source)
    at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader.getImageTypes(Unknown Source)
    at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader.read(Unknown Source)
    at javax.imageio.ImageIO.read(ImageIO.java:1448)
    at javax.imageio.ImageIO.read(ImageIO.java:1308)

Thanks, Christian

haraldk commented 8 years ago

Hi Christian,

Thanks for reporting!

You seem to have run into a TIFF using CIELab color space. The exception message is a little incorrect, as it should say Unsupported TIFF PhotometricInterpretation value (the value is well known). Most likely, there's nothing wrong with the TIFF file.

But in any case, it's a TIFF extension that we don't support yet (we don't support any of the Lab* types, ie. PhotometricInterpretation 8, 9 or 10).

If you have a sample image (or a few), please attach it to this issue (rename to foo_tiff.png to get around the GitHub image filter), and I'll see what I can do.

If you want to have a go at this yourself, have a look at the TIFF 6.0 specification "Section 23: CIE Lab* Images".

Best regards,

Harald K

ksclarke commented 8 years ago

I have some of these but don't have permission to post the images publicly (like on this ticket). I can provide a download link in an email for a couple though if you'd like (and if you have the time to look into this). My email is ksclarke@ksclarke.io Thanks (and also thanks for the wonderful library)!

haraldk commented 8 years ago

Thanks!

@ksclarke I sent you a private email.

I have found a single sample TIFF (downloadable from http://www.brucelindbloom.com/index.html?ColorCheckerRGB.html) in CIE Lab. But as mentioned in the email, it's always good to have multiple sample files, to make sure I have everything covered.

Best regards,

Harald K

haraldk commented 8 years ago

Okay,

Just pushed quite a large change including support for CIELab (incl. ICC and ITU variants, as far as I understand the specs, but I haven't actually seen any ICC variant files). Looks okay for all my sample files, including Kevin's samples and some ITU variants I found, even JPEG compressed but not planar versions yet.

Would be great if you could test and provide some feedback on this, to see if it works for you. :-)

A quick note on the implementation: For the CIE Lab* -> sRGB conversion, I used a very fast (but not very accurate) approximation for Math.pow(). This reduced the decoding of Kevin's sample files from > 10 sec to ~ 2.5 sec on my computer. By visual inspection, this looks okay to me, but please let me know what you think.

@ksclarke Thanks for the sample files!

Best regards,

Harald K

haraldk commented 8 years ago

Closing for now, please reopen if you have issues with the current implementation of CIELab color handling.

ksclarke commented 8 years ago

Can confirm this is working for me now. Thanks!