mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-18 17:28:11 +00:00
small image tag refactoring/fixes
This commit is contained in:
@@ -129,7 +129,6 @@ import com.jpexs.decompiler.graph.GraphSourceItemContainer;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.TranslateStack;
|
||||
import com.jpexs.decompiler.graph.model.LocalData;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.Cache;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.NulStream;
|
||||
@@ -1434,20 +1433,6 @@ public final class SWF implements SWFContainerItem, Timelined {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasErrorHeader(byte[] data) {
|
||||
return hasErrorHeader(new ByteArrayRange(data));
|
||||
}
|
||||
|
||||
public static boolean hasErrorHeader(ByteArrayRange data) {
|
||||
if (data.getLength() > 4) {
|
||||
if ((data.get(0) & 0xff) == 0xff && (data.get(1) & 0xff) == 0xd9
|
||||
&& (data.get(2) & 0xff) == 0xff && (data.get(3) & 0xff) == 0xd8) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void populateVideoFrames(int streamId, List<Tag> tags, HashMap<Integer, VideoFrameTag> output) {
|
||||
for (Tag t : tags) {
|
||||
if (t instanceof VideoFrameTag) {
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
|
||||
@@ -27,7 +27,6 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
|
||||
@@ -34,6 +34,10 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DefineBinaryDataTag extends CharacterTag {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
|
||||
@@ -32,7 +32,13 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DefineBitsJPEG2Tag extends ImageTag implements AloneTag {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
@@ -55,10 +61,8 @@ public class DefineBitsJPEG2Tag extends ImageTag implements AloneTag {
|
||||
|
||||
@Override
|
||||
public InputStream getImageData() {
|
||||
if (SWF.hasErrorHeader(imageData)) {
|
||||
return new ByteArrayInputStream(imageData.getArray(), imageData.getPos() + 4, imageData.getLength() - 4);
|
||||
}
|
||||
return new ByteArrayInputStream(imageData.getArray(), imageData.getPos(), imageData.getLength());
|
||||
int errorLength = hasErrorHeader(imageData) ? 4 : 0;
|
||||
return new ByteArrayInputStream(imageData.getArray(), imageData.getPos() + errorLength, imageData.getLength() - errorLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,6 +76,7 @@ public class DefineBitsJPEG2Tag extends ImageTag implements AloneTag {
|
||||
cachedImage = ret;
|
||||
return ret;
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(DefineBitsJPEG2Tag.class.getName()).log(Level.SEVERE, "Failed to get image", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,13 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
@@ -80,7 +86,8 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
|
||||
@Override
|
||||
public InputStream getImageData() {
|
||||
return null;
|
||||
int errorLength = hasErrorHeader(imageData) ? 4 : 0;
|
||||
return new ByteArrayInputStream(imageData.getArray(), imageData.getPos() + errorLength, imageData.getLength() - errorLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,14 +96,7 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
return cachedImage;
|
||||
}
|
||||
try {
|
||||
InputStream stream;
|
||||
if (SWF.hasErrorHeader(imageData)) {
|
||||
stream = new ByteArrayInputStream(imageData.getArray(), imageData.getPos() + 4, imageData.getLength() - 4);
|
||||
} else {
|
||||
stream = new ByteArrayInputStream(imageData.getArray(), imageData.getPos(), imageData.getLength());
|
||||
}
|
||||
|
||||
BufferedImage image = ImageHelper.read(stream);
|
||||
BufferedImage image = ImageHelper.read(getImageData());
|
||||
SerializableImage img = image == null ? null : new SerializableImage(image);
|
||||
if (bitmapAlphaData.length == 0) {
|
||||
cachedImage = img;
|
||||
@@ -112,6 +112,7 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
cachedImage = img;
|
||||
return img;
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(DefineBitsJPEG3Tag.class.getName()).log(Level.SEVERE, "Failed to get image", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -33,9 +33,10 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
@@ -88,7 +89,7 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
|
||||
|
||||
@Override
|
||||
public InputStream getImageData() {
|
||||
return null;
|
||||
return new ByteArrayInputStream(imageData.getArray(), imageData.getPos(), imageData.getLength());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,7 +98,7 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
|
||||
return cachedImage;
|
||||
}
|
||||
try {
|
||||
BufferedImage image = ImageHelper.read(new ByteArrayInputStream(imageData.getArray(), imageData.getPos(), imageData.getLength()));
|
||||
BufferedImage image = ImageHelper.read(getImageData());
|
||||
SerializableImage img = image == null ? null : new SerializableImage(image);
|
||||
if (bitmapAlphaData.getLength() == 0) {
|
||||
cachedImage = img;
|
||||
@@ -113,6 +114,7 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
|
||||
cachedImage = img;
|
||||
return img;
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(DefineBitsJPEG4Tag.class.getName()).log(Level.SEVERE, "Failed to get image", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,10 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
@@ -267,6 +271,7 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
pos32aligned++;
|
||||
}
|
||||
}
|
||||
|
||||
cachedImage = bi;
|
||||
return bi;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,10 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
|
||||
@@ -30,7 +30,13 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DefineBitsTag extends ImageTag implements TagChangedListener {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
@@ -88,17 +94,17 @@ public class DefineBitsTag extends ImageTag implements TagChangedListener {
|
||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||
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));
|
||||
baos.write(jpegData.getArray(), jpegData.getPos() + (SWF.hasErrorHeader(jpegData) ? 6 : 2), jpegData.getLength() - (jttError ? 6 : 2));
|
||||
} else {
|
||||
baos.write(jpegData.getArray(), jpegData.getPos(), jpegData.getLength());
|
||||
int jttErrorLength = hasErrorHeader(jttdata) ? 4 : 0;
|
||||
baos.write(jttdata, jttErrorLength, jttdata.length - jttErrorLength - 2);
|
||||
}
|
||||
|
||||
int jpegDataErrorLength = hasErrorHeader(jpegData) ? 4 : 0;
|
||||
baos.write(jpegData.getArray(), jpegData.getPos() + jpegDataErrorLength + 2, jpegData.getLength() - jpegDataErrorLength - 2);
|
||||
SerializableImage ret = new SerializableImage(ImageHelper.read(new ByteArrayInputStream(baos.toByteArray())));
|
||||
cachedImage = ret;
|
||||
return ret;
|
||||
} catch (IOException ex) {
|
||||
return null;
|
||||
Logger.getLogger(DefineBitsTag.class.getName()).log(Level.SEVERE, "Failed to get image", ex);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
|
||||
@@ -78,7 +78,6 @@ import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
|
||||
@@ -38,7 +38,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
|
||||
@@ -41,6 +41,10 @@ import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DefineFont3Tag extends FontTag {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
|
||||
@@ -28,6 +28,10 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DefineFont4Tag extends CharacterTag {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
|
||||
@@ -32,6 +32,10 @@ import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DefineFontAlignZonesTag extends Tag implements CharacterIdTag {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
|
||||
@@ -33,7 +33,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
|
||||
@@ -32,7 +32,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
|
||||
@@ -27,6 +27,10 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DefineFontNameTag extends Tag implements CharacterIdTag {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
|
||||
@@ -34,7 +34,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,6 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
|
||||
@@ -32,7 +32,6 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DefineScalingGridTag extends Tag implements CharacterIdTag {
|
||||
|
||||
@@ -28,7 +28,6 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
|
||||
@@ -33,6 +33,10 @@ import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DefineShape2Tag extends ShapeTag {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
|
||||
@@ -33,6 +33,10 @@ import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DefineShape3Tag extends ShapeTag {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
|
||||
@@ -34,6 +34,10 @@ import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DefineShape4Tag extends ShapeTag {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
|
||||
@@ -32,6 +32,10 @@ import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DefineShapeTag extends ShapeTag {
|
||||
|
||||
@SWFType(BasicType.UI16)
|
||||
|
||||
@@ -42,7 +42,6 @@ import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
|
||||
@@ -53,6 +53,8 @@ import java.util.Set;
|
||||
|
||||
/**
|
||||
* Defines a sprite character
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DefineSpriteTag extends CharacterTag implements DrawableTag, Timelined {
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
|
||||
@@ -28,7 +28,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
|
||||
@@ -32,7 +32,6 @@ import java.io.OutputStream;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
|
||||
@@ -36,6 +36,8 @@ import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Defines a series of ActionScript 3 bytecodes to be executed
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DoABCDefineTag extends Tag implements ABCContainerTag {
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Defines a series of ActionScript 3 bytecodes to be executed
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DoABCTag extends Tag implements ABCContainerTag {
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ import java.util.logging.Logger;
|
||||
/**
|
||||
* Instructs Flash Player to perform a list of actions when the current frame is
|
||||
* complete.
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DoActionTag extends Tag implements ASMSource {
|
||||
|
||||
|
||||
@@ -39,6 +39,10 @@ import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class DoInitActionTag extends Tag implements CharacterIdTag, ASMSource {
|
||||
|
||||
/**
|
||||
|
||||
@@ -71,7 +71,7 @@ public abstract class ImageTag extends CharacterTag implements DrawableTag {
|
||||
}
|
||||
|
||||
public static String getImageFormat(ByteArrayRange data) {
|
||||
if (SWF.hasErrorHeader(data)) {
|
||||
if (hasErrorHeader(data)) {
|
||||
return "jpg";
|
||||
}
|
||||
if (data.getLength() > 2 && ((data.get(0) & 0xff) == 0xff) && ((data.get(1) & 0xff) == 0xd8)) {
|
||||
@@ -88,6 +88,20 @@ public abstract class ImageTag extends CharacterTag implements DrawableTag {
|
||||
return "unk";
|
||||
}
|
||||
|
||||
public static boolean hasErrorHeader(byte[] data) {
|
||||
return hasErrorHeader(new ByteArrayRange(data));
|
||||
}
|
||||
|
||||
public static boolean hasErrorHeader(ByteArrayRange data) {
|
||||
if (data.getLength() > 4) {
|
||||
if ((data.get(0) & 0xff) == 0xff && (data.get(1) & 0xff) == 0xd9
|
||||
&& (data.get(2) & 0xff) == 0xff && (data.get(3) & 0xff) == 0xd8) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static int max255(float val) {
|
||||
if (val > 255) {
|
||||
return 255;
|
||||
|
||||
Reference in New Issue
Block a user