Hi,

I'm just trying to implement tool processing full color RGB images
which also works with the pdf files and to load and save these images
it uses pdfbox. I've implemented class that does the reverse of
PDPixelMap, so it just stores raw compressed data into PDFStream.
Problem is that between the following piece of code and DeflateFilter
input it gots somehow mangled and the first 32 bytes are changed to
something else (but constant values) and I'm unable to track where
exactly. Any ideas?

public PDDeflate(PDDocument doc, BufferedImage bi) throws IOException {
        super(new PDStream(doc), "rawlzw");

        COSDictionary dic = getCOSStream();

        dic.setItem(COSName.FILTER, COSName.FLATE_DECODE);
        dic.setItem(COSName.SUBTYPE, COSName.IMAGE);
        dic.setItem(COSName.TYPE, COSName.getPDFName("XObject"));

        getCOSStream().setFilters(COSName.FLATE_DECODE);

        java.io.OutputStream os = getCOSStream().createUnfilteredStream();

        // optimize - not efficient enough - few ms can be saved ...
        byte[] imageData = ((DataBufferByte)
                bi.getRaster().getDataBuffer()).getData();
        byte[] data = new byte[imageData.length];

        System.arraycopy(imageData, 0, data, 0, data.length);

        for (int i = 0; i < data.length-1; i += 3) {
            byte tmp = data[i+2];
            data[i+2] = data[i];
            data[i] = tmp;
        }

        os.write(data);

        ColorModel cm = bi.getColorModel();
        ColorSpace cs = cm.getColorSpace();

        PDColorSpace pdColorSpace =
PDColorSpaceFactory.createColorSpace(doc, cs);
        setColorSpace(pdColorSpace);
        setBitsPerComponent(8);
        setWidth(bi.getWidth());
        setHeight(bi.getHeight());

    }

Reply via email to