From 9212d6958b96580e291e7c64faab5e8686070319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sun, 25 Aug 2013 13:31:10 +0200 Subject: [PATCH] Cache fixes --- trunk/src/com/jpexs/decompiler/flash/SWF.java | 5 ++- .../flash/types/shaperecords/SHAPERECORD.java | 36 +++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index faa7c9e29..faebc338a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -2208,7 +2208,10 @@ public class SWF { String key = "frame_" + frame + "_" + containerId; if (cache.contains(key)) { - return ((CachedImage) cache.get(key)).getImage(); + CachedImage ciret = ((CachedImage) cache.get(key)); + if (ciret != null) { + return ciret.getImage(); + } } float unzoom = 20; BufferedImage ret = new BufferedImage((int) (displayRect.Xmax / unzoom), (int) (displayRect.Ymax / unzoom), BufferedImage.TYPE_INT_ARGB); 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 ba2b98a13..b62411aba 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SHAPERECORD.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/SHAPERECORD.java @@ -52,6 +52,10 @@ import java.awt.geom.GeneralPath; import java.awt.geom.PathIterator; import java.awt.geom.Point2D; import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -61,6 +65,7 @@ import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; +import javax.imageio.ImageIO; import javax.swing.JPanel; /** @@ -836,7 +841,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters { public static BufferedImage shapeToImage(List tags, int shapeNum, FILLSTYLEARRAY fillStyles, LINESTYLEARRAY lineStylesList, List records, Color defaultColor) { String key = "shape_" + records.hashCode() + "_" + (defaultColor == null ? "null" : defaultColor.hashCode()); if (cache.contains(key)) { - return (BufferedImage) cache.get(key); + return (BufferedImage) ((SerializableImage)cache.get(key)).getImage(); } RECT rect = new RECT(); List paths = getPaths(rect, shapeNum, fillStyles, lineStylesList, /*numFillBits, numLineBits,*/ records); @@ -856,7 +861,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters { } p.drawTo(tags, -rect.Xmin, -rect.Ymin, g, shapeNum); } - cache.put(key, ret); + cache.put(key, new SerializableImage(ret)); return ret; } @@ -1066,4 +1071,31 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters { double y = p0.getY() + ((p1.getY() - p0.getY()) * ratio); return new Point2D.Double(x, y); } + + private static class SerializableImage implements Serializable { + + transient BufferedImage image; + + public BufferedImage getImage() { + return image; + } + + public void setImage(BufferedImage image) { + this.image = image; + } + + public SerializableImage(BufferedImage image) { + this.image = image; + } + + private void writeObject(ObjectOutputStream out) throws IOException { + out.defaultWriteObject(); + ImageIO.write(image, "png", out); + } + + private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); + image = ImageIO.read(in); + } + } }