mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-27 11:40:45 +00:00
caching images and other smallfixes 2
This commit is contained in:
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -261,7 +261,7 @@ public final class SWF implements SWFContainerItem, Timelined {
|
||||
public boolean isAS3;
|
||||
public Map<Integer, CharacterTag> characters = new HashMap<>();
|
||||
public List<ABCContainerTag> abcList;
|
||||
public JPEGTablesTag jtt;
|
||||
private JPEGTablesTag jtt;
|
||||
public Map<Integer, String> sourceFontNamesMap = new HashMap<>();
|
||||
public static final double unitDivisor = 20;
|
||||
private static final Logger logger = Logger.getLogger(SWF.class.getName());
|
||||
@@ -287,6 +287,19 @@ public final class SWF implements SWFContainerItem, Timelined {
|
||||
return max + 1;
|
||||
}
|
||||
|
||||
public synchronized JPEGTablesTag getJtt() {
|
||||
if (jtt == null) {
|
||||
for (Tag t : tags) {
|
||||
if (t instanceof JPEGTablesTag) {
|
||||
jtt = (JPEGTablesTag) t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return jtt;
|
||||
}
|
||||
|
||||
public void fixCharactersOrder(boolean checkAll) {
|
||||
Set<Integer> addedCharacterIds = new HashSet<>();
|
||||
Set<CharacterTag> movedTags = new HashSet<>();
|
||||
|
||||
@@ -43,6 +43,8 @@ public class DefineBitsJPEG2Tag extends ImageTag implements AloneTag {
|
||||
|
||||
public static final int ID = 21;
|
||||
|
||||
private SerializableImage cachedImage;
|
||||
|
||||
@Override
|
||||
public int getCharacterId() {
|
||||
return characterID;
|
||||
@@ -63,9 +65,14 @@ public class DefineBitsJPEG2Tag extends ImageTag implements AloneTag {
|
||||
|
||||
@Override
|
||||
public SerializableImage getImage() {
|
||||
if (cachedImage != null) {
|
||||
return cachedImage;
|
||||
}
|
||||
try {
|
||||
BufferedImage image = ImageIO.read(getImageData());
|
||||
return image == null ? null : new SerializableImage(image);
|
||||
SerializableImage ret = image == null ? null : new SerializableImage(image);
|
||||
cachedImage = ret;
|
||||
return ret;
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
return null;
|
||||
@@ -97,6 +104,7 @@ public class DefineBitsJPEG2Tag extends ImageTag implements AloneTag {
|
||||
@Override
|
||||
public void setImage(byte[] data) {
|
||||
imageData = new ByteArrayRange(data);
|
||||
cachedImage = null;
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
public byte[] bitmapAlphaData;
|
||||
|
||||
public static final int ID = 35;
|
||||
|
||||
private SerializableImage cachedImage;
|
||||
|
||||
@Override
|
||||
public int getCharacterId() {
|
||||
@@ -64,6 +66,7 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
bitmapAlphaData = new byte[0];
|
||||
}
|
||||
imageData = new ByteArrayRange(data);
|
||||
cachedImage = null;
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
@@ -83,6 +86,9 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
|
||||
@Override
|
||||
public SerializableImage getImage() {
|
||||
if (cachedImage != null) {
|
||||
return cachedImage;
|
||||
}
|
||||
try {
|
||||
InputStream stream;
|
||||
if (SWF.hasErrorHeader(imageData)) {
|
||||
@@ -104,6 +110,7 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
img2.setRGB(x, y, colorToInt(multiplyAlpha(intToColor(val))));
|
||||
}
|
||||
}
|
||||
cachedImage = img2;
|
||||
return img2;
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
|
||||
@@ -54,6 +54,8 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
|
||||
|
||||
public static final int ID = 90;
|
||||
|
||||
private SerializableImage cachedImage;
|
||||
|
||||
@Override
|
||||
public int getCharacterId() {
|
||||
return characterID;
|
||||
@@ -91,6 +93,9 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
|
||||
|
||||
@Override
|
||||
public SerializableImage getImage() {
|
||||
if (cachedImage != null) {
|
||||
return cachedImage;
|
||||
}
|
||||
try {
|
||||
BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageData.getArray(), imageData.getPos(), imageData.getLength()));
|
||||
SerializableImage img = image == null ? null : new SerializableImage(image);
|
||||
@@ -106,6 +111,7 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
|
||||
img2.setRGB(x, y, colorToInt(multiplyAlpha(intToColor(val))));
|
||||
}
|
||||
}
|
||||
cachedImage = img2;
|
||||
return img2;
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
|
||||
@@ -66,6 +66,8 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
|
||||
public static final int ID = 36;
|
||||
|
||||
private SerializableImage cachedImage;
|
||||
|
||||
@Override
|
||||
public int getCharacterId() {
|
||||
return characterID;
|
||||
@@ -127,6 +129,7 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
sos2.writeBytesZlib(bitmapDataOS.toByteArray());
|
||||
zlibBitmapData = new ByteArrayRange(zlibOS.toByteArray());
|
||||
decompressed = false;
|
||||
cachedImage = null;
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
@@ -224,6 +227,9 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
|
||||
@Override
|
||||
public SerializableImage getImage() {
|
||||
if (cachedImage != null) {
|
||||
return cachedImage;
|
||||
}
|
||||
SerializableImage bi = new SerializableImage(bitmapWidth, bitmapHeight, SerializableImage.TYPE_INT_ARGB);
|
||||
ALPHACOLORMAPDATA colorMapData = null;
|
||||
ALPHABITMAPDATA bitmapData = null;
|
||||
@@ -252,6 +258,7 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
pos32aligned++;
|
||||
}
|
||||
}
|
||||
cachedImage = bi;
|
||||
return bi;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,8 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
|
||||
|
||||
public static final int ID = 20;
|
||||
|
||||
private SerializableImage cachedImage;
|
||||
|
||||
private byte[] createEmptyImage() {
|
||||
try {
|
||||
BITMAPDATA bitmapData = new BITMAPDATA();
|
||||
@@ -126,6 +128,7 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
|
||||
sos2.writeBytesZlib(bitmapDataOS.toByteArray());
|
||||
zlibBitmapData = new ByteArrayRange(zlibOS.toByteArray());
|
||||
decompressed = false;
|
||||
cachedImage = null;
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
@@ -136,6 +139,9 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
|
||||
|
||||
@Override
|
||||
public SerializableImage getImage() {
|
||||
if (cachedImage != null) {
|
||||
return cachedImage;
|
||||
}
|
||||
SerializableImage bi = new SerializableImage(bitmapWidth, bitmapHeight, SerializableImage.TYPE_INT_RGB);
|
||||
COLORMAPDATA colorMapData = null;
|
||||
BITMAPDATA bitmapData = null;
|
||||
@@ -168,6 +174,7 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
|
||||
pos32aligned++;
|
||||
}
|
||||
}
|
||||
cachedImage = bi;
|
||||
return bi;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.jpexs.decompiler.flash.SWFInputStream;
|
||||
import com.jpexs.decompiler.flash.SWFOutputStream;
|
||||
import com.jpexs.decompiler.flash.tags.base.ImageTag;
|
||||
import com.jpexs.decompiler.flash.types.BasicType;
|
||||
import com.jpexs.decompiler.flash.types.annotations.Internal;
|
||||
import com.jpexs.decompiler.flash.types.annotations.SWFType;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.SerializableImage;
|
||||
@@ -32,7 +31,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class DefineBitsTag extends ImageTag {
|
||||
public class DefineBitsTag extends ImageTag implements TagChangedListener {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
public int characterID;
|
||||
@@ -40,10 +39,10 @@ public class DefineBitsTag extends ImageTag {
|
||||
@SWFType(BasicType.UI8)
|
||||
public ByteArrayRange jpegData;
|
||||
|
||||
@Internal
|
||||
private JPEGTablesTag jtt = null;
|
||||
public static final int ID = 6;
|
||||
|
||||
private SerializableImage cachedImage;
|
||||
|
||||
@Override
|
||||
public void setImage(byte[] data) {
|
||||
throw new UnsupportedOperationException("Set image is not supported for DefineBits");
|
||||
@@ -72,17 +71,6 @@ public class DefineBitsTag extends ImageTag {
|
||||
jpegData = sis.readByteRangeEx(sis.available(), "jpegData");
|
||||
}
|
||||
|
||||
private void getJPEGTables() {
|
||||
if (jtt == null) {
|
||||
for (Tag t : swf.tags) {
|
||||
if (t instanceof JPEGTablesTag) {
|
||||
jtt = (JPEGTablesTag) t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getImageData() {
|
||||
return null;
|
||||
@@ -90,10 +78,12 @@ public class DefineBitsTag extends ImageTag {
|
||||
|
||||
@Override
|
||||
public SerializableImage getImage() {
|
||||
getJPEGTables();
|
||||
if ((jtt != null)) {
|
||||
if (cachedImage != null) {
|
||||
return cachedImage;
|
||||
}
|
||||
if (swf.getJtt() != null) {
|
||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||
byte[] jttdata = jtt.jpegData;
|
||||
byte[] jttdata = swf.getJtt().jpegData;
|
||||
if (jttdata.length != 0) {
|
||||
boolean jttError = SWF.hasErrorHeader(jttdata);
|
||||
baos.write(jttdata, jttError ? 4 : 0, jttdata.length - (jttError ? 6 : 2));
|
||||
@@ -101,7 +91,9 @@ public class DefineBitsTag extends ImageTag {
|
||||
} else {
|
||||
baos.write(jpegData.getArray(), jpegData.getPos(), jpegData.getLength());
|
||||
}
|
||||
return new SerializableImage(ImageIO.read(new ByteArrayInputStream(baos.toByteArray())));
|
||||
SerializableImage ret = new SerializableImage(ImageIO.read(new ByteArrayInputStream(baos.toByteArray())));
|
||||
cachedImage = ret;
|
||||
return ret;
|
||||
} catch (IOException ex) {
|
||||
return null;
|
||||
}
|
||||
@@ -137,4 +129,9 @@ public class DefineBitsTag extends ImageTag {
|
||||
public String getImageFormat() {
|
||||
return "jpg";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEvent(Tag tag) {
|
||||
cachedImage = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,8 @@ public abstract class Tag implements NeedsCharacters, Exportable, ContainerItem,
|
||||
@Internal
|
||||
private ByteArrayRange originalRange;
|
||||
|
||||
private final HashSet<TagChangedListener> listeners = new HashSet<>();
|
||||
|
||||
public String getTagName() {
|
||||
return tagName;
|
||||
}
|
||||
@@ -407,6 +409,23 @@ public abstract class Tag implements NeedsCharacters, Exportable, ContainerItem,
|
||||
|
||||
public void setModified(boolean value) {
|
||||
modified = value;
|
||||
if (value) {
|
||||
informListeners();
|
||||
}
|
||||
}
|
||||
|
||||
public final void addEventListener(TagChangedListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public final void removeEventListener(TagChangedListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
protected void informListeners() {
|
||||
for (TagChangedListener listener : listeners) {
|
||||
listener.handleEvent(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void createOriginalData() {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2014 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.tags;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public interface TagChangedListener {
|
||||
|
||||
public void handleEvent(Tag tag);
|
||||
}
|
||||
@@ -509,7 +509,11 @@ public class Timeline {
|
||||
|
||||
int dframe = 0;
|
||||
if (c instanceof Timelined) {
|
||||
dframe = (time + ds.time) % ((Timelined) c).getTimeline().frames.size();
|
||||
int frameCount = ((Timelined) c).getTimeline().frames.size();
|
||||
if (frameCount < 1) {
|
||||
frameCount = 1;
|
||||
}
|
||||
dframe = (time + ds.time) % frameCount;
|
||||
if (c instanceof ButtonTag) {
|
||||
ButtonTag bt = (ButtonTag) c;
|
||||
dframe = ButtonTag.FRAME_UP;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.types;
|
||||
|
||||
import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
|
||||
import com.jpexs.decompiler.flash.types.annotations.Calculated;
|
||||
import com.jpexs.decompiler.flash.types.annotations.Conditional;
|
||||
import com.jpexs.decompiler.flash.types.annotations.SWFType;
|
||||
|
||||
@@ -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.types.filters;
|
||||
|
||||
import com.jpexs.helpers.SerializableImage;
|
||||
|
||||
Reference in New Issue
Block a user