mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-04-30 00:00:01 -04:00
#323 JPEGSegmentImageInputStream now rewrites duplicate SOF/SOS ids.
And emits warnings when it applies rewrites.
This commit is contained in:
+35
@@ -62,6 +62,7 @@ import static com.twelvemonkeys.imageio.util.IIOUtil.lookupProviderByName;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.assumeNoException;
|
||||
import static org.junit.Assume.assumeNotNull;
|
||||
import static org.mockito.AdditionalMatchers.and;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
@@ -1608,10 +1609,16 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
try {
|
||||
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/exif-jfif-app13-app14ycck-3channel.jpg")));
|
||||
|
||||
IIOReadWarningListener listener = mock(IIOReadWarningListener.class);
|
||||
reader.addIIOReadWarningListener(listener);
|
||||
|
||||
assertEquals(310, reader.getWidth(0));
|
||||
assertEquals(384, reader.getHeight(0));
|
||||
|
||||
BufferedImage image = reader.read(0, null);
|
||||
|
||||
verify(listener, times(1)).warningOccurred(eq(reader), matches("(?i).*Adobe App14.*(?-i)CMYK.*SOF.*"));
|
||||
|
||||
assertNotNull(image);
|
||||
assertEquals(310, image.getWidth());
|
||||
assertEquals(384, image.getHeight());
|
||||
@@ -1621,4 +1628,32 @@ public class JPEGImageReaderTest extends ImageReaderAbstractTest<JPEGImageReader
|
||||
reader.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadDuplicateComponentIds() throws IOException {
|
||||
JPEGImageReader reader = createReader();
|
||||
|
||||
try {
|
||||
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/duplicate-component-ids.jpg")));
|
||||
|
||||
IIOReadWarningListener listener = mock(IIOReadWarningListener.class);
|
||||
reader.addIIOReadWarningListener(listener);
|
||||
|
||||
assertEquals(367, reader.getWidth(0));
|
||||
assertEquals(242, reader.getHeight(0));
|
||||
|
||||
BufferedImage image = reader.read(0, null);
|
||||
|
||||
verify(listener, times(1)).warningOccurred(eq(reader), and(matches("(?i).*duplicate component id.*(?-i)SOF.*"), contains("1")));
|
||||
verify(listener, times(1)).warningOccurred(eq(reader), and(matches("(?i).*duplicate component selector.*(?-i)SOS.*"), contains("1")));
|
||||
|
||||
assertNotNull(image);
|
||||
assertEquals(367, image.getWidth());
|
||||
assertEquals(242, image.getHeight());
|
||||
assertEquals(ColorSpace.TYPE_RGB, image.getColorModel().getColorSpace().getType());
|
||||
}
|
||||
finally {
|
||||
reader.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -59,7 +59,7 @@ public class JPEGSegmentImageInputStreamTest {
|
||||
ImageIO.setUseCache(false);
|
||||
}
|
||||
|
||||
protected URL getClassLoaderResource(final String pName) {
|
||||
private URL getClassLoaderResource(final String pName) {
|
||||
return getClass().getResource(pName);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class JPEGSegmentImageInputStreamTest {
|
||||
length++;
|
||||
}
|
||||
|
||||
assertThat(length, new LessOrEqual<Long>(10203l)); // In no case should length increase
|
||||
assertThat(length, new LessOrEqual<>(10203L)); // In no case should length increase
|
||||
|
||||
assertEquals(9607L, length); // May change, if more chunks are passed to reader...
|
||||
}
|
||||
@@ -149,7 +149,7 @@ public class JPEGSegmentImageInputStreamTest {
|
||||
length++;
|
||||
}
|
||||
|
||||
assertEquals(9281L, length); // Sanity check: same as file size
|
||||
assertEquals(9281L, length); // Sanity check: same as file size, except..?
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,7 +162,7 @@ public class JPEGSegmentImageInputStreamTest {
|
||||
assertEquals(JPEG.APP1, appSegments.get(0).marker());
|
||||
assertEquals("Exif", appSegments.get(0).identifier());
|
||||
|
||||
stream.seek(0l);
|
||||
stream.seek(0L);
|
||||
|
||||
long length = 0;
|
||||
while (stream.read() != -1) {
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
Reference in New Issue
Block a user