use of javax.imageio.stream.FileImageOutputStream in project imageio-ext by geosolutions-it.
the class JPEGWriterSpeedTest method testJPEGJDK.
@Test
@Ignore
public void testJPEGJDK() throws FileNotFoundException, IOException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
assumeTrue(!SKIP_TESTS);
String fileName = null;
ImageOutputStream out1 = null;
try {
ImageWriterSpi spi = standardSPI;
fileName = OUTPUT_FOLDER + ((SAMPLE_IMAGE.getSampleModel().getNumBands() == 1) ? "GRAY" : "jdkRGB") + "METAoutput.jpeg";
final File file = new File(fileName);
out1 = new FileImageOutputStream(file);
ImageWriter writer1 = spi.createWriterInstance();
ImageWriteParam param = writer1.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionQuality(0.75f);
writer1.setOutput(out1);
writer1.write(null, new IIOImage(SAMPLE_IMAGE, null, null), param);
out1.close();
writer1.dispose();
// Writing loops
long start = System.nanoTime();
for (int i = 0; i < LOOP; i++) {
// Startup write
out1 = new FileImageOutputStream(file);
writer1 = spi.createWriterInstance();
writer1.setOutput(out1);
writer1.write(null, new IIOImage(SAMPLE_IMAGE, null, null), param);
out1.close();
writer1.dispose();
}
long end = System.nanoTime();
long total = end - start;
reportTime("JDK", total, LOOP);
} catch (Throwable t) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning(t.getLocalizedMessage());
}
} finally {
if (out1 != null) {
try {
out1.close();
} catch (Throwable t) {
//
}
}
}
}
use of javax.imageio.stream.FileImageOutputStream in project imageio-ext by geosolutions-it.
the class JPEGWriterSpeedTest method testJPEGCLIB.
@Test
@Ignore
public void testJPEGCLIB() throws FileNotFoundException, IOException, SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
assumeTrue(!SKIP_TESTS);
String fileName = null;
ImageOutputStream out1 = null;
try {
ImageWriterSpi spi = clibSPI;
fileName = OUTPUT_FOLDER + ((SAMPLE_IMAGE.getSampleModel().getNumBands() == 1) ? "GRAY" : "RGB") + "CLIBoutput.jpeg";
final File file = new File(fileName);
out1 = new FileImageOutputStream(file);
ImageWriter writer1 = spi.createWriterInstance();
ImageWriteParam param = writer1.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionQuality(0.75f);
writer1.setOutput(out1);
writer1.write(null, new IIOImage(SAMPLE_IMAGE, null, null), param);
out1.close();
writer1.dispose();
// Writing loops
long start = System.nanoTime();
for (int i = 0; i < LOOP; i++) {
// Startup write
out1 = new FileImageOutputStream(file);
writer1 = spi.createWriterInstance();
writer1.setOutput(out1);
writer1.write(null, new IIOImage(SAMPLE_IMAGE, null, null), param);
out1.close();
writer1.dispose();
}
long end = System.nanoTime();
long total = end - start;
reportTime("Clib", total, LOOP);
} catch (Throwable t) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning(t.getLocalizedMessage());
}
} finally {
if (out1 != null) {
try {
out1.close();
} catch (Throwable t) {
//
}
}
}
}
use of javax.imageio.stream.FileImageOutputStream in project imageio-ext by geosolutions-it.
the class TIFFWriteTest method readWriteFromFileDirect.
@Test
public void readWriteFromFileDirect() throws IOException {
// JAI.getDefaultInstance().getTileCache().setMemoryCapacity(512*1024*1024);
// final TCTool tc= new TCTool((SunTileCache)JAI.getDefaultInstance().getTileCache());
// new File("c:\\work\\dem30_final.tiff");
final File inputFile = TestData.file(this, "test.tif");
final File outputFile = TestData.temp(this, "testw.tif", true);
final ImageReadParam param = new ImageReadParam();
param.setSourceRegion(new Rectangle(0, 0, 10, 10));
TIFFImageReader reader = (TIFFImageReader) new TIFFImageReaderSpi().createReaderInstance();
reader.setInput(new FileImageInputStream(inputFile));
BufferedImage image = reader.read(0, param);
// RenderedImage image = ImageReadDescriptor.create(new FileImageInputStream(inputFile),
// Integer.valueOf(0), false, false, false, null, null, null,
// reader, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, new ImageLayout().setTileGridXOffset(0).setTileGridYOffset(0).setTileHeight(512).setTileWidth(512)));
final TIFFImageWriter writer = (TIFFImageWriter) new TIFFImageWriterSpi().createWriterInstance();
final ImageWriteParam writeParam = new TIFFImageWriteParam(Locale.getDefault());
writeParam.setTilingMode(ImageWriteParam.MODE_EXPLICIT);
writeParam.setTiling(512, 512, 0, 0);
// for( int i=0;i<1;i++){
writer.setOutput(new FileImageOutputStream(outputFile));
// BUG
// writer.write(metadata, new IIOImage(image, null, metadata), null);
writer.addIIOWriteProgressListener(new IIOWriteProgressListener() {
public void writeAborted(ImageWriter source) {
// TODO Auto-generated method stub
}
public void thumbnailStarted(ImageWriter source, int imageIndex, int thumbnailIndex) {
assertTrue(imageIndex >= 0);
assertTrue(thumbnailIndex == 0);
}
public void thumbnailProgress(ImageWriter source, float percentageDone) {
assertTrue(percentageDone >= 0 && percentageDone <= 100);
}
public void thumbnailComplete(ImageWriter source) {
// TODO Auto-generated method stub
}
public void imageStarted(ImageWriter source, int imageIndex) {
assertTrue(imageIndex >= 0);
LOGGER.info("imageStarted");
}
public void imageProgress(ImageWriter source, float percentageDone) {
assertTrue(percentageDone >= 0 && percentageDone <= 100);
LOGGER.info(percentageDone + "%");
}
public void imageComplete(ImageWriter source) {
LOGGER.info("imageComplete");
}
});
writer.write(null, new IIOImage(image, null, null), writeParam);
// }
writer.dispose();
reader.reset();
reader.setInput(new FileImageInputStream(outputFile));
image = reader.read(0);
Assert.assertEquals(10, image.getWidth());
Assert.assertEquals(10, image.getHeight());
image.flush();
image = null;
reader.dispose();
}
use of javax.imageio.stream.FileImageOutputStream in project chordatlas by twak.
the class Imagez method writeJPG.
public static void writeJPG(BufferedImage rendered, float quality, File f) {
try {
JPEGImageWriteParam jpegParams = new JPEGImageWriteParam(null);
jpegParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
jpegParams.setCompressionQuality(1f);
ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
ImageWriteParam param = writer.getDefaultWriteParam();
// Needed see javadoc
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
// Highest quality
param.setCompressionQuality(quality);
writer.setOutput(new FileImageOutputStream(f));
writer.write(null, new IIOImage(rendered, null, null), jpegParams);
} catch (Throwable th) {
th.printStackTrace();
}
}
use of javax.imageio.stream.FileImageOutputStream in project h2database by h2database.
the class TestMVRTree method render.
private static void render(MVRTreeMap<String> r, String fileName) {
int width = 1000, height = 500;
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = (Graphics2D) img.getGraphics();
g2d.setBackground(Color.WHITE);
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, width, height);
g2d.setComposite(AlphaComposite.SrcOver.derive(0.5f));
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.BLACK);
SpatialKey b = new SpatialKey(0, Float.MAX_VALUE, Float.MIN_VALUE, Float.MAX_VALUE, Float.MIN_VALUE);
for (SpatialKey x : r.keySet()) {
b.setMin(0, Math.min(b.min(0), x.min(0)));
b.setMin(1, Math.min(b.min(1), x.min(1)));
b.setMax(0, Math.max(b.max(0), x.max(0)));
b.setMax(1, Math.max(b.max(1), x.max(1)));
}
// System.out.println(b);
for (SpatialKey x : r.keySet()) {
int[] rect = scale(b, x, width, height);
g2d.drawRect(rect[0], rect[1], rect[2] - rect[0], rect[3] - rect[1]);
String s = r.get(x);
g2d.drawChars(s.toCharArray(), 0, s.length(), rect[0], rect[1] - 4);
}
g2d.setColor(Color.red);
ArrayList<SpatialKey> list = New.arrayList();
r.addNodeKeys(list, r.getRoot());
for (SpatialKey x : list) {
int[] rect = scale(b, x, width, height);
g2d.drawRect(rect[0], rect[1], rect[2] - rect[0], rect[3] - rect[1]);
}
ImageWriter out = ImageIO.getImageWritersByFormatName("png").next();
try {
out.setOutput(new FileImageOutputStream(new File(fileName)));
out.write(img);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations