mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-18 15:18:11 +00:00
convert image tags from command line
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.importers;
|
||||
|
||||
import com.jpexs.decompiler.flash.tags.DefineFont2Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineFont3Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineFont4Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineFontTag;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class FontImporter {
|
||||
|
||||
public static int getFontTagType(String format) {
|
||||
int res = 0;
|
||||
switch (format) {
|
||||
case "font":
|
||||
res = DefineFontTag.ID;
|
||||
break;
|
||||
case "font2":
|
||||
res = DefineFont2Tag.ID;
|
||||
break;
|
||||
case "font3":
|
||||
res = DefineFont3Tag.ID;
|
||||
break;
|
||||
case "font4":
|
||||
res = DefineFont4Tag.ID;
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ImageTag;
|
||||
import com.jpexs.decompiler.flash.tags.enums.ImageFormat;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -112,4 +113,31 @@ public class ImageImporter extends TagImporter {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void convertImage(ImageTag it, int tagType) throws IOException {
|
||||
importImage(it, Helper.readStream(it.getImageData()), tagType);
|
||||
}
|
||||
|
||||
public static int getImageTagType(String format) {
|
||||
int res = 0;
|
||||
switch (format) {
|
||||
case "lossless":
|
||||
res = DefineBitsLosslessTag.ID;
|
||||
break;
|
||||
case "lossless2":
|
||||
res = DefineBitsLossless2Tag.ID;
|
||||
break;
|
||||
case "jpeg2":
|
||||
res = DefineBitsJPEG2Tag.ID;
|
||||
break;
|
||||
case "jpeg3":
|
||||
res = DefineBitsJPEG3Tag.ID;
|
||||
break;
|
||||
case "jpeg4":
|
||||
res = DefineBitsJPEG4Tag.ID;
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.importers;
|
||||
|
||||
import com.jpexs.decompiler.flash.tags.DefineMorphShape2Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineMorphShapeTag;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class MorphShapeImporter {
|
||||
|
||||
public static int getMorphShapeTagType(String format) {
|
||||
int res = 0;
|
||||
switch (format) {
|
||||
case "morphshape":
|
||||
res = DefineMorphShapeTag.ID;
|
||||
break;
|
||||
case "morphshape2":
|
||||
res = DefineMorphShape2Tag.ID;
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,10 @@ 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.DefineShape2Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineShape3Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineShape4Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineShapeTag;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ImageTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ShapeTag;
|
||||
@@ -113,4 +117,24 @@ public class ShapeImporter {
|
||||
st.shapes = shapes;
|
||||
return (Tag) st;
|
||||
}
|
||||
|
||||
public static int getShapeTagType(String format) {
|
||||
int res = 0;
|
||||
switch (format) {
|
||||
case "shape":
|
||||
res = DefineShapeTag.ID;
|
||||
break;
|
||||
case "shape2":
|
||||
res = DefineShape2Tag.ID;
|
||||
break;
|
||||
case "shape3":
|
||||
res = DefineShape3Tag.ID;
|
||||
break;
|
||||
case "shape4":
|
||||
res = DefineShape4Tag.ID;
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,9 @@ package com.jpexs.decompiler.flash.importers;
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings;
|
||||
import com.jpexs.decompiler.flash.tags.DefineEditTextTag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineText2Tag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineTextTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.MissingCharacterHandler;
|
||||
import com.jpexs.decompiler.flash.tags.base.TextImportErrorHandler;
|
||||
import com.jpexs.decompiler.flash.tags.base.TextTag;
|
||||
@@ -167,4 +170,21 @@ public class TextImporter {
|
||||
return !errorHandler.handle(textTag, ex.text, ex.line);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getTextTagType(String format) {
|
||||
int res = 0;
|
||||
switch (format) {
|
||||
case "text":
|
||||
res = DefineTextTag.ID;
|
||||
break;
|
||||
case "text2":
|
||||
res = DefineText2Tag.ID;
|
||||
break;
|
||||
case "edittext":
|
||||
res = DefineEditTextTag.ID;
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,9 @@ import com.jpexs.decompiler.flash.gui.Main;
|
||||
import com.jpexs.decompiler.flash.gui.helpers.CheckResources;
|
||||
import com.jpexs.decompiler.flash.helpers.FileTextWriter;
|
||||
import com.jpexs.decompiler.flash.importers.BinaryDataImporter;
|
||||
import com.jpexs.decompiler.flash.importers.FontImporter;
|
||||
import com.jpexs.decompiler.flash.importers.ImageImporter;
|
||||
import com.jpexs.decompiler.flash.importers.MorphShapeImporter;
|
||||
import com.jpexs.decompiler.flash.importers.ShapeImporter;
|
||||
import com.jpexs.decompiler.flash.importers.SwfXmlImporter;
|
||||
import com.jpexs.decompiler.flash.importers.TextImporter;
|
||||
@@ -88,8 +90,6 @@ 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.DefineSpriteTag;
|
||||
import com.jpexs.decompiler.flash.tags.JPEGTablesTag;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
@@ -97,8 +97,10 @@ import com.jpexs.decompiler.flash.tags.base.ASMSource;
|
||||
import com.jpexs.decompiler.flash.tags.base.ButtonTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.CharacterIdTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.CharacterTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.FontTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ImageTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.MissingCharacterHandler;
|
||||
import com.jpexs.decompiler.flash.tags.base.MorphShapeTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.ShapeTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.SoundTag;
|
||||
import com.jpexs.decompiler.flash.tags.base.TextImportErrorHandler;
|
||||
@@ -639,6 +641,8 @@ public class CommandLineArgumentParser {
|
||||
parseReplaceCharacter(args);
|
||||
} else if (command.equals("replacecharacterid")) {
|
||||
parseReplaceCharacterId(args);
|
||||
} else if (command.equals("convert")) {
|
||||
parseConvert(args);
|
||||
} else if (command.equals("remove")) {
|
||||
parseRemove(args);
|
||||
} else if (command.equals("removecharacter")) {
|
||||
@@ -2024,26 +2028,7 @@ public class CommandLineArgumentParser {
|
||||
return 0;
|
||||
}
|
||||
|
||||
String format = args.peek();
|
||||
int res = 0;
|
||||
switch (format) {
|
||||
case "lossless":
|
||||
res = DefineBitsLosslessTag.ID;
|
||||
break;
|
||||
case "lossless2":
|
||||
res = DefineBitsLossless2Tag.ID;
|
||||
break;
|
||||
case "jpeg2":
|
||||
res = DefineBitsJPEG2Tag.ID;
|
||||
break;
|
||||
case "jpeg3":
|
||||
res = DefineBitsJPEG3Tag.ID;
|
||||
break;
|
||||
case "jpeg4":
|
||||
res = DefineBitsJPEG4Tag.ID;
|
||||
break;
|
||||
}
|
||||
|
||||
int res = ImageImporter.getImageTagType(args.peek().toLowerCase());
|
||||
if (res != 0) {
|
||||
args.pop();
|
||||
}
|
||||
@@ -2225,6 +2210,73 @@ public class CommandLineArgumentParser {
|
||||
}
|
||||
}
|
||||
|
||||
private static void parseConvert(Stack<String> args) {
|
||||
if (args.size() < 4) {
|
||||
badArguments("convert");
|
||||
}
|
||||
|
||||
File inFile = new File(args.pop());
|
||||
File outFile = new File(args.pop());
|
||||
try {
|
||||
try (FileInputStream is = new FileInputStream(inFile)) {
|
||||
SWF swf = new SWF(is, Configuration.parallelSpeedUp.get());
|
||||
|
||||
String objectToConvert = args.pop();
|
||||
|
||||
int characterId = 0;
|
||||
try {
|
||||
characterId = Integer.parseInt(objectToConvert);
|
||||
} catch (NumberFormatException nfe) {
|
||||
System.err.println("CharacterId should be integer");
|
||||
badArguments("convert");
|
||||
}
|
||||
if (!swf.getCharacters().containsKey(characterId)) {
|
||||
System.err.println("CharacterId does not exist");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
CharacterTag characterTag = swf.getCharacter(characterId);
|
||||
String targetType = args.pop().toLowerCase();
|
||||
if (characterTag instanceof ImageTag) {
|
||||
int format = ImageImporter.getImageTagType(targetType);
|
||||
ImageTag imageTag = (ImageTag) characterTag;
|
||||
new ImageImporter().convertImage(imageTag, format);
|
||||
} else if (characterTag instanceof ShapeTag) {
|
||||
int format = ShapeImporter.getShapeTagType(targetType);
|
||||
ShapeTag shapeTag = (ShapeTag) characterTag;
|
||||
System.err.println("Converting shape tag is currently not supported");
|
||||
} else if (characterTag instanceof MorphShapeTag) {
|
||||
int format = MorphShapeImporter.getMorphShapeTagType(targetType);
|
||||
MorphShapeTag morphShapeTag = (MorphShapeTag) characterTag;
|
||||
System.err.println("Converting morph shape tag is currently not supported");
|
||||
} else if (characterTag instanceof FontTag) {
|
||||
int format = FontImporter.getFontTagType(targetType);
|
||||
FontTag fontTag = (FontTag) characterTag;
|
||||
System.err.println("Converting font tag is currently not supported");
|
||||
} else if (characterTag instanceof TextTag) {
|
||||
int format = TextImporter.getTextTagType(targetType);
|
||||
TextTag textTag = (TextTag) characterTag;
|
||||
System.err.println("Converting text tag is currently not supported");
|
||||
} else {
|
||||
System.err.println("The specified tag type is not supported for import");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) {
|
||||
swf.saveTo(fos);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("I/O error during writing");
|
||||
System.exit(2);
|
||||
}
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
System.err.println("I/O error during reading");
|
||||
System.exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
private static void parseRemove(Stack<String> args) {
|
||||
if (args.size() < 3) {
|
||||
badArguments("remove");
|
||||
|
||||
Reference in New Issue
Block a user