mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-27 20:50:46 +00:00
image tag refactorings/fixes
This commit is contained in:
@@ -45,20 +45,50 @@ public class DefineBitsJPEG2Tag extends ImageTag implements AloneTag {
|
||||
|
||||
public static final String NAME = "DefineBitsJPEG2";
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
public int characterID;
|
||||
|
||||
@SWFType(BasicType.UI8)
|
||||
public ByteArrayRange imageData;
|
||||
|
||||
@Override
|
||||
public int getCharacterId() {
|
||||
return characterID;
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param swf
|
||||
*/
|
||||
public DefineBitsJPEG2Tag(SWF swf) {
|
||||
super(swf, ID, NAME, null);
|
||||
characterID = swf.getNextCharacterId();
|
||||
imageData = ByteArrayRange.EMPTY;
|
||||
forceWriteAsLong = true;
|
||||
}
|
||||
|
||||
public DefineBitsJPEG2Tag(SWF swf, ByteArrayRange data, int characterID, byte[] imageData) throws IOException {
|
||||
super(swf, ID, NAME, data);
|
||||
this.characterID = characterID;
|
||||
this.imageData = new ByteArrayRange(imageData);
|
||||
}
|
||||
|
||||
public DefineBitsJPEG2Tag(SWFInputStream sis, ByteArrayRange data) throws IOException {
|
||||
super(sis.getSwf(), ID, NAME, data);
|
||||
readData(sis, data, 0, false, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCharacterId(int characterId) {
|
||||
this.characterID = characterId;
|
||||
public final void readData(SWFInputStream sis, ByteArrayRange data, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) throws IOException {
|
||||
characterID = sis.readUI16("characterID");
|
||||
imageData = sis.readByteRangeEx(sis.available(), "imageData");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getData() {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
OutputStream os = baos;
|
||||
SWFOutputStream sos = new SWFOutputStream(os, getVersion());
|
||||
try {
|
||||
sos.writeUI16(characterID);
|
||||
sos.write(imageData);
|
||||
} catch (IOException e) {
|
||||
throw new Error("This should never happen.", e);
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,52 +123,10 @@ public class DefineBitsJPEG2Tag extends ImageTag implements AloneTag {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param swf
|
||||
*/
|
||||
public DefineBitsJPEG2Tag(SWF swf) {
|
||||
super(swf, ID, NAME, null);
|
||||
characterID = swf.getNextCharacterId();
|
||||
imageData = ByteArrayRange.EMPTY;
|
||||
}
|
||||
|
||||
public DefineBitsJPEG2Tag(SWFInputStream sis, ByteArrayRange data) throws IOException {
|
||||
super(sis.getSwf(), ID, NAME, data);
|
||||
readData(sis, data, 0, false, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void readData(SWFInputStream sis, ByteArrayRange data, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) throws IOException {
|
||||
characterID = sis.readUI16("characterID");
|
||||
imageData = sis.readByteRangeEx(sis.available(), "imageData");
|
||||
}
|
||||
|
||||
public DefineBitsJPEG2Tag(SWF swf, ByteArrayRange data, int characterID, byte[] imageData) throws IOException {
|
||||
super(swf, ID, NAME, data);
|
||||
this.characterID = characterID;
|
||||
this.imageData = new ByteArrayRange(imageData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setImage(byte[] data) {
|
||||
imageData = new ByteArrayRange(data);
|
||||
clearCache();
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getData() {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
OutputStream os = baos;
|
||||
SWFOutputStream sos = new SWFOutputStream(os, getVersion());
|
||||
try {
|
||||
sos.writeUI16(characterID);
|
||||
sos.write(imageData);
|
||||
} catch (IOException e) {
|
||||
throw new Error("This should never happen.", e);
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,23 +46,64 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
|
||||
public static final String NAME = "DefineBitsJPEG3";
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
public int characterID;
|
||||
|
||||
@SWFType(BasicType.UI8)
|
||||
public ByteArrayRange imageData;
|
||||
|
||||
@SWFType(BasicType.UI8)
|
||||
public byte[] bitmapAlphaData;
|
||||
public ByteArrayRange bitmapAlphaData;
|
||||
|
||||
@Override
|
||||
public int getCharacterId() {
|
||||
return characterID;
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param swf
|
||||
*/
|
||||
public DefineBitsJPEG3Tag(SWF swf) {
|
||||
super(swf, ID, NAME, null);
|
||||
characterID = swf.getNextCharacterId();
|
||||
imageData = new ByteArrayRange(createEmptyImage());
|
||||
bitmapAlphaData = ByteArrayRange.EMPTY;
|
||||
forceWriteAsLong = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param sis
|
||||
* @param data
|
||||
* @throws IOException
|
||||
*/
|
||||
public DefineBitsJPEG3Tag(SWFInputStream sis, ByteArrayRange data) throws IOException {
|
||||
super(sis.getSwf(), ID, NAME, data);
|
||||
readData(sis, data, 0, false, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCharacterId(int characterId) {
|
||||
this.characterID = characterId;
|
||||
public final void readData(SWFInputStream sis, ByteArrayRange data, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) throws IOException {
|
||||
characterID = sis.readUI16("characterID");
|
||||
long alphaDataOffset = sis.readUI32("alphaDataOffset");
|
||||
imageData = sis.readByteRangeEx(alphaDataOffset, "imageData");
|
||||
bitmapAlphaData = sis.readByteRangeEx(sis.available(), "bitmapAlphaData");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets data bytes
|
||||
*
|
||||
* @return Bytes of data
|
||||
*/
|
||||
@Override
|
||||
public byte[] getData() {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
OutputStream os = baos;
|
||||
SWFOutputStream sos = new SWFOutputStream(os, getVersion());
|
||||
try {
|
||||
sos.writeUI16(characterID);
|
||||
sos.writeUI32(imageData.getLength());
|
||||
sos.write(imageData);
|
||||
sos.write(bitmapAlphaData);
|
||||
} catch (IOException e) {
|
||||
throw new Error("This should never happen.", e);
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
private byte[] createEmptyImage() {
|
||||
@@ -80,10 +121,12 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
for (int i = 0; i < ba.length; i++) {
|
||||
ba[i] = (byte) 255;
|
||||
}
|
||||
bitmapAlphaData = ba;
|
||||
|
||||
bitmapAlphaData = new ByteArrayRange(SWFOutputStream.compressByteArray(ba));
|
||||
} else {
|
||||
bitmapAlphaData = new byte[0];
|
||||
bitmapAlphaData = ByteArrayRange.EMPTY;
|
||||
}
|
||||
|
||||
imageData = new ByteArrayRange(data);
|
||||
clearCache();
|
||||
setModified(true);
|
||||
@@ -117,14 +160,15 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
}
|
||||
|
||||
SerializableImage img = new SerializableImage(image);
|
||||
if (bitmapAlphaData.length == 0) {
|
||||
if (bitmapAlphaData.getLength() == 0) {
|
||||
cachedImage = img;
|
||||
return img;
|
||||
}
|
||||
|
||||
byte[] alphaData = SWFInputStream.uncompressByteArray(bitmapAlphaData.getRangeData());
|
||||
int[] pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
int a = bitmapAlphaData[i] & 0xff;
|
||||
int a = alphaData[i] & 0xff;
|
||||
pixels[i] = multiplyAlpha((pixels[i] & 0xffffff) | (a << 24));
|
||||
}
|
||||
|
||||
@@ -135,50 +179,4 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param swf
|
||||
*/
|
||||
public DefineBitsJPEG3Tag(SWF swf) {
|
||||
super(swf, ID, NAME, null);
|
||||
characterID = swf.getNextCharacterId();
|
||||
imageData = ByteArrayRange.EMPTY;
|
||||
bitmapAlphaData = new byte[0];
|
||||
}
|
||||
|
||||
public DefineBitsJPEG3Tag(SWFInputStream sis, ByteArrayRange data) throws IOException {
|
||||
super(sis.getSwf(), ID, NAME, data);
|
||||
readData(sis, data, 0, false, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void readData(SWFInputStream sis, ByteArrayRange data, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) throws IOException {
|
||||
characterID = sis.readUI16("characterID");
|
||||
long alphaDataOffset = sis.readUI32("alphaDataOffset");
|
||||
imageData = sis.readByteRangeEx(alphaDataOffset, "imageData");
|
||||
bitmapAlphaData = sis.readBytesZlib(sis.available(), "bitmapAlphaData");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets data bytes
|
||||
*
|
||||
* @return Bytes of data
|
||||
*/
|
||||
@Override
|
||||
public byte[] getData() {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
OutputStream os = baos;
|
||||
SWFOutputStream sos = new SWFOutputStream(os, getVersion());
|
||||
try {
|
||||
sos.writeUI16(characterID);
|
||||
sos.writeUI32(imageData.getLength());
|
||||
sos.write(imageData);
|
||||
sos.writeBytesZlib(bitmapAlphaData);
|
||||
} catch (IOException e) {
|
||||
throw new Error("This should never happen.", e);
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +46,6 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
|
||||
|
||||
public static final String NAME = "DefineBitsJPEG4";
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
public int characterID;
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
public int deblockParam;
|
||||
|
||||
@@ -58,86 +55,6 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
|
||||
@SWFType(BasicType.UI8)
|
||||
public ByteArrayRange bitmapAlphaData;
|
||||
|
||||
@Override
|
||||
public int getCharacterId() {
|
||||
return characterID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCharacterId(int characterId) {
|
||||
this.characterID = characterId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImageFormat() {
|
||||
String fmt = ImageTag.getImageFormat(imageData);
|
||||
if (fmt.equals("jpg")) {
|
||||
fmt = "png"; //transparency
|
||||
}
|
||||
return fmt;
|
||||
}
|
||||
|
||||
private byte[] createEmptyImage() {
|
||||
BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
|
||||
ByteArrayOutputStream bitmapDataOS = new ByteArrayOutputStream();
|
||||
ImageHelper.write(img, "JPG", bitmapDataOS);
|
||||
return bitmapDataOS.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setImage(byte[] data) {
|
||||
imageData = new ByteArrayRange(data);
|
||||
if (ImageTag.getImageFormat(data).equals("jpg")) {
|
||||
SerializableImage image = getImage();
|
||||
byte[] ba = new byte[image.getWidth() * image.getHeight()];
|
||||
for (int i = 0; i < ba.length; i++) {
|
||||
ba[i] = (byte) 255;
|
||||
}
|
||||
bitmapAlphaData = new ByteArrayRange(ba);
|
||||
} else {
|
||||
bitmapAlphaData = ByteArrayRange.EMPTY;
|
||||
}
|
||||
clearCache();
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getImageData() {
|
||||
return new ByteArrayInputStream(imageData.getArray(), imageData.getPos(), imageData.getLength());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SerializableImage getImage() {
|
||||
if (cachedImage != null) {
|
||||
return cachedImage;
|
||||
}
|
||||
try {
|
||||
BufferedImage image = ImageHelper.read(getImageData());
|
||||
if (image == null) {
|
||||
Logger.getLogger(DefineBitsJPEG4Tag.class.getName()).log(Level.SEVERE, "Failed to load image");
|
||||
return null;
|
||||
}
|
||||
|
||||
SerializableImage img = new SerializableImage(image);
|
||||
if (bitmapAlphaData.getLength() == 0) {
|
||||
cachedImage = img;
|
||||
return img;
|
||||
}
|
||||
|
||||
int[] pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
int a = bitmapAlphaData.get(i) & 0xff;
|
||||
pixels[i] = multiplyAlpha((pixels[i] & 0xffffff) | (a << 24));
|
||||
}
|
||||
|
||||
cachedImage = img;
|
||||
return img;
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(DefineBitsJPEG4Tag.class.getName()).log(Level.SEVERE, "Failed to get image", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -148,6 +65,7 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
|
||||
characterID = swf.getNextCharacterId();
|
||||
imageData = new ByteArrayRange(createEmptyImage());
|
||||
bitmapAlphaData = ByteArrayRange.EMPTY;
|
||||
forceWriteAsLong = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,4 +110,77 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
private byte[] createEmptyImage() {
|
||||
BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
|
||||
ByteArrayOutputStream bitmapDataOS = new ByteArrayOutputStream();
|
||||
ImageHelper.write(img, "JPG", bitmapDataOS);
|
||||
return bitmapDataOS.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setImage(byte[] data) throws IOException {
|
||||
if (ImageTag.getImageFormat(data).equals("jpg")) {
|
||||
SerializableImage image = new SerializableImage(ImageHelper.read(data));
|
||||
byte[] ba = new byte[image.getWidth() * image.getHeight()];
|
||||
for (int i = 0; i < ba.length; i++) {
|
||||
ba[i] = (byte) 255;
|
||||
}
|
||||
|
||||
bitmapAlphaData = new ByteArrayRange(SWFOutputStream.compressByteArray(ba));
|
||||
} else {
|
||||
bitmapAlphaData = ByteArrayRange.EMPTY;
|
||||
}
|
||||
|
||||
imageData = new ByteArrayRange(data);
|
||||
clearCache();
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImageFormat() {
|
||||
String fmt = ImageTag.getImageFormat(imageData);
|
||||
if (fmt.equals("jpg")) {
|
||||
fmt = "png"; //transparency
|
||||
}
|
||||
return fmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getImageData() {
|
||||
return new ByteArrayInputStream(imageData.getArray(), imageData.getPos(), imageData.getLength());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SerializableImage getImage() {
|
||||
if (cachedImage != null) {
|
||||
return cachedImage;
|
||||
}
|
||||
try {
|
||||
BufferedImage image = ImageHelper.read(getImageData());
|
||||
if (image == null) {
|
||||
Logger.getLogger(DefineBitsJPEG4Tag.class.getName()).log(Level.SEVERE, "Failed to load image");
|
||||
return null;
|
||||
}
|
||||
|
||||
SerializableImage img = new SerializableImage(image);
|
||||
if (bitmapAlphaData.getLength() == 0) {
|
||||
cachedImage = img;
|
||||
return img;
|
||||
}
|
||||
|
||||
byte[] alphaData = SWFInputStream.uncompressByteArray(bitmapAlphaData.getRangeData());
|
||||
int[] pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
int a = alphaData[i] & 0xff;
|
||||
pixels[i] = multiplyAlpha((pixels[i] & 0xffffff) | (a << 24));
|
||||
}
|
||||
|
||||
cachedImage = img;
|
||||
return img;
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(DefineBitsJPEG4Tag.class.getName()).log(Level.SEVERE, "Failed to get image", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,9 +52,6 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
|
||||
public static final String NAME = "DefineBitsLossless2";
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
public int characterID;
|
||||
|
||||
@SWFType(BasicType.UI8)
|
||||
public int bitmapFormat;
|
||||
|
||||
@@ -83,14 +80,61 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
@Internal
|
||||
private boolean decompressed = false;
|
||||
|
||||
@Override
|
||||
public int getCharacterId() {
|
||||
return characterID;
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param swf
|
||||
*/
|
||||
public DefineBitsLossless2Tag(SWF swf) {
|
||||
super(swf, ID, NAME, null);
|
||||
characterID = swf.getNextCharacterId();
|
||||
bitmapFormat = DefineBitsLossless2Tag.FORMAT_32BIT_ARGB;
|
||||
bitmapWidth = 1;
|
||||
bitmapHeight = 1;
|
||||
zlibBitmapData = new ByteArrayRange(createEmptyImage());
|
||||
forceWriteAsLong = true;
|
||||
}
|
||||
|
||||
public DefineBitsLossless2Tag(SWFInputStream sis, ByteArrayRange data) throws IOException {
|
||||
super(sis.getSwf(), ID, NAME, data);
|
||||
readData(sis, data, 0, false, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCharacterId(int characterId) {
|
||||
this.characterID = characterId;
|
||||
public final void readData(SWFInputStream sis, ByteArrayRange data, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) throws IOException {
|
||||
characterID = sis.readUI16("characterID");
|
||||
bitmapFormat = sis.readUI8("bitmapFormat");
|
||||
bitmapWidth = sis.readUI16("bitmapWidth");
|
||||
bitmapHeight = sis.readUI16("bitmapHeight");
|
||||
if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) {
|
||||
bitmapColorTableSize = sis.readUI8("bitmapColorTableSize");
|
||||
}
|
||||
zlibBitmapData = sis.readByteRangeEx(sis.available(), "zlibBitmapData");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets data bytes
|
||||
*
|
||||
* @return Bytes of data
|
||||
*/
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
|
||||
private byte[] createEmptyImage() {
|
||||
@@ -148,37 +192,6 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param swf
|
||||
*/
|
||||
public DefineBitsLossless2Tag(SWF swf) {
|
||||
super(swf, ID, NAME, null);
|
||||
characterID = swf.getNextCharacterId();
|
||||
bitmapFormat = DefineBitsLossless2Tag.FORMAT_32BIT_ARGB;
|
||||
bitmapWidth = 1;
|
||||
bitmapHeight = 1;
|
||||
zlibBitmapData = new ByteArrayRange(createEmptyImage());
|
||||
}
|
||||
|
||||
public DefineBitsLossless2Tag(SWFInputStream sis, ByteArrayRange data) throws IOException {
|
||||
super(sis.getSwf(), ID, NAME, data);
|
||||
readData(sis, data, 0, false, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void readData(SWFInputStream sis, ByteArrayRange data, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) throws IOException {
|
||||
characterID = sis.readUI16("characterID");
|
||||
bitmapFormat = sis.readUI8("bitmapFormat");
|
||||
bitmapWidth = sis.readUI16("bitmapWidth");
|
||||
bitmapHeight = sis.readUI16("bitmapHeight");
|
||||
if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) {
|
||||
bitmapColorTableSize = sis.readUI8("bitmapColorTableSize");
|
||||
}
|
||||
zlibBitmapData = sis.readByteRangeEx(sis.available(), "zlibBitmapData");
|
||||
}
|
||||
|
||||
public ALPHACOLORMAPDATA getColorMapData() {
|
||||
if (!decompressed) {
|
||||
uncompressData();
|
||||
@@ -207,31 +220,6 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
decompressed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets data bytes
|
||||
*
|
||||
* @return Bytes of data
|
||||
*/
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImageFormat() {
|
||||
return "png";
|
||||
|
||||
@@ -52,9 +52,6 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
|
||||
|
||||
public static final String NAME = "DefineBitsLossless";
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
public int characterID;
|
||||
|
||||
@SWFType(BasicType.UI8)
|
||||
public int bitmapFormat;
|
||||
|
||||
@@ -85,6 +82,63 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
|
||||
@Internal
|
||||
private boolean decompressed = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param swf
|
||||
*/
|
||||
public DefineBitsLosslessTag(SWF swf) {
|
||||
super(swf, ID, NAME, null);
|
||||
characterID = swf.getNextCharacterId();
|
||||
bitmapFormat = DefineBitsLosslessTag.FORMAT_24BIT_RGB;
|
||||
bitmapWidth = 1;
|
||||
bitmapHeight = 1;
|
||||
zlibBitmapData = new ByteArrayRange(createEmptyImage());
|
||||
forceWriteAsLong = true;
|
||||
}
|
||||
|
||||
public DefineBitsLosslessTag(SWFInputStream sis, ByteArrayRange data) throws IOException {
|
||||
super(sis.getSwf(), ID, NAME, data);
|
||||
readData(sis, data, 0, false, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void readData(SWFInputStream sis, ByteArrayRange data, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) throws IOException {
|
||||
characterID = sis.readUI16("characterID");
|
||||
bitmapFormat = sis.readUI8("bitmapFormat");
|
||||
bitmapWidth = sis.readUI16("bitmapWidth");
|
||||
bitmapHeight = sis.readUI16("bitmapHeight");
|
||||
if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) {
|
||||
bitmapColorTableSize = sis.readUI8("bitmapColorTableSize");
|
||||
}
|
||||
zlibBitmapData = sis.readByteRangeEx(sis.available(), "zlibBitmapData");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets data bytes
|
||||
*
|
||||
* @return Bytes of data
|
||||
*/
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
|
||||
private byte[] createEmptyImage() {
|
||||
try {
|
||||
BITMAPDATA bitmapData = new BITMAPDATA();
|
||||
@@ -188,16 +242,6 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
|
||||
return bi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCharacterId() {
|
||||
return characterID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCharacterId(int characterId) {
|
||||
this.characterID = characterId;
|
||||
}
|
||||
|
||||
public COLORMAPDATA getColorMapData() {
|
||||
if (!decompressed) {
|
||||
uncompressData();
|
||||
@@ -226,62 +270,6 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
|
||||
decompressed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param swf
|
||||
*/
|
||||
public DefineBitsLosslessTag(SWF swf) {
|
||||
super(swf, ID, NAME, null);
|
||||
characterID = swf.getNextCharacterId();
|
||||
bitmapFormat = DefineBitsLosslessTag.FORMAT_24BIT_RGB;
|
||||
bitmapWidth = 1;
|
||||
bitmapHeight = 1;
|
||||
zlibBitmapData = new ByteArrayRange(createEmptyImage());
|
||||
}
|
||||
|
||||
public DefineBitsLosslessTag(SWFInputStream sis, ByteArrayRange data) throws IOException {
|
||||
super(sis.getSwf(), ID, NAME, data);
|
||||
readData(sis, data, 0, false, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void readData(SWFInputStream sis, ByteArrayRange data, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) throws IOException {
|
||||
characterID = sis.readUI16("characterID");
|
||||
bitmapFormat = sis.readUI8("bitmapFormat");
|
||||
bitmapWidth = sis.readUI16("bitmapWidth");
|
||||
bitmapHeight = sis.readUI16("bitmapHeight");
|
||||
if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) {
|
||||
bitmapColorTableSize = sis.readUI8("bitmapColorTableSize");
|
||||
}
|
||||
zlibBitmapData = sis.readByteRangeEx(sis.available(), "zlibBitmapData");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets data bytes
|
||||
*
|
||||
* @return Bytes of data
|
||||
*/
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImageFormat() {
|
||||
return "png";
|
||||
|
||||
@@ -43,9 +43,6 @@ public class DefineBitsTag extends ImageTag implements TagChangedListener {
|
||||
|
||||
public static final String NAME = "DefineBits";
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
public int characterID;
|
||||
|
||||
@SWFType(BasicType.UI8)
|
||||
public ByteArrayRange jpegData;
|
||||
|
||||
@@ -69,6 +66,7 @@ public class DefineBitsTag extends ImageTag implements TagChangedListener {
|
||||
super(swf, ID, NAME, null);
|
||||
characterID = swf.getNextCharacterId();
|
||||
jpegData = ByteArrayRange.EMPTY;
|
||||
forceWriteAsLong = true;
|
||||
}
|
||||
|
||||
public DefineBitsTag(SWFInputStream sis, ByteArrayRange data) throws IOException {
|
||||
@@ -82,6 +80,25 @@ public class DefineBitsTag extends ImageTag implements TagChangedListener {
|
||||
jpegData = sis.readByteRangeEx(sis.available(), "jpegData");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets data bytes
|
||||
*
|
||||
* @return Bytes of data
|
||||
*/
|
||||
@Override
|
||||
public byte[] getData() {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
OutputStream os = baos;
|
||||
SWFOutputStream sos = new SWFOutputStream(os, getVersion());
|
||||
try {
|
||||
sos.writeUI16(characterID);
|
||||
sos.write(jpegData);
|
||||
} catch (IOException e) {
|
||||
throw new Error("This should never happen.", e);
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getImageData() {
|
||||
return null;
|
||||
@@ -119,35 +136,6 @@ public class DefineBitsTag extends ImageTag implements TagChangedListener {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets data bytes
|
||||
*
|
||||
* @return Bytes of data
|
||||
*/
|
||||
@Override
|
||||
public byte[] getData() {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
OutputStream os = baos;
|
||||
SWFOutputStream sos = new SWFOutputStream(os, getVersion());
|
||||
try {
|
||||
sos.writeUI16(characterID);
|
||||
sos.write(jpegData);
|
||||
} catch (IOException e) {
|
||||
throw new Error("This should never happen.", e);
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCharacterId() {
|
||||
return characterID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCharacterId(int characterId) {
|
||||
this.characterID = characterId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImageFormat() {
|
||||
return "jpg";
|
||||
@@ -155,6 +143,7 @@ public class DefineBitsTag extends ImageTag implements TagChangedListener {
|
||||
|
||||
@Override
|
||||
public void handleEvent(Tag tag) {
|
||||
// cache should be cleared when Jtt tag changes
|
||||
clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter;
|
||||
import com.jpexs.decompiler.flash.exporters.shape.BitmapExporter;
|
||||
import com.jpexs.decompiler.flash.exporters.shape.CanvasShapeExporter;
|
||||
import com.jpexs.decompiler.flash.exporters.shape.SVGShapeExporter;
|
||||
import com.jpexs.decompiler.flash.types.BasicType;
|
||||
import com.jpexs.decompiler.flash.types.ColorTransform;
|
||||
import com.jpexs.decompiler.flash.types.FILLSTYLE;
|
||||
import com.jpexs.decompiler.flash.types.FILLSTYLEARRAY;
|
||||
@@ -31,6 +32,7 @@ import com.jpexs.decompiler.flash.types.MATRIX;
|
||||
import com.jpexs.decompiler.flash.types.RECT;
|
||||
import com.jpexs.decompiler.flash.types.RGBA;
|
||||
import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE;
|
||||
import com.jpexs.decompiler.flash.types.annotations.SWFType;
|
||||
import com.jpexs.decompiler.flash.types.shaperecords.EndShapeRecord;
|
||||
import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord;
|
||||
import com.jpexs.decompiler.flash.types.shaperecords.StyleChangeRecord;
|
||||
@@ -48,6 +50,9 @@ import java.util.Set;
|
||||
*/
|
||||
public abstract class ImageTag extends CharacterTag implements DrawableTag {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
public int characterID;
|
||||
|
||||
protected SerializableImage cachedImage;
|
||||
|
||||
public ImageTag(SWF swf, int id, String name, ByteArrayRange data) {
|
||||
@@ -239,4 +244,14 @@ public abstract class ImageTag extends CharacterTag implements DrawableTag {
|
||||
public void clearCache() {
|
||||
cachedImage = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCharacterId() {
|
||||
return characterID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCharacterId(int characterId) {
|
||||
this.characterID = characterId;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user