private ImageInputStream createImageInputStream(InputStream is) throws IOException { if (this.cacheDir != null) { return new FileCacheImageInputStream(is, this.cacheDir); } else { return new MemoryCacheImageInputStream(is); } }
private ImageOutputStream createImageOutputStream(OutputStream os) throws IOException { if (this.cacheDir != null) { return new FileCacheImageOutputStream(os, this.cacheDir); } else { return new MemoryCacheImageOutputStream(os); } }
private void initBoolDecoder() throws IOException { value = 0; /* value = first 16 input bits */ data.seek(offset); value = data.readUnsignedByte() << 8; // value = (data[offset]) << 8; offset++; range = 255; /* initial range is full */ bit_count = 0; /* have not yet shifted out any bits */ }
public void setFrame(ImageInputStream frame) { try { this.frame.flush(); this.frame.close(); this.frame = frame; offset = frame.getStreamPosition(); this.coefProbs=Globals.getDefaultCoefProbs(); tokenBoolDecoders = new Vector<BoolDecoder>(); } catch (IOException e) { e.printStackTrace(); } } }
public static void main(String[] args) throws Exception { if (args.length > 1) { // grab the output image type from the first image in the sequence BufferedImage firstImage = ImageIO.read(new File(args[0])); // create a new BufferedOutputStream with the last argument ImageOutputStream output = new FileImageOutputStream(new File(args[args.length - 1])); // create a gif sequence with the type of the first image, 1 second // between frames, which loops continuously GifSequenceWriter writer = new GifSequenceWriter(output, firstImage.getType(), 1, false); // write out the first image to our sequence... writer.writeToSequence(firstImage); for(int i=1; i<args.length-1; i++) { BufferedImage nextImage = ImageIO.read(new File(args[i])); writer.writeToSequence(nextImage); } writer.close(); output.close(); } else { System.out.println( "Usage: java GifSequenceWriter [list of gif files] [output file]"); } }
@Override public void writeImageFile(OutputStream outStream, String format, ByteBuffer imageData, int width, int height) throws IOException { BufferedImage awtImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR); Screenshots.convertScreenShot2(imageData.asIntBuffer(), awtImage); ImageWriter writer = ImageIO.getImageWritersByFormatName(format).next(); ImageWriteParam writeParam = writer.getDefaultWriteParam(); if (format.equals("jpg")) { JPEGImageWriteParam jpegParam = (JPEGImageWriteParam) writeParam; jpegParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); jpegParam.setCompressionQuality(0.95f); } awtImage = verticalFlip(awtImage); ImageOutputStream imgOut = new MemoryCacheImageOutputStream(outStream); writer.setOutput(imgOut); IIOImage outputImage = new IIOImage(awtImage, null, null); try { writer.write(null, outputImage, writeParam); } finally { imgOut.close(); writer.dispose(); } }
/** * produce the gif image as byte array * @return the gif image */ public byte[] get() { if (ios != null) try { ios.close(); ios = null; } catch (final IOException e) {} if (writer != null) { writer.dispose(); writer = null; } return baos.toByteArray(); }
public static BufferedImage getBufferedImage(InputStream is) { try { final Class<?> clVP8Decoder = Class.forName("net.sourceforge.plantuml.webp.VP8Decoder"); final Object vp8Decoder = clVP8Decoder.newInstance(); // final VP8Decoder vp8Decoder = new VP8Decoder(); final Method decodeFrame = clVP8Decoder.getMethod("decodeFrame", ImageInputStream.class); final ImageInputStream iis = ImageIO.createImageInputStream(is); decodeFrame.invoke(vp8Decoder, iis); // vp8Decoder.decodeFrame(iis); iis.close(); final Object frame = clVP8Decoder.getMethod("getFrame").invoke(vp8Decoder); return (BufferedImage) frame.getClass().getMethod("getBufferedImage").invoke(frame); // final VP8Frame frame = vp8Decoder.getFrame(); // return frame.getBufferedImage(); } catch (Exception e) { e.printStackTrace(); return null; } }
public void seek() throws IOException { data.seek(offset); }
public VP8Frame(ImageInputStream stream, int[][][][] coefProbs) throws IOException { this.frame = stream; offset = frame.getStreamPosition(); this.coefProbs=coefProbs; tokenBoolDecoders = new Vector<BoolDecoder>(); } public void addIIOReadProgressListener(IIOReadProgressListener listener) {
/** * create a gif animation producer * @param loops - number of loops for the animated images. -1 = no loops; 0 = indefinitely loops; else: number of loops */ public AnimationGIF(int loops) { this.counter = 0; this.loops = loops; this.ios = null; this.writer = null; this.baos = new ByteArrayOutputStream(); Iterator<ImageWriter> writerIterator = ImageIO.getImageWritersByFormatName("GIF"); this.writer = writerIterator.next(); // com.sun.media.imageioimpl.plugins.gif.GIFImageWriter, com.sun.imageio.plugins.gif.GIFImageWriter this.ios = new MemoryCacheImageOutputStream(baos); this.writer.setOutput(ios); this.iwp = writer.getDefaultWriteParam(); }
final ImageWriter writer = ImageIO.getImageWritersByFormatName("jpg").next(); // specifies where the jpg image has to be written writer.setOutput(new FileImageOutputStream( new File(folder.toString() + "/" + filename + ".jpg"))); // writes the file with given compression level // from your JPEGImageWriteParam instance writer.write(null, new IIOImage(capture, null, null), jpegParams);
private Dimension getImageDim(final String path) { Dimension result = null; String suffix = this.getFileSuffix(path); Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix); if (iter.hasNext()) { ImageReader reader = iter.next(); try { ImageInputStream stream = new FileImageInputStream(new File(path)); reader.setInput(stream); int width = reader.getWidth(reader.getMinIndex()); int height = reader.getHeight(reader.getMinIndex()); result = new Dimension(width, height); } catch (IOException e) { log(e.getMessage()); } finally { reader.dispose(); } } else { log("No reader found for given format: " + suffix)); } return result; }
value |= data.readUnsignedByte() << (-count);
private void setupTokenDecoder(BoolDecoder bc, int first_partition_length_in_bytes, long offset) throws IOException { long partitionSize = 0; long partitionsStart = offset+first_partition_length_in_bytes; long partition = partitionsStart; multiTokenPartition = bc.readLiteral(2); int num_part = 1 << multiTokenPartition; if (num_part > 1) { partition += 3 * (num_part - 1); } for (int i = 0; i < num_part; i++) { /* * Calculate the length of this partition. The last partition size * is implicit. */ if (i < num_part - 1) { partitionSize = readPartitionSize(partitionsStart+(i*3)); bc.seek(); } else { partitionSize = frame.length() - partition; } tokenBoolDecoders.add(new BoolDecoder(frame, partition)); partition+=partitionSize; } tokenBoolDecoder = tokenBoolDecoders.elementAt(0); }
imageOutputStream.close();
private int readPartitionSize(long l) throws IOException { frame.seek(l); int size =frame.readUnsignedByte() + (frame.readUnsignedByte() << 8) + (frame.readUnsignedByte() << 16); return size; } private int readSubBlockMode(BoolDecoder bc, int A, int L) throws IOException {
private ImageInputStream createImageInputStream(InputStream is) throws IOException { if (this.cacheDir != null) { return new FileCacheImageInputStream(is, this.cacheDir); } else { return new MemoryCacheImageInputStream(is); } }
private ImageOutputStream createImageOutputStream(OutputStream os) throws IOException { if (this.cacheDir != null) { return new FileCacheImageOutputStream(os, this.cacheDir); } else { return new MemoryCacheImageOutputStream(os); } }
public VP8Frame(ImageInputStream stream) throws IOException { this.frame = stream; offset = frame.getStreamPosition(); this.coefProbs=Globals.getDefaultCoefProbs(); tokenBoolDecoders = new Vector<BoolDecoder>(); } public VP8Frame(ImageInputStream stream, int[][][][] coefProbs) throws IOException {