mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-08 08:55:05 +00:00
do not serialize images when memory cache is used
This commit is contained in:
@@ -104,7 +104,6 @@ import com.jpexs.decompiler.flash.types.MATRIX;
|
||||
import com.jpexs.decompiler.flash.types.RECT;
|
||||
import com.jpexs.decompiler.flash.types.filters.BlendComposite;
|
||||
import com.jpexs.decompiler.flash.types.filters.FILTER;
|
||||
import com.jpexs.decompiler.flash.types.filters.Filtering;
|
||||
import com.jpexs.decompiler.flash.types.sound.AdpcmDecoder;
|
||||
import com.jpexs.decompiler.flash.xfl.XFLConverter;
|
||||
import com.jpexs.decompiler.graph.ExportMode;
|
||||
@@ -135,7 +134,6 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.EmptyStackException;
|
||||
@@ -2042,41 +2040,16 @@ public final class SWF implements TreeItem {
|
||||
XFLConverter.convertSWF(handler, this, swfName, outfile, false, generator, generatorVerName, generatorVersion, parallel);
|
||||
}
|
||||
|
||||
public static float twipToPixel(int twip) {
|
||||
return ((float) twip) / 20.0f;
|
||||
}
|
||||
|
||||
private static class CachedImage implements Serializable {
|
||||
|
||||
private final int[] data;
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final int type;
|
||||
public static final long serialVersionUID = 1L;
|
||||
|
||||
public CachedImage(BufferedImage img) {
|
||||
width = img.getWidth();
|
||||
height = img.getHeight();
|
||||
type = img.getType();
|
||||
data = Filtering.getRGB(img, 0, 0, width, height);
|
||||
}
|
||||
|
||||
public BufferedImage getImage() {
|
||||
BufferedImage ret = new BufferedImage(width, height, type);
|
||||
Filtering.setRGB(ret, 0, 0, width, height, data);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public static AffineTransform matrixToTransform(MATRIX mat) {
|
||||
return new AffineTransform(mat.getScaleXFloat(), mat.getRotateSkew0Float(),
|
||||
mat.getRotateSkew1Float(), mat.getScaleYFloat(),
|
||||
mat.translateX, mat.translateY);
|
||||
}
|
||||
private static Cache cache = Cache.getInstance(false);
|
||||
|
||||
private static Cache frameCache = Cache.getInstance(false);
|
||||
|
||||
public void clearImageCache() {
|
||||
cache.clear();
|
||||
frameCache.clear();
|
||||
BitmapExporter.clearShapeCache();
|
||||
}
|
||||
|
||||
@@ -2121,11 +2094,9 @@ public final class SWF implements TreeItem {
|
||||
displayRect = fixRect(displayRect);
|
||||
|
||||
String key = "frame_" + frame + "_" + containerId;
|
||||
if (cache.contains(key)) {
|
||||
CachedImage ciret = ((CachedImage) cache.get(key));
|
||||
if (ciret != null) {
|
||||
return ciret.getImage();
|
||||
}
|
||||
if (frameCache.contains(key)) {
|
||||
BufferedImage ciret = ((BufferedImage) frameCache.get(key));
|
||||
return ciret;
|
||||
}
|
||||
float unzoom = 20;
|
||||
BufferedImage ret = new BufferedImage((int) (displayRect.Xmax / unzoom), (int) (displayRect.Ymax / unzoom), BufferedImage.TYPE_INT_ARGB);
|
||||
@@ -2240,7 +2211,7 @@ public final class SWF implements TreeItem {
|
||||
g.setTransform(AffineTransform.getScaleInstance(1, 1));
|
||||
/*g.setPaint(Color.yellow);
|
||||
g.draw(new Rectangle(ret.getWidth()-1,ret.getHeight()-1));*/
|
||||
cache.put(key, new CachedImage(ret));
|
||||
frameCache.put(key, ret);
|
||||
|
||||
/*try {
|
||||
ImageIO.write(ret, "png", new File("tst_id_" + containerId + "_time_" + System.currentTimeMillis() + ".png"));
|
||||
@@ -2262,12 +2233,12 @@ public final class SWF implements TreeItem {
|
||||
public static void framesToImage(int containerId, List<BufferedImage> ret, int startFrame, int stopFrame, List<Tag> allTags, List<Tag> controlTags, RECT displayRect, int totalFrameCount, Stack<Integer> visited) {
|
||||
for (int i = startFrame; i <= stopFrame; i++) {
|
||||
String key = "frame_" + i + "_" + containerId;
|
||||
if (cache.contains(key)) {
|
||||
CachedImage g = (CachedImage) cache.get(key);
|
||||
if (frameCache.contains(key)) {
|
||||
BufferedImage g = (BufferedImage) frameCache.get(key);
|
||||
if (g == null) {
|
||||
break;
|
||||
}
|
||||
ret.add(g.getImage());
|
||||
ret.add(g);
|
||||
startFrame++;
|
||||
} else {
|
||||
break;
|
||||
|
||||
@@ -27,7 +27,6 @@ import com.jpexs.decompiler.flash.types.RECT;
|
||||
import com.jpexs.decompiler.flash.types.RGB;
|
||||
import com.jpexs.decompiler.flash.types.SHAPE;
|
||||
import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD;
|
||||
import com.jpexs.decompiler.flash.types.shaperecords.SerializableImage;
|
||||
import com.jpexs.helpers.Cache;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
@@ -98,7 +97,7 @@ public class BitmapExporter extends ShapeExporterBase implements IShapeExporter
|
||||
List<SHAPERECORD> records = shape.shapeRecords;
|
||||
String key = "shape_" + records.hashCode() + "_" + (defaultColor == null ? "null" : defaultColor.hashCode());
|
||||
if (cache.contains(key)) {
|
||||
image = (BufferedImage) ((SerializableImage) cache.get(key)).getImage();
|
||||
image = (BufferedImage) cache.get(key);
|
||||
return;
|
||||
}
|
||||
RECT bounds = SHAPERECORD.getBounds(records);
|
||||
@@ -113,7 +112,7 @@ public class BitmapExporter extends ShapeExporterBase implements IShapeExporter
|
||||
defaultStroke = graphics.getStroke();
|
||||
super.export();
|
||||
if (putToCache) {
|
||||
cache.put(key, new SerializableImage(image));
|
||||
cache.put(key, image);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.types;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import java.awt.Point;
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -157,12 +156,4 @@ public class MATRIX implements Serializable {
|
||||
public boolean isEmpty() {
|
||||
return (translateX == 0) && (translateY == 0) && (!hasRotate) && (!hasScale);
|
||||
}
|
||||
|
||||
public double getRotation() {
|
||||
float x = getRotateSkew1Float();
|
||||
float y = SWF.twipToPixel((int) getScaleYFloat());
|
||||
double rotation = ((180 / Math.PI) * Math.atan2(y, x) - 90);
|
||||
if(rotation < 0) { rotation = 360 + rotation; }
|
||||
return rotation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,17 +21,12 @@ import com.jpexs.decompiler.flash.SWFOutputStream;
|
||||
import com.jpexs.decompiler.flash.exporters.BitmapExporter;
|
||||
import com.jpexs.decompiler.flash.tags.base.FontTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.NeedsCharacters;
|
||||
import com.jpexs.decompiler.flash.types.FILLSTYLE;
|
||||
import com.jpexs.decompiler.flash.types.FILLSTYLEARRAY;
|
||||
import com.jpexs.decompiler.flash.types.LINESTYLE;
|
||||
import com.jpexs.decompiler.flash.types.LINESTYLEARRAY;
|
||||
import com.jpexs.decompiler.flash.types.RECT;
|
||||
import com.jpexs.decompiler.flash.types.SHAPE;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.Shape;
|
||||
import java.awt.font.GlyphVector;
|
||||
import java.awt.geom.PathIterator;
|
||||
@@ -39,13 +34,9 @@ import java.awt.geom.Point2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
*/
|
||||
package com.jpexs.helpers;
|
||||
|
||||
import com.jpexs.decompiler.flash.types.shaperecords.SerializableImage;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -47,6 +50,7 @@ public class Cache {
|
||||
instances.add(instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static int storageType = STORAGE_FILES;
|
||||
|
||||
public static void clearAll() {
|
||||
@@ -126,7 +130,11 @@ public class Cache {
|
||||
File f = cacheFiles.get(key);
|
||||
try (FileInputStream fis = new FileInputStream(f)) {
|
||||
ObjectInputStream ois = new ObjectInputStream(fis);
|
||||
return ois.readObject();
|
||||
Object item = ois.readObject();
|
||||
if (item instanceof SerializableImage) {
|
||||
item = ((SerializableImage) item).getImage();
|
||||
}
|
||||
return item;
|
||||
} catch (IOException | ClassNotFoundException ex) {
|
||||
Logger.getLogger(Helper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
@@ -157,7 +165,17 @@ public class Cache {
|
||||
return;
|
||||
}
|
||||
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(temp))) {
|
||||
oos.writeObject(value);
|
||||
if (value instanceof Serializable) {
|
||||
oos.writeObject(value);
|
||||
} else {
|
||||
if (value instanceof BufferedImage) {
|
||||
value = new SerializableImage((BufferedImage) value);
|
||||
oos.writeObject(value);
|
||||
} else {
|
||||
// Object serialization not supported
|
||||
return;
|
||||
}
|
||||
}
|
||||
oos.flush();
|
||||
|
||||
cacheFiles.put(key, temp);
|
||||
|
||||
Reference in New Issue
Block a user