Permalink
Browse files

TMI-39: Cleanup after merge.

  • Loading branch information...
1 parent d607450 commit e3bab84e82a2eb09a1f12c94a3088c0aaee84074 @haraldk haraldk committed Mar 2, 2014
@@ -438,20 +438,21 @@ else if (profile != null) {
// Unfortunately looping is slower than reading all at once, but
// that requires 2 x memory or more, so a few steps is an ok compromise I guess
try {
- final int step = Math.max(1024, srcRegion.height / 10); // * param.getSourceYSubsampling(); // TODO: Using a multiple of 8 is probably a good idea for JPEG
+ final int step = Math.max(1024, srcRegion.height / 10); // TODO: Using a multiple of 8 is probably a good idea for JPEG
final int srcMaxY = srcRegion.y + srcRegion.height;
int destY = dstRegion.y;
for (int y = srcRegion.y; y < srcMaxY; y += step) {
int scan = Math.min(step, srcMaxY - y);
- if(scan <= param.getSubsamplingYOffset()) {
- param.setSourceSubsampling(param.getSourceXSubsampling(),param.getSourceYSubsampling(),param.getSubsamplingXOffset(),0);
- }
-
// Let the progress delegator handle progress, using corrected range
progressDelegator.updateProgressRange(100f * (y + scan) / srcRegion.height);
+ // Make sure subsampling is within bounds
+ if (scan <= param.getSubsamplingYOffset()) {
+ param.setSourceSubsampling(param.getSourceXSubsampling(), param.getSourceYSubsampling(), param.getSubsamplingXOffset(), scan - 1);
+ }
+
Rectangle subRegion = new Rectangle(srcRegion.x, y, srcRegion.width, scan);
param.setSourceRegion(subRegion);
Raster raster = delegate.readRaster(imageIndex, param); // non-converted
@@ -30,6 +30,7 @@
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
import org.hamcrest.core.IsInstanceOf;
+import org.junit.Ignore;
import org.junit.Test;
import org.mockito.internal.matchers.GreaterThan;
import org.w3c.dom.Element;
@@ -685,6 +686,122 @@ public void testReadNoJFIFYCbCr() throws IOException {
}
}
+ // Regression: Test subsampling offset within of bounds
+ // NOTE: These tests assumes the reader will read at least 1024 scanlines (if available) each iteration,
+ // this might change in the future. If so, the tests will no longer test what tey are supposed to....
+ @Test
+ public void testReadSubsamplingBounds1028() throws IOException {
+ JPEGImageReader reader = createReader();
+ reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/read-error1028.jpg")));
+
+ ImageReadParam param = reader.getDefaultReadParam();
+ param.setSourceSubsampling(3, 3, 1, 1);
+
+ BufferedImage image = reader.read(0, param);
+
+ assertNotNull(image);
+ }
+
+ @Ignore
+ @Test
+ public void testReadSubsamplingNotSkippingLines1028() throws IOException {
+ JPEGImageReader reader = createReader();
+ reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/read-error1028.jpg")));
+
+ ImageReadParam param = reader.getDefaultReadParam();
+ param.setSourceSubsampling(3, 3, 1, 1);
+
+ BufferedImage image = reader.read(0, param);
+
+ assertNotNull(image);
+
+ // Make sure correct color is actually read, not just left empty
+ assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 2) & 0xffffff);
+ assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 1) & 0xffffff);
+ }
+
+ @Test
+ public void testReadSubsamplingBounds1027() throws IOException {
+ JPEGImageReader reader = createReader();
+ reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/read-error1027.jpg")));
+
+ ImageReadParam param = reader.getDefaultReadParam();
+ param.setSourceSubsampling(3, 3, 2, 2);
+
+ BufferedImage image = reader.read(0, param);
+
+ assertNotNull(image);
+
+ // Make sure correct color is actually read, not just left empty
+ assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 2) & 0xffffff);
+ assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 1) & 0xffffff);
+ }
+
+ @Test
+ public void testReadSubsamplingBounds1026() throws IOException {
+ JPEGImageReader reader = createReader();
+ reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/read-error1026.jpg")));
+
+ ImageReadParam param = reader.getDefaultReadParam();
+ param.setSourceSubsampling(3, 3, 1, 1);
+
+ BufferedImage image = reader.read(0, param);
+
+ assertNotNull(image);
+
+ // Make sure correct color is actually read, not just left empty
+ assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 2) & 0xffffff);
+ assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 1) & 0xffffff);
+ }
+
+ @Test
+ public void testReadSubsamplingBounds1025() throws IOException {
+ JPEGImageReader reader = createReader();
+ reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/read-error1025.jpg")));
+
+ ImageReadParam param = reader.getDefaultReadParam();
+ param.setSourceSubsampling(3, 3, 1, 1);
+
+ BufferedImage image = reader.read(0, param);
+
+ assertNotNull(image);
+ }
+
+ @Ignore
+ @Test
+ public void testReadSubsamplingNotSkippingLines1025() throws IOException {
+ JPEGImageReader reader = createReader();
+ reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/read-error1025.jpg")));
+
+ ImageReadParam param = reader.getDefaultReadParam();
+ param.setSourceSubsampling(3, 3, 1, 1);
+
+ BufferedImage image = reader.read(0, param);
+
+ assertNotNull(image);
+
+ // Make sure correct color is actually read, not just left empty
+ assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 2) & 0xffffff);
+ assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 1) & 0xffffff);
+ }
+
+ @Test
+ public void testReadSubsamplingBounds1024() throws IOException {
+ JPEGImageReader reader = createReader();
+ reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/read-error1024.jpg")));
+
+ ImageReadParam param = reader.getDefaultReadParam();
+ param.setSourceSubsampling(3, 3, 1, 1);
+
+ BufferedImage image = reader.read(0, param);
+
+ assertNotNull(image);
+
+ // Make sure correct color is actually read, not just left empty
+ assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 2) & 0xffffff);
+ assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 1) & 0xffffff);
+ }
+
@Test
public void testXDensityOutOfRangeIssue() throws IOException {
// Image has JFIF with x/y density 0
@@ -988,54 +1105,4 @@ public int compare(IIOMetadataNode left, IIOMetadataNode right) {
return sortedNodes;
}
- @Test
- public void testReadImage1028() throws IOException {
- JPEGImageReader reader = createReader();
- reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/read-error1028.jpg")));
-
- ImageReadParam param = reader.getDefaultReadParam();
- param.setSourceSubsampling(3, 3, 1, 1);
- BufferedImage image = reader.read(0, param);
- assertNotNull(image);
- }
- @Test
- public void testReadImage1027() throws IOException {
- JPEGImageReader reader = createReader();
- reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/read-error1027.jpg")));
-
- ImageReadParam param = reader.getDefaultReadParam();
- param.setSourceSubsampling(3, 3, 2, 2);
- BufferedImage image = reader.read(0, param);
- assertNotNull(image);
- }
- @Test
- public void testReadImage1026() throws IOException {
- JPEGImageReader reader = createReader();
- reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/read-error1026.jpg")));
-
- ImageReadParam param = reader.getDefaultReadParam();
- param.setSourceSubsampling(3, 3, 1, 1);
- BufferedImage image = reader.read(0, param);
- assertNotNull(image);
- }
- @Test
- public void testReadImage1025() throws IOException {
- JPEGImageReader reader = createReader();
- reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/read-error1025.jpg")));
-
- ImageReadParam param = reader.getDefaultReadParam();
- param.setSourceSubsampling(3, 3, 1, 1);
- BufferedImage image = reader.read(0, param);
- assertNotNull(image);
- }
- @Test
- public void testReadImage1024() throws IOException {
- JPEGImageReader reader = createReader();
- reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/read-error1024.jpg")));
-
- ImageReadParam param = reader.getDefaultReadParam();
- param.setSourceSubsampling(3, 3, 1, 1);
- BufferedImage image = reader.read(0, param);
- assertNotNull(image);
- }
}

0 comments on commit e3bab84

Please sign in to comment.