Examples of MemoryCacheImageOutputStream


Examples of javax.imageio.stream.MemoryCacheImageOutputStream

    {
        ArrayList<byte[]> codeTable = createCodeTable();
        int chunk = 9;

        byte[] inputPattern = null;
        MemoryCacheImageOutputStream out = new MemoryCacheImageOutputStream(result);
        out.writeBits(CLEAR_TABLE, chunk);
        int foundCode = -1;
        int r;
        while ((r = rawData.read()) != -1)
        {
            byte by = (byte) r;
            if (inputPattern == null)
            {
                inputPattern = new byte[]
                {
                    by
                };
                foundCode = by & 0xff;
            }
            else
            {
                byte[] inputPatternCopy = new byte[inputPattern.length + 1];
                for (int i = 0; i < inputPattern.length; ++i)
                    inputPatternCopy[i] = inputPattern[i];
                inputPattern = inputPatternCopy;
                inputPattern[inputPattern.length - 1] = by;
                int newFoundCode = findPatternCode(codeTable, inputPattern);
                if (newFoundCode == -1)
                {
                    // use previous
                    chunk = calculateChunk(codeTable.size() - 1);
                    out.writeBits(foundCode, chunk);
                    // create new table entry
                    codeTable.add(inputPattern);

                    if (codeTable.size() == 4096)
                    {
                        // code table is full
                        out.writeBits(CLEAR_TABLE, chunk);
                        chunk = 9;
                        codeTable = createCodeTable();
                    }

                    inputPattern = new byte[]
                    {
                        by
                    };
                    foundCode = by & 0xff;
                }
                else
                {
                    foundCode = newFoundCode;
                }
            }
        }
        if (foundCode != -1)
        {
            chunk = calculateChunk(codeTable.size() - 1);
            out.writeBits(foundCode, chunk);
        }

        // PPDFBOX-1977: the decoder wouldn't know that the encoder would output
        // an EOD as code, so he would have increased his own code table and
        // possibly adjusted the chunk. Therefore, the encoder must behave as
        // if the code table had just grown and thus it must be checked it is
        // needed to adjust the chunk, based on an increased table size parameter
        chunk = calculateChunk(codeTable.size());

        out.writeBits(EOD, chunk);
        out.writeBits(0, 7); // pad with 0
        out.flush(); // must do or file will be empty :-(
    }
View Full Code Here

Examples of javax.imageio.stream.MemoryCacheImageOutputStream

