TwelveMonkeys
TwelveMonkeys copied to clipboard
ResampleOp: incorrect colors in scaled images
I am trying to scale TIFF images (CMYK, assigned ICC profile SO Coated v2 300% (ECI)).
BufferedImage scaledImage = new ResampleOp(newWidth, newHeight, ResampleOp.FILTER_TRIANGLE).filter(image, null);
This works fine for most of the images. The scaled images affected by the error either look black and white or contain additional pink color components. These images can be scaled without errors - although very slowly - e.g. with Scalr. Attached is a problematic picture: 6102131.zip
I have come a little closer to the cause of the error: For all images that are scaled incorrectly, the following exception is thrown when writing without scaling
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 2626872 out of bounds for length 2626870
at java.desktop/java.awt.image.DataBufferByte.getElem(DataBufferByte.java:256)
at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageWriter.writeImageData(TIFFImageWriter.java:566)
at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageWriter.writePage(TIFFImageWriter.java:253)
at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageWriter.writeToSequence(TIFFImageWriter.java:954)
at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageWriter.write(TIFFImageWriter.java:138)
at de.werkzeugeylert.imagedb.PerformanceTest.main(PerformanceTest.java:99)
There seems to be a problem in determining the buffer sizes.
The line 99 in the code is:
writer.write(null, iioImage, param);
TwelveMonkeys version is 3.5
Hi Holger,
Thanks for reporting & digging further! Much appreciated.
I will try to look into the issue as soon as possible, but anything you can do to isolate the problem/reproduce with a test case will help a lot.
The exception from TIFFImageWriter:566
could possibly indicate that there's a difference between the row length in the data buffer, and the width of the image tile (or how we compute these values). But I'll know more when I have looked at your sample image.
Best regards,
-- Harald K
Hi again Holger,
Thank you for your patience. 😉
Sorry about the delay, but I finally found some time to look into this. Your file is a planar (as opposed to interleaved) CMYK TIFF. This is quite uncommon, but completely valid.
For the ResampleOp, this is probably just too much to handle, but can be worked around by converting to normal interleaved RGB before scaling (this will also fix the writing).
I think the behavior in the TIFFImageWriter
is a bug, but I need to look more into what is the problem here.
-- Harald K