add new tag fixes 2

This commit is contained in:
honfika@gmail.com
2014-11-05 20:57:17 +01:00
parent 0035d7c7d9
commit e34ba41174
22 changed files with 166 additions and 33 deletions

View File

@@ -72,6 +72,7 @@ public class DefineBinaryDataTag extends CharacterTag {
public DefineBinaryDataTag(SWF swf) {
super(swf, ID, "DefineBinaryData", null);
tag = swf.getNextCharacterId();
binaryData = new byte[0];
}
public DefineBinaryDataTag(SWFInputStream sis, ByteArrayRange data) throws IOException {

View File

@@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.types.BasicType;
import com.jpexs.decompiler.flash.types.annotations.SWFType;
import com.jpexs.helpers.ByteArrayRange;
import com.jpexs.helpers.SerializableImage;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -63,7 +64,8 @@ public class DefineBitsJPEG2Tag extends ImageTag implements AloneTag {
@Override
public SerializableImage getImage() {
try {
return new SerializableImage(ImageIO.read(getImageData()));
BufferedImage image = ImageIO.read(getImageData());
return image == null ? null : new SerializableImage(image);
} catch (IOException ex) {
}
return null;

View File

@@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.types.BasicType;
import com.jpexs.decompiler.flash.types.annotations.SWFType;
import com.jpexs.helpers.ByteArrayRange;
import com.jpexs.helpers.SerializableImage;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -89,7 +90,8 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
} else {
stream = new ByteArrayInputStream(imageData);
}
SerializableImage img = new SerializableImage(ImageIO.read(stream));
BufferedImage image = ImageIO.read(stream);
SerializableImage img = image == null ? null : new SerializableImage(image);
if (bitmapAlphaData.length == 0) {
return img;
}
@@ -116,6 +118,7 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
super(swf, ID, "DefineBitsJPEG3", null);
characterID = swf.getNextCharacterId();
imageData = new byte[0];
bitmapAlphaData = new byte[0];
}
public DefineBitsJPEG3Tag(SWFInputStream sis, ByteArrayRange data) throws IOException {

View File

@@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.types.BasicType;
import com.jpexs.decompiler.flash.types.annotations.SWFType;
import com.jpexs.helpers.ByteArrayRange;
import com.jpexs.helpers.SerializableImage;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -91,7 +92,8 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
@Override
public SerializableImage getImage() {
try {
SerializableImage img = new SerializableImage(ImageIO.read(new ByteArrayInputStream(imageData)));
BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageData));
SerializableImage img = image == null ? null : new SerializableImage(image);
if (bitmapAlphaData.length == 0) {
return img;
}
@@ -140,6 +142,7 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
super(swf, ID, "DefineBitsJPEG4", null);
characterID = swf.getNextCharacterId();
imageData = new byte[0];
bitmapAlphaData = new byte[0];
}
/**

View File

@@ -36,6 +36,8 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.InflaterInputStream;
import javax.imageio.ImageIO;
@@ -69,11 +71,30 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
return characterID;
}
private byte[] createEmptyImage() {
try {
ALPHABITMAPDATA bitmapData = new ALPHABITMAPDATA();
bitmapData.bitmapPixelData = new ARGB[1];
bitmapData.bitmapPixelData[0] = new ARGB();
bitmapData.bitmapPixelData[0].alpha = 0xff;
ByteArrayOutputStream bitmapDataOS = new ByteArrayOutputStream();
SWFOutputStream sos = new SWFOutputStream(bitmapDataOS, getVersion());
sos.writeALPHABITMAPDATA(bitmapData, FORMAT_32BIT_ARGB, 1, 1);
ByteArrayOutputStream zlibOS = new ByteArrayOutputStream();
SWFOutputStream sos2 = new SWFOutputStream(zlibOS, getVersion());
sos2.writeBytesZlib(bitmapDataOS.toByteArray());
return zlibOS.toByteArray();
} catch (IOException ex) {
Logger.getLogger(DefineBitsLossless2Tag.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
@Override
public void setImage(byte[] data) throws IOException {
SerializableImage image = new SerializableImage(ImageIO.read(new ByteArrayInputStream(data)));
ALPHABITMAPDATA bitmapData = new ALPHABITMAPDATA();
bitmapFormat = DefineBitsLosslessTag.FORMAT_24BIT_RGB;
bitmapFormat = FORMAT_32BIT_ARGB;
bitmapWidth = image.getWidth();
bitmapHeight = image.getHeight();
bitmapData.bitmapPixelData = new ARGB[bitmapWidth * bitmapHeight];
@@ -116,8 +137,10 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
public DefineBitsLossless2Tag(SWF swf) {
super(swf, ID, "DefineBitsLossless2", null);
characterID = swf.getNextCharacterId();
bitmapFormat = DefineBitsLossless2Tag.FORMAT_32BIT_ARGB;
bitmapWidth = 1;
bitmapHeight = 1;
zlibBitmapData = createEmptyImage();
}
public DefineBitsLossless2Tag(SWFInputStream sis, ByteArrayRange data) throws IOException {

View File

@@ -38,6 +38,8 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.InflaterInputStream;
import javax.imageio.ImageIO;
@@ -73,6 +75,25 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
public static final int ID = 20;
private byte[] createEmptyImage() {
try {
BITMAPDATA bitmapData = new BITMAPDATA();
bitmapData.bitmapPixelDataPix24 = new PIX24[1];
bitmapData.bitmapPixelDataPix24[0] = new PIX24();
bitmapData.bitmapPixelDataPix24[0].reserved = 0xff;
ByteArrayOutputStream bitmapDataOS = new ByteArrayOutputStream();
SWFOutputStream sos = new SWFOutputStream(bitmapDataOS, getVersion());
sos.writeBITMAPDATA(bitmapData, FORMAT_24BIT_RGB, 1, 1);
ByteArrayOutputStream zlibOS = new ByteArrayOutputStream();
SWFOutputStream sos2 = new SWFOutputStream(zlibOS, getVersion());
sos2.writeBytesZlib(bitmapDataOS.toByteArray());
return zlibOS.toByteArray();
} catch (IOException ex) {
Logger.getLogger(DefineBitsLosslessTag.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
@Override
public void setImage(byte[] data) throws IOException {
SerializableImage image = new SerializableImage(ImageIO.read(new ByteArrayInputStream(data)));
@@ -190,8 +211,10 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
public DefineBitsLosslessTag(SWF swf) {
super(swf, ID, "DefineBitsLossless", null);
characterID = swf.getNextCharacterId();
bitmapFormat = DefineBitsLosslessTag.FORMAT_24BIT_RGB;
bitmapWidth = 1;
bitmapHeight = 1;
zlibBitmapData = createEmptyImage();
}
public DefineBitsLosslessTag(SWFInputStream sis, ByteArrayRange data) throws IOException {

View File

@@ -102,7 +102,7 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
super(swf, ID, "DefineButton", null);
buttonId = swf.getNextCharacterId();
characters = new ArrayList<>();
actionBytes = new ByteArrayRange(new byte[0]);
actionBytes = new ByteArrayRange(new byte[] {0});
}
/**
@@ -118,7 +118,11 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
characters = sis.readBUTTONRECORDList(false, "characters");
int pos = (int) sis.getPos();
byte[] bytes = sis.readBytesEx(sis.available(), "actionBytes");
actionBytes = new ByteArrayRange(data.array, pos, bytes.length);
if (data != null) {
actionBytes = new ByteArrayRange(data.array, pos, bytes.length);
} else {
actionBytes = new ByteArrayRange(bytes, 0, bytes.length);
}
}
/**

View File

@@ -33,7 +33,9 @@ import com.jpexs.decompiler.flash.types.BasicType;
import com.jpexs.decompiler.flash.types.ColorTransform;
import com.jpexs.decompiler.flash.types.FILLSTYLEARRAY;
import com.jpexs.decompiler.flash.types.LINESTYLEARRAY;
import com.jpexs.decompiler.flash.types.MORPHFILLSTYLE;
import com.jpexs.decompiler.flash.types.MORPHFILLSTYLEARRAY;
import com.jpexs.decompiler.flash.types.MORPHLINESTYLE2;
import com.jpexs.decompiler.flash.types.MORPHLINESTYLEARRAY;
import com.jpexs.decompiler.flash.types.RECT;
import com.jpexs.decompiler.flash.types.SHAPE;
@@ -155,6 +157,16 @@ public class DefineMorphShape2Tag extends CharacterTag implements MorphShapeTag
public DefineMorphShape2Tag(SWF swf) {
super(swf, ID, "DefineMorphShape2", null);
characterId = swf.getNextCharacterId();
startBounds = new RECT();
endBounds = new RECT();
startEdgeBounds = new RECT();
endEdgeBounds = new RECT();
startEdges = SHAPE.createEmpty(2);
endEdges = SHAPE.createEmpty(2);
morphFillStyles = new MORPHFILLSTYLEARRAY();
morphFillStyles.fillStyles = new MORPHFILLSTYLE[0];
morphLineStyles = new MORPHLINESTYLEARRAY();
morphLineStyles.lineStyles2 = new MORPHLINESTYLE2[0];
}
/**

View File

@@ -33,7 +33,9 @@ import com.jpexs.decompiler.flash.types.BasicType;
import com.jpexs.decompiler.flash.types.ColorTransform;
import com.jpexs.decompiler.flash.types.FILLSTYLEARRAY;
import com.jpexs.decompiler.flash.types.LINESTYLEARRAY;
import com.jpexs.decompiler.flash.types.MORPHFILLSTYLE;
import com.jpexs.decompiler.flash.types.MORPHFILLSTYLEARRAY;
import com.jpexs.decompiler.flash.types.MORPHLINESTYLE;
import com.jpexs.decompiler.flash.types.MORPHLINESTYLEARRAY;
import com.jpexs.decompiler.flash.types.RECT;
import com.jpexs.decompiler.flash.types.SHAPE;
@@ -133,6 +135,14 @@ public class DefineMorphShapeTag extends CharacterTag implements MorphShapeTag {
public DefineMorphShapeTag(SWF swf) {
super(swf, ID, "DefineMorphShape", null);
characterId = swf.getNextCharacterId();
startBounds = new RECT();
endBounds = new RECT();
startEdges = SHAPE.createEmpty(1);
endEdges = SHAPE.createEmpty(1);
morphFillStyles = new MORPHFILLSTYLEARRAY();
morphFillStyles.fillStyles = new MORPHFILLSTYLE[0];
morphLineStyles = new MORPHLINESTYLEARRAY();
morphLineStyles.lineStyles = new MORPHLINESTYLE[0];
}
/**

View File

@@ -81,7 +81,7 @@ public class DefineShape2Tag extends ShapeTag {
super(swf, ID, "DefineShape2", null);
shapeId = swf.getNextCharacterId();
shapeBounds = new RECT();
shapes = new SHAPEWITHSTYLE();
shapes = SHAPEWITHSTYLE.createEmpty(2);
}
public DefineShape2Tag(SWFInputStream sis, ByteArrayRange data) throws IOException {

View File

@@ -81,6 +81,7 @@ public class DefineShape3Tag extends ShapeTag {
super(swf, ID, "DefineShape3", null);
shapeId = swf.getNextCharacterId();
shapeBounds = new RECT();
shapes = SHAPEWITHSTYLE.createEmpty(3);
}
public DefineShape3Tag(SWFInputStream sis, ByteArrayRange data) throws IOException {

View File

@@ -88,6 +88,9 @@ public class DefineShape4Tag extends ShapeTag {
public DefineShape4Tag(SWF swf) {
super(swf, ID, "DefineShape4", null);
shapeId = swf.getNextCharacterId();
shapeBounds = new RECT();
edgeBounds = new RECT();
shapes = SHAPEWITHSTYLE.createEmpty(4);
}
public DefineShape4Tag(SWFInputStream sis, ByteArrayRange data) throws IOException {

View File

@@ -75,7 +75,7 @@ public class DefineShapeTag extends ShapeTag {
super(swf, ID, "DefineShape", null);
shapeId = swf.getNextCharacterId();
shapeBounds = new RECT();
shapes = new SHAPEWITHSTYLE();
shapes = SHAPEWITHSTYLE.createEmpty(1);
}
public DefineShapeTag(SWFInputStream sis, ByteArrayRange data) throws IOException {

View File

@@ -103,6 +103,7 @@ public class DefineSoundTag extends CharacterTag implements SoundTag {
public DefineSoundTag(SWF swf) {
super(swf, ID, "DefineSound", null);
soundId = swf.getNextCharacterId();
soundData = new byte[] {0};
}
/**

View File

@@ -481,6 +481,7 @@ public class DefineText2Tag extends TextTag {
super(swf, ID, "DefineText2", null);
characterID = swf.getNextCharacterId();
textBounds = new RECT();
textMatrix = new MATRIX();
textRecords = new ArrayList<>();
glyphBits = 0;
advanceBits = 0;

View File

@@ -443,6 +443,7 @@ public class DefineTextTag extends TextTag {
characterID = swf.getNextCharacterId();
textBounds = new RECT();
textMatrix = new MATRIX();
textRecords = new ArrayList<>();
glyphBits = 0;
advanceBits = 0;
}

View File

@@ -88,8 +88,12 @@ public final class DefineCompactedFont extends FontTag implements DrawableTag {
public DefineCompactedFont(SWF swf) {
super(swf, ID, "DefineCompactedFont", null);
fontId = swf.getNextCharacterId();
fonts = new ArrayList<>();
shapeCache = new ArrayList<>();
FontType ft = new FontType();
fonts.add(ft);
rebuildShapeCache();
}
/**

View File

@@ -12,17 +12,20 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.types;
import com.jpexs.decompiler.flash.exporters.shape.PathExporter;
import com.jpexs.decompiler.flash.tags.base.NeedsCharacters;
import com.jpexs.decompiler.flash.types.annotations.SWFType;
import com.jpexs.decompiler.flash.types.shaperecords.EndShapeRecord;
import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.GeneralPath;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -67,4 +70,11 @@ public class SHAPE implements NeedsCharacters, Serializable {
return area;
}
public static SHAPE createEmpty(int shapeNum) {
SHAPE ret = new SHAPE();
ret.shapeRecords = new ArrayList<>();
ret.shapeRecords.add(new EndShapeRecord());
return ret;
}
}

View File

@@ -12,12 +12,15 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.types;
import com.jpexs.decompiler.flash.tags.base.NeedsCharacters;
import com.jpexs.decompiler.flash.types.shaperecords.EndShapeRecord;
import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Set;
/**
@@ -48,4 +51,20 @@ public class SHAPEWITHSTYLE extends SHAPE implements NeedsCharacters, Serializab
}
return modified;
}
public static SHAPEWITHSTYLE createEmpty(int shapeNum) {
SHAPEWITHSTYLE ret = new SHAPEWITHSTYLE();
ret.shapeRecords = new ArrayList<>();
ret.shapeRecords.add(new EndShapeRecord());
ret.fillStyles = new FILLSTYLEARRAY();
ret.fillStyles.fillStyles = new FILLSTYLE[0];
ret.lineStyles = new LINESTYLEARRAY();
if ((shapeNum == 1 || shapeNum == 2 || shapeNum == 3)) {
ret.lineStyles.lineStyles = new LINESTYLE[0];
} else if (shapeNum == 4) {
ret.lineStyles.lineStyles = new LINESTYLE2[0];
}
return ret;
}
}

View File

@@ -41,6 +41,13 @@ public class FontType implements Serializable {
public List<GlyphInfoType> glyphInfo;
public List<KerningPairType> kerning;
public FontType() {
fontName = "New font";
glyphInfo = new ArrayList<>();
kerning = new ArrayList<>();
glyphs = new ArrayList<>();
}
public FontType(GFxInputStream sis) throws IOException {
long offset = sis.getPos();
fontName = sis.readString("fontName");

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.helpers;
import java.awt.AlphaComposite;