From 62b070d1a6042a2feacb40d57f9b7c6ad37cd22b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sat, 4 May 2013 09:39:19 +0200 Subject: [PATCH] Issue #83 - Fixed Zlib compression (Images transparency,...) --- .../decompiler/flash/SWFOutputStream.java | 5 +++-- .../flash/tags/DefineBitsJPEG3Tag.java | 18 +++++++++++++++--- .../flash/tags/DefineBitsJPEG4Tag.java | 17 ++++++++++++++--- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/SWFOutputStream.java b/trunk/src/com/jpexs/decompiler/flash/SWFOutputStream.java index 13e391f8d..d8099a5ad 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWFOutputStream.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWFOutputStream.java @@ -37,6 +37,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.List; +import java.util.zip.Deflater; import java.util.zip.DeflaterOutputStream; /** @@ -1602,9 +1603,9 @@ public class SWFOutputStream extends OutputStream { } public void writeBytesZlib(byte data[]) throws IOException { - DeflaterOutputStream deflater = new DeflaterOutputStream(this); + DeflaterOutputStream deflater = new DeflaterOutputStream(this,new Deflater(9)); deflater.write(data); - deflater.flush(); + deflater.finish(); } /** diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java index d3f605c7e..9c4314b20 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java @@ -16,8 +16,10 @@ */ package com.jpexs.decompiler.flash.tags; +import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; +import com.jpexs.decompiler.flash.abc.CopyOutputStream; import com.jpexs.decompiler.flash.tags.base.AloneTag; import com.jpexs.decompiler.flash.tags.base.ImageTag; import java.awt.image.BufferedImage; @@ -27,6 +29,8 @@ import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.imageio.ImageIO; public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag { @@ -45,10 +49,18 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag { imageData = data; if (ImageTag.getImageFormat(data).equals("jpg")) { BufferedImage image = getImage(new ArrayList()); - bitmapAlphaData = new byte[image.getWidth() * image.getHeight()]; - for (int i = 0; i < bitmapAlphaData.length; i++) { - bitmapAlphaData[i] = (byte) 255; + byte ba[] = new byte[image.getWidth() * image.getHeight()]; + for (int i = 0; i < ba.length; i++) { + ba[i] = (byte) 255; } + ByteArrayOutputStream baos=new ByteArrayOutputStream(); + SWFOutputStream sos=new SWFOutputStream(baos, SWF.DEFAULT_VERSION); + try { + sos.writeBytesZlib(ba); + } catch (IOException ex) { + Logger.getLogger(DefineBitsJPEG3Tag.class.getName()).log(Level.SEVERE, null, ex); + } + bitmapAlphaData = baos.toByteArray(); } else { bitmapAlphaData = new byte[0]; } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG4Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG4Tag.java index 1da59d68c..d9658bdb9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG4Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG4Tag.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.tags; +import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.tags.base.AloneTag; @@ -27,6 +28,8 @@ import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.imageio.ImageIO; /** @@ -56,10 +59,18 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag { imageData = data; if (ImageTag.getImageFormat(data).equals("jpg")) { BufferedImage image = getImage(new ArrayList()); - bitmapAlphaData = new byte[image.getWidth() * image.getHeight()]; - for (int i = 0; i < bitmapAlphaData.length; i++) { - bitmapAlphaData[i] = (byte) 255; + byte ba[] = new byte[image.getWidth() * image.getHeight()]; + for (int i = 0; i < ba.length; i++) { + ba[i] = (byte) 255; } + ByteArrayOutputStream baos=new ByteArrayOutputStream(); + SWFOutputStream sos=new SWFOutputStream(baos, SWF.DEFAULT_VERSION); + try { + sos.writeBytesZlib(ba); + } catch (IOException ex) { + Logger.getLogger(DefineBitsJPEG4Tag.class.getName()).log(Level.SEVERE, null, ex); + } + bitmapAlphaData = baos.toByteArray(); } else { bitmapAlphaData = new byte[0]; }