Issue #395 GFx tag fixes

This commit is contained in:
Jindra Pet��k
2013-09-23 20:04:19 +02:00
parent f07be3b21f
commit 691e91bbe4
4 changed files with 30 additions and 6 deletions
@@ -379,7 +379,7 @@ public class SWFOutputStream extends OutputStream {
int tagLength = data.length;
int tagID = tag.getId();
int tagIDLength = (tagID << 6);
if ((tagLength < 0x3f) && (!tag.forceWriteAsLong)) {
if ((tagLength <= 62) && (!tag.forceWriteAsLong)) {
tagIDLength += tagLength;
sos.writeUI16(tagIDLength);
} else {
@@ -105,7 +105,7 @@ public class GFxDefineCompactedFont extends FontTag implements DrawableTag {
* @return Bytes of data
*/
@Override
public byte[] getData(int version) {
public byte[] getData(int version) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream os = baos;
SWFOutputStream sos = new SWFOutputStream(os, version);
@@ -37,6 +37,7 @@ public class GFxDefineExternalImage2 extends Tag {
public int targetWidth;
public int targetHeight;
public String fileName;
public byte[] extraData; //?
public static final int BITMAP_FORMAT_DEFAULT = 0;
public static final int BITMAP_FORMAT_TGA = 1;
public static final int BITMAP_FORMAT_DDS = 2;
@@ -60,6 +61,9 @@ public class GFxDefineExternalImage2 extends Tag {
byte fileNameBytes[] = fileName.getBytes();
sos.writeUI8(fileNameBytes.length);
sos.write(fileNameBytes);
if (extraData != null) {
sos.write(extraData);
}
} catch (IOException e) {
}
return baos.toByteArray();
@@ -83,5 +87,8 @@ public class GFxDefineExternalImage2 extends Tag {
targetHeight = sis.readUI16();
int fileNameLen = sis.readUI8();
fileName = new String(sis.readBytes(fileNameLen));
if (sis.available() > 0) {
extraData = sis.readBytes(sis.available());
}
}
}
@@ -23,6 +23,8 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
/**
*
@@ -39,6 +41,7 @@ public class GFxExporterInfoTag extends Tag {
public int bitmapFormat;
public byte[] prefix;
public String swfName;
public List<Long> codeOffsets;
public static final int BITMAP_FORMAT_TGA = 1;
public static final int BITMAP_FORMAT_DDS = 2;
public static final int FLAG_CONTAINS_GLYPH_TEXTURES = 1;
@@ -57,8 +60,8 @@ public class GFxExporterInfoTag extends Tag {
OutputStream os = baos;
SWFOutputStream sos = new SWFOutputStream(os, version);
try {
sos.writeUI16(version);
if (version >= 0x10a) {
sos.writeUI16(this.version);
if (this.version >= 0x10a) {
sos.writeUI32(flags);
}
sos.writeUI16(bitmapFormat);
@@ -67,6 +70,12 @@ public class GFxExporterInfoTag extends Tag {
byte swfNameBytes[] = swfName.getBytes();
sos.writeUI8(swfNameBytes.length);
sos.write(swfNameBytes);
if (codeOffsets != null) {
sos.writeUI16(codeOffsets.size());
for (long l : codeOffsets) {
sos.writeUI32(l);
}
}
} catch (IOException e) {
}
return baos.toByteArray();
@@ -84,8 +93,8 @@ public class GFxExporterInfoTag extends Tag {
public GFxExporterInfoTag(SWF swf, byte[] data, int version, long pos) throws IOException {
super(swf, ID, "ExporterInfo", data, pos);
SWFInputStream sis = new SWFInputStream(new ByteArrayInputStream(data), version);
version = sis.readUI16();
if (version >= 0x10a) {
this.version = sis.readUI16();
if (this.version >= 0x10a) {
flags = sis.readUI32();
}
bitmapFormat = sis.readUI16();
@@ -93,5 +102,13 @@ public class GFxExporterInfoTag extends Tag {
prefix = sis.readBytes(prefixLen);
int swfNameLen = sis.readUI8();
swfName = new String(sis.readBytes(swfNameLen));
if (sis.available() > 0) // (version >= 0x401) //?
{
codeOffsets = new ArrayList<>();
int numCodeOffsets = sis.readUI16();
for (int i = 0; i < numCodeOffsets; i++) {
codeOffsets.add(sis.readUI32());
}
}
}
}