From 317308a6401880cb6c8d025bd54367600f399d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sun, 5 May 2019 13:33:08 +0200 Subject: [PATCH] #1378 Transparent background on PNG/GIF sprite export, SWF background on shape BMP export --- CHANGELOG.md | 4 ++++ .../decompiler/flash/exporters/FrameExporter.java | 3 ++- .../decompiler/flash/exporters/ShapeExporter.java | 15 +++++++++++++-- .../flash/importers/svg/SvgImporter.java | 5 +++-- .../flash/console/CommandLineArgumentParser.java | 2 +- src/com/jpexs/decompiler/flash/gui/MainPanel.java | 6 +++--- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64bc7ae10..ab0716581 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ All notable changes to this project will be documented in this file. - AS3 direct editation - invalid generation of lookupswitch - AS3 direct editation - fix access to protected members with super +### Changed +- #1378 Transparent background on PNG/GIF sprite export +- SWF background on shape BMP export + ## [11.2.0] - 2018-09-08 ### Added - Warning panel on scripts containing ยงยง instructions (Tip for Settings/Automatic deobfuscation) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/FrameExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/FrameExporter.java index 11414216c..0b4f3ea5e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/FrameExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/FrameExporter.java @@ -379,6 +379,7 @@ public class FrameExporter { } final Color fbackgroundColor = backgroundColor; + final boolean fusesTransparency = settings.mode == FrameExportMode.PNG || settings.mode == FrameExportMode.GIF; final Iterator frameImages = new Iterator() { private int pos = 0; @@ -406,7 +407,7 @@ public class FrameExporter { } int fframe = fframes.get(pos++); - BufferedImage result = SWF.frameToImageGet(tim, fframe, fframe, null, 0, tim.displayRect, new Matrix(), null, null, settings.zoom).getBufferedImage(); + BufferedImage result = SWF.frameToImageGet(tim, fframe, fframe, null, 0, tim.displayRect, new Matrix(), null, fusesTransparency ? null : fbackgroundColor, settings.zoom).getBufferedImage(); if (evl != null) { evl.handleExportedEvent("frame", pos, fframes.size(), tagName); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ShapeExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ShapeExporter.java index 01760f0dc..f9a20e4af 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ShapeExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ShapeExporter.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.exporters; import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler; @@ -35,11 +36,13 @@ import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.tags.enums.ImageFormat; import com.jpexs.decompiler.flash.types.CXFORMWITHALPHA; import com.jpexs.decompiler.flash.types.RECT; +import com.jpexs.decompiler.flash.types.RGB; import com.jpexs.decompiler.flash.types.SHAPE; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Path; import com.jpexs.helpers.SerializableImage; import com.jpexs.helpers.utf8.Utf8Helper; +import java.awt.Graphics2D; import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -59,7 +62,7 @@ import java.util.logging.Logger; */ public class ShapeExporter { - public List exportShapes(AbortRetryIgnoreHandler handler, final String outdir, ReadOnlyTagList tags, final ShapeExportSettings settings, EventListener evl) throws IOException, InterruptedException { + public List exportShapes(AbortRetryIgnoreHandler handler, final String outdir, final SWF swf, ReadOnlyTagList tags, final ShapeExportSettings settings, EventListener evl) throws IOException, InterruptedException { List ret = new ArrayList<>(); if (tags.isEmpty()) { return ret; @@ -109,6 +112,14 @@ public class ShapeExporter { int newHeight = (int) (rect.getHeight() * settings.zoom / SWF.unitDivisor) + 1; SerializableImage img = new SerializableImage(newWidth, newHeight, SerializableImage.TYPE_INT_ARGB_PRE); img.fillTransparent(); + if (settings.mode == ShapeExportMode.BMP) { + RGB backColor = swf.getBackgroundColor().backgroundColor; + if (backColor != null) { + Graphics2D g = (Graphics2D) img.getGraphics(); + g.setColor(backColor.toColor()); + g.fillRect(0, 0, img.getWidth(), img.getHeight()); + } + } Matrix m = Matrix.getScaleInstance(settings.zoom); m.translate(-rect.Xmin, -rect.Ymin); st.toImage(0, 0, 0, new RenderContext(), img, false, m, m, m, new CXFORMWITHALPHA()); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/svg/SvgImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/svg/SvgImporter.java index e5449112a..ab6092ccf 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/svg/SvgImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/svg/SvgImporter.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.importers.svg; import com.jpexs.decompiler.flash.ReadOnlyTagList; @@ -1062,7 +1063,7 @@ public class SvgImporter { swf.assignExportNamesToSymbols(); st.shapeBounds.Xmax = (int) (si.getWidth() * SWF.unitDivisor); st.shapeBounds.Ymax = (int) (si.getHeight() * SWF.unitDivisor); - new ShapeExporter().exportShapes(null, "./outex/", new ReadOnlyTagList(li), new ShapeExportSettings(ShapeExportMode.SVG, 1), null); + new ShapeExporter().exportShapes(null, "./outex/", swf, new ReadOnlyTagList(li), new ShapeExportSettings(ShapeExportMode.SVG, 1), null); } //Test for SVG diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index 82220134d..eb5ac2ea0 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -2239,7 +2239,7 @@ public class CommandLineArgumentParser { if (exportAll || exportFormats.contains("shape")) { System.out.println("Exporting shapes..."); - new ShapeExporter().exportShapes(handler, outDir + (multipleExportTypes ? File.separator + ShapeExportSettings.EXPORT_FOLDER_NAME : ""), new ReadOnlyTagList(extags), new ShapeExportSettings(enumFromStr(formats.get("shape"), ShapeExportMode.class), zoom), evl); + new ShapeExporter().exportShapes(handler, outDir + (multipleExportTypes ? File.separator + ShapeExportSettings.EXPORT_FOLDER_NAME : ""), swf, new ReadOnlyTagList(extags), new ShapeExportSettings(enumFromStr(formats.get("shape"), ShapeExportMode.class), zoom), evl); } if (exportAll || exportFormats.contains("morphshape")) { diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index d7da6dfb9..c5ffcb93e 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -1240,7 +1240,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se } if (export.isOptionEnabled(ShapeExportMode.class)) { - ret.addAll(new ShapeExporter().exportShapes(handler, selFile2 + File.separator + ShapeExportSettings.EXPORT_FOLDER_NAME, new ReadOnlyTagList(shapes), + ret.addAll(new ShapeExporter().exportShapes(handler, selFile2 + File.separator + ShapeExportSettings.EXPORT_FOLDER_NAME, swf, new ReadOnlyTagList(shapes), new ShapeExportSettings(export.getValue(ShapeExportMode.class), export.getZoom()), evl)); } @@ -1352,7 +1352,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se } if (export.isOptionEnabled(ShapeExportMode.class)) { - new ShapeExporter().exportShapes(handler, Path.combine(selFile, ShapeExportSettings.EXPORT_FOLDER_NAME), swf.getTags(), + new ShapeExporter().exportShapes(handler, Path.combine(selFile, ShapeExportSettings.EXPORT_FOLDER_NAME), swf, swf.getTags(), new ShapeExportSettings(export.getValue(ShapeExportMode.class), export.getZoom()), evl); } @@ -1446,7 +1446,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se if (export.isOptionEnabled(ShapeExportMode.class)) { for (ShapeExportMode exportMode : ShapeExportMode.values()) { - new ShapeExporter().exportShapes(handler, Path.combine(selFile, ShapeExportSettings.EXPORT_FOLDER_NAME, exportMode.name()), swf.getTags(), + new ShapeExporter().exportShapes(handler, Path.combine(selFile, ShapeExportSettings.EXPORT_FOLDER_NAME, exportMode.name()), swf, swf.getTags(), new ShapeExportSettings(exportMode, export.getZoom()), evl); } }