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.83k stars 309 forks source link

Unsupported BitsPerSample for SampleFormat 3/Floating Point (expected 16/32): 64 #948

Closed sroettering closed 1 month ago

sroettering commented 1 month ago

Describe the bug When reading the attached tiff file I get the error already stated in the issue title. Here is the complete stacktrace:

javax.imageio.IIOException: Unsupported BitsPerSample for SampleFormat 3/Floating Point (expected 16/32): 64
    at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader.getDataType(TIFFImageReader.java:819)
    at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader.getRawImageType(TIFFImageReader.java:459)
    at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader.getImageTypes(TIFFImageReader.java:909)
    at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:938)
    at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1466)
    at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1363)
    at com.x.x.x.x.png.PngRendererAccessor.renderGrayScaleGeoTiff(PngRendererAccessor.java:71)

Image is in this zip file since Github says it does not support tiff. analysisTiff.tif.zip

Version information

  1. The version of the TwelveMonkeys ImageIO library in use.
    dependencies {
    implementation 'com.twelvemonkeys.imageio:imageio-jpeg:3.10.1'
    implementation 'com.twelvemonkeys.imageio:imageio-tiff:3.10.1'
    implementation 'com.twelvemonkeys.contrib:contrib:3.10.0'
    }

To Reproduce Steps to reproduce the behavior:

The following code already throws the error:

ImageIO.read(tiffInputStream)

Expected behavior The attached file can be read without problems.

I just added the twelvemonkeys tiff plugin today and one of our tests broke because the tiff could not be read anymore. Without the plugin ImageIO was able to read it. However, I need the plugin for another usecase to work correctly.

Bit of context that may be useful: In the agricultural sector (geo)tiffs are often used to transport/encode information that might not always be used to be viewed directly but analyzed or transformed further. As is in this case I need to create a grayscale image from the input tiff.

haraldk commented 1 month ago

Hi @sroettering

Sorry about the delayed response, I've been busy celebrating national holidays and enjoying spring time away from the IDE... 😉

Thanks for reporting! I'm not sure if Java 2D has a good way of storing 64 bit FP (Java: double) samples... But if the JDK TIFF plugin supports that, there must be a way. 😀

I'll look into it!

haraldk commented 1 month ago

I think I figured it out, just needed a few extra methods, but the main code seems to work fine for 64 bit FP.

However, the resulting image doesn't look exactly like the one from the JDK TIFF plugin... Unfortunately, I have no other tools that can process/display this image and no knowledge of what it's supposed to resemble. But at least it can be read:

JDK TIFF plugin: image

TwelveMonkeys TIFF plugin: image

sroettering commented 1 month ago

Wow great to hear! I will give it a try when I find the time, thanks.

haraldk commented 1 month ago

Fixed in 3e7ad05