#681: Fix for little-endian "packed" USHORT types + rewritten stream handling

This commit is contained in:
Harald Kuhr
2022-06-03 19:23:50 +02:00
parent 84a8ceeb93
commit bcb87c09d2
3 changed files with 95 additions and 77 deletions
@@ -44,7 +44,7 @@ import javax.imageio.metadata.IIOMetadata;
import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.stream.ImageInputStream;
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.color.*;
import java.awt.image.*;
import java.io.IOException;
import java.nio.ByteOrder;
@@ -56,7 +56,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.AdditionalMatchers.and;
import static org.mockito.Mockito.*;
@@ -892,6 +895,32 @@ public class TIFFImageReaderTest extends ImageReaderAbstractTest<TIFFImageReader
assertSubsampledImageDataEquals("Subsampled image data does not match expected", image, subsampled, param);
}
@Test
public void testReadLittleEndian4444ARGB() throws IOException {
ImageReader reader = createReader();
try (ImageInputStream stream = ImageIO.createImageInputStream(getClassLoaderResource("/tiff/little-endian-rgba-4444.tiff"))) {
reader.setInput(stream);
BufferedImage image = null;
try {
image = reader.read(0);
}
catch (IOException e) {
failBecause("Image could not be read", e);
}
assertNotNull(image);
assertEquals(589, image.getWidth());
assertEquals(340, image.getHeight());
assertRGBEquals("Red", 0xffff1111, image.getRGB(124, 42), 4);
assertRGBEquals("Green", 0xff66ee11, image.getRGB(476, 100), 4);
assertRGBEquals("Yellow", 0xffffff00, image.getRGB(312, 186), 4);
assertRGBEquals("Blue", 0xff1155dd, image.getRGB(366, 192), 4);
}
}
@Test
public void testReadUnsupported() throws IOException {
ImageReader reader = createReader();