Node.js swf extraction definebitslossless2 incorrect pixels

Hello all,
I made an library to extract images and binary (.bin files) from an SWF File.

But for DefineBitsLossless2 tag (PNG images with alpha), I have a problem: some pixels aren’t at their right place, but the others are OK.

Here’s my current code (written in Typescript) using Jimp (http://npmjs.com/package/jimp) library for image manipulation (I also tried node-canvas, same thing)

private async DefineBitsLossless2(buff: SWFBuffer, tag: any, tagHeader: any, Callback: Function) {
        var id     = buff.readUIntLE(16);
        var format = buff.readUInt8();
        var width  = buff.readUIntLE(16);
        var height = buff.readUIntLE(16);

        var data   = buff.buffer.slice(buff.pointer, (buff.pointer + tagHeader.length) - 7);
                     buff.addPointer(tagHeader.length - 7);

        if(format != 5) {
            throw new Error(`Unsupported DefineBitsLossless2 image format. Only format 5 is supported, got format ${format}`);
        }
        
        var GZBuffer = this.concatSWFHeader(zlib.unzipSync(data), data);
        var image    = await new Jimp(width, height);
        var position = 0;

        for(var y = 0; y < height; y++) {
            for(var x = 0; x < width; x++) {
                var alpha = GZBuffer.readUInt8(position++);
				var red   = GZBuffer.readUInt8(position++);
				var green = GZBuffer.readUInt8(position++);
				var blue  = GZBuffer.readUInt8(position++);

                image.setPixelColor(Jimp.rgbaToInt(red, green, blue, alpha), x, y);
            }
        }

        image.getBuffer(Jimp.MIME_PNG, function(err, buffer) {
            tag.id     = id;
            tag.format = format;
            tag.width  = width;
            tag.height = height;
            tag.data   = buffer;
            Callback(null);
        });
    } 



private concatSWFHeader(buff: Buffer, swf: Buffer) {
    return Buffer.concat([swf.slice(0, 8), buff]);
}

Here’s the result of this SWF that I used for test pruposes:

Using my library:


Using FFDec (Free Flash Decompiler in Java)

https://i.imgur.com/cUiB8D3.png

What’s wrong with my code?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.