use of javax.imageio.stream.FileImageInputStream 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.stream.FileImageInputStream in project jdk8u_jdk by JetBrains.
the class ImageStreamFromRAF method main.
public static void main(String[] args) {
try {
File f = new File("ImageInputStreamFromRAF.tmp");
RandomAccessFile raf = new RandomAccessFile(f, "rw");
ImageInputStream istream = ImageIO.createImageInputStream(raf);
ImageOutputStream ostream = ImageIO.createImageOutputStream(raf);
f.delete();
if (istream == null) {
throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) returned null!");
}
if (ostream == null) {
throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) returned null!");
}
if (!(istream instanceof FileImageInputStream)) {
throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) did not return a FileImageInputStream!");
}
if (!(ostream instanceof FileImageOutputStream)) {
throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) did not return a FileImageOutputStream!");
}
} catch (IOException ioe) {
throw new RuntimeException("Unexpected IOException: " + ioe);
}
}
use of javax.imageio.stream.FileImageInputStream in project Lucee by lucee.
the class Image method getMetaData.
public IIOMetadata getMetaData(Struct parent) {
InputStream is = null;
javax.imageio.stream.ImageInputStreamImpl iis = null;
try {
if (source instanceof File) {
iis = new FileImageInputStream((File) source);
} else if (source == null)
iis = new MemoryCacheImageInputStream(new ByteArrayInputStream(getImageBytes(format, true)));
else
iis = new MemoryCacheImageInputStream(is = source.getInputStream());
Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);
if (readers.hasNext()) {
// pick the first available ImageReader
ImageReader reader = readers.next();
IIOMetadata meta = null;
synchronized (sync) {
// attach source to the reader
reader.setInput(iis, true);
// read metadata of first image
meta = reader.getImageMetadata(0);
meta.setFromTree(FORMAT, meta.getAsTree(FORMAT));
reader.reset();
}
// generating dump
if (parent != null) {
String[] formatNames = meta.getMetadataFormatNames();
for (int i = 0; i < formatNames.length; i++) {
Node root = meta.getAsTree(formatNames[i]);
// print.out(XMLCaster.toString(root));
addMetaddata(parent, "metadata", root);
}
}
return meta;
}
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
} finally {
ImageUtil.closeEL(iis);
IOUtil.closeEL(is);
}
return null;
}
use of javax.imageio.stream.FileImageInputStream in project imageio-ext by geosolutions-it.
the class JPEGWriterCompareTest method writeAsJpeg.
@Test
public void writeAsJpeg() throws Exception {
if (!TestData.isExtensiveTest()) {
LOGGER.info("Skipping compare tests. Use Extensive tests to enable it");
return;
}
if (SKIP_TESTS) {
LOGGER.warning(ERROR_LIB_MESSAGE);
assumeTrue(!SKIP_TESTS);
return;
}
ImageReaderSpi spiReader = new PNGImageReaderSpi();
ImageReader reader = null;
File inputFile = TestData.file(this, "testmergb.png");
FileImageInputStream fis = null;
try {
reader = spiReader.createReaderInstance();
fis = new FileImageInputStream(inputFile);
reader.setInput(fis);
BufferedImage buffered = reader.read(0);
writeAsJpeg(buffered);
} catch (Throwable th) {
if (fis != null) {
try {
fis.close();
} catch (Throwable t) {
}
}
if (reader != null) {
try {
reader.dispose();
} catch (Throwable t) {
}
}
th.printStackTrace();
}
// System.in.read();
}
use of javax.imageio.stream.FileImageInputStream in project imageio-ext by geosolutions-it.
the class TIFFMetadataTest method testImageRead.
/**
* This test class is used for testing the capability of the TIFFImageReader
* class to read EXIF metadata. TIFFImageReader class presented a bug when
* the EXIF IFD pointer tag type was not LONG (type = 4) but was the new
* IFD_POINTER type (type = 13) defined in the Technical Note 1 of the TIFF
* Specification Supplement documentation. This variation provoked a
* ClassCastException when the reader tried to cast the EXIF IFD pointer
* data to the TIFFIFD class. This bug has been fixed by adding the
* possibility to contain the IFD_POINTER type to the EXIF IFD pointer tag.
* The testImageRead() method reads an image with the new TIFF tag type and
* checks if the EXIF tags has been read by the TIFFImageReader.
*
* @throws IOException
*/
@Test
public void testImageRead() throws IOException {
// Selection of the input file from the TestData directory
File inputFile = TestData.file(this, "test_IFD.tif");
// Instantiation of the read-params
final TIFFImageReadParam param = new TIFFImageReadParam();
// Instantiation of the file-reader
TIFFImageReader reader = (TIFFImageReader) new TIFFImageReaderSpi().createReaderInstance();
// Creation of the file input stream associated to the selected file
FileImageInputStream stream0 = new FileImageInputStream(inputFile);
try {
// Setting the inputstream to the reader
reader.setInput(stream0);
// Reading of the image
RenderedImage img = reader.read(0, param);
// Reading of the associated metadata
TIFFImageMetadata metadata = (TIFFImageMetadata) reader.getImageMetadata(0);
// Check if the Exif pointer metadata is present
int tagPointer = 34665;
boolean fieldPointer = metadata.getRootIFD().containsTIFFField(tagPointer);
assertTrue(fieldPointer);
// Selection of the subIFD associated to the exif pointer
TIFFIFD subIFD = (TIFFIFD) metadata.getTIFFField(tagPointer).getData();
// Selection of the tags associated to the EXIF pointer
int tagNumberExifVersion = 36864;
int tagNumberDateTime = 36868;
int tagNumberCompConfig = 37121;
int tagNumberFlashPix = 40960;
int tagNumberColor = 40961;
int tagNumberXpixelRes = 40962;
int tagNumberYpixelRes = 40963;
// Test Assertions
assertTrue(subIFD.containsTIFFField(tagNumberExifVersion));
assertTrue(subIFD.containsTIFFField(tagNumberDateTime));
assertTrue(subIFD.containsTIFFField(tagNumberCompConfig));
assertTrue(subIFD.containsTIFFField(tagNumberFlashPix));
assertTrue(subIFD.containsTIFFField(tagNumberColor));
assertTrue(subIFD.containsTIFFField(tagNumberXpixelRes));
assertTrue(subIFD.containsTIFFField(tagNumberYpixelRes));
} catch (Exception e) {
// If an exception occurred the logger catch the exception and print
// the message
logger.log(Level.SEVERE, e.getMessage(), e);
} finally {
// and the input stream are closed
if (stream0 != null) {
stream0.flush();
stream0.close();
}
if (reader != null) {
reader.dispose();
}
}
}
Aggregations