Better testing of source region reading. A few readers are failing for now, added @Ignore.

This commit is contained in:
Harald Kuhr 2014-09-26 15:59:19 +02:00
parent afff6f78a8
commit 8c93be05a5
5 changed files with 73 additions and 2 deletions

View File

@ -29,10 +29,13 @@
package com.twelvemonkeys.imageio.plugins.svg;
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
import org.junit.Ignore;
import org.junit.Test;
import javax.imageio.spi.ImageReaderSpi;
import java.awt.*;
import java.awt.image.ImagingOpException;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@ -77,6 +80,7 @@ public class SVGImageReaderTestCase extends ImageReaderAbstractTestCase<SVGImage
return Arrays.asList("image/svg+xml");
}
@Test
@Override
public void testReadWithSizeParam() {
try {
@ -99,4 +103,11 @@ public class SVGImageReaderTestCase extends ImageReaderAbstractTestCase<SVGImage
}
}
}
@Test
@Ignore("Known issue: Source region reading not supported")
@Override
public void testReadWithSourceRegionParamEqualImage() throws IOException {
super.testReadWithSourceRegionParamEqualImage();
}
}

View File

@ -29,9 +29,12 @@
package com.twelvemonkeys.imageio.plugins.wmf;
import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
import org.junit.Ignore;
import org.junit.Test;
import javax.imageio.spi.ImageReaderSpi;
import java.awt.*;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@ -76,4 +79,11 @@ public class WMFImageReaderTestCase extends ImageReaderAbstractTestCase<WMFImage
protected List<String> getMIMETypes() {
return Arrays.asList("image/x-wmf", "application/x-msmetafile");
}
@Test
@Ignore("Known issue: Source region reading not supported")
@Override
public void testReadWithSourceRegionParamEqualImage() throws IOException {
super.testReadWithSourceRegionParamEqualImage();
}
}

View File

@ -548,6 +548,44 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> {
assertEquals("Read image has wrong height: " + image.getHeight(), 10, image.getHeight());
}
@Test
public void testReadWithSourceRegionParamEqualImage() throws IOException {
// Default invocation
assertReadWithSourceRegionParamEqualImage(new Rectangle(3, 3, 9, 9), getTestData().get(0), 0);
}
protected void assertReadWithSourceRegionParamEqualImage(final Rectangle r, final TestData data, final int imageIndex) throws IOException {
ImageReader reader = createReader();
reader.setInput(data.getInputStream());
ImageReadParam param = reader.getDefaultReadParam();
// Read full image and get sub image for comparison
final BufferedImage roi = reader.read(imageIndex, param).getSubimage(r.x, r.y, r.width, r.height);
param.setSourceRegion(r);
final BufferedImage image = reader.read(imageIndex, param);
// try {
// SwingUtilities.invokeAndWait(new Runnable() {
// public void run() {
// JPanel panel = new JPanel(new FlowLayout());
// panel.add(new JLabel(new BufferedImageIcon(roi, r.width * 10, r.height * 10, true)));
// panel.add(new JLabel(new BufferedImageIcon(image, r.width * 10, r.height * 10, true)));
// JOptionPane.showConfirmDialog(null, panel);
// }
// });
// }
// catch (Exception e) {
// throw new RuntimeException(e);
// }
assertNotNull("Image was null!", image);
assertEquals("Read image has wrong width: " + image.getWidth(), r.width, image.getWidth());
assertEquals("Read image has wrong height: " + image.getHeight(), r.height, image.getHeight());
assertImageDataEquals("Images differ", roi, image);
}
@Test
public void testReadWithSizeAndSourceRegionParam() {
// TODO: Is this test correct???

View File

@ -138,4 +138,11 @@ public class ICNSImageReaderTest extends ImageReaderAbstractTestCase {
public void testReadWithSubsampleParamPixels() throws IOException {
super.testReadWithSubsampleParamPixels();
}
@Test
@Ignore("Known issue: Source region reading not supported")
@Override
public void testReadWithSourceRegionParamEqualImage() throws IOException {
super.testReadWithSourceRegionParamEqualImage();
}
}

View File

@ -2623,8 +2623,13 @@ public class PICTImageReader extends ImageReaderBase {
Graphics2D g = image.createGraphics();
try {
// TODO: Might need to clear background
g.setTransform(AffineTransform.getScaleInstance(screenImageXRatio / subX, screenImageYRatio / subY));
AffineTransform instance = new AffineTransform();
if (pParam != null && pParam.getSourceRegion() != null) {
Rectangle rectangle = pParam.getSourceRegion();
instance.translate(-rectangle.x, -rectangle.y);
}
instance.scale(screenImageXRatio / subX, screenImageYRatio / subY);
g.setTransform(instance);
// try {
drawOnto(g);
// }