mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-23 15:25:33 +00:00
replacing images
This commit is contained in:
@@ -52,12 +52,6 @@ import com.jpexs.decompiler.flash.gui.TagNode;
|
||||
import com.jpexs.decompiler.flash.helpers.Helper;
|
||||
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineBitsJPEG2Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineBitsJPEG3Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineBitsJPEG4Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineBitsLossless2Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineBitsLosslessTag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineBitsTag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineButton2Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineButtonTag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineSoundTag;
|
||||
@@ -75,6 +69,7 @@ import com.jpexs.decompiler.flash.tags.VideoFrameTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ASMSource;
|
||||
import com.jpexs.decompiler.flash.tags.base.CharacterTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.Container;
|
||||
import com.jpexs.decompiler.flash.tags.base.ImageTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ShapeTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.TextTag;
|
||||
import com.jpexs.decompiler.flash.types.RECT;
|
||||
@@ -560,24 +555,6 @@ public class SWF {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getImageFormat(byte data[]) {
|
||||
if (hasErrorHeader(data)) {
|
||||
return "jpg";
|
||||
}
|
||||
if (data.length > 2 && ((data[0] & 0xff) == 0xff) && ((data[1] & 0xff) == 0xd8)) {
|
||||
return "jpg";
|
||||
}
|
||||
if (data.length > 6 && ((data[0] & 0xff) == 0x47) && ((data[1] & 0xff) == 0x49) && ((data[2] & 0xff) == 0x46) && ((data[3] & 0xff) == 0x38) && ((data[4] & 0xff) == 0x39) && ((data[5] & 0xff) == 0x61)) {
|
||||
return "gif";
|
||||
}
|
||||
|
||||
if (data.length > 8 && ((data[0] & 0xff) == 0x89) && ((data[1] & 0xff) == 0x50) && ((data[2] & 0xff) == 0x4e) && ((data[3] & 0xff) == 0x47) && ((data[4] & 0xff) == 0x0d) && ((data[5] & 0xff) == 0x0a) && ((data[6] & 0xff) == 0x1a) && ((data[7] & 0xff) == 0x0a)) {
|
||||
return "png";
|
||||
}
|
||||
|
||||
return "unk";
|
||||
}
|
||||
|
||||
public static boolean hasErrorHeader(byte data[]) {
|
||||
if (data.length > 4) {
|
||||
if ((data[0] & 0xff) == 0xff) {
|
||||
@@ -864,7 +841,7 @@ public class SWF {
|
||||
}
|
||||
}
|
||||
|
||||
public static void exportImages(String outdir, List<Tag> tags, JPEGTablesTag jtt) throws IOException {
|
||||
public void exportImages(String outdir, List<Tag> tags) throws IOException {
|
||||
if (tags.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -872,64 +849,8 @@ public class SWF {
|
||||
(new File(outdir)).mkdirs();
|
||||
}
|
||||
for (Tag t : tags) {
|
||||
if ((t instanceof DefineBitsJPEG2Tag) || (t instanceof DefineBitsJPEG3Tag) || (t instanceof DefineBitsJPEG4Tag)) {
|
||||
byte imageData[] = null;
|
||||
int characterID = 0;
|
||||
if (t instanceof DefineBitsJPEG2Tag) {
|
||||
imageData = ((DefineBitsJPEG2Tag) t).imageData;
|
||||
characterID = ((DefineBitsJPEG2Tag) t).characterID;
|
||||
}
|
||||
if (t instanceof DefineBitsJPEG3Tag) {
|
||||
imageData = ((DefineBitsJPEG3Tag) t).imageData;
|
||||
characterID = ((DefineBitsJPEG3Tag) t).characterID;
|
||||
}
|
||||
if (t instanceof DefineBitsJPEG4Tag) {
|
||||
imageData = ((DefineBitsJPEG4Tag) t).imageData;
|
||||
characterID = ((DefineBitsJPEG4Tag) t).characterID;
|
||||
}
|
||||
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(outdir + File.separator + characterID + "." + getImageFormat(imageData));
|
||||
if (hasErrorHeader(imageData)) {
|
||||
fos.write(imageData, 4, imageData.length - 4);
|
||||
} else {
|
||||
fos.write(imageData);
|
||||
}
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (Exception ex) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (t instanceof DefineBitsLosslessTag) {
|
||||
DefineBitsLosslessTag dbl = (DefineBitsLosslessTag) t;
|
||||
ImageIO.write(dbl.getImage(), "PNG", new File(outdir + File.separator + dbl.characterID + ".png"));
|
||||
}
|
||||
if (t instanceof DefineBitsLossless2Tag) {
|
||||
DefineBitsLossless2Tag dbl = (DefineBitsLossless2Tag) t;
|
||||
|
||||
ImageIO.write(dbl.getImage(), "PNG", new File(outdir + File.separator + dbl.characterID + ".png"));
|
||||
}
|
||||
if ((jtt != null) && (t instanceof DefineBitsTag)) {
|
||||
DefineBitsTag dbt = (DefineBitsTag) t;
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(outdir + File.separator + dbt.characterID + ".jpg");
|
||||
fos.write(dbt.getFullImageData(jtt));
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
try {
|
||||
fos.close();
|
||||
} catch (Exception ex) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
if (t instanceof ImageTag) {
|
||||
ImageIO.write(((ImageTag) t).getImage(this.tags), ((ImageTag) t).getImageFormat().toUpperCase(), new File(outdir + File.separator + ((ImageTag) t).getCharacterID() + "." + ((ImageTag) t).getImageFormat()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -941,7 +862,7 @@ public class SWF {
|
||||
jtt = (JPEGTablesTag) t;
|
||||
}
|
||||
}
|
||||
exportImages(outdir, tags, jtt);
|
||||
exportImages(outdir, tags);
|
||||
}
|
||||
|
||||
public void exportShapes(String outdir) throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user