From 201f9a40bd6c79d61b01e22a4efecc1f2eb3b392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sun, 2 Jun 2013 21:24:06 +0200 Subject: [PATCH] viewer fixes --- .../jpexs/decompiler/flash/Configuration.java | 4 - trunk/src/com/jpexs/decompiler/flash/SWF.java | 19 +++++ .../com/jpexs/decompiler/flash/gui/Main.java | 3 +- .../flash/tags/DefineSpriteTag.java | 10 +++ .../types/filters/GRADIENTBEVELFILTER.java | 11 +-- .../flash/types/shaperecords/SHAPERECORD.java | 82 +++++++++++++++---- 6 files changed, 100 insertions(+), 29 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/Configuration.java b/trunk/src/com/jpexs/decompiler/flash/Configuration.java index d43b36a67..c1e6fd42c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/Configuration.java +++ b/trunk/src/com/jpexs/decompiler/flash/Configuration.java @@ -29,9 +29,7 @@ public class Configuration { public static final boolean DISPLAY_FILENAME = true; public static boolean DEBUG_COPY = false; - public static boolean dump_tags = false; - /** * Debug mode = throwing an error when comparing original file and * recompiled @@ -54,14 +52,12 @@ public class Configuration { * Find latest constant pool in the code */ public static final boolean LATEST_CONSTANTPOOL_HACK = false; - /** * Limit of code subs (for obfuscated code) */ public static final int SUBLIMITER = 500; //using parameter names in decompiling may cause problems because oficial programs like Flash CS 5.5 inserts wrong parameter names indices public static final boolean PARAM_NAMES_ENABLE = false; - private static HashMap config = new HashMap(); /** * List of replacements diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index 9ce81460a..8b2506ba4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -1384,6 +1384,17 @@ public class SWF { ret.Xmax = rect.Xmax; ret.Ymin = rect.Ymin; ret.Ymax = rect.Ymax; + + + + if (ret.Xmax <= 0) { + ret.Xmax = ret.getWidth(); + ret.Xmin = 0; + } + if (ret.Ymax <= 0) { + ret.Ymax = ret.getHeight(); + ret.Ymin = 0; + } if (ret.Xmin < 0) { ret.Xmax += (-ret.Xmin); ret.Xmin = 0; @@ -1392,11 +1403,19 @@ public class SWF { ret.Ymax += (-ret.Ymin); ret.Ymin = 0; } + + if (ret.getWidth() < 1 || ret.getHeight() < 1) { + ret.Xmin = 0; + ret.Ymin = 0; + ret.Xmax = 20; + ret.Ymax = 20; + } return ret; } public static BufferedImage frameToImage(int containerId, int maxDepth, HashMap layers, Color backgroundColor, HashMap characters, int frame, List allTags, List controlTags, RECT displayRect) { displayRect = fixRect(displayRect); + String key = "frame_" + frame + "_" + containerId; if (cache.contains(key)) { return ((CachedImage) cache.get(key)).getImage(); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java index cc42789da..32a8a26c9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java @@ -97,12 +97,11 @@ public class Main { public static boolean isCommandLineMode() { return commandLineMode; } + /** * Dump tags to stdout */ // - - public static String getFileTitle() { if (maskURL != null) { return maskURL; diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java index a0c462cd2..32cfa4dce 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java @@ -66,6 +66,7 @@ public class DefineSpriteTag extends CharacterTag implements Container, BoundedT private RECT getCharacterBounds(HashMap allCharacters, Set characters) { RECT ret = new RECT(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE); + boolean foundSomething = false; for (int c : characters) { Tag t = allCharacters.get(c); RECT r = null; @@ -73,12 +74,16 @@ public class DefineSpriteTag extends CharacterTag implements Container, BoundedT r = ((BoundedTag) t).getRect(allCharacters); } if (r != null) { + foundSomething = true; ret.Xmin = Math.min(r.Xmin, ret.Xmin); ret.Ymin = Math.min(r.Ymin, ret.Ymin); ret.Xmax = Math.max(r.Xmax, ret.Xmax); ret.Ymax = Math.max(r.Ymax, ret.Ymax); } } + if (!foundSomething) { + return new RECT(); + } return ret; } @@ -86,6 +91,7 @@ public class DefineSpriteTag extends CharacterTag implements Container, BoundedT public RECT getRect(HashMap characters) { RECT ret = new RECT(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE); HashMap depthMap = new HashMap(); + boolean foundSomething = false; for (Tag t : subTags) { MATRIX m = null; int characterId = -1; @@ -129,6 +135,10 @@ public class DefineSpriteTag extends CharacterTag implements Container, BoundedT ret.Ymin = Math.min(r.Ymin, ret.Ymin); ret.Xmax = Math.max(r.Xmax, ret.Xmax); ret.Ymax = Math.max(r.Ymax, ret.Ymax); + foundSomething = true; + } + if (!foundSomething) { + return new RECT(); } return ret; } diff --git a/trunk/src/com/jpexs/decompiler/flash/types/filters/GRADIENTBEVELFILTER.java b/trunk/src/com/jpexs/decompiler/flash/types/filters/GRADIENTBEVELFILTER.java index 94f19710a..e97ade6b1 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/filters/GRADIENTBEVELFILTER.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/filters/GRADIENTBEVELFILTER.java @@ -93,6 +93,11 @@ public class GRADIENTBEVELFILTER extends FILTER { colors.add(gradientColors[i].toColor()); ratios.add(gradientRatio[i] / 255f); } + float ratiosAr[] = new float[ratios.size()]; + for (int i = 0; i < ratios.size(); i++) { + ratiosAr[i] = ratios.get(i); + } + Color colorsArr[] = colors.toArray(new Color[colors.size()]); int type = Filtering.INNER; if (onTop && !innerShadow) { type = Filtering.FULL; @@ -100,10 +105,6 @@ public class GRADIENTBEVELFILTER extends FILTER { type = Filtering.OUTER; } - float ratiosAr[] = new float[ratios.size()]; - for (int i = 0; i < ratios.size(); i++) { - ratiosAr[i] = ratios.get(i); - } - return Filtering.gradientBevel(src, colors.toArray(new Color[colors.size()]), ratiosAr, (int) blurX, (int) blurY, strength, type, (int) (angle * 180 / Math.PI), (float) distance, knockout, passes); + return Filtering.gradientBevel(src, colorsArr, ratiosAr, (int) blurX, (int) blurY, strength, type, (int) (angle * 180 / Math.PI), (float) distance, knockout, passes); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SHAPERECORD.java b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SHAPERECORD.java index 2f7dcb686..a070c1c05 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SHAPERECORD.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SHAPERECORD.java @@ -164,16 +164,28 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters { } break; case FILLSTYLE.FOCAL_RADIAL_GRADIENT: - float focRadFractions[] = new float[fillStyle0.focalGradient.gradientRecords.length]; - Color focRadColors[] = new Color[fillStyle0.focalGradient.gradientRecords.length]; - for (int i = 0; i < fillStyle0.focalGradient.gradientRecords.length; i++) { - focRadFractions[i] = fillStyle0.focalGradient.gradientRecords[i].getRatioFloat(); + + List colorsFocRad = new ArrayList(); + List ratiosFocRad = new ArrayList(); + for (int i = 0; i < fillStyle0.gradient.gradientRecords.length; i++) { + if ((i > 0) && (fillStyle0.gradient.gradientRecords[i - 1].ratio == fillStyle0.gradient.gradientRecords[i].ratio)) { + continue; + } + ratiosFocRad.add(fillStyle0.gradient.gradientRecords[i].getRatioFloat()); if (shapeNum >= 3) { - focRadColors[i] = new Color(fillStyle0.focalGradient.gradientRecords[i].colorA.red, fillStyle0.focalGradient.gradientRecords[i].colorA.green, fillStyle0.focalGradient.gradientRecords[i].colorA.blue, fillStyle0.focalGradient.gradientRecords[i].colorA.alpha); + colorsFocRad.add(new Color(fillStyle0.gradient.gradientRecords[i].colorA.red, fillStyle0.gradient.gradientRecords[i].colorA.green, fillStyle0.gradient.gradientRecords[i].colorA.blue, fillStyle0.gradient.gradientRecords[i].colorA.alpha)); } else { - focRadColors[i] = new Color(fillStyle0.focalGradient.gradientRecords[i].color.red, fillStyle0.focalGradient.gradientRecords[i].color.green, fillStyle0.focalGradient.gradientRecords[i].color.blue); + colorsFocRad.add(new Color(fillStyle0.gradient.gradientRecords[i].color.red, fillStyle0.gradient.gradientRecords[i].color.green, fillStyle0.gradient.gradientRecords[i].color.blue)); } } + + + float focRadFractions[] = new float[ratiosFocRad.size()]; + for (int i = 0; i < ratiosFocRad.size(); i++) { + focRadFractions[i] = ratiosFocRad.get(i); + } + Color focRadColors[] = colorsFocRad.toArray(new Color[colorsFocRad.size()]); + RGB focEndColor = fillStyle0.focalGradient.gradientRecords[fillStyle0.focalGradient.gradientRecords.length - 1].color; RGBA focEndColorA = fillStyle0.focalGradient.gradientRecords[fillStyle0.focalGradient.gradientRecords.length - 1].colorA; if (shapeNum >= 3) { @@ -204,16 +216,28 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters { g.setClip(null); return; case FILLSTYLE.RADIAL_GRADIENT: - float radFractions[] = new float[fillStyle0.gradient.gradientRecords.length]; - Color radColors[] = new Color[fillStyle0.gradient.gradientRecords.length]; + List colorsRad = new ArrayList(); + List ratiosRad = new ArrayList(); for (int i = 0; i < fillStyle0.gradient.gradientRecords.length; i++) { - radFractions[i] = fillStyle0.gradient.gradientRecords[i].getRatioFloat(); + if ((i > 0) && (fillStyle0.gradient.gradientRecords[i - 1].ratio == fillStyle0.gradient.gradientRecords[i].ratio)) { + continue; + } + ratiosRad.add(fillStyle0.gradient.gradientRecords[i].getRatioFloat()); if (shapeNum >= 3) { - radColors[i] = new Color(fillStyle0.gradient.gradientRecords[i].colorA.red, fillStyle0.gradient.gradientRecords[i].colorA.green, fillStyle0.gradient.gradientRecords[i].colorA.blue, fillStyle0.gradient.gradientRecords[i].colorA.alpha); + colorsRad.add(new Color(fillStyle0.gradient.gradientRecords[i].colorA.red, fillStyle0.gradient.gradientRecords[i].colorA.green, fillStyle0.gradient.gradientRecords[i].colorA.blue, fillStyle0.gradient.gradientRecords[i].colorA.alpha)); } else { - radColors[i] = new Color(fillStyle0.gradient.gradientRecords[i].color.red, fillStyle0.gradient.gradientRecords[i].color.green, fillStyle0.gradient.gradientRecords[i].color.blue); + colorsRad.add(new Color(fillStyle0.gradient.gradientRecords[i].color.red, fillStyle0.gradient.gradientRecords[i].color.green, fillStyle0.gradient.gradientRecords[i].color.blue)); } } + + + + float ratiosRadAr[] = new float[ratiosRad.size()]; + for (int i = 0; i < ratiosRad.size(); i++) { + ratiosRadAr[i] = ratiosRad.get(i); + } + Color colorsRadArr[] = colorsRad.toArray(new Color[colorsRad.size()]); + RGB endColor = fillStyle0.gradient.gradientRecords[fillStyle0.gradient.gradientRecords.length - 1].color; RGBA endColorA = fillStyle0.gradient.gradientRecords[fillStyle0.gradient.gradientRecords.length - 1].colorA; if (shapeNum >= 3) { @@ -238,22 +262,34 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters { cmRad = CycleMethod.REPEAT; } - g.setPaint(new RadialGradientPaint(new Point(0, 0), 16384, radFractions, radColors, cmRad)); + g.setPaint(new RadialGradientPaint(new Point(0, 0), 16384, ratiosRadAr, colorsRadArr, cmRad)); g.fill(new Rectangle(-16384 * maxRepeat, -16384 * maxRepeat, 16384 * 2 * maxRepeat, 16384 * 2 * maxRepeat)); g.setTransform(oldAf); g.setClip(null); return; case FILLSTYLE.LINEAR_GRADIENT: - float fractions[] = new float[fillStyle0.gradient.gradientRecords.length]; - Color colors[] = new Color[fillStyle0.gradient.gradientRecords.length]; + List colors = new ArrayList(); + List ratios = new ArrayList(); for (int i = 0; i < fillStyle0.gradient.gradientRecords.length; i++) { - fractions[i] = fillStyle0.gradient.gradientRecords[i].getRatioFloat(); + if ((i > 0) && (fillStyle0.gradient.gradientRecords[i - 1].ratio == fillStyle0.gradient.gradientRecords[i].ratio)) { + continue; + } + ratios.add(fillStyle0.gradient.gradientRecords[i].getRatioFloat()); if (shapeNum >= 3) { - colors[i] = new Color(fillStyle0.gradient.gradientRecords[i].colorA.red, fillStyle0.gradient.gradientRecords[i].colorA.green, fillStyle0.gradient.gradientRecords[i].colorA.blue, fillStyle0.gradient.gradientRecords[i].colorA.alpha); + colors.add(new Color(fillStyle0.gradient.gradientRecords[i].colorA.red, fillStyle0.gradient.gradientRecords[i].colorA.green, fillStyle0.gradient.gradientRecords[i].colorA.blue, fillStyle0.gradient.gradientRecords[i].colorA.alpha)); } else { - colors[i] = new Color(fillStyle0.gradient.gradientRecords[i].color.red, fillStyle0.gradient.gradientRecords[i].color.green, fillStyle0.gradient.gradientRecords[i].color.blue); + colors.add(new Color(fillStyle0.gradient.gradientRecords[i].color.red, fillStyle0.gradient.gradientRecords[i].color.green, fillStyle0.gradient.gradientRecords[i].color.blue)); } } + + + + float ratiosAr[] = new float[ratios.size()]; + for (int i = 0; i < ratios.size(); i++) { + ratiosAr[i] = ratios.get(i); + } + Color colorsArr[] = colors.toArray(new Color[colors.size()]); + GeneralPath pathLin = toGeneralPath(startX, startY); g.fill(pathLin); g.setClip(pathLin); @@ -272,7 +308,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters { } - g.setPaint(new LinearGradientPaint(new Point(-16384, 0), new Point(16384, 0), fractions, colors, cmLin)); + g.setPaint(new LinearGradientPaint(new Point(-16384, 0), new Point(16384, 0), ratiosAr, colorsArr, cmLin)); g.fill(new Rectangle(-16384 * maxRepeat, -16384 * maxRepeat, 16384 * 2 * maxRepeat, 16384 * 2 * maxRepeat)); g.setTransform(oldAf); g.setClip(null); @@ -307,6 +343,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters { GeneralPath ret = new GeneralPath(); int x = startX; int y = startY; + boolean wasMoveTo = false; for (SHAPERECORD rec : edges) { int nx = rec.changeX(x); int ny = rec.changeY(y); @@ -316,12 +353,21 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters { nx += startX; ny += startY; ret.moveTo(nx, ny); + wasMoveTo = true; } } if (rec instanceof StraightEdgeRecord) { + if (!wasMoveTo) { + ret.moveTo(x, y); + wasMoveTo = true; + } ret.lineTo(nx, ny); } if (rec instanceof CurvedEdgeRecord) { + if (!wasMoveTo) { + ret.moveTo(x, y); + wasMoveTo = true; + } CurvedEdgeRecord cer = (CurvedEdgeRecord) rec; ret.quadTo((x + cer.controlDeltaX), (y + cer.controlDeltaY), (x + cer.controlDeltaX + cer.anchorDeltaX), (y + cer.controlDeltaY + cer.anchorDeltaY)); }