当前位置: 首页 > 工具软件 > JPEXS > 使用案例 >

Jpexs分析

张腾
2023-12-01

DefineBitsLossLess2Tag.java

    public byte[] getData() {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        OutputStream os = baos;
        SWFOutputStream sos = new SWFOutputStream(os, getVersion());
        try {
            sos.writeUI16(characterID);
            sos.writeUI8(bitmapFormat);
            sos.writeUI16(bitmapWidth);
            sos.writeUI16(bitmapHeight);
            if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) {
                sos.writeUI8(bitmapColorTableSize);
            }
            sos.write(zlibBitmapData);
        } catch (IOException e) {
            throw new Error("This should never happen.", e);
        }
        return baos.toByteArray();
    }

Tag.java中调用上述函数

    public void writeTag(SWFOutputStream sos) throws IOException {
        if (isModified()) {
            byte[] newData = getData();
            byte[] newHeaderData = getHeader(newData);
            sos.write(newHeaderData);
            sos.write(newData);
        } else {
            sos.write(originalRange.getArray(), originalRange.getPos(), originalRange.getLength());
        }
    }

SWFOutputStream.java中调用上述函数

    public void writeTags(List<Tag> tags) throws IOException {
        for (Tag tag : tags) {
            tag.writeTag(this);
        }
    }


SWF.java中调用上述函数

    public void saveTo(OutputStream os, SWFCompression compression) throws IOException {
        try {
            fixCharactersOrder(false);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            SWFOutputStream sos = new SWFOutputStream(baos, version);
            sos.writeRECT(displayRect);
            sos.writeUI8(0);
            sos.writeUI8(frameRate);
            sos.writeUI16(frameCount);

            sos.writeTags(tags);
            if (hasEndTag) {
                sos.writeUI16(0);
            }
            sos.close();
            os.write(Utf8Helper.getBytes(getHeaderBytes(compression, gfx)));
            os.write(version);
            byte[] data = baos.toByteArray();
            sos = new SWFOutputStream(os, version);
            sos.writeUI32(data.length + 8);

            if (compression == SWFCompression.LZMA || compression == SWFCompression.LZMA_ABC) {
                long uncompressedLength = data.length;
                Encoder enc = new Encoder();
                int val = lzmaProperties[0] & 0xFF;
                int lc = val % 9;
                int remainder = val / 9;
                int lp = remainder % 5;
                int pb = remainder / 5;
                int dictionarySize = 0;
                for (int i = 0; i < 4; i++) {
                    dictionarySize += ((int) (lzmaProperties[1 + i]) & 0xFF) << (i * 8);
                }
                if (Configuration.lzmaFastBytes.get() > 0) {
                    enc.SetNumFastBytes(Configuration.lzmaFastBytes.get());
                }
                enc.SetDictionarySize(dictionarySize);
                enc.SetLcLpPb(lc, lp, pb);
                baos = new ByteArrayOutputStream();
                enc.SetEndMarkerMode(true);
                enc.Code(new ByteArrayInputStream(data), baos, -1, -1, null);
                data = baos.toByteArray();
                if (compression == SWFCompression.LZMA) {
                    byte[] udata = new byte[4];
                    udata[0] = (byte) (data.length & 0xFF);
                    udata[1] = (byte) ((data.length >> 8) & 0xFF);
                    udata[2] = (byte) ((data.length >> 16) & 0xFF);
                    udata[3] = (byte) ((data.length >> 24) & 0xFF);
                    os.write(udata);
                }
                enc.WriteCoderProperties(os);
                if (compression == SWFCompression.LZMA_ABC) {
                    byte[] udata = new byte[8];
                    udata[0] = (byte) (uncompressedLength & 0xFF);
                    udata[1] = (byte) ((uncompressedLength >> 8) & 0xFF);
                    udata[2] = (byte) ((uncompressedLength >> 16) & 0xFF);
                    udata[3] = (byte) ((uncompressedLength >> 24) & 0xFF);
                    udata[4] = (byte) ((uncompressedLength >> 32) & 0xFF);
                    udata[5] = (byte) ((uncompressedLength >> 40) & 0xFF);
                    udata[6] = (byte) ((uncompressedLength >> 48) & 0xFF);
                    udata[7] = (byte) ((uncompressedLength >> 56) & 0xFF);
                    os.write(udata);
                }
            } else if (compression == SWFCompression.ZLIB) {
                os = new DeflaterOutputStream(os);
            }
            os.write(data);
        } finally {
            if (os != null) {
                os.close();
            }
        }
    }


 类似资料: