From c5a3be1ff68218b193760d4ea4a07dd2a1233bde Mon Sep 17 00:00:00 2001 From: honfika Date: Wed, 4 Jun 2014 22:54:02 +0200 Subject: [PATCH] preview image cropping fixed --- src/com/jpexs/decompiler/flash/SWF.java | 37 ++- .../decompiler/flash/gui/PreviewImage.java | 4 +- src/com/jpexs/helpers/SerializableImage.java | 312 +++++++++--------- 3 files changed, 178 insertions(+), 175 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/SWF.java b/src/com/jpexs/decompiler/flash/SWF.java index d48e94a22..4d105f853 100644 --- a/src/com/jpexs/decompiler/flash/SWF.java +++ b/src/com/jpexs/decompiler/flash/SWF.java @@ -2326,7 +2326,7 @@ public final class SWF implements TreeItem, Timelined { sb.append("\t\t\tctx = cctx;\r\n"); } - if (layer.filters != null) { + if (layer.filters != null && layer.filters.size() > 0) { sb.append("\t\t\tvar oldctx = ctx;\r\n"); sb.append("\t\t\tvar fcanvas = createCanvas(canvas.width,canvas.height);"); sb.append("\t\t\tvar fctx = fcanvas.getContext(\"2d\");\r\n"); @@ -2352,7 +2352,7 @@ public final class SWF implements TreeItem, Timelined { .append(placeMatrix.translateX).append(",") .append(placeMatrix.translateY).append("],").append(ctrans_str).append(",").append("").append(layer.blendMode < 1 ? 1 : layer.blendMode).append(",").append(fstr).append(",").append(layer.ratio < 0 ? 0 : layer.ratio).append(",time").append(");\r\n"); - if (layer.filters != null) { + if (layer.filters != null && layer.filters.size() > 0) { for (FILTER filter : layer.filters) { if (filter instanceof COLORMATRIXFILTER) { COLORMATRIXFILTER cmf = (COLORMATRIXFILTER) filter; @@ -2461,8 +2461,8 @@ public final class SWF implements TreeItem, Timelined { sb.append("\t\t\tctx.setTransform(1,0,0,1,0,0);\r\n"); sb.append("\t\t\tctx.drawImage(fcanvas,0,0);\r\n"); sb.append("\t\t\tctx.applyTransforms(ms);\r\n"); - } + if (layer.clipDepth != -1) { sb.append("\t\t\tclips[clips.length-1].clipCanvas = canvas;\r\n"); sb.append("\t\t\tcanvas = createCanvas(canvas.width,canvas.height);\r\n"); @@ -2688,7 +2688,7 @@ public final class SWF implements TreeItem, Timelined { ExportRectangle rect = new ExportRectangle(boundRect); rect = mat.transform(rect); Matrix m = mat.clone(); - if (layer.filters != null) { + if (layer.filters != null && layer.filters.size() > 0) { // calculate size after applying the filters double deltaXMax = 0; double deltaYMax = 0; @@ -2704,6 +2704,8 @@ public final class SWF implements TreeItem, Timelined { rect.yMax += deltaYMax * SWF.unitDivisor; } + rect.xMin -= SWF.unitDivisor; + rect.yMin -= SWF.unitDivisor; rect.xMin = Math.max(0, rect.xMin); rect.yMin = Math.max(0, rect.yMin); @@ -2871,12 +2873,14 @@ public final class SWF implements TreeItem, Timelined { if (t instanceof RemoveTag) { RemoveTag rt = (RemoveTag) t; int depth = rt.getDepth(); - int currentCharId = stage.get(depth); - stage.remove(depth); - if (dependingChars.contains(currentCharId)) { - timeline.tags.remove(i); - i--; - continue; + if (stage.containsKey(depth)) { + int currentCharId = stage.get(depth); + stage.remove(depth); + if (dependingChars.contains(currentCharId)) { + timeline.tags.remove(i); + i--; + continue; + } } } if (t instanceof PlaceObjectTypeTag) { @@ -2885,12 +2889,11 @@ public final class SWF implements TreeItem, Timelined { int depth = po.getDepth(); if (placeCharId != 0) { stage.put(depth, placeCharId); - } - int currentCharId = stage.get(depth); - if (dependingChars.contains(currentCharId)) { - timeline.tags.remove(i); - i--; - continue; + if (dependingChars.contains(placeCharId)) { + timeline.tags.remove(i); + i--; + continue; + } } } if (t instanceof CharacterIdTag) { @@ -2979,4 +2982,4 @@ public final class SWF implements TreeItem, Timelined { updateCharacters(); clearImageCache(); } -} +} \ No newline at end of file diff --git a/src/com/jpexs/decompiler/flash/gui/PreviewImage.java b/src/com/jpexs/decompiler/flash/gui/PreviewImage.java index 437e9a5d2..47106f36c 100644 --- a/src/com/jpexs/decompiler/flash/gui/PreviewImage.java +++ b/src/com/jpexs/decompiler/flash/gui/PreviewImage.java @@ -186,8 +186,8 @@ public class PreviewImage extends JPanel { } else if (treeItem instanceof BoundedTag) { BoundedTag boundedTag = (BoundedTag) treeItem; RECT rect = boundedTag.getRect(); - width = (int) (rect.getWidth() / SWF.unitDivisor); - height = (int) (rect.getHeight() / SWF.unitDivisor); + width = (int) (rect.getWidth() / SWF.unitDivisor) + 1; + height = (int) (rect.getHeight() / SWF.unitDivisor) + 1; m.translate(-rect.Xmin, -rect.Ymin); } diff --git a/src/com/jpexs/helpers/SerializableImage.java b/src/com/jpexs/helpers/SerializableImage.java index b8b01a7b0..5fba9b333 100644 --- a/src/com/jpexs/helpers/SerializableImage.java +++ b/src/com/jpexs/helpers/SerializableImage.java @@ -1,156 +1,156 @@ -/* - * Copyright (C) 2010-2014 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.helpers; - -import java.awt.AlphaComposite; -import java.awt.Color; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.RenderingHints; -import java.awt.image.BufferedImage; -import java.awt.image.ColorModel; -import java.awt.image.IndexColorModel; -import java.awt.image.WritableRaster; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.Hashtable; -import javax.imageio.ImageIO; - -/** - * - * @author JPEXS - */ -public class SerializableImage implements Serializable { - - public static int TYPE_INT_ARGB = BufferedImage.TYPE_INT_ARGB; - public static int TYPE_INT_RGB = BufferedImage.TYPE_INT_RGB; - public static int TYPE_INT_ARGB_PRE = BufferedImage.TYPE_INT_ARGB_PRE; - public static int TYPE_4BYTE_ABGR = BufferedImage.TYPE_4BYTE_ABGR; - - static int imageid = 0; - private BufferedImage image; - private transient Graphics graphics; - - private SerializableImage() { - } - - public SerializableImage(BufferedImage image) { - this.image = image; - } - - public SerializableImage(int i, int i1, int i2) { - image = new BufferedImage(i, i1, i2); - } - - public SerializableImage(ColorModel cm, WritableRaster wr, boolean bln, Hashtable hshtbl) { - image = new BufferedImage(cm, wr, bln, hshtbl); - } - - public SerializableImage(int i, int i1, int i2, IndexColorModel icm) { - image = new BufferedImage(i, i1, i2, icm); - } - - public BufferedImage getBufferedImage() { - /*try { - ImageIO.write(image, "png", new File("c:\\10\\x\\imageid" + String.format("%03d", imageid++) + ".png")); - } catch (IOException ex) { - }*/ - return image; - } - - public void fillTransparent() { - // Make all pixels transparent - Graphics2D g = (Graphics2D) getGraphics(); - g.setComposite(AlphaComposite.Src); - g.setColor(new Color(0, 0, 0, 0f)); - g.fillRect(0, 0, getWidth(), getHeight()); - } - - @Override - protected Object clone() throws CloneNotSupportedException { - SerializableImage retImage = new SerializableImage(); - retImage.image = image; - return retImage; - } - - public Graphics getGraphics() { - //One graphics rule them all - if (graphics != null) { - return graphics; - } - Graphics2D g = (Graphics2D) image.getGraphics(); - g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); - g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); - g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - return graphics = g; - } - - public int getType() { - return image.getType(); - } - - public int getWidth() { - return image.getWidth(); - } - - public int getHeight() { - return image.getHeight(); - } - - public int getRGB(int i, int i1) { - return image.getRGB(i, i1); - } - - public int[] getRGB(int i, int i1, int i2, int i3, int[] ints, int i4, int i5) { - return image.getRGB(i, i1, i2, i3, ints, i4, i5); - } - - public synchronized void setRGB(int i, int i1, int i2) { - image.setRGB(i, i1, i2); - } - - public void setRGB(int i, int i1, int i2, int i3, int[] ints, int i4, int i5) { - image.setRGB(i, i1, i2, i3, ints, i4, i5); - } - - public ColorModel getColorModel() { - return image.getColorModel(); - } - - public WritableRaster getRaster() { - return image.getRaster(); - } - - @Override - public String toString() { - return image.toString(); - } - - private void writeObject(ObjectOutputStream out) throws IOException { - try { - ImageIO.write(image, "png", out); - } catch (Exception ex) { - //ignore - } - } - - private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { - image = ImageIO.read(in); - } -} +/* + * Copyright (C) 2010-2014 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.helpers; + +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.image.BufferedImage; +import java.awt.image.ColorModel; +import java.awt.image.IndexColorModel; +import java.awt.image.WritableRaster; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.Hashtable; +import javax.imageio.ImageIO; + +/** + * + * @author JPEXS + */ +public class SerializableImage implements Serializable { + + public static int TYPE_INT_ARGB = BufferedImage.TYPE_INT_ARGB; + public static int TYPE_INT_RGB = BufferedImage.TYPE_INT_RGB; + public static int TYPE_INT_ARGB_PRE = BufferedImage.TYPE_INT_ARGB_PRE; + public static int TYPE_4BYTE_ABGR = BufferedImage.TYPE_4BYTE_ABGR; + + static int imageid = 0; + private BufferedImage image; + private transient Graphics graphics; + + private SerializableImage() { + } + + public SerializableImage(BufferedImage image) { + this.image = image; + } + + public SerializableImage(int i, int i1, int i2) { + image = new BufferedImage(i, i1, i2); + } + + public SerializableImage(ColorModel cm, WritableRaster wr, boolean bln, Hashtable hshtbl) { + image = new BufferedImage(cm, wr, bln, hshtbl); + } + + public SerializableImage(int i, int i1, int i2, IndexColorModel icm) { + image = new BufferedImage(i, i1, i2, icm); + } + + public BufferedImage getBufferedImage() { + /*try { + javax.imageio.ImageIO.write(image, "png", new File("c:\\10\\x\\imageid" + String.format("%03d", imageid++) + ".png")); + } catch (IOException ex) { + }*/ + return image; + } + + public void fillTransparent() { + // Make all pixels transparent + Graphics2D g = (Graphics2D) getGraphics(); + g.setComposite(AlphaComposite.Src); + g.setColor(new Color(0, 0, 0, 0f)); + g.fillRect(0, 0, getWidth(), getHeight()); + } + + @Override + protected Object clone() throws CloneNotSupportedException { + SerializableImage retImage = new SerializableImage(); + retImage.image = image; + return retImage; + } + + public Graphics getGraphics() { + //One graphics rule them all + if (graphics != null) { + return graphics; + } + Graphics2D g = (Graphics2D) image.getGraphics(); + g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + return graphics = g; + } + + public int getType() { + return image.getType(); + } + + public int getWidth() { + return image.getWidth(); + } + + public int getHeight() { + return image.getHeight(); + } + + public int getRGB(int i, int i1) { + return image.getRGB(i, i1); + } + + public int[] getRGB(int i, int i1, int i2, int i3, int[] ints, int i4, int i5) { + return image.getRGB(i, i1, i2, i3, ints, i4, i5); + } + + public synchronized void setRGB(int i, int i1, int i2) { + image.setRGB(i, i1, i2); + } + + public void setRGB(int i, int i1, int i2, int i3, int[] ints, int i4, int i5) { + image.setRGB(i, i1, i2, i3, ints, i4, i5); + } + + public ColorModel getColorModel() { + return image.getColorModel(); + } + + public WritableRaster getRaster() { + return image.getRaster(); + } + + @Override + public String toString() { + return image.toString(); + } + + private void writeObject(ObjectOutputStream out) throws IOException { + try { + ImageIO.write(image, "png", out); + } catch (Exception ex) { + //ignore + } + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + image = ImageIO.read(in); + } +}