From be6332c59764c5e15599f0f4b519bdfef7e420a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sat, 5 Jan 2013 11:34:25 +0100 Subject: [PATCH] Fixed some tags, Image export stub --- trunk/src/com/jpexs/asdec/Main.java | 22 ++- trunk/src/com/jpexs/asdec/SWF.java | 112 +++++++++++-- trunk/src/com/jpexs/asdec/SWFInputStream.java | 154 ++++++++++++++++++ .../src/com/jpexs/asdec/SWFOutputStream.java | 28 ++-- trunk/src/com/jpexs/asdec/abc/ABC.java | 1 - .../com/jpexs/asdec/abc/avm2/AVM2Code.java | 2 - .../instructions/other/GetScopeObjectIns.java | 4 - .../asdec/tags/DefineBitsLossless2Tag.java | 38 ++++- .../asdec/tags/DefineBitsLosslessTag.java | 38 ++++- .../jpexs/asdec/tags/DefineButton2Tag.java | 4 +- .../com/jpexs/asdec/tags/DefineButtonTag.java | 4 +- .../com/jpexs/asdec/tags/DefineFont3Tag.java | 11 +- .../asdec/tags/DefineFontAlignZonesTag.java | 2 +- .../com/jpexs/asdec/tags/DefineSpriteTag.java | 4 +- .../com/jpexs/asdec/tags/DoInitActionTag.java | 4 +- .../com/jpexs/asdec/tags/ExportAssetsTag.java | 5 +- .../jpexs/asdec/types/ALPHABITMAPDATA.java | 27 +++ .../jpexs/asdec/types/ALPHACOLORMAPDATA.java | 28 ++++ trunk/src/com/jpexs/asdec/types/ARGB.java | 5 + .../src/com/jpexs/asdec/types/BITMAPDATA.java | 28 ++++ .../com/jpexs/asdec/types/COLORMAPDATA.java | 28 ++++ .../com/jpexs/asdec/types/KERNINGRECORD.java | 4 +- trunk/src/com/jpexs/asdec/types/PIX15.java | 38 +++++ trunk/src/com/jpexs/asdec/types/PIX24.java | 38 +++++ trunk/src/com/jpexs/asdec/types/RECT.java | 5 + trunk/src/com/jpexs/asdec/types/ZONEDATA.java | 4 +- .../src/com/jpexs/asdec/types/ZONERECORD.java | 13 +- 27 files changed, 570 insertions(+), 81 deletions(-) create mode 100644 trunk/src/com/jpexs/asdec/types/ALPHABITMAPDATA.java create mode 100644 trunk/src/com/jpexs/asdec/types/ALPHACOLORMAPDATA.java create mode 100644 trunk/src/com/jpexs/asdec/types/BITMAPDATA.java create mode 100644 trunk/src/com/jpexs/asdec/types/COLORMAPDATA.java create mode 100644 trunk/src/com/jpexs/asdec/types/PIX15.java create mode 100644 trunk/src/com/jpexs/asdec/types/PIX24.java diff --git a/trunk/src/com/jpexs/asdec/Main.java b/trunk/src/com/jpexs/asdec/Main.java index c9d905d7d..efe09b5c1 100644 --- a/trunk/src/com/jpexs/asdec/Main.java +++ b/trunk/src/com/jpexs/asdec/Main.java @@ -23,9 +23,7 @@ import com.jpexs.asdec.gui.LoadingDialog; import com.jpexs.asdec.gui.ModeFrame; import com.jpexs.asdec.gui.View; import com.jpexs.asdec.gui.proxy.ProxyFrame; -import com.jpexs.asdec.tags.DefineBitsTag; import com.jpexs.asdec.tags.DoABCTag; -import com.jpexs.asdec.tags.JPEGTablesTag; import com.jpexs.asdec.tags.Tag; import java.awt.*; import java.awt.event.ActionEvent; @@ -416,8 +414,8 @@ public class Main { System.out.println(" ...opens SWF file with the decompiler GUI"); System.out.println(" 3) -proxy (-PXXX)"); System.out.println(" ...auto start proxy in the tray. Optional parameter -P specifies port for proxy. Defaults to 55555. "); - System.out.println(" 4) -export (as|pcode) outdirectory infile"); - System.out.println(" ...export infile actionscript to outdirectory as AsctionScript code (\"as\" argument) or as PCode (\"pcode\" argument)"); + System.out.println(" 4) -export (as|pcode|image) outdirectory infile"); + System.out.println(" ...export infile sources to outdirectory as AsctionScript code (\"as\" argument) or as PCode (\"pcode\" argument) or images"); System.out.println(" 5) -dumpSWF infile"); System.out.println(" ...dumps list of SWF tags to console"); System.out.println(" 6) -compress infile outfile"); @@ -478,8 +476,10 @@ public class Main { String exportFormat = args[pos + 1]; if (!exportFormat.toLowerCase().equals("as")) { if (!exportFormat.toLowerCase().equals("pcode")) { - System.err.println("Invalid export format:" + exportFormat); - badArguments(); + if (!exportFormat.toLowerCase().equals("image")) { + System.err.println("Invalid export format:" + exportFormat); + badArguments(); + } } } File outDir = new File(args[pos + 2]); @@ -492,6 +492,7 @@ public class Main { boolean exportOK; try { printHeader(); + dump_tags = true; SWF exfile = new SWF(new FileInputStream(inFile)); exfile.addEventListener(new EventListener() { public void handleEvent(String event, Object data) { @@ -500,7 +501,14 @@ public class Main { } } }); - exportOK = exfile.exportActionScript(outDir.getAbsolutePath(), exportFormat.equals("pcode")); + if (exportFormat.equals("image")) { + exfile.exportImages(outDir.getAbsolutePath()); + exportOK = true; + } else if (exportFormat.equals("as") || exportFormat.equals("pcode")) { + exportOK = exfile.exportActionScript(outDir.getAbsolutePath(), exportFormat.equals("pcode")); + } else { + exportOK = false; + } } catch (Exception ex) { exportOK = false; System.err.print("FAIL: Exporting Failed on Exception - "); diff --git a/trunk/src/com/jpexs/asdec/SWF.java b/trunk/src/com/jpexs/asdec/SWF.java index affa82072..c6719837e 100644 --- a/trunk/src/com/jpexs/asdec/SWF.java +++ b/trunk/src/com/jpexs/asdec/SWF.java @@ -22,20 +22,31 @@ import com.jpexs.asdec.helpers.Highlighting; import com.jpexs.asdec.tags.DefineBitsJPEG2Tag; import com.jpexs.asdec.tags.DefineBitsJPEG3Tag; import com.jpexs.asdec.tags.DefineBitsJPEG4Tag; +import com.jpexs.asdec.tags.DefineBitsLossless2Tag; +import com.jpexs.asdec.tags.DefineBitsLosslessTag; import com.jpexs.asdec.tags.DefineBitsTag; import com.jpexs.asdec.tags.DoABCTag; import com.jpexs.asdec.tags.JPEGTablesTag; import com.jpexs.asdec.tags.Tag; import com.jpexs.asdec.tags.base.ASMSource; import com.jpexs.asdec.tags.base.TagName; +import com.jpexs.asdec.types.ALPHABITMAPDATA; +import com.jpexs.asdec.types.ALPHACOLORMAPDATA; +import com.jpexs.asdec.types.BITMAPDATA; +import com.jpexs.asdec.types.COLORMAPDATA; import com.jpexs.asdec.types.RECT; +import com.jpexs.asdec.types.RGB; +import com.jpexs.asdec.types.RGBA; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.image.BufferedImage; import java.io.*; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.zip.DeflaterOutputStream; import java.util.zip.InflaterInputStream; +import javax.imageio.ImageIO; /** * Class representing SWF file @@ -483,27 +494,27 @@ public class SWF { } for (Tag t : tags) { - if ((t instanceof DefineBitsJPEG2Tag)||(t instanceof DefineBitsJPEG3Tag)||(t instanceof DefineBitsJPEG4Tag)) { - byte imageData[]=null; - int characterID=0; - if(t instanceof DefineBitsJPEG2Tag){ - imageData=((DefineBitsJPEG2Tag)t).imageData; - characterID=((DefineBitsJPEG2Tag)t).characterID; + if ((t instanceof DefineBitsJPEG2Tag) || (t instanceof DefineBitsJPEG3Tag) || (t instanceof DefineBitsJPEG4Tag)) { + byte imageData[] = null; + int characterID = 0; + if (t instanceof DefineBitsJPEG2Tag) { + imageData = ((DefineBitsJPEG2Tag) t).imageData; + characterID = ((DefineBitsJPEG2Tag) t).characterID; } - if(t instanceof DefineBitsJPEG3Tag){ - imageData=((DefineBitsJPEG3Tag)t).imageData; - characterID=((DefineBitsJPEG3Tag)t).characterID; + if (t instanceof DefineBitsJPEG3Tag) { + imageData = ((DefineBitsJPEG3Tag) t).imageData; + characterID = ((DefineBitsJPEG3Tag) t).characterID; } - if(t instanceof DefineBitsJPEG4Tag){ - imageData=((DefineBitsJPEG4Tag)t).imageData; - characterID=((DefineBitsJPEG4Tag)t).characterID; + if (t instanceof DefineBitsJPEG4Tag) { + imageData = ((DefineBitsJPEG4Tag) t).imageData; + characterID = ((DefineBitsJPEG4Tag) t).characterID; } - + FileOutputStream fos = null; try { - fos = new FileOutputStream(outdir + File.separator + characterID + "."+getImageFormat(imageData)); + fos = new FileOutputStream(outdir + File.separator + characterID + "." + getImageFormat(imageData)); if (hasErrorHeader(imageData)) { - fos.write(imageData,4,imageData.length-4); + fos.write(imageData, 4, imageData.length - 4); } else { fos.write(imageData); } @@ -517,6 +528,75 @@ public class SWF { } } } + if (t instanceof DefineBitsLosslessTag) { + DefineBitsLosslessTag dbl = (DefineBitsLosslessTag) t; + BufferedImage bi = new BufferedImage(dbl.bitmapWidth, dbl.bitmapHeight, BufferedImage.TYPE_INT_RGB); + Graphics g = bi.getGraphics(); + COLORMAPDATA colorMapData = null; + BITMAPDATA bitmapData = null; + if (dbl.bitmapFormat == DefineBitsLosslessTag.FORMAT_8BIT_COLORMAPPED) { + colorMapData = dbl.getColorMapData(); + } + if ((dbl.bitmapFormat == DefineBitsLosslessTag.FORMAT_15BIT_RGB) || (dbl.bitmapFormat == DefineBitsLosslessTag.FORMAT_24BIT_RGB)) { + bitmapData = dbl.getBitmapData(); + } + int pos32aligned = 0; + int pos = 0; + for (int y = 0; y < dbl.bitmapHeight; y++) { + for (int x = 0; x < dbl.bitmapWidth; x++) { + if (dbl.bitmapFormat == DefineBitsLosslessTag.FORMAT_8BIT_COLORMAPPED) { + RGB color = colorMapData.colorTableRGB[colorMapData.colorMapPixelData[pos32aligned]]; + g.setColor(new Color(color.red, color.green, color.blue)); + } + if (dbl.bitmapFormat == DefineBitsLosslessTag.FORMAT_15BIT_RGB) { + g.setColor(new Color(bitmapData.bitmapPixelDataPix15[pos].red * 8, bitmapData.bitmapPixelDataPix15[pos].green * 8, bitmapData.bitmapPixelDataPix15[pos].blue * 8)); + } + if (dbl.bitmapFormat == DefineBitsLosslessTag.FORMAT_24BIT_RGB) { + g.setColor(new Color(bitmapData.bitmapPixelDataPix24[pos].red, bitmapData.bitmapPixelDataPix24[pos].green, bitmapData.bitmapPixelDataPix24[pos].blue)); + } + g.fillRect(x, y, 1, 1); + pos32aligned++; + pos++; + } + while ((pos32aligned % 4 != 0)) { + pos32aligned++; + } + } + ImageIO.write(bi, "PNG", new File(outdir + File.separator + dbl.characterID + ".png")); + } + if (t instanceof DefineBitsLossless2Tag) { + DefineBitsLossless2Tag dbl = (DefineBitsLossless2Tag) t; + BufferedImage bi = new BufferedImage(dbl.bitmapWidth, dbl.bitmapHeight, BufferedImage.TYPE_INT_ARGB); + Graphics g = bi.getGraphics(); + ALPHACOLORMAPDATA colorMapData = null; + ALPHABITMAPDATA bitmapData = null; + if (dbl.bitmapFormat == DefineBitsLossless2Tag.FORMAT_8BIT_COLORMAPPED) { + colorMapData = dbl.getColorMapData(); + } + if ((dbl.bitmapFormat == DefineBitsLossless2Tag.FORMAT_15BIT_RGB) || (dbl.bitmapFormat == DefineBitsLossless2Tag.FORMAT_24BIT_RGB)) { + bitmapData = dbl.getBitmapData(); + } + int pos32aligned = 0; + int pos = 0; + for (int y = 0; y < dbl.bitmapHeight; y++) { + for (int x = 0; x < dbl.bitmapWidth; x++) { + if ((dbl.bitmapFormat == DefineBitsLossless2Tag.FORMAT_8BIT_COLORMAPPED)) { + RGBA color = colorMapData.colorTableRGB[colorMapData.colorMapPixelData[pos32aligned]]; + g.setColor(new Color(color.red, color.green, color.blue, color.alpha)); + } + if ((dbl.bitmapFormat == DefineBitsLossless2Tag.FORMAT_15BIT_RGB) || (dbl.bitmapFormat == DefineBitsLossless2Tag.FORMAT_24BIT_RGB)) { + g.setColor(new Color(bitmapData.bitmapPixelData[pos].red, bitmapData.bitmapPixelData[pos].green, bitmapData.bitmapPixelData[pos].blue, bitmapData.bitmapPixelData[pos].alpha)); + } + g.fillRect(x, y, 1, 1); + pos32aligned++; + pos++; + } + while ((pos32aligned % 4 != 0)) { + pos32aligned++; + } + } + ImageIO.write(bi, "PNG", new File(outdir + File.separator + dbl.characterID + ".png")); + } if ((jtt != null) && (t instanceof DefineBitsTag)) { DefineBitsTag dbt = (DefineBitsTag) t; FileOutputStream fos = null; diff --git a/trunk/src/com/jpexs/asdec/SWFInputStream.java b/trunk/src/com/jpexs/asdec/SWFInputStream.java index 82e159d00..4b4b93beb 100644 --- a/trunk/src/com/jpexs/asdec/SWFInputStream.java +++ b/trunk/src/com/jpexs/asdec/SWFInputStream.java @@ -1166,6 +1166,21 @@ public class SWFInputStream extends InputStream { return ret; } + /** + * Reads one ARGB value from the stream + * + * @return ARGB value + * @throws IOException + */ + public ARGB readARGB() throws IOException { + ARGB ret = new ARGB(); + ret.alpha = readUI8(); + ret.red = readUI8(); + ret.green = readUI8(); + ret.blue = readUI8(); + return ret; + } + /** * Reads one RGB value from the stream * @@ -2136,6 +2151,145 @@ public class SWFInputStream extends InputStream { return ret; } + /** + * Reads one PIX15 value from the stream + * + * @return PIX15 value + * @throws IOException + */ + public PIX15 readPIX15() throws IOException { + PIX15 ret = new PIX15(); + readUB(1); + ret.red = (int) readUB(5); + ret.green = (int) readUB(5); + ret.blue = (int) readUB(5); + return ret; + } + + /** + * Reads one PIX24 value from the stream + * + * @return PIX24 value + * @throws IOException + */ + public PIX24 readPIX24() throws IOException { + PIX24 ret = new PIX24(); + readUI8(); + ret.red = readUI8(); + ret.green = readUI8(); + ret.blue = readUI8(); + return ret; + } + + /** + * Reads one COLORMAPDATA value from the stream + * + * @return COLORMAPDATA value + * @throws IOException + */ + public COLORMAPDATA readCOLORMAPDATA(int colorTableSize, int bitmapWidth, int bitmapHeight) throws IOException { + COLORMAPDATA ret = new COLORMAPDATA(); + ret.colorTableRGB = new RGB[colorTableSize + 1]; + for (int i = 0; i < colorTableSize + 1; i++) { + ret.colorTableRGB[i] = readRGB(); + } + int dataLen = 0; + for (int y = 0; y < bitmapHeight; y++) { + int x = 0; + for (; x < bitmapWidth; x++) { + dataLen++; + } + while ((x % 4) != 0) { + dataLen++; + x++; + } + } + ret.colorMapPixelData = readBytes(dataLen); + return ret; + } + + /** + * Reads one BITMAPDATA value from the stream + * + * @return COLORMAPDATA value + * @throws IOException + */ + public BITMAPDATA readBITMAPDATA(int bitmapFormat, int bitmapWidth, int bitmapHeight) throws IOException { + BITMAPDATA ret = new BITMAPDATA(); + List pix15 = new ArrayList(); + List pix24 = new ArrayList(); + int dataLen = 0; + for (int y = 0; y < bitmapHeight; y++) { + int x = 0; + for (; x < bitmapWidth; x++) { + if (bitmapFormat == DefineBitsLosslessTag.FORMAT_15BIT_RGB) { + dataLen += 2; + pix15.add(readPIX15()); + } + if (bitmapFormat == DefineBitsLosslessTag.FORMAT_24BIT_RGB) { + dataLen += 4; + pix24.add(readPIX24()); + } + dataLen++; + } + while ((x % 4) != 0) { + dataLen++; + readUI8(); + x++; + } + } + if (bitmapFormat == DefineBitsLosslessTag.FORMAT_15BIT_RGB) { + ret.bitmapPixelDataPix15 = pix15.toArray(new PIX15[pix15.size()]); + } else if (bitmapFormat == DefineBitsLosslessTag.FORMAT_24BIT_RGB) { + ret.bitmapPixelDataPix24 = pix24.toArray(new PIX24[pix24.size()]); + } + return ret; + } + + /** + * Reads one BITMAPDATA value from the stream + * + * @return COLORMAPDATA value + * @throws IOException + */ + public ALPHABITMAPDATA readALPHABITMAPDATA(int bitmapFormat, int bitmapWidth, int bitmapHeight) throws IOException { + ALPHABITMAPDATA ret = new ALPHABITMAPDATA(); + ret.bitmapPixelData = new ARGB[bitmapWidth * bitmapHeight]; + for (int y = 0; y < bitmapHeight; y++) { + for (int x = 0; x < bitmapWidth; x++) { + ret.bitmapPixelData[y * bitmapWidth + x] = readARGB(); + } + } + return ret; + } + + /** + * Reads one ALPHACOLORMAPDATA value from the stream + * + * @return ALPHACOLORMAPDATA value + * @throws IOException + */ + public ALPHACOLORMAPDATA readALPHACOLORMAPDATA(int colorTableSize, int bitmapWidth, int bitmapHeight) throws IOException { + ALPHACOLORMAPDATA ret = new ALPHACOLORMAPDATA(); + ret.colorTableRGB = new RGBA[colorTableSize + 1]; + for (int i = 0; i < colorTableSize + 1; i++) { + ret.colorTableRGB[i] = readRGBA(); + } + int dataLen = 0; + for (int y = 0; y < bitmapHeight; y++) { + int x = 0; + for (; x < bitmapWidth; x++) { + dataLen++; + } + while ((x % 4) != 0) { + dataLen++; + x++; + } + } + ret.colorMapPixelData = readBytes(dataLen); + return ret; + } + @Override public int available() throws IOException { return is.available(); diff --git a/trunk/src/com/jpexs/asdec/SWFOutputStream.java b/trunk/src/com/jpexs/asdec/SWFOutputStream.java index 539707359..f3e41dff2 100644 --- a/trunk/src/com/jpexs/asdec/SWFOutputStream.java +++ b/trunk/src/com/jpexs/asdec/SWFOutputStream.java @@ -44,8 +44,6 @@ public class SWFOutputStream extends OutputStream { return pos; } - - /** * Constructor * @@ -322,6 +320,20 @@ public class SWFOutputStream extends OutputStream { writeSB(nBits, longVal); } + private static int bitCount(int value) { + value = Math.abs(value); + int nBits = 0; + while ((value & ~0xF) != 0) { + value >>= 4; + nBits += 4; + } + while (value != 0) { + value >>= 1; + nBits++; + } + return nBits; + } + /** * Writes RECT value to the stream * @@ -390,17 +402,7 @@ public class SWFOutputStream extends OutputStream { * @return */ public static int getNeededBits(int number, int bits) { - number = Math.abs(number); - int val = 1; - for (int x = 1; val <= number && !(bits > 32); x <<= 1) { - val = val | x; - bits++; - } - - if (bits > 32) { - assert false : ("minBits " + bits + " must not exceed 32"); - } - return bits; + return bitCount(number) + bits; } /** diff --git a/trunk/src/com/jpexs/asdec/abc/ABC.java b/trunk/src/com/jpexs/asdec/abc/ABC.java index feb672274..bd539ce74 100644 --- a/trunk/src/com/jpexs/asdec/abc/ABC.java +++ b/trunk/src/com/jpexs/asdec/abc/ABC.java @@ -300,7 +300,6 @@ public class ABC { } aos.writeU30(constants.constant_multiname.length); - //System.out.println("Writing "+constants.constant_multiname.length+" multinames"); for (int i = 1; i < constants.constant_multiname.length; i++) { aos.writeMultiname(constants.constant_multiname[i]); } diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java b/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java index ed541e10c..385b543db 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java @@ -2298,11 +2298,9 @@ public class AVM2Code { ins.ignored = true; ip++; } else if (ins.definition instanceof IfTrueIns) { - System.out.println("iftrue found"); boolean val = myStack.pop(); if (val) { code.get(ip).definition = new JumpIns(); - System.out.println("changed to jump"); ip = adr2pos(pos2adr(ip + 1) + code.get(ip).operands[0]); } else { code.get(ip).ignored = true; diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetScopeObjectIns.java b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetScopeObjectIns.java index fdd3cb98d..ee62b84ad 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetScopeObjectIns.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetScopeObjectIns.java @@ -36,10 +36,6 @@ public class GetScopeObjectIns extends InstructionDefinition { @Override public void translate(boolean isStatic, int classIndex, java.util.HashMap localRegs, Stack stack, java.util.Stack scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List output, com.jpexs.asdec.abc.types.MethodBody body, com.jpexs.asdec.abc.ABC abc, HashMap localRegNames, List fullyQualifiedNames) { int index = ins.operands[0]; - /* System.out.println("Getting scope object"+index+":"); - for(TreeItem ti:scopeStack){ - System.out.println(ti.toString(constants)); - }*/ stack.push(scopeStack.get(index)); } diff --git a/trunk/src/com/jpexs/asdec/tags/DefineBitsLossless2Tag.java b/trunk/src/com/jpexs/asdec/tags/DefineBitsLossless2Tag.java index 5a0e81050..fde832bc3 100644 --- a/trunk/src/com/jpexs/asdec/tags/DefineBitsLossless2Tag.java +++ b/trunk/src/com/jpexs/asdec/tags/DefineBitsLossless2Tag.java @@ -18,10 +18,13 @@ package com.jpexs.asdec.tags; import com.jpexs.asdec.SWFInputStream; import com.jpexs.asdec.SWFOutputStream; +import com.jpexs.asdec.types.ALPHABITMAPDATA; +import com.jpexs.asdec.types.ALPHACOLORMAPDATA; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.util.zip.InflaterInputStream; public class DefineBitsLossless2Tag extends Tag { @@ -42,11 +45,42 @@ public class DefineBitsLossless2Tag extends Tag { bitmapFormat = sis.readUI8(); bitmapWidth = sis.readUI16(); bitmapHeight = sis.readUI16(); - if (bitmapFormat == FORMAT_15BIT_RGB) { + if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) { bitmapColorTableSize = sis.readUI8(); } zlibBitmapData = sis.readBytes(sis.available()); } + private ALPHACOLORMAPDATA colorMapData; + private ALPHABITMAPDATA bitmapData; + private boolean decompressed = false; + + public ALPHACOLORMAPDATA getColorMapData() { + if (!decompressed) { + uncompressData(); + } + return colorMapData; + } + + public ALPHABITMAPDATA getBitmapData() { + if (!decompressed) { + uncompressData(); + } + return bitmapData; + } + + private void uncompressData() { + try { + SWFInputStream sis = new SWFInputStream(new InflaterInputStream(new ByteArrayInputStream(zlibBitmapData)), 10); + if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) { + colorMapData = sis.readALPHACOLORMAPDATA(bitmapColorTableSize, bitmapWidth, bitmapHeight); + } + if ((bitmapFormat == FORMAT_15BIT_RGB) || (bitmapFormat == FORMAT_24BIT_RGB)) { + bitmapData = sis.readALPHABITMAPDATA(bitmapFormat, bitmapWidth, bitmapHeight); + } + } catch (IOException ex) { + } + decompressed = true; + } /** * Gets data bytes @@ -64,7 +98,7 @@ public class DefineBitsLossless2Tag extends Tag { sos.writeUI8(bitmapFormat); sos.writeUI16(bitmapWidth); sos.writeUI16(bitmapHeight); - if (bitmapFormat == FORMAT_15BIT_RGB) { + if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) { sos.writeUI8(bitmapColorTableSize); } sos.write(zlibBitmapData); diff --git a/trunk/src/com/jpexs/asdec/tags/DefineBitsLosslessTag.java b/trunk/src/com/jpexs/asdec/tags/DefineBitsLosslessTag.java index b300b10cb..fcc07626d 100644 --- a/trunk/src/com/jpexs/asdec/tags/DefineBitsLosslessTag.java +++ b/trunk/src/com/jpexs/asdec/tags/DefineBitsLosslessTag.java @@ -18,10 +18,13 @@ package com.jpexs.asdec.tags; import com.jpexs.asdec.SWFInputStream; import com.jpexs.asdec.SWFOutputStream; +import com.jpexs.asdec.types.BITMAPDATA; +import com.jpexs.asdec.types.COLORMAPDATA; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.util.zip.InflaterInputStream; public class DefineBitsLosslessTag extends Tag { @@ -34,6 +37,37 @@ public class DefineBitsLosslessTag extends Tag { public static final int FORMAT_8BIT_COLORMAPPED = 3; public static final int FORMAT_15BIT_RGB = 4; public static final int FORMAT_24BIT_RGB = 5; + private COLORMAPDATA colorMapData; + private BITMAPDATA bitmapData; + private boolean decompressed = false; + + public COLORMAPDATA getColorMapData() { + if (!decompressed) { + uncompressData(); + } + return colorMapData; + } + + public BITMAPDATA getBitmapData() { + if (!decompressed) { + uncompressData(); + } + return bitmapData; + } + + private void uncompressData() { + try { + SWFInputStream sis = new SWFInputStream(new InflaterInputStream(new ByteArrayInputStream(zlibBitmapData)), 10); + if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) { + colorMapData = sis.readCOLORMAPDATA(bitmapColorTableSize, bitmapWidth, bitmapHeight); + } + if ((bitmapFormat == FORMAT_15BIT_RGB) || (bitmapFormat == FORMAT_24BIT_RGB)) { + bitmapData = sis.readBITMAPDATA(bitmapFormat, bitmapWidth, bitmapHeight); + } + } catch (IOException ex) { + } + decompressed = true; + } public DefineBitsLosslessTag(byte[] data, int version, long pos) throws IOException { super(20, data, pos); @@ -42,7 +76,7 @@ public class DefineBitsLosslessTag extends Tag { bitmapFormat = sis.readUI8(); bitmapWidth = sis.readUI16(); bitmapHeight = sis.readUI16(); - if (bitmapFormat == FORMAT_15BIT_RGB) { + if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) { bitmapColorTableSize = sis.readUI8(); } zlibBitmapData = sis.readBytes(sis.available()); @@ -64,7 +98,7 @@ public class DefineBitsLosslessTag extends Tag { sos.writeUI8(bitmapFormat); sos.writeUI16(bitmapWidth); sos.writeUI16(bitmapHeight); - if (bitmapFormat == FORMAT_15BIT_RGB) { + if (bitmapFormat == FORMAT_8BIT_COLORMAPPED) { sos.writeUI8(bitmapColorTableSize); } sos.write(zlibBitmapData); diff --git a/trunk/src/com/jpexs/asdec/tags/DefineButton2Tag.java b/trunk/src/com/jpexs/asdec/tags/DefineButton2Tag.java index 1e3a95977..627d89322 100644 --- a/trunk/src/com/jpexs/asdec/tags/DefineButton2Tag.java +++ b/trunk/src/com/jpexs/asdec/tags/DefineButton2Tag.java @@ -177,8 +177,8 @@ public class DefineButton2Tag extends Tag implements Container, TagName { public String toString() { String name = ""; for (ExportAssetsTag eat : exportAssetsTags) { - int pos=eat.tags.indexOf(buttonId); - if (pos>-1) { + int pos = eat.tags.indexOf(buttonId); + if (pos > -1) { name = ": " + eat.names.get(pos); } } diff --git a/trunk/src/com/jpexs/asdec/tags/DefineButtonTag.java b/trunk/src/com/jpexs/asdec/tags/DefineButtonTag.java index 185ff386b..c9d7d5ccf 100644 --- a/trunk/src/com/jpexs/asdec/tags/DefineButtonTag.java +++ b/trunk/src/com/jpexs/asdec/tags/DefineButtonTag.java @@ -110,8 +110,8 @@ public class DefineButtonTag extends Tag implements ASMSource, TagName { public String toString() { String name = ""; for (ExportAssetsTag eat : exportAssetsTags) { - int pos=eat.tags.indexOf(buttonId); - if (pos>-1) { + int pos = eat.tags.indexOf(buttonId); + if (pos > -1) { name = ": " + eat.names.get(pos); } } diff --git a/trunk/src/com/jpexs/asdec/tags/DefineFont3Tag.java b/trunk/src/com/jpexs/asdec/tags/DefineFont3Tag.java index 64ee2e37b..a68e4d81c 100644 --- a/trunk/src/com/jpexs/asdec/tags/DefineFont3Tag.java +++ b/trunk/src/com/jpexs/asdec/tags/DefineFont3Tag.java @@ -18,7 +18,6 @@ package com.jpexs.asdec.tags; import com.jpexs.asdec.SWFInputStream; import com.jpexs.asdec.SWFOutputStream; -import com.jpexs.asdec.abc.CopyOutputStream; import com.jpexs.asdec.types.KERNINGRECORD; import com.jpexs.asdec.types.LANGCODE; import com.jpexs.asdec.types.RECT; @@ -27,7 +26,6 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.util.Arrays; public class DefineFont3Tag extends Tag { @@ -83,13 +81,9 @@ public class DefineFont3Tag extends Tag { } else { codeTableOffset = sis.readUI16(); } - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - CopyOutputStream cos = new CopyOutputStream(baos, new ByteArrayInputStream(Arrays.copyOfRange(data, (int) sis.getPos(), data.length - (int) sis.getPos()))); - SWFOutputStream scos = new SWFOutputStream(cos, 10); glyphShapeTable = new SHAPE[numGlyphs]; for (int i = 0; i < numGlyphs; i++) { glyphShapeTable[i] = sis.readSHAPE(1); - scos.writeSHAPE(glyphShapeTable[i], 1); } codeTable = new int[numGlyphs]; for (int i = 0; i < numGlyphs; i++) { @@ -157,8 +151,7 @@ public class DefineFont3Tag extends Tag { byte ba2[] = baos2.toByteArray(); ByteArrayOutputStream baos3 = new ByteArrayOutputStream(); - CopyOutputStream cos = new CopyOutputStream(baos3, new ByteArrayInputStream(Arrays.copyOfRange(data, (int) sos.getPos() + ba2.length + (fontFlagsWideOffsets ? 4 : 2), (int) data.length - (int) sos.getPos() - ba2.length - (fontFlagsWideOffsets ? 4 : 2)))); - SWFOutputStream sos3 = new SWFOutputStream(cos, version); + SWFOutputStream sos3 = new SWFOutputStream(baos3, version); for (int i = 0; i < numGlyphs; i++) { sos3.writeSHAPE(glyphShapeTable[i], 1); } @@ -170,7 +163,7 @@ public class DefineFont3Tag extends Tag { sos.writeUI32(offset); } else { long offset = ba2.length + ba3.length + 2; - sos.writeUI16((int)offset); + sos.writeUI16((int) offset); } sos.write(ba3); diff --git a/trunk/src/com/jpexs/asdec/tags/DefineFontAlignZonesTag.java b/trunk/src/com/jpexs/asdec/tags/DefineFontAlignZonesTag.java index b3feabdab..58b33e6a0 100644 --- a/trunk/src/com/jpexs/asdec/tags/DefineFontAlignZonesTag.java +++ b/trunk/src/com/jpexs/asdec/tags/DefineFontAlignZonesTag.java @@ -40,7 +40,7 @@ public class DefineFontAlignZonesTag extends Tag { sis.readUB(6); zoneTable = new ArrayList(); while (sis.available() > 0) { - ZONERECORD zr=sis.readZONERECORD(); + ZONERECORD zr = sis.readZONERECORD(); zoneTable.add(zr); } } diff --git a/trunk/src/com/jpexs/asdec/tags/DefineSpriteTag.java b/trunk/src/com/jpexs/asdec/tags/DefineSpriteTag.java index 81fb81090..4ca29d375 100644 --- a/trunk/src/com/jpexs/asdec/tags/DefineSpriteTag.java +++ b/trunk/src/com/jpexs/asdec/tags/DefineSpriteTag.java @@ -105,8 +105,8 @@ public class DefineSpriteTag extends Tag implements Container, TagName { public String toString() { String name = ""; for (ExportAssetsTag eat : exportAssetsTags) { - int pos=eat.tags.indexOf(spriteId); - if (pos>-1) { + int pos = eat.tags.indexOf(spriteId); + if (pos > -1) { name = ": " + eat.names.get(pos); } } diff --git a/trunk/src/com/jpexs/asdec/tags/DoInitActionTag.java b/trunk/src/com/jpexs/asdec/tags/DoInitActionTag.java index 5bb0317c4..19d79d689 100644 --- a/trunk/src/com/jpexs/asdec/tags/DoInitActionTag.java +++ b/trunk/src/com/jpexs/asdec/tags/DoInitActionTag.java @@ -84,8 +84,8 @@ public class DoInitActionTag extends Tag implements ASMSource, TagName { public String toString() { String name = ""; for (ExportAssetsTag eat : exportAssetsTags) { - int pos=eat.tags.indexOf(spriteId); - if (pos>-1) { + int pos = eat.tags.indexOf(spriteId); + if (pos > -1) { name = ": " + eat.names.get(pos); } } diff --git a/trunk/src/com/jpexs/asdec/tags/ExportAssetsTag.java b/trunk/src/com/jpexs/asdec/tags/ExportAssetsTag.java index 07a49bbd8..d40a74b3f 100644 --- a/trunk/src/com/jpexs/asdec/tags/ExportAssetsTag.java +++ b/trunk/src/com/jpexs/asdec/tags/ExportAssetsTag.java @@ -23,7 +23,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; /** @@ -50,8 +49,8 @@ public class ExportAssetsTag extends Tag { super(56, data, pos); SWFInputStream sis = new SWFInputStream(new ByteArrayInputStream(data), version); int count = sis.readUI16(); - tags=new ArrayList(); - names=new ArrayList(); + tags = new ArrayList(); + names = new ArrayList(); for (int i = 0; i < count; i++) { int characterId = sis.readUI16(); tags.add(characterId); diff --git a/trunk/src/com/jpexs/asdec/types/ALPHABITMAPDATA.java b/trunk/src/com/jpexs/asdec/types/ALPHABITMAPDATA.java new file mode 100644 index 000000000..a014f30cd --- /dev/null +++ b/trunk/src/com/jpexs/asdec/types/ALPHABITMAPDATA.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2010-2011 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.asdec.types; + +/** + * Represents 32-bit alpha, red, green and blue value + * + * @author JPEXS + */ +public class ALPHABITMAPDATA { + + public ARGB bitmapPixelData[]; +} diff --git a/trunk/src/com/jpexs/asdec/types/ALPHACOLORMAPDATA.java b/trunk/src/com/jpexs/asdec/types/ALPHACOLORMAPDATA.java new file mode 100644 index 000000000..1f13db2d3 --- /dev/null +++ b/trunk/src/com/jpexs/asdec/types/ALPHACOLORMAPDATA.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2010-2011 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.asdec.types; + +/** + * Represents 32-bit alpha, red, green and blue value + * + * @author JPEXS + */ +public class ALPHACOLORMAPDATA { + + public RGBA colorTableRGB[]; + public byte colorMapPixelData[]; +} diff --git a/trunk/src/com/jpexs/asdec/types/ARGB.java b/trunk/src/com/jpexs/asdec/types/ARGB.java index a8d5bcec9..ce6eaa395 100644 --- a/trunk/src/com/jpexs/asdec/types/ARGB.java +++ b/trunk/src/com/jpexs/asdec/types/ARGB.java @@ -39,4 +39,9 @@ public class ARGB { * Blue color value */ public int blue; + + @Override + public String toString() { + return "[ARGB a=" + alpha + ",r=" + red + ",g=" + green + ",b=" + blue + "]"; + } } diff --git a/trunk/src/com/jpexs/asdec/types/BITMAPDATA.java b/trunk/src/com/jpexs/asdec/types/BITMAPDATA.java new file mode 100644 index 000000000..fec5096a4 --- /dev/null +++ b/trunk/src/com/jpexs/asdec/types/BITMAPDATA.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2010-2011 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.asdec.types; + +/** + * Represents 32-bit alpha, red, green and blue value + * + * @author JPEXS + */ +public class BITMAPDATA { + + public PIX15 bitmapPixelDataPix15[]; + public PIX24 bitmapPixelDataPix24[]; +} diff --git a/trunk/src/com/jpexs/asdec/types/COLORMAPDATA.java b/trunk/src/com/jpexs/asdec/types/COLORMAPDATA.java new file mode 100644 index 000000000..27333ece0 --- /dev/null +++ b/trunk/src/com/jpexs/asdec/types/COLORMAPDATA.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2010-2011 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.asdec.types; + +/** + * Represents 32-bit alpha, red, green and blue value + * + * @author JPEXS + */ +public class COLORMAPDATA { + + public RGB colorTableRGB[]; + public byte colorMapPixelData[]; +} diff --git a/trunk/src/com/jpexs/asdec/types/KERNINGRECORD.java b/trunk/src/com/jpexs/asdec/types/KERNINGRECORD.java index 72a2f3ef8..9a15707de 100644 --- a/trunk/src/com/jpexs/asdec/types/KERNINGRECORD.java +++ b/trunk/src/com/jpexs/asdec/types/KERNINGRECORD.java @@ -29,8 +29,6 @@ public class KERNINGRECORD { @Override public String toString() { - return "[KERNINGRECORD fontKerningCode1="+fontKerningCode1+", fontKerningCode2="+fontKerningCode2+", fontKerningAdjustment="+fontKerningAdjustment+"]"; + return "[KERNINGRECORD fontKerningCode1=" + fontKerningCode1 + ", fontKerningCode2=" + fontKerningCode2 + ", fontKerningAdjustment=" + fontKerningAdjustment + "]"; } - - } diff --git a/trunk/src/com/jpexs/asdec/types/PIX15.java b/trunk/src/com/jpexs/asdec/types/PIX15.java new file mode 100644 index 000000000..29cd9d154 --- /dev/null +++ b/trunk/src/com/jpexs/asdec/types/PIX15.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2010-2011 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.asdec.types; + +/** + * Represents 15-bit red, green and blue value + * + * @author JPEXS + */ +public class PIX15 { + + /** + * Red color value + */ + public int red; + /** + * Green color value + */ + public int green; + /** + * Blue color value + */ + public int blue; +} diff --git a/trunk/src/com/jpexs/asdec/types/PIX24.java b/trunk/src/com/jpexs/asdec/types/PIX24.java new file mode 100644 index 000000000..c0cfc910a --- /dev/null +++ b/trunk/src/com/jpexs/asdec/types/PIX24.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2010-2011 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.asdec.types; + +/** + * Represents 15-bit red, green and blue value + * + * @author JPEXS + */ +public class PIX24 { + + /** + * Red color value + */ + public int red; + /** + * Green color value + */ + public int green; + /** + * Blue color value + */ + public int blue; +} diff --git a/trunk/src/com/jpexs/asdec/types/RECT.java b/trunk/src/com/jpexs/asdec/types/RECT.java index 5aae734b4..868decd77 100644 --- a/trunk/src/com/jpexs/asdec/types/RECT.java +++ b/trunk/src/com/jpexs/asdec/types/RECT.java @@ -39,4 +39,9 @@ public class RECT { * Y maximum position for rectangle in twips */ public int Ymax; + + @Override + public String toString() { + return "[RECT x=" + Xmin + "-" + Xmax + ", y=" + Ymin + "-" + Ymax + "]"; + } } diff --git a/trunk/src/com/jpexs/asdec/types/ZONEDATA.java b/trunk/src/com/jpexs/asdec/types/ZONEDATA.java index af8eefcc8..7c0cd099f 100644 --- a/trunk/src/com/jpexs/asdec/types/ZONEDATA.java +++ b/trunk/src/com/jpexs/asdec/types/ZONEDATA.java @@ -28,8 +28,6 @@ public class ZONEDATA { @Override public String toString() { - return "[ZONEDATA alignmentCoordinate="+alignmentCoordinate+", range="+range+"]"; + return "[ZONEDATA alignmentCoordinate=" + alignmentCoordinate + ", range=" + range + "]"; } - - } diff --git a/trunk/src/com/jpexs/asdec/types/ZONERECORD.java b/trunk/src/com/jpexs/asdec/types/ZONERECORD.java index 05f3f5b60..cd635e914 100644 --- a/trunk/src/com/jpexs/asdec/types/ZONERECORD.java +++ b/trunk/src/com/jpexs/asdec/types/ZONERECORD.java @@ -29,14 +29,13 @@ public class ZONERECORD { @Override public String toString() { - String ret="[ZONERECORD data:"; - for(int i=0;i0){ - ret+=", "; + String ret = "[ZONERECORD data:"; + for (int i = 0; i < zonedata.length; i++) { + if (i > 0) { + ret += ", "; } - ret+=zonedata[i]; + ret += zonedata[i]; } - return ret+", zoneMaskX:"+zoneMaskX+", zoneMaskY:"+zoneMaskY+"]"; + return ret + ", zoneMaskX:" + zoneMaskX + ", zoneMaskY:" + zoneMaskY + "]"; } - }