use of javax.imageio.ImageReadParam in project jdk8u_jdk by JetBrains.
the class ReadAsGrayTest method testType.
private static void testType(ImageReader reader, ImageTypeSpecifier t, BufferedImage src) throws IOException {
ImageReadParam p = reader.getDefaultReadParam();
p.setDestinationType(t);
BufferedImage dst = reader.read(0, p);
verify(src, dst, t);
}
use of javax.imageio.ImageReadParam in project jdk8u_jdk by JetBrains.
the class ReadingInterruptionTest method doTest.
public void doTest() {
try {
reader.addIIOReadProgressListener(this);
iis = ImageIO.createImageInputStream(file);
reader.setInput(iis);
ImageReadParam p = reader.getDefaultReadParam();
Thread.sleep(70);
BufferedImage res = reader.read(0, p);
Thread.sleep(70);
} catch (Exception e) {
/*
* we do expect that concurrent attempt to dispose this
* instance of image reader will be blocked. So, this image
* should be read sucessfuly. Otherwise, something went wrong
* and we need to report test failure.
*/
throw new RuntimeException("Test FAILED", e);
} finally {
/*
* it would happen that concurrent invocation of dispose() method
* will be successful. Due to race condition it seems to be possible
* that dispose operation will be performed after than read() operation
* leaveled thread lock. In this case all subsequent calls for reader
* methods should results in IllegalStateException. So, we treat
* IllegalStateException as success. Everything else means test failure.
*/
try {
reader.reset();
} catch (IllegalStateException e) {
System.out.println("Expected exception was caught: " + e);
} catch (Exception e) {
throw new RuntimeException("Test FAILED.", e);
}
}
System.out.println("Test PASSED.");
}
use of javax.imageio.ImageReadParam in project jdk8u_jdk by JetBrains.
the class JPEGsNotAcceleratedTest method readTestImage.
public static BufferedImage readTestImage(String fileName, BufferedImage dest, Rectangle srcROI) {
BufferedImage bi = null;
try {
FileImageInputStream is = new FileImageInputStream(new File(fileName));
ImageReader reader = (ImageReader) ImageIO.getImageReaders(is).next();
ImageReadParam param = reader.getDefaultReadParam();
if (dest != null) {
param.setDestination(dest);
}
if (srcROI != null) {
param.setSourceRegion(srcROI);
}
reader.setInput(is);
bi = reader.read(0, param);
} catch (IOException e) {
System.err.println("Error " + e + " when reading file: " + fileName);
throw new RuntimeException(e);
}
return bi;
}
use of javax.imageio.ImageReadParam in project jdk8u_jdk by JetBrains.
the class ConcurrentReadingTest method run.
public void run() {
try {
ImageInputStream iis = ImageIO.createImageInputStream(file);
r.setInput(iis);
ImageReadParam p = r.getDefaultReadParam();
Thread.sleep(70);
BufferedImage res = r.read(0, p);
Thread.sleep(70);
r.reset();
} catch (IllegalStateException e) {
System.out.println(e);
} catch (IOException e) {
System.out.println(e);
} catch (Throwable e) {
// Unexpected exception. Test failed.
throw new RuntimeException("Test failed.", e);
} finally {
synchronized (lock) {
completeCount++;
}
}
}
use of javax.imageio.ImageReadParam in project jdk8u_jdk by JetBrains.
the class WbmpBigDestinationTest method main.
public static void main(String[] args) {
try {
BufferedImage src = new BufferedImage(100, 100, BufferedImage.TYPE_BYTE_BINARY);
Graphics2D g = src.createGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, 100, 100);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageWriter iw = (ImageWriter) ImageIO.getImageWritersByFormatName(format).next();
if (iw == null) {
throw new RuntimeException("No writer available. Test failed.");
}
iw.setOutput(ImageIO.createImageOutputStream(baos));
iw.write(src);
byte[] data = baos.toByteArray();
ImageReader ir = (ImageReader) ImageIO.getImageReadersByFormatName(format).next();
ir.setInput(ImageIO.createImageInputStream(new ByteArrayInputStream(data)));
Iterator specifiers = ir.getImageTypes(0);
ImageTypeSpecifier typeSpecifier = null;
if (specifiers.hasNext()) {
typeSpecifier = (ImageTypeSpecifier) specifiers.next();
}
ImageReadParam param = new ImageReadParam();
BufferedImage dst = typeSpecifier.createBufferedImage(200, 200);
param.setDestination(dst);
ir.read(0, param);
checkResults(src, dst);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Unexpected exception. Test failed.");
}
}
Aggregations