From 0a38121ca361b07a88fddbe85193564156d1f92d Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sun, 1 Feb 2015 14:29:28 +0100 Subject: [PATCH] shape caching fixed --- .../exporters/shape/ShapeExportData.java | 36 +++++++++++++++ .../exporters/shape/ShapeExporterBase.java | 44 ++++++++++--------- .../decompiler/flash/timeline/Timeline.java | 6 +++ .../jpexs/decompiler/flash/gui/MainPanel.java | 6 +-- 4 files changed, 69 insertions(+), 23 deletions(-) create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/ShapeExportData.java diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/ShapeExportData.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/ShapeExportData.java new file mode 100644 index 000000000..1ab573e4a --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/ShapeExportData.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2010-2015 JPEXS, All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.exporters.shape; + +import com.jpexs.decompiler.flash.types.FILLSTYLE; +import com.jpexs.decompiler.flash.types.LINESTYLE; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class ShapeExportData { + + public List fillStyles; + + public List lineStyles; + + public List> fillPaths; + + public List> linePaths; +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/ShapeExporterBase.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/ShapeExporterBase.java index c9a1da868..38393dbbd 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/ShapeExporterBase.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/ShapeExporterBase.java @@ -58,42 +58,46 @@ public abstract class ShapeExporterBase implements IShapeExporter { private final ColorTransform colorTransform; - private static final Cache>> fillEdgeMapCache = Cache.getInstance(true, true, "fillEdgeMap"); - - private static final Cache>> lineEdgeMapCache = Cache.getInstance(true, true, "lineEdgeMap"); + private static final Cache exportDataCache = Cache.getInstance(true, true, "shapeExportDataCache"); public ShapeExporterBase(SHAPE shape, ColorTransform colorTransform) { this.shape = shape; this.colorTransform = colorTransform; - _fillStyles = new ArrayList<>(); - _lineStyles = new ArrayList<>(); - if (shape instanceof SHAPEWITHSTYLE) { - SHAPEWITHSTYLE shapeWithStyle = (SHAPEWITHSTYLE) shape; - _fillStyles.addAll(Arrays.asList(shapeWithStyle.fillStyles.fillStyles)); - _lineStyles.addAll(Arrays.asList(shapeWithStyle.lineStyles.lineStyles)); - } - List> fillPaths = fillEdgeMapCache.get(shape); - List> linePaths = lineEdgeMapCache.get(shape); - if (fillPaths == null || linePaths == null) { + ShapeExportData cachedData = exportDataCache.get(shape); + if (cachedData == null) { + List fillStyles = new ArrayList<>(); + List lineStyles = new ArrayList<>(); + if (shape instanceof SHAPEWITHSTYLE) { + SHAPEWITHSTYLE shapeWithStyle = (SHAPEWITHSTYLE) shape; + fillStyles.addAll(Arrays.asList(shapeWithStyle.fillStyles.fillStyles)); + lineStyles.addAll(Arrays.asList(shapeWithStyle.lineStyles.lineStyles)); + } + // Create edge maps List>> fillEdgeMaps = new ArrayList<>(); List>> lineEdgeMaps = new ArrayList<>(); - createEdgeMaps(shape, _fillStyles, _lineStyles, fillEdgeMaps, lineEdgeMaps); + createEdgeMaps(shape, fillStyles, lineStyles, fillEdgeMaps, lineEdgeMaps); int count = lineEdgeMaps.size(); - fillPaths = new ArrayList<>(count); - linePaths = new ArrayList<>(count); + List> fillPaths = new ArrayList<>(count); + List> linePaths = new ArrayList<>(count); for (int i = 0; i < count; i++) { fillPaths.add(createPathFromEdgeMap(fillEdgeMaps.get(i))); linePaths.add(createPathFromEdgeMap(lineEdgeMaps.get(i))); } - fillEdgeMapCache.put(shape, fillPaths); - lineEdgeMapCache.put(shape, linePaths); + cachedData = new ShapeExportData(); + cachedData.fillPaths = fillPaths; + cachedData.linePaths = linePaths; + cachedData.fillStyles = fillStyles; + cachedData.lineStyles = lineStyles; + exportDataCache.put(shape, cachedData); } - _fillPaths = fillPaths; - _linePaths = linePaths; + _fillStyles = cachedData.fillStyles; + _lineStyles = cachedData.lineStyles; + _fillPaths = cachedData.fillPaths; + _linePaths = cachedData.linePaths; } public void export() { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/Timeline.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/Timeline.java index 208e6c8f1..d82c06b18 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/Timeline.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/Timeline.java @@ -100,6 +100,12 @@ public class Timeline { return frames; } + public void addFrame(Frame frame) { + ensureInitialized(); + frames.add(frame); + maxDepth = getMaxDepthInternal(); + } + public AS2Package getAS2RootPackage() { ensureInitialized(); return as2RootPackage; diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 3342c8300..c35362d66 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -2661,7 +2661,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec ds.matrix = new MATRIX(); ds.ratio = i * 65535 / framesCnt; f.layers.put(1, ds); - tim.getFrames().add(f); + tim.addFrame(f); } } else if (tag instanceof FontTag) { int pageCount = PreviewPanel.getFontPageCount((FontTag) tag); @@ -2672,7 +2672,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec ds.matrix = new MATRIX(); ds.time = i; f.layers.put(1, ds); - tim.getFrames().add(f); + tim.addFrame(f); } } else { Frame f = new Frame(tim, 0); @@ -2680,7 +2680,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec ds.characterId = ((CharacterTag) tag).getCharacterId(); ds.matrix = new MATRIX(); f.layers.put(1, ds); - tim.getFrames().add(f); + tim.addFrame(f); } tim.displayRect = getRect(); return tim;