mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-03 03:25:28 -04:00
Added test for PICTImageReader to makes sure JPEGs or other images with PICT magic are recognized.
Better Exception handling.
This commit is contained in:
parent
a493cebe13
commit
79ca02c8b0
2
twelvemonkeys-imageio/core/src/test/java/com/twelvemonkeys/imageio/util/ImageReaderAbstractTestCase.java
Executable file → Normal file
2
twelvemonkeys-imageio/core/src/test/java/com/twelvemonkeys/imageio/util/ImageReaderAbstractTestCase.java
Executable file → Normal file
@ -204,7 +204,7 @@ public abstract class ImageReaderAbstractTestCase<T extends ImageReader> extends
|
||||
reader.setInput(null);
|
||||
}
|
||||
|
||||
public void testRead() throws IOException {
|
||||
public void testRead() {
|
||||
ImageReader reader = createReader();
|
||||
for (TestData data : getTestData()) {
|
||||
// TODO: Is it required to call reset before setInput?
|
||||
|
26
twelvemonkeys-imageio/pict/src/main/java/com/twelvemonkeys/imageio/plugins/pict/PICTImageReader.java
Executable file → Normal file
26
twelvemonkeys-imageio/pict/src/main/java/com/twelvemonkeys/imageio/plugins/pict/PICTImageReader.java
Executable file → Normal file
@ -191,7 +191,7 @@ public class PICTImageReader extends ImageReaderBase {
|
||||
|
||||
// Get frame at 72 dpi
|
||||
// NOTE: These are not pixel sizes!
|
||||
// Need sto be multiplied with hRes/screenResolution and vRes/screenResolution
|
||||
// Need to be multiplied with hRes/screenResolution and vRes/screenResolution
|
||||
int y = pStream.readUnsignedShort();
|
||||
int x = pStream.readUnsignedShort();
|
||||
int h = pStream.readUnsignedShort();
|
||||
@ -1664,10 +1664,18 @@ public class PICTImageReader extends ImageReaderBase {
|
||||
throw e;
|
||||
}
|
||||
catch (EOFException e) {
|
||||
throw new IIOException("Error in PICT format: Unexpected end of File", e);
|
||||
String pos;
|
||||
try {
|
||||
pos = String.format("position %d", mImageInput.getStreamPosition());
|
||||
}
|
||||
catch (IOException ignore) {
|
||||
pos = "unknown position";
|
||||
}
|
||||
|
||||
throw new IIOException(String.format("Error in PICT format: Unexpected end of File at %s", pos), e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IIOException("Error in PICT format: " + e.getMessage(), e);
|
||||
throw new IIOException(String.format("Error in PICT format: %s", e.getMessage()), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2528,7 +2536,7 @@ public class PICTImageReader extends ImageReaderBase {
|
||||
/*
|
||||
* Read a long comment from the stream.
|
||||
*/
|
||||
private void readLongComment(DataInput pStream) throws IOException {
|
||||
private void readLongComment(final DataInput pStream) throws IOException {
|
||||
// Comment kind and data byte count
|
||||
pStream.readShort();
|
||||
|
||||
@ -2604,12 +2612,12 @@ public class PICTImageReader extends ImageReaderBase {
|
||||
// TODO: Might need to clear background
|
||||
|
||||
g.setTransform(AffineTransform.getScaleInstance(mScreenImageXRatio, mScreenImageYRatio));
|
||||
try {
|
||||
// try {
|
||||
drawOnto(g);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// }
|
||||
// catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
finally {
|
||||
g.dispose();
|
||||
|
12
twelvemonkeys-imageio/pict/src/test/java/com/twelvemonkeys/imageio/plugins/pict/PICTImageReaderTestCase.java
Executable file → Normal file
12
twelvemonkeys-imageio/pict/src/test/java/com/twelvemonkeys/imageio/plugins/pict/PICTImageReaderTestCase.java
Executable file → Normal file
@ -4,6 +4,7 @@ import com.twelvemonkeys.imageio.util.ImageReaderAbstractTestCase;
|
||||
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@ -18,7 +19,7 @@ public class PICTImageReaderTestCase extends ImageReaderAbstractTestCase<PICTIma
|
||||
|
||||
static ImageReaderSpi sProvider = new PICTImageReaderSpi();
|
||||
|
||||
// TODO: Should also test the cliboard format (without 512 byte header)
|
||||
// TODO: Should also test the clipboard format (without 512 byte header)
|
||||
protected List<TestData> getTestData() {
|
||||
return Arrays.asList(
|
||||
new TestData(getClassLoaderResource("/pict/test.pct"), new Dimension(300, 200)),
|
||||
@ -57,4 +58,13 @@ public class PICTImageReaderTestCase extends ImageReaderAbstractTestCase<PICTIma
|
||||
protected List<String> getMIMETypes() {
|
||||
return Arrays.asList("image/pict", "image/x-pict");
|
||||
}
|
||||
|
||||
public void testProviderNotMatchJPEG() throws IOException {
|
||||
// This JPEG contains PICT magic bytes at locations a PICT would normally have them.
|
||||
// We should not claim to be able read it.
|
||||
assertFalse(sProvider.canDecodeInput(new TestData(
|
||||
getClassLoaderResource("/jpeg/R-7439-1151526181.jpeg"),
|
||||
new Dimension(386, 396)
|
||||
)));
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
Loading…
x
Reference in New Issue
Block a user