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 3ca672ef2..96714b26f 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 @@ -28,6 +28,7 @@ import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter; import com.jpexs.decompiler.flash.exporters.modes.FrameExportMode; import com.jpexs.decompiler.flash.exporters.settings.ButtonExportSettings; import com.jpexs.decompiler.flash.exporters.settings.FrameExportSettings; +import com.jpexs.decompiler.flash.exporters.settings.SpriteExportSettings; import com.jpexs.decompiler.flash.exporters.shape.CanvasShapeExporter; import com.jpexs.decompiler.flash.helpers.BMPFile; import com.jpexs.decompiler.flash.helpers.ImageHelper; @@ -110,6 +111,38 @@ public class FrameExporter { return exportFrames(handler, outdir, swf, containerId, frames, fes, evl); } + public List exportFrames(AbortRetryIgnoreHandler handler, String outdir, SWF swf, int containerId, List frames, SpriteExportSettings settings, EventListener evl) throws IOException { + FrameExportMode fem; + switch (settings.mode) { + case PNG: + fem = FrameExportMode.PNG; + break; + case GIF: + fem = FrameExportMode.GIF; + break; + case AVI: + fem = FrameExportMode.AVI; + break; + case SVG: + fem = FrameExportMode.SVG; + break; + case CANVAS: + fem = FrameExportMode.CANVAS; + break; + case PDF: + fem = FrameExportMode.PDF; + break; + case BMP: + fem = FrameExportMode.BMP; + break; + default: + throw new Error("Unsupported sprite export mode"); + } + + FrameExportSettings fes = new FrameExportSettings(fem, settings.zoom); + return exportFrames(handler, outdir, swf, containerId, frames, fes, evl); + } + public List exportFrames(AbortRetryIgnoreHandler handler, String outdir, final SWF swf, int containerId, List frames, final FrameExportSettings settings, final EventListener evl) throws IOException { final List ret = new ArrayList<>(); if (swf.tags.isEmpty()) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/modes/SpriteExportMode.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/modes/SpriteExportMode.java new file mode 100644 index 000000000..172ae11a4 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/modes/SpriteExportMode.java @@ -0,0 +1,32 @@ +/* + * 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.modes; + +/** + * + * @author JPEXS + */ +public enum SpriteExportMode { + + PNG, + GIF, + AVI, + SVG, + CANVAS, + PDF, + BMP +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/FrameExportSettings.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/FrameExportSettings.java index 50f7b74cb..52a8accf8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/FrameExportSettings.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/FrameExportSettings.java @@ -26,8 +26,6 @@ public class FrameExportSettings { public static final String EXPORT_FOLDER_NAME = "frames"; - public static final String EXPORT_FOLDER_NAME_SPRITE = "sprites"; - public FrameExportMode mode; public double zoom; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/SpriteExportSettings.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/SpriteExportSettings.java new file mode 100644 index 000000000..2cfba14ec --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/settings/SpriteExportSettings.java @@ -0,0 +1,37 @@ +/* + * 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.settings; + +import com.jpexs.decompiler.flash.exporters.modes.SpriteExportMode; + +/** + * + * @author JPEXS + */ +public class SpriteExportSettings { + + public static final String EXPORT_FOLDER_NAME = "sprites"; + + public SpriteExportMode mode; + + public double zoom; + + public SpriteExportSettings(SpriteExportMode mode, double zoom) { + this.mode = mode; + this.zoom = zoom; + } +} diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index c9b616ac1..f380c8ec7 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -57,6 +57,7 @@ import com.jpexs.decompiler.flash.exporters.modes.MovieExportMode; import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; import com.jpexs.decompiler.flash.exporters.modes.ShapeExportMode; import com.jpexs.decompiler.flash.exporters.modes.SoundExportMode; +import com.jpexs.decompiler.flash.exporters.modes.SpriteExportMode; import com.jpexs.decompiler.flash.exporters.modes.TextExportMode; import com.jpexs.decompiler.flash.exporters.settings.BinaryDataExportSettings; import com.jpexs.decompiler.flash.exporters.settings.ButtonExportSettings; @@ -68,6 +69,7 @@ import com.jpexs.decompiler.flash.exporters.settings.MovieExportSettings; import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings; import com.jpexs.decompiler.flash.exporters.settings.ShapeExportSettings; import com.jpexs.decompiler.flash.exporters.settings.SoundExportSettings; +import com.jpexs.decompiler.flash.exporters.settings.SpriteExportSettings; import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings; import com.jpexs.decompiler.flash.exporters.swf.SwfXmlExporter; import com.jpexs.decompiler.flash.gui.Main; @@ -177,6 +179,8 @@ public class CommandLineArgumentParser { out.println(" movie - Movies (Default format: FLV without sound)"); out.println(" font - Fonts (Default format: TTF)"); out.println(" frame - Frames (Default format: PNG)"); + out.println(" sprite - Sprites (Default format: PNG)"); + out.println(" button - Buttons (Default format: PNG)"); out.println(" sound - Sounds (Default format: MP3/WAV/FLV only sound)"); out.println(" binaryData - Binary data (Default format: Raw data)"); out.println(" text - Texts (Default format: Plain text)"); @@ -209,6 +213,13 @@ public class CommandLineArgumentParser { out.println(" frame:canvas - HTML5 Canvas format for Frames"); out.println(" frame:pdf - PDF format for Frames"); out.println(" frame:bmp - BMP format for Frames"); + out.println(" sprite:png - PNG format for Sprites"); + out.println(" sprite:gif - GIF format for Sprites"); + out.println(" sprite:avi - AVI format for Sprites"); + out.println(" sprite:svg - SVG format for Sprites"); + out.println(" sprite:canvas - HTML5 Canvas format for Sprites"); + out.println(" sprite:pdf - PDF format for Sprites"); + out.println(" sprite:bmp - BMP format for Sprites"); out.println(" button:png - PNG format for Buttons"); out.println(" button:svg - SVG format for Buttons"); out.println(" button:bmp - BMP format for Buttons"); @@ -1104,9 +1115,14 @@ public class CommandLineArgumentParser { } FrameExportSettings fes = new FrameExportSettings(enumFromStr(formats.get("frame"), FrameExportMode.class), zoom); frameExporter.exportFrames(handler, outDir + (multipleExportTypes ? File.separator + FrameExportSettings.EXPORT_FOLDER_NAME : ""), swf, 0, frames, fes, evl); + } + + if (exportAll || exportFormats.contains("sprite")) { + System.out.println("Exporting sprite..."); + SpriteExportSettings ses = new SpriteExportSettings(enumFromStr(formats.get("sprite"), SpriteExportMode.class), zoom); for (CharacterTag c : swf.getCharacters().values()) { if (c instanceof DefineSpriteTag) { - frameExporter.exportFrames(handler, outDir + (multipleExportTypes ? File.separator + FrameExportSettings.EXPORT_FOLDER_NAME_SPRITE : ""), swf, c.getCharacterId(), null, fes, evl); + frameExporter.exportFrames(handler, outDir + (multipleExportTypes ? File.separator + SpriteExportSettings.EXPORT_FOLDER_NAME : ""), swf, c.getCharacterId(), null, ses, evl); } } } diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 17b89e616..583d3b2c3 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -52,6 +52,7 @@ import com.jpexs.decompiler.flash.exporters.modes.MovieExportMode; import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; import com.jpexs.decompiler.flash.exporters.modes.ShapeExportMode; import com.jpexs.decompiler.flash.exporters.modes.SoundExportMode; +import com.jpexs.decompiler.flash.exporters.modes.SpriteExportMode; import com.jpexs.decompiler.flash.exporters.modes.SymbolClassExportMode; import com.jpexs.decompiler.flash.exporters.modes.TextExportMode; import com.jpexs.decompiler.flash.exporters.script.AS2ScriptExporter; @@ -65,6 +66,7 @@ import com.jpexs.decompiler.flash.exporters.settings.MovieExportSettings; import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings; import com.jpexs.decompiler.flash.exporters.settings.ShapeExportSettings; import com.jpexs.decompiler.flash.exporters.settings.SoundExportSettings; +import com.jpexs.decompiler.flash.exporters.settings.SpriteExportSettings; import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings; import com.jpexs.decompiler.flash.exporters.swf.SwfJavaExporter; import com.jpexs.decompiler.flash.exporters.swf.SwfXmlExporter; @@ -1190,8 +1192,21 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se FrameExportSettings fes = new FrameExportSettings(export.getValue(FrameExportMode.class), export.getZoom()); for (Entry> entry : frames.entrySet()) { int containerId = entry.getKey(); - String subFolder = containerId == 0 ? FrameExportSettings.EXPORT_FOLDER_NAME : FrameExportSettings.EXPORT_FOLDER_NAME_SPRITE; - ret.addAll(frameExporter.exportFrames(handler, selFile + File.separator + subFolder, swf, containerId, entry.getValue(), fes, evl)); + if (containerId == 0) { + String subFolder = FrameExportSettings.EXPORT_FOLDER_NAME; + ret.addAll(frameExporter.exportFrames(handler, selFile + File.separator + subFolder, swf, containerId, entry.getValue(), fes, evl)); + } + } + } + + if (export.isOptionEnabled(SpriteExportMode.class)) { + SpriteExportSettings ses = new SpriteExportSettings(export.getValue(SpriteExportMode.class), export.getZoom()); + for (Entry> entry : frames.entrySet()) { + int containerId = entry.getKey(); + if (containerId != 0) { + String subFolder = SpriteExportSettings.EXPORT_FOLDER_NAME; + ret.addAll(frameExporter.exportFrames(handler, selFile + File.separator + subFolder, swf, containerId, entry.getValue(), ses, evl)); + } } } @@ -1294,9 +1309,13 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se if (export.isOptionEnabled(FrameExportMode.class)) { FrameExportSettings fes = new FrameExportSettings(export.getValue(FrameExportMode.class), export.getZoom()); frameExporter.exportFrames(handler, Path.combine(selFile, FrameExportSettings.EXPORT_FOLDER_NAME), swf, 0, null, fes, evl); + } + + if (export.isOptionEnabled(SpriteExportMode.class)) { + SpriteExportSettings ses = new SpriteExportSettings(export.getValue(SpriteExportMode.class), export.getZoom()); for (CharacterTag c : swf.getCharacters().values()) { if (c instanceof DefineSpriteTag) { - frameExporter.exportFrames(handler, Path.combine(selFile, FrameExportSettings.EXPORT_FOLDER_NAME_SPRITE), swf, c.getCharacterId(), null, fes, evl); + frameExporter.exportFrames(handler, Path.combine(selFile, SpriteExportSettings.EXPORT_FOLDER_NAME), swf, c.getCharacterId(), null, ses, evl); } } } @@ -1396,9 +1415,15 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se for (FrameExportMode exportMode : FrameExportMode.values()) { FrameExportSettings fes = new FrameExportSettings(exportMode, export.getZoom()); frameExporter.exportFrames(handler, Path.combine(selFile, FrameExportSettings.EXPORT_FOLDER_NAME, exportMode.name()), swf, 0, null, fes, evl); + } + } + + if (export.isOptionEnabled(SpriteExportMode.class)) { + for (SpriteExportMode exportMode : SpriteExportMode.values()) { + SpriteExportSettings ses = new SpriteExportSettings(exportMode, export.getZoom()); for (CharacterTag c : swf.getCharacters().values()) { if (c instanceof DefineSpriteTag) { - frameExporter.exportFrames(handler, Path.combine(selFile, FrameExportSettings.EXPORT_FOLDER_NAME_SPRITE, exportMode.name()), swf, c.getCharacterId(), null, fes, evl); + frameExporter.exportFrames(handler, Path.combine(selFile, SpriteExportSettings.EXPORT_FOLDER_NAME, exportMode.name()), swf, c.getCharacterId(), null, ses, evl); } } }