Examples of MemoryCacheImageOutputStream


Examples of javax.imageio.stream.MemoryCacheImageOutputStream

        if (quality != null)
            q = quality.floatValue();
        writeParam.setCompressionQuality(q);

        DAByteArrayOutputStream buffer = new DAByteArrayOutputStream();
        writer.setOutput(new MemoryCacheImageOutputStream(buffer));

        IIOImage ioImage = new IIOImage(bufferedImage, null, null);

        writer.write(null, ioImage, writeParam);
        writer.dispose();
View Full Code Here

Examples of javax.imageio.stream.MemoryCacheImageOutputStream

            {
                setColorSpace(new PDDeviceGray());
                bpc = bi.getColorModel().getPixelSize();
                if (bpc < 8)
                {
                    MemoryCacheImageOutputStream mcios = new MemoryCacheImageOutputStream(os);
                    for (int y = 0; y < height; ++y)
                    {
                        for (int x = 0; x < width; ++x)
                        {
                            // grayscale images need one color per sample
                            mcios.writeBits(bi.getRGB(x, y) & 0xFF, bpc);
                        }
                    }
                    // padding
                    while (mcios.getBitOffset() != 0)
                    {
                        mcios.writeBit(0);
                    }
                    mcios.flush();
                    mcios.close();
                }
                else
                {
                    //BEWARE: the gray values must be extracted from raster
                    // and not from getRGB or the TYPE_BYTE_GRAY tests will fail
View Full Code Here

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

    {
        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, 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, 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(), 1);

        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

                        JPEGImageWriteParam param = new JPEGImageWriteParam(null);
                        param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                        param.setCompressionQuality((float)(q/100.0));
                        ImageOutputStream ios = null;
                        try{
                                ios = new MemoryCacheImageOutputStream(os);
                                writer.setOutput(ios);
                                writer.write((IIOMetadata)null, new IIOImage(bi, null, null), param);
                        } catch (IOException e) {
                                logger.error(e,e);
                        }
View Full Code Here

Examples of javax.imageio.stream.MemoryCacheImageOutputStream

        ByteArrayOutputStream os = null;
        ImageOutputStream ios = null;
        try {
            os = new ByteArrayOutputStream();
            ios = new MemoryCacheImageOutputStream(os);
            metaData.setFromTree(metaFormatName, root);

            writer.setOutput(ios);
           
            writer.prepareWriteSequence(null);
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

                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                BufferedOutputStream bos = new BufferedOutputStream(baos);
                if (ImageIO.getUseCache()) {
                    ios = new FileCacheImageOutputStream(bos, null);
                } else {
                    ios = new MemoryCacheImageOutputStream(bos);
                }
                break;
            case OUTPUT_FILECHANNEL:
                FileOutputStream fos = new FileOutputStream((File)output);
                origStream = fos;
View Full Code Here

Examples of javax.imageio.stream.MemoryCacheImageOutputStream

    public ImageOutputStream createOutputStreamInstance(Object output, boolean useCache, File cacheDir) throws IOException {
        if (output instanceof OutputStream) {
            if (useCache) {
                return new FileCacheImageOutputStream((OutputStream) output, cacheDir);
            } else {
                return new MemoryCacheImageOutputStream((OutputStream) output);
            }
        }
        throw new IllegalArgumentException(Messages.getString("imageio.85"));
    }
View Full Code Here

Examples of javax.imageio.stream.MemoryCacheImageOutputStream

            if (formatName.toLowerCase().equals("jpeg") || formatName.toLowerCase().equals("jpg")) {
                iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                iwp.setCompressionQuality(compressionQuality);
            }

            MemoryCacheImageOutputStream output = new MemoryCacheImageOutputStream(bos);
            writer.setOutput(output);

            IIOImage iomage = new IIOImage(image, null,null);
            writer.write(null, iomage, iwp);
            bos.flush();
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.