From 3ddb7b0d6e31477274954300b09162e4054ab0a0 Mon Sep 17 00:00:00 2001 From: Honfika Date: Mon, 24 Feb 2014 22:10:43 +0100 Subject: [PATCH] layers which has filters (outside of the bounding box) are cropped: fixed --- trunk/src/com/jpexs/decompiler/flash/SWF.java | 27 ++++++++++++------- .../flash/configuration/Configuration.java | 2 ++ .../flash/exporters/BitmapExporter.java | 1 - .../decompiler/flash/gui/ImagePanel.java | 4 --- .../com/jpexs/helpers/SerializableImage.java | 14 +++------- 5 files changed, 22 insertions(+), 26 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index f02cfbfcb..cf1396a9c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -2089,7 +2089,9 @@ public final class SWF implements TreeItem { } public static void putToCache(String key, SerializableImage img) { - frameCache.put(key, img); + if (Configuration.useFrameCache.get()) { + frameCache.put(key, img); + } } public static void clearImageCache() { @@ -2131,9 +2133,9 @@ public final class SWF implements TreeItem { public static SerializableImage frameToImage(int containerId, int frame, List allTags, List controlTags, RECT displayRect, int totalFrameCount, Stack visited, Matrix transformation) { String key = "frame_" + frame + "_" + containerId + "_" + allTags.get(0).getSwf().hashCode(); - if (frameCache.contains(key)) { - SerializableImage ciret = ((SerializableImage) frameCache.get(key)); - return ciret; + SerializableImage image = getFromCache(key); + if (image != null) { + return image; } List frameInfos = getFrameInfo(frame, frame, allTags, controlTags, totalFrameCount); @@ -2144,12 +2146,12 @@ public final class SWF implements TreeItem { FrameInfo fi = frameInfos.get(0); RECT rect = displayRect; - SerializableImage image = new SerializableImage((int) (rect.getWidth() / SWF.unitDivisor) + 1, + image = new SerializableImage((int) (rect.getWidth() / SWF.unitDivisor) + 1, (int) (rect.getHeight() / SWF.unitDivisor) + 1, SerializableImage.TYPE_INT_ARGB); Matrix m = new Matrix(); m.translate(-rect.Xmin, -rect.Ymin); frameToImage(containerId, fi.maxDepth, fi.layers, fi.backgroundColor, fi.characters, fi.frame, allTags, controlTags, displayRect, visited, image, m); - frameCache.put(key, image); + putToCache(key, image); return image; } @@ -2326,11 +2328,16 @@ public final class SWF implements TreeItem { RECT boundRect = bounded.getRect(characters, new Stack()); ExportRectangle rect = new ExportRectangle(boundRect); rect = mat.transform(rect); - img = new SerializableImage((int) (rect.getWidth() / SWF.unitDivisor) + 1, - (int) (rect.getHeight() / SWF.unitDivisor) + 1, SerializableImage.TYPE_INT_ARGB); Matrix m = mat.clone(); - m.translate(-rect.xMin, -rect.yMin); - drawMatrix.translate(rect.xMin, rect.yMin); + if (layer.filters != null) { + // needs the whole size because of the filters + img = new SerializableImage(image.getWidth(), image.getHeight(), SerializableImage.TYPE_INT_ARGB); + } else { + img = new SerializableImage((int) (rect.getWidth() / SWF.unitDivisor) + 1, + (int) (rect.getHeight() / SWF.unitDivisor) + 1, SerializableImage.TYPE_INT_ARGB); + m.translate(-rect.xMin, -rect.yMin); + drawMatrix.translate(rect.xMin, rect.yMin); + } drawable.toImage(layer.ratio < 0 ? 0 : layer.ratio/*layer.duration*/, allTags, characters, visited, img, m); } else { // only DefineFont tags diff --git a/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java index adceaa03b..ac782e079 100644 --- a/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -91,6 +91,8 @@ public class Configuration { @ConfigurationDefaultBoolean(false) public static final ConfigurationItem showAllAddresses = null; @ConfigurationDefaultBoolean(true) + public static final ConfigurationItem useFrameCache = null; + @ConfigurationDefaultBoolean(true) public static final ConfigurationItem useRibbonInterface = null; @ConfigurationDefaultBoolean(false) public static final ConfigurationItem openFolderAfterFlaExport = null; diff --git a/trunk/src/com/jpexs/decompiler/flash/exporters/BitmapExporter.java b/trunk/src/com/jpexs/decompiler/flash/exporters/BitmapExporter.java index 03a6d36b0..143a2e056 100644 --- a/trunk/src/com/jpexs/decompiler/flash/exporters/BitmapExporter.java +++ b/trunk/src/com/jpexs/decompiler/flash/exporters/BitmapExporter.java @@ -110,7 +110,6 @@ public class BitmapExporter extends ShapeExporterBase implements IShapeExporter graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); defaultStroke = graphics.getStroke(); super.export(); - image.bounds = new Rectangle2D.Double(deltaX, deltaY, width, height); } private void exportTo(SerializableImage image, Matrix transformation) { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index e4988b1c4..8474c7702 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -143,9 +143,6 @@ public final class ImagePanel extends JPanel implements ActionListener, FlashDis } SWF.putToCache(key, img); } - if (img != null && img.bounds != null && mat != null) { - mat.translate(img.bounds.getMinX(), img.bounds.getMinY()); - } if (img != null) { setImage(img); } @@ -217,7 +214,6 @@ public final class ImagePanel extends JPanel implements ActionListener, FlashDis } SWF.putToCache(key, img); } - mat.translate(img.bounds.getMinX(), img.bounds.getMinY()); ImageIcon icon = new ImageIcon(img.getBufferedImage()); label.setIcon(icon); frame = nframe; diff --git a/trunk/src/com/jpexs/helpers/SerializableImage.java b/trunk/src/com/jpexs/helpers/SerializableImage.java index 2f4972293..f0b174189 100644 --- a/trunk/src/com/jpexs/helpers/SerializableImage.java +++ b/trunk/src/com/jpexs/helpers/SerializableImage.java @@ -17,11 +17,11 @@ package com.jpexs.helpers; import java.awt.Graphics; -import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.awt.image.IndexColorModel; import java.awt.image.WritableRaster; +import java.io.File; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -42,7 +42,6 @@ public class SerializableImage implements Serializable { static int imageid = 0; private BufferedImage image; - public Rectangle2D bounds = new Rectangle2D.Double(); public SerializableImage() { } @@ -63,11 +62,6 @@ public class SerializableImage implements Serializable { image = new BufferedImage(i, i1, i2, icm); } - public void setBufferedImage(BufferedImage image, Rectangle2D bounds) { - this.image = image; - this.bounds = bounds; - } - public BufferedImage getBufferedImage() { /*try { ImageIO.write(image, "png", new File("c:\\10\\x\\imageid" + String.format("%03d", imageid++) + ".png")); @@ -80,8 +74,6 @@ public class SerializableImage implements Serializable { protected Object clone() throws CloneNotSupportedException { SerializableImage retImage = new SerializableImage(); retImage.image = image; - retImage.bounds = new Rectangle2D.Double(bounds.getMinX(), bounds.getMinY(), - bounds.getWidth(), bounds.getHeight()); return retImage; } @@ -131,12 +123,12 @@ public class SerializableImage implements Serializable { } private void writeObject(ObjectOutputStream out) throws IOException { - out.writeObject(bounds); + // out.writeObject(bounds); ImageIO.write(image, "png", out); } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { - bounds = (Rectangle2D) in.readObject(); + // bounds = (Rectangle2D) in.readObject(); image = ImageIO.read(in); } }