//                    && bi.getColorModel().getPixelSize() <= 8)
            if (bi.getType() == BufferedImage.TYPE_BYTE_BINARY
                    && bi.getColorModel().getPixelSize() <= 8)
            {
                setColorSpace(new PDDeviceGray());
                MemoryCacheImageOutputStream mcios = new MemoryCacheImageOutputStream(bos);

                // grayscale images need one color per sample
                bpc = bi.getColorModel().getPixelSize();
                int h = rgbImage.getHeight();
                int w = rgbImage.getWidth();
                for (int y = 0; y < h; ++y)
                {
                    for (int x = 0; x < w; ++x)
                    {
                        mcios.writeBits(rgbImage.getRGB(x, y), bpc);
                    }
                }
                mcios.writeBits(0, 7); // padding
                mcios.flush();
                mcios.close();
            }
            else
            {
                // RGB
                setColorSpace(PDDeviceRGB.INSTANCE);
View Full Code Here

Examples of javax.imageio.stream.MemoryCacheImageOutputStream

            int INITIAL_BUFSIZE = 4096;
            int MAZ_BUFSIZE = 65535 - 2 - PREAMBLE_SIZE;
            try {
                ByteArrayOutputStream baos =
                    new ByteArrayOutputStream(INITIAL_BUFSIZE);
                MemoryCacheImageOutputStream mos =
                    new MemoryCacheImageOutputStream(baos);

                JPEGImageWriter thumbWriter = new JPEGImageWriter(null);

                thumbWriter.setOutput(mos);
View Full Code Here

Examples of javax.imageio.stream.MemoryCacheImageOutputStream

        if (output instanceof OutputStream) {
            OutputStream os = (OutputStream)output;
            if (useCache) {
                return new FileCacheImageOutputStream(os, cacheDir);
            } else {
                return new MemoryCacheImageOutputStream(os);
            }
        } else {
            throw new IllegalArgumentException();
        }
    }
View Full Code Here

Examples of javax.imageio.stream.MemoryCacheImageOutputStream

            int INITIAL_BUFSIZE = 4096;
            int MAZ_BUFSIZE = 65535 - 2 - PREAMBLE_SIZE;
            try {
                ByteArrayOutputStream baos =
                    new ByteArrayOutputStream(INITIAL_BUFSIZE);
                MemoryCacheImageOutputStream mos =
                    new MemoryCacheImageOutputStream(baos);

                JPEGImageWriter thumbWriter = new JPEGImageWriter(null);

                thumbWriter.setOutput(mos);
View Full Code Here

Examples of javax.imageio.stream.MemoryCacheImageOutputStream

        Rectangle tileRegion = tiles[tileIdx];
        RenderedImage tile = createTile(tileRegion.x, tileRegion.y, tileRegion.width,
                tileRegion.height);

        OutputStream outputStream = target.getOutputStream();
        ImageOutputStream imgOut = new MemoryCacheImageOutputStream(outputStream);
        writer.setOutput(imgOut);
        IIOImage image = new IIOImage(tile, null, null);
        try {
            writer.write(null, image, param);
        } finally {
            imgOut.close();
            writer.dispose();
        }

        return true;
    }
View Full Code Here

Examples of javax.imageio.stream.MemoryCacheImageOutputStream

  private ImageOutputStream createImageOutputStream(OutputStream os) throws IOException {
    if (this.cacheDir != null) {
      return new FileCacheImageOutputStream(os, this.cacheDir);
    }
    else {
      return new MemoryCacheImageOutputStream(os);
    }
  }
View Full Code Here

Examples of javax.imageio.stream.MemoryCacheImageOutputStream

                if (lastImage == null
                    || image.getRaster().getDataBuffer().getDataType() != DataBuffer.TYPE_INT) {
                    lastImage = image;
                    imageOutput.reset();
                    ImageIO.write(image, "jpeg",
                        new MemoryCacheImageOutputStream(imageOutput));
                    maxBandwidthUsed = Math.max(maxBandwidthUsed,
                        imageOutput.size());
                    objectOut.writeObject(new Tile(imageOutput.toByteArray(),
                        0, 0, image.getWidth(), image.getHeight(), image
                            .getWidth(), image.getHeight()));
                } else {

                    int[] rasterOld = ((DataBufferInt) lastImage.getRaster()
                        .getDataBuffer()).getData();
                    int[] rasterNew = ((DataBufferInt) image.getRaster()
                        .getDataBuffer()).getData();

                    int bytesWritten = 0;

                    for (DirtyTile dirtyTile : getDirtyTiles(rasterOld,
                        rasterNew)) {

                        BufferedImage dirtySubImage = image.getSubimage(
                            dirtyTile.x, dirtyTile.y, dirtyTile.w, dirtyTile.h);

                        imageOutput.reset();
                        ImageIO.write(dirtySubImage, "jpeg",
                            new MemoryCacheImageOutputStream(imageOutput));
                        bytesWritten += imageOutput.size();
                        objectOut.writeObject(new Tile(imageOutput
                            .toByteArray(), dirtyTile.x, dirtyTile.y,
                            dirtyTile.w, dirtyTile.h, image.getWidth(), image
                                .getHeight()));
View Full Code Here

Examples of javax.imageio.stream.MemoryCacheImageOutputStream

        if (output instanceof OutputStream) {
            OutputStream os = (OutputStream)output;
            if (useCache) {
                return new FileCacheImageOutputStream(os, cacheDir);
            } else {
                return new MemoryCacheImageOutputStream(os);
            }
        } else {
            throw new IllegalArgumentException();
        }
    }
View Full Code Here

Examples of javax.imageio.stream.MemoryCacheImageOutputStream

            int INITIAL_BUFSIZE = 4096;
            int MAZ_BUFSIZE = 65535 - 2 - PREAMBLE_SIZE;
            try {
                ByteArrayOutputStream baos =
                    new ByteArrayOutputStream(INITIAL_BUFSIZE);
                MemoryCacheImageOutputStream mos =
                    new MemoryCacheImageOutputStream(baos);

                JPEGImageWriter thumbWriter = new JPEGImageWriter(null);

                thumbWriter.setOutput(mos);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.