From bc818266488916bbfd75c7a06339ae61d8e294e2 Mon Sep 17 00:00:00 2001 From: honfika Date: Sat, 16 Aug 2014 16:09:03 +0200 Subject: [PATCH] Issue #612: show color in hex format --- src/com/jpexs/decompiler/flash/SWF.java | 2 + .../flash/configuration/Configuration.java | 4 + .../jpexs/decompiler/flash/gui/MainPanel.java | 2 +- .../flash/gui/dumpview/DumpTree.java | 8 +- .../locales/AdvancedSettingsDialog.properties | 4 +- .../AdvancedSettingsDialog_hu.properties | 3 + src/com/jpexs/decompiler/flash/types/RGB.java | 175 +++++++++--------- .../jpexs/decompiler/flash/types/RGBA.java | 169 +++++++++-------- 8 files changed, 194 insertions(+), 173 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/SWF.java b/src/com/jpexs/decompiler/flash/SWF.java index f9a50e94f..daa4e3a54 100644 --- a/src/com/jpexs/decompiler/flash/SWF.java +++ b/src/com/jpexs/decompiler/flash/SWF.java @@ -253,6 +253,7 @@ public final class SWF implements TreeItem, Timelined { */ public byte[] lzmaProperties; public byte[] uncompressedData; + public byte[] originalUncompressedData; public FileAttributesTag fileAttributes; /** * ScaleForm GFx @@ -537,6 +538,7 @@ public final class SWF implements TreeItem, Timelined { compression = header.compression; lzmaProperties = header.lzmaProperties; uncompressedData = baos.toByteArray(); + originalUncompressedData = uncompressedData; SWFInputStream sis = new SWFInputStream(this, uncompressedData); dumpInfo = new DumpInfoSwfNode(this, "rootswf", "", null, 0, 0); diff --git a/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/src/com/jpexs/decompiler/flash/configuration/Configuration.java index 7fe65dfef..f2dbe6c95 100644 --- a/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -96,6 +96,10 @@ public class Configuration { @ConfigurationCategory("display") public static final ConfigurationItem dumpView = null; + @ConfigurationDefaultBoolean(false) + @ConfigurationCategory("display") + public static final ConfigurationItem useHexColorFormat = null; + @ConfigurationDefaultBoolean(false) @ConfigurationCategory("ui") public static final ConfigurationItem gotoMainClassOnStartup = null; diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 4e211dc94..65d3b12d9 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -2170,7 +2170,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec return; } - dumpViewPanel.setData(DumpInfoSwfNode.getSwfNode(dumpInfo).getSwf().uncompressedData, dumpInfo); + dumpViewPanel.setData(DumpInfoSwfNode.getSwfNode(dumpInfo).getSwf().originalUncompressedData, dumpInfo); dumpViewPanel.revalidate(); showCard(CARDDUMPVIEW); } diff --git a/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTree.java b/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTree.java index eb5548f16..a364f501c 100644 --- a/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTree.java +++ b/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTree.java @@ -228,7 +228,7 @@ public class DumpTree extends JTree implements ActionListener { if (fc.showSaveDialog(f) == JFileChooser.APPROVE_OPTION) { File sf = Helper.fixDialogFile(fc.getSelectedFile()); try (FileOutputStream fos = new FileOutputStream(sf)) { - byte[] data = DumpInfoSwfNode.getSwfNode(dumpInfo).getSwf().uncompressedData; + byte[] data = DumpInfoSwfNode.getSwfNode(dumpInfo).getSwf().originalUncompressedData; fos.write(data, (int) dumpInfo.startByte, (int) (dumpInfo.getEndByte() - dumpInfo.startByte + 1)); } catch (IOException ex) { Logger.getLogger(DumpTree.class.getName()).log(Level.SEVERE, null, ex); @@ -240,7 +240,7 @@ public class DumpTree extends JTree implements ActionListener { TreePath[] paths = getSelectionPaths(); DumpInfo dumpInfo = (DumpInfo) paths[0].getLastPathComponent(); SWF swf = DumpInfoSwfNode.getSwfNode(dumpInfo).getSwf(); - byte[] data = swf.uncompressedData; + byte[] data = swf.originalUncompressedData; int prevLength = (int) dumpInfo.startByte; try { SWFInputStream rri = new SWFInputStream(swf, data); @@ -266,7 +266,7 @@ public class DumpTree extends JTree implements ActionListener { TreePath[] paths = getSelectionPaths(); DumpInfo dumpInfo = (DumpInfo) paths[0].getLastPathComponent(); SWF swf = DumpInfoSwfNode.getSwfNode(dumpInfo).getSwf(); - byte[] data = swf.uncompressedData; + byte[] data = swf.originalUncompressedData; int prevLength = (int) dumpInfo.startByte; try { ABCInputStream ais = new ABCInputStream(new MemoryInputStream(data, 0, prevLength + (int) dumpInfo.lengthBytes)); @@ -283,7 +283,7 @@ public class DumpTree extends JTree implements ActionListener { TreePath[] paths = getSelectionPaths(); DumpInfo dumpInfo = (DumpInfo) paths[0].getLastPathComponent(); SWF swf = DumpInfoSwfNode.getSwfNode(dumpInfo).getSwf(); - byte[] data = swf.uncompressedData; + byte[] data = swf.originalUncompressedData; int prevLength = (int) dumpInfo.startByte; try { ABCInputStream ais = new ABCInputStream(new MemoryInputStream(data, 0, prevLength + (int) dumpInfo.lengthBytes)); diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties index dd7682928..904831dbb 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties @@ -50,7 +50,6 @@ config.group.description.decompilation = Global decompilation related functions config.group.name.other = Other config.group.description.other = Other uncategorized configs - config.name.openMultipleFiles = Open multiple files config.description.openMultipleFiles = Allows opening multiple files at once in one window @@ -60,6 +59,9 @@ config.description.decompile = You can disable AS decompilation, then only P-cod config.name.dumpView = Dump View config.description.dumpView = View raw data dump +config.name.useHexColorFormat = Hex color format +config.description.useHexColorFormat = Show the colors in hex format + config.name.parallelSpeedUp = Parallel SpeedUp config.description.parallelSpeedUp = Parallelism can speed up decompilation diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_hu.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_hu.properties index b95916f88..9fbf3b80b 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_hu.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_hu.properties @@ -60,6 +60,9 @@ config.description.decompile = Kikapcsolhatja az AS visszaford\u00edt\u00e1s\u00 config.name.dumpView = Dump N\u00e9zet config.description.dumpView = Nyers adatok mutat\u00e1sa +config.name.useHexColorFormat = Hexa sz\u00edn form\u00e1tum +config.description.useHexColorFormat = A sz\u00ednek hexa form\u00e1tum\u00fa mutat\u00e1sa + config.name.parallelSpeedUp = P\u00e1rhuzamos gyors\u00edt\u00e1s config.description.parallelSpeedUp = P\u00e1rhuzamos\u00edt\u00e1s fel tudja gyors\u00edtani a visszaford\u00edt\u00e1st diff --git a/src/com/jpexs/decompiler/flash/types/RGB.java b/src/com/jpexs/decompiler/flash/types/RGB.java index bc58992dd..0454137be 100644 --- a/src/com/jpexs/decompiler/flash/types/RGB.java +++ b/src/com/jpexs/decompiler/flash/types/RGB.java @@ -1,85 +1,90 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.types; - -import com.jpexs.decompiler.flash.types.annotations.SWFType; -import java.awt.Color; -import java.io.Serializable; - -/** - * Represents 24-bit red, green, blue value - * - * @author JPEXS - */ -public class RGB implements Serializable { - - /** - * Red color value - */ - @SWFType(BasicType.UI8) - public int red; - /** - * Green color value - */ - @SWFType(BasicType.UI8) - public int green; - /** - * Blue color value - */ - @SWFType(BasicType.UI8) - public int blue; - - public RGB(int red, int green, int blue) { - this.red = red; - this.green = green; - this.blue = blue; - } - - public RGB() { - } - - public String toHexRGB() { - String rh = Integer.toHexString(red); - if (rh.length() < 2) { - rh = "0" + rh; - } - String gh = Integer.toHexString(green); - if (gh.length() < 2) { - gh = "0" + gh; - } - String bh = Integer.toHexString(blue); - if (bh.length() < 2) { - bh = "0" + bh; - } - return "#" + rh + gh + bh; - } - - public Color toColor() { - return new Color(red, green, blue); - } - - public RGB(Color color) { - this.red = color.getRed(); - this.green = color.getGreen(); - this.blue = color.getBlue(); - } - - @Override - public String toString() { - return "[RGB red:" + red + ", green:" + green + ", blue:" + blue + "]"; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.types; + +import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.types.annotations.SWFType; +import java.awt.Color; +import java.io.Serializable; + +/** + * Represents 24-bit red, green, blue value + * + * @author JPEXS + */ +public class RGB implements Serializable { + + /** + * Red color value + */ + @SWFType(BasicType.UI8) + public int red; + /** + * Green color value + */ + @SWFType(BasicType.UI8) + public int green; + /** + * Blue color value + */ + @SWFType(BasicType.UI8) + public int blue; + + public RGB(int red, int green, int blue) { + this.red = red; + this.green = green; + this.blue = blue; + } + + public RGB() { + } + + public String toHexRGB() { + String rh = Integer.toHexString(red); + if (rh.length() < 2) { + rh = "0" + rh; + } + String gh = Integer.toHexString(green); + if (gh.length() < 2) { + gh = "0" + gh; + } + String bh = Integer.toHexString(blue); + if (bh.length() < 2) { + bh = "0" + bh; + } + return "#" + rh + gh + bh; + } + + public Color toColor() { + return new Color(red, green, blue); + } + + public RGB(Color color) { + this.red = color.getRed(); + this.green = color.getGreen(); + this.blue = color.getBlue(); + } + + @Override + public String toString() { + if (Configuration.useHexColorFormat.get()) { + return "[RGB " + toHexRGB() + "]"; + } else { + return "[RGB red:" + red + ", green:" + green + ", blue:" + blue + "]"; + } + } +} diff --git a/src/com/jpexs/decompiler/flash/types/RGBA.java b/src/com/jpexs/decompiler/flash/types/RGBA.java index 4c14339c9..2dd93bc39 100644 --- a/src/com/jpexs/decompiler/flash/types/RGBA.java +++ b/src/com/jpexs/decompiler/flash/types/RGBA.java @@ -1,82 +1,87 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.types; - -import com.jpexs.decompiler.flash.types.annotations.SWFType; -import java.awt.Color; -import java.io.Serializable; - -/** - * Represents 32-bit red, green, blue and alpha value - * - * @author JPEXS - */ -public class RGBA extends RGB implements Serializable { - - /** - * Alpha value defining opacity - */ - @SWFType(BasicType.UI8) - public int alpha; - - public float getAlphaFloat() { - return ((float) alpha) / 255.0f; - } - - public String toHexARGB() { - String ra = Integer.toHexString(alpha); - if (ra.length() < 2) { - ra = "0" + ra; - } - String rh = Integer.toHexString(red); - if (rh.length() < 2) { - rh = "0" + rh; - } - String gh = Integer.toHexString(green); - if (gh.length() < 2) { - gh = "0" + gh; - } - String bh = Integer.toHexString(blue); - if (bh.length() < 2) { - bh = "0" + bh; - } - return "#" + ra + rh + gh + bh; - } - - public RGBA(int red, int green, int blue, int alpha) { - super(red, green, blue); - this.alpha = alpha; - } - - public RGBA(Color color) { - super(color); - this.alpha = color.getAlpha(); - } - - public RGBA() { - } - - @Override - public Color toColor() { - return new Color(red, green, blue, alpha); - } - - @Override - public String toString() { - return "[RGB red:" + red + ", green:" + green + ", blue:" + blue + ", alpha:" + alpha + "]"; - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.types; + +import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.types.annotations.SWFType; +import java.awt.Color; +import java.io.Serializable; + +/** + * Represents 32-bit red, green, blue and alpha value + * + * @author JPEXS + */ +public class RGBA extends RGB implements Serializable { + + /** + * Alpha value defining opacity + */ + @SWFType(BasicType.UI8) + public int alpha; + + public float getAlphaFloat() { + return ((float) alpha) / 255.0f; + } + + public String toHexARGB() { + String ra = Integer.toHexString(alpha); + if (ra.length() < 2) { + ra = "0" + ra; + } + String rh = Integer.toHexString(red); + if (rh.length() < 2) { + rh = "0" + rh; + } + String gh = Integer.toHexString(green); + if (gh.length() < 2) { + gh = "0" + gh; + } + String bh = Integer.toHexString(blue); + if (bh.length() < 2) { + bh = "0" + bh; + } + return "#" + ra + rh + gh + bh; + } + + public RGBA(int red, int green, int blue, int alpha) { + super(red, green, blue); + this.alpha = alpha; + } + + public RGBA(Color color) { + super(color); + this.alpha = color.getAlpha(); + } + + public RGBA() { + } + + @Override + public Color toColor() { + return new Color(red, green, blue, alpha); + } + + @Override + public String toString() { + if (Configuration.useHexColorFormat.get()) { + return "[RGB " + toHexRGB() + "]"; + } else { + return "[RGB red:" + red + ", green:" + green + ", blue:" + blue + ", alpha:" + alpha + "]"; + } + } +}