I made an library to extract images and binary (
.bin
DefineBitsLossless2
PNG
Typescript
node-canvas
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]);
}
144
DefineBitsLossless2
I believe this:
var GZBuffer = this.concatSWFHeader(zlib.unzipSync(data), data);
should instead be:
var GZBuffer = zlib.unzipSync(data);
Not sure what you were going for with concatSWFHeader
, but that would rather be part of the ZLIB header you're adding, and it should account for whole image being offset by 2 pixels.