From 9689f16a4b745ffc51c5ef1dc3e09cabf789de5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Wed, 28 Dec 2022 08:46:39 +0100 Subject: [PATCH] Fixed #1922 FLA/XFL/Canvas/SVG export - exporting DefineBitsJPEG3/4 with alpha as JPEG with PNG extension --- CHANGELOG.md | 2 ++ .../src/com/jpexs/decompiler/flash/SWF.java | 2 +- .../morphshape/SVGMorphShapeExporter.java | 2 +- .../exporters/shape/SVGShapeExporter.java | 2 +- .../flash/importers/ImageImporter.java | 2 +- .../decompiler/flash/tags/base/ImageTag.java | 20 +++++++++++++++++++ .../decompiler/flash/xfl/XFLConverter.java | 3 ++- 7 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8cad9dd7..f0ebe25e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. ## [Unreleased] ### Fixed - Copy/Move/Cut with dependencies did not handle original tag when not charactertag +- [#1922] FLA/XFL/Canvas/SVG export - exporting DefineBitsJPEG3/4 with alpha as JPEG with PNG extension ## [18.2.0] - 2022-12-27 ### Added @@ -2804,6 +2805,7 @@ All notable changes to this project will be documented in this file. [alpha 9]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha8...alpha9 [alpha 8]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha7...alpha8 [alpha 7]: https://github.com/jindrapetrik/jpexs-decompiler/releases/tag/alpha7 +[#1922]: https://www.free-decompiler.com/flash/issues/1922 [#1917]: https://www.free-decompiler.com/flash/issues/1917 [#1827]: https://www.free-decompiler.com/flash/issues/1827 [#1424]: https://www.free-decompiler.com/flash/issues/1424 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index 59afba593..0ca6ff9da 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -2425,7 +2425,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { if (ch instanceof ImageTag) { ImageTag image = (ImageTag) ch; ImageFormat format = image.getImageFormat(); - byte[] imageData = Helper.readStream(image.getImageData()); + byte[] imageData = Helper.readStream(image.getConvertedImageData()); String base64ImgData = Helper.byteArrayToBase64String(imageData); fos.write(Utf8Helper.getBytes("var imageObj" + c + " = document.createElement(\"img\");\r\nimageObj" + c + ".src=\"data:image/" + format + ";base64," + base64ImgData + "\";\r\n")); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/SVGMorphShapeExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/SVGMorphShapeExporter.java index 28307c12e..15bf98546 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/SVGMorphShapeExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/SVGMorphShapeExporter.java @@ -119,7 +119,7 @@ public class SVGMorphShapeExporter extends DefaultSVGMorphShapeExporter { lastPatternId++; String patternId = "PatternID_" + id + "_" + lastPatternId; ImageFormat format = image.getImageFormat(); - byte[] imageData = Helper.readStream(image.getImageData()); + byte[] imageData = Helper.readStream(image.getConvertedImageData()); String base64ImgData = Helper.byteArrayToBase64String(imageData); path.setAttribute("style", "fill:url(#" + patternId + ")"); Element pattern = exporter.createElement("pattern"); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/SVGShapeExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/SVGShapeExporter.java index 65f6b4ce0..9333d1f8c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/SVGShapeExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/SVGShapeExporter.java @@ -120,7 +120,7 @@ public class SVGShapeExporter extends DefaultSVGShapeExporter { lastPatternId++; String patternId = "PatternID_" + id + "_" + lastPatternId; ImageFormat format = image.getImageFormat(); - byte[] imageData = Helper.readStream(image.getImageData()); + byte[] imageData = Helper.readStream(image.getConvertedImageData()); String base64ImgData = Helper.byteArrayToBase64String(imageData); Element pattern = exporter.createElement("pattern"); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ImageImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ImageImporter.java index 8852cd86d..9060eb629 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ImageImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ImageImporter.java @@ -146,7 +146,7 @@ public class ImageImporter extends TagImporter { } public void convertImage(ImageTag it, int tagType) throws IOException { - importImage(it, Helper.readStream(it.getImageData()), tagType); + importImage(it, Helper.readStream(it.getConvertedImageData()), tagType); } public static int getImageTagType(String format) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ImageTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ImageTag.java index f2fee2bdb..c240b3db8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ImageTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ImageTag.java @@ -120,6 +120,26 @@ public abstract class ImageTag extends DrawableTag { return image; } + /** + * Gets converted image data. Converted means for example DefineBitsJPEG3 including alpha channel - PNG images + * @return + */ + public InputStream getConvertedImageData() { + if (getImageFormat() == getOriginalImageFormat()) { //no need to convert + InputStream is = getOriginalImageData(); + if (is != null) { + return is; + } + } + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ImageHelper.write(getImage().getBufferedImage(), getImageFormat(), baos); + return new ByteArrayInputStream(baos.toByteArray()); + } + + /** + * Gets original image data if available, if not, then converted. Original image data can be for example DefineBitsJPEG3 without transparency. + * @return + */ public InputStream getImageData() { InputStream is = getOriginalImageData(); if (is != null) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index eba9eef31..9eb912d23 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -43,6 +43,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter; import com.jpexs.decompiler.flash.amf.amf3.Amf3Value; import com.jpexs.decompiler.flash.amf.amf3.types.ObjectType; import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.exporters.ImageExporter; import com.jpexs.decompiler.flash.exporters.MovieExporter; import com.jpexs.decompiler.flash.exporters.SoundExporter; import com.jpexs.decompiler.flash.exporters.commonshape.Matrix; @@ -1819,7 +1820,7 @@ public class XFLConverter { } } - byte[] imageBytes = Helper.readStream(imageTag.getImageData()); + byte[] imageBytes = Helper.readStream(imageTag.getConvertedImageData()); SerializableImage image = imageTag.getImageCached(); ImageFormat format = imageTag.getImageFormat(); String symbolFile = "bitmap" + symbol.getCharacterId() + imageTag.getImageFormat().getExtension();