node.js swf提取definebitslossless2不正确的像素
node.js swf extraction definebitslossless2 incorrect pixels
我制作了一个库来从 SWF 中提取 images 和 binary (.bin
) 数据 文件.
但是对于 DefineBitsLossless2
标签(PNG
带有 alpha 的图像),我遇到了一个问题:有些像素不在正确的位置,但其他的 OK.
这是我当前的代码(用 Typescript
编写)使用 Jimp 库进行图像处理(我也试过 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]);
}
这是我用于测试目的的 this SWF 结果:
使用我的图书馆:
使用 FFDec(Java 中的免费 Flash 反编译器)
我按照 this Adobe guide 创建了我的图书馆(请参阅 144
页面的 DefineBitsLossless2
标签)
我的代码有什么问题?
我相信:
var GZBuffer = this.concatSWFHeader(zlib.unzipSync(data), data);
应该改为:
var GZBuffer = zlib.unzipSync(data);
不确定您要使用 concatSWFHeader
做什么,但这更像是您要添加的 ZLIB header 的一部分,并且它应该考虑到整个图像被偏移 2 个像素.
我制作了一个库来从 SWF 中提取 images 和 binary (.bin
) 数据 文件.
但是对于 DefineBitsLossless2
标签(PNG
带有 alpha 的图像),我遇到了一个问题:有些像素不在正确的位置,但其他的 OK.
这是我当前的代码(用 Typescript
编写)使用 Jimp 库进行图像处理(我也试过 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]);
}
这是我用于测试目的的 this SWF 结果:
使用我的图书馆:
使用 FFDec(Java 中的免费 Flash 反编译器)
我按照 this Adobe guide 创建了我的图书馆(请参阅 144
页面的 DefineBitsLossless2
标签)
我的代码有什么问题?
我相信:
var GZBuffer = this.concatSWFHeader(zlib.unzipSync(data), data);
应该改为:
var GZBuffer = zlib.unzipSync(data);
不确定您要使用 concatSWFHeader
做什么,但这更像是您要添加的 ZLIB header 的一部分,并且它应该考虑到整个图像被偏移 2 个像素.