FileDocCategorySizeDatePackage
PICT.javaAPI DocApache Poi 3.0.14081Thu May 31 18:45:28 BST 2007org.apache.poi.hslf.blip

PICT

public class PICT extends Metafile
Represents Macintosh PICT picture data.
author
Yegor Kozlov

Fields Summary
Constructors Summary
public PICT()

        super();
    
Methods Summary
public byte[]getData()
Extract compressed PICT data from a ppt

        byte[] rawdata = getRawData();
        try {
            byte[] macheader = new byte[512];
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            out.write(macheader);
            int pos = CHECKSUM_SIZE;
            byte[] pict;
            try {
                pict = read(rawdata, pos);
            } catch (IOException e){
                //weird MAC behaviour.
                //if failed to read right after the checksum - skip 16 bytes and try again
                pict = read(rawdata, pos + 16);
            }
            out.write(pict);
            return out.toByteArray();
        } catch (IOException e){
            throw new HSLFException(e);
        }
    
public intgetSignature()
PICT signature is 0x5430

return
PICT signature (0x5430)

        return 0x5430;
    
public intgetType()

see
org.apache.poi.hslf.model.Picture#PICT

        return Picture.PICT;
    
private byte[]read(byte[] data, int pos)

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ByteArrayInputStream bis = new ByteArrayInputStream(data);
        Header header = new Header();
        header.read(data, pos);
        bis.skip(pos + header.getSize());
        InflaterInputStream inflater = new InflaterInputStream( bis );
        byte[] chunk = new byte[4096];
        int count;
        while ((count = inflater.read(chunk)) >=0 ) {
            out.write(chunk,0,count);
        }
        inflater.close();
        return out.toByteArray();
    
public voidsetData(byte[] data)

        int pos = 512; //skip the first 512 bytes - they are MAC specific crap
        byte[] compressed = compress(data, pos, data.length-pos);

        Header header = new Header();
        header.wmfsize = data.length - 512;
        //we don't have a PICT reader in java, have to set default image size  200x200
        header.bounds = new java.awt.Rectangle(0, 0, 200, 200);
        header.size = new java.awt.Dimension(header.bounds.width*Shape.EMU_PER_POINT,
                header.bounds.height*Shape.EMU_PER_POINT);
        header.zipsize = compressed.length;

        byte[] checksum = getChecksum(data);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        out.write(checksum);

        out.write(new byte[16]); //16-byte prefix which is safe to ignore
        header.write(out);
        out.write(compressed);

        setRawData(out.toByteArray());