mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-09 22:25:05 +00:00
image performance improvements
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.abc.avm2.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
@@ -22,7 +23,6 @@ import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
import com.jpexs.decompiler.graph.model.LocalData;
|
||||
|
||||
@@ -12,18 +12,17 @@
|
||||
* 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.abc.avm2.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.xml.EscXAttrIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.xml.EscXAttrIns;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
import com.jpexs.decompiler.graph.model.LocalData;
|
||||
|
||||
@@ -26,7 +26,6 @@ import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import static com.jpexs.decompiler.graph.GraphTargetItem.toSourceMerge;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.model.BinaryOpItem;
|
||||
import com.jpexs.decompiler.graph.model.LocalData;
|
||||
|
||||
@@ -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.abc.avm2.parser.script;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
@@ -27,17 +28,12 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.other.SetPropertyIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.DupIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PopIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertDIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertDIns;
|
||||
import static com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item.ins;
|
||||
import static com.jpexs.decompiler.flash.abc.avm2.parser.script.AssignableAVM2Item.dupSetTemp;
|
||||
import static com.jpexs.decompiler.flash.abc.avm2.parser.script.AssignableAVM2Item.getTemp;
|
||||
import com.jpexs.decompiler.flash.abc.types.Multiname;
|
||||
import com.jpexs.decompiler.flash.abc.types.NamespaceSet;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
import com.jpexs.decompiler.graph.model.LocalData;
|
||||
|
||||
@@ -36,7 +36,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertBIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertDIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertIIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertUIns;
|
||||
import static com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item.ins;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.NanAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.NullAVM2Item;
|
||||
|
||||
@@ -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.abc.avm2.parser.script;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
@@ -31,19 +32,12 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.DupIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PopIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertDIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertSIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertSIns;
|
||||
import static com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item.ins;
|
||||
import static com.jpexs.decompiler.flash.abc.avm2.parser.script.AssignableAVM2Item.dupSetTemp;
|
||||
import static com.jpexs.decompiler.flash.abc.avm2.parser.script.AssignableAVM2Item.getTemp;
|
||||
import static com.jpexs.decompiler.flash.abc.avm2.parser.script.AssignableAVM2Item.killTemp;
|
||||
import static com.jpexs.decompiler.flash.abc.avm2.parser.script.AssignableAVM2Item.setTemp;
|
||||
import com.jpexs.decompiler.flash.abc.types.Multiname;
|
||||
import com.jpexs.decompiler.flash.abc.types.NamespaceSet;
|
||||
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
import com.jpexs.decompiler.graph.model.LocalData;
|
||||
@@ -117,10 +111,10 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
|
||||
*/
|
||||
if (name != null) {
|
||||
return toSourceMerge(localData, generator,
|
||||
return toSourceMerge(localData, generator,
|
||||
ns, NameAVM2Item.generateCoerce(localData, generator, new TypeItem("Namespace")),
|
||||
ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList<Integer>()), true)),
|
||||
dupSetTemp(localData, generator, name_temp),
|
||||
dupSetTemp(localData, generator, name_temp),
|
||||
ns, NameAVM2Item.generateCoerce(localData, generator, new TypeItem("Namespace")),
|
||||
dupSetTemp(localData, generator, ns_temp),
|
||||
//Start get original
|
||||
//getTemp(localData, generator, ns_temp), generateCoerce(generator, "Namespace"), ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAME, g.abc.constants.getStringId(variableName, true), 0, 0, 0, new ArrayList<Integer>()), true)),
|
||||
@@ -169,8 +163,8 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
|
||||
if (name == null) {
|
||||
if (assignedValue != null) {
|
||||
return toSourceMerge(localData, generator,
|
||||
return toSourceMerge(localData, generator,
|
||||
obj == null ? ns : null, obj == null ? generateCoerce(localData, generator, new TypeItem("Namespace")) : null, nameItem, ins(new ConvertSIns()), obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList<Integer>()), true)),
|
||||
obj == null ? ns : null, obj == null ? NameAVM2Item.generateCoerce(localData, generator, new TypeItem("Namespace")) : null, nameItem, ins(new ConvertSIns()), obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList<Integer>()), true)),
|
||||
ns, NameAVM2Item.generateCoerce(localData, generator, new TypeItem("Namespace")), nameItem, ins(new ConvertSIns()), assignedValue,
|
||||
needsReturn ? dupSetTemp(localData, generator, ret_temp) : null,
|
||||
ins(new SetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList<Integer>()), true)),
|
||||
needsReturn ? getTemp(localData, generator, ret_temp) : null,
|
||||
@@ -178,9 +172,9 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
|
||||
);
|
||||
} else {
|
||||
return toSourceMerge(localData, generator,
|
||||
return toSourceMerge(localData, generator,
|
||||
obj == null ? ns : null, obj == null ? NameAVM2Item.generateCoerce(localData, generator, new TypeItem("Namespace")) : null, nameItem, ins(new ConvertSIns()), obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList<Integer>()), true)),
|
||||
call ? dupSetTemp(localData, generator, obj_temp) : null,
|
||||
call ? dupSetTemp(localData, generator, obj_temp) : null,
|
||||
ns, NameAVM2Item.generateCoerce(localData, generator, new TypeItem("Namespace")), nameItem, ins(new ConvertSIns()),
|
||||
construct ? callargs : null,
|
||||
ins(construct ? new ConstructPropIns() : delete ? new DeletePropertyIns() : new GetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(Multiname.RTQNAMEL, 0, 0, 0, 0, new ArrayList<Integer>()), true), construct ? callargs.size() : null),
|
||||
call ? getTemp(localData, generator, obj_temp) : null,
|
||||
@@ -193,8 +187,8 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
|
||||
} else {
|
||||
if (assignedValue != null) {
|
||||
return toSourceMerge(localData, generator,
|
||||
return toSourceMerge(localData, generator,
|
||||
obj == null ? ns : null, obj == null ? generateCoerce(localData, generator, new TypeItem("Namespace")) : null, obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.RTQNAMEA : Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList<Integer>()), true)),
|
||||
obj == null ? ns : null, obj == null ? NameAVM2Item.generateCoerce(localData, generator, new TypeItem("Namespace")) : null, obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.RTQNAMEA : Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList<Integer>()), true)),
|
||||
ns, NameAVM2Item.generateCoerce(localData, generator, new TypeItem("Namespace")), assignedValue,
|
||||
needsReturn ? dupSetTemp(localData, generator, ret_temp) : null,
|
||||
ins(new SetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.RTQNAMEA : Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList<Integer>()), true)),
|
||||
needsReturn ? getTemp(localData, generator, ret_temp) : null,
|
||||
@@ -202,9 +196,9 @@ public class NamespacedAVM2Item extends AssignableAVM2Item {
|
||||
);
|
||||
} else {
|
||||
return toSourceMerge(localData, generator,
|
||||
return toSourceMerge(localData, generator,
|
||||
obj == null ? ns : null, obj == null ? NameAVM2Item.generateCoerce(localData, generator, new TypeItem("Namespace")) : null, obj != null ? obj : ins(new FindPropertyStrictIns(), g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.RTQNAMEA : Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList<Integer>()), true)),
|
||||
call ? dupSetTemp(localData, generator, obj_temp) : null,
|
||||
call ? dupSetTemp(localData, generator, obj_temp) : null,
|
||||
ns, NameAVM2Item.generateCoerce(localData, generator, new TypeItem("Namespace")),
|
||||
construct ? callargs : null,
|
||||
ins(construct ? new ConstructPropIns() : delete ? new DeletePropertyIns() : new GetPropertyIns(), g.abc.constants.getMultinameId(new Multiname(attr ? Multiname.RTQNAMEA : Multiname.RTQNAME, g.abc.constants.getStringId(name, true), 0, 0, 0, new ArrayList<Integer>()), true), construct ? callargs.size() : null),
|
||||
call ? getTemp(localData, generator, obj_temp) : null,
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.types.CoerceAIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.CoerceIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.CoerceSIns;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.instructions.types.ConvertIIns;
|
||||
import static com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item.ins;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.NanAVM2Item;
|
||||
import com.jpexs.decompiler.flash.abc.avm2.model.NullAVM2Item;
|
||||
|
||||
@@ -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.action.model;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
@@ -24,7 +25,6 @@ import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.model.LocalData;
|
||||
import java.util.List;
|
||||
|
||||
@@ -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.action.model.operations;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
@@ -25,7 +26,6 @@ import com.jpexs.decompiler.flash.ecma.EcmaScript;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
import com.jpexs.decompiler.graph.model.BinaryOpItem;
|
||||
|
||||
@@ -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.action.model.operations;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
@@ -23,7 +24,6 @@ import com.jpexs.decompiler.flash.action.swf6.ActionStringGreater;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
import com.jpexs.decompiler.graph.model.BinaryOpItem;
|
||||
|
||||
@@ -448,7 +448,7 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
|
||||
}
|
||||
} else {
|
||||
// We should never get here
|
||||
lineStyle(1, 1, new RGB(Color.BLACK), new RGB(Color.BLACK), false, "NORMAL", 0, 0, 0, 3);
|
||||
lineStyle(1, 1, new RGB(Color.black), new RGB(Color.BLACK), false, "NORMAL", 0, 0, 0, 3);
|
||||
}
|
||||
}
|
||||
if (!e.getFrom().equals(pos)) {
|
||||
|
||||
@@ -60,10 +60,10 @@ public class SVGMorphShapeExporter extends DefaultSVGMorphShapeExporter {
|
||||
@Override
|
||||
public void beginFill(RGB color, RGB colorEnd) {
|
||||
if (color == null) {
|
||||
color = new RGB(defaultColor == null ? Color.BLACK : defaultColor);
|
||||
color = new RGB(defaultColor == null ? Color.black : defaultColor);
|
||||
}
|
||||
if (colorEnd == null) {
|
||||
colorEnd = new RGB(defaultColor == null ? Color.BLACK : defaultColor);
|
||||
colorEnd = new RGB(defaultColor == null ? Color.black : defaultColor);
|
||||
}
|
||||
finalizePath();
|
||||
path.setAttribute("stroke", "none");
|
||||
|
||||
@@ -32,7 +32,6 @@ import com.jpexs.decompiler.flash.types.RGBA;
|
||||
import com.jpexs.decompiler.flash.types.SHAPE;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.SerializableImage;
|
||||
import java.awt.Color;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -225,8 +224,8 @@ public class CanvasShapeExporter extends ShapeExporterBase {
|
||||
fillData += "\tctx.fillStyle = grd;\r\n";
|
||||
}
|
||||
|
||||
public static String color(Color color) {
|
||||
return color(new RGBA(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()));
|
||||
public static String color(int color) {
|
||||
return color(new RGBA(color));
|
||||
}
|
||||
|
||||
public static String color(RGB rgb) {
|
||||
|
||||
@@ -369,7 +369,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
|
||||
}
|
||||
} else {
|
||||
// We should never get here
|
||||
lineStyle(1, new RGB(Color.BLACK), false, "NORMAL", 0, 0, 0, 3);
|
||||
lineStyle(1, new RGB(Color.black), false, "NORMAL", 0, 0, 0, 3);
|
||||
}
|
||||
}
|
||||
if (!e.getFrom().equals(pos)) {
|
||||
|
||||
@@ -32,7 +32,19 @@ import javax.imageio.ImageIO;
|
||||
public class ImageHelper {
|
||||
|
||||
public static BufferedImage read(InputStream input) throws IOException {
|
||||
return ImageIO.read(input);
|
||||
BufferedImage in = ImageIO.read(input);
|
||||
int type = in.getType();
|
||||
if (type != BufferedImage.TYPE_INT_ARGB && type != BufferedImage.TYPE_INT_RGB) {
|
||||
// convert to ARGB
|
||||
int width = in.getWidth();
|
||||
int height = in.getHeight();
|
||||
int[] imgData = in.getRGB(0, 0, width, height, null, 0, width);
|
||||
BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
newImage.getRaster().setDataElements(0, 0, width, height, imgData);
|
||||
return newImage;
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
public static void write(BufferedImage image, String formatName, OutputStream output) throws IOException {
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.jpexs.decompiler.flash.types.annotations.SWFType;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.SerializableImage;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -102,20 +103,14 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
return img;
|
||||
}
|
||||
|
||||
int width = img.getWidth();
|
||||
int height = img.getHeight();
|
||||
SerializableImage img2 = new SerializableImage(width, height, SerializableImage.TYPE_INT_ARGB);
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int val = img.getRGB(x, y);
|
||||
int a = bitmapAlphaData[x + y * width] & 0xff;
|
||||
val = (val & 0xffffff) | (a << 24);
|
||||
img2.setRGB(x, y, multiplyAlpha(val));
|
||||
}
|
||||
int[] pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
int a = bitmapAlphaData[i] & 0xff;
|
||||
pixels[i] = multiplyAlpha((pixels[i] & 0xffffff) | (a << 24));
|
||||
}
|
||||
|
||||
cachedImage = img2;
|
||||
return img2;
|
||||
|
||||
cachedImage = img;
|
||||
return img;
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.jpexs.decompiler.flash.types.annotations.SWFType;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.SerializableImage;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -103,20 +104,14 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
|
||||
return img;
|
||||
}
|
||||
|
||||
int width = img.getWidth();
|
||||
int height = img.getHeight();
|
||||
SerializableImage img2 = new SerializableImage(width, height, SerializableImage.TYPE_INT_ARGB);
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int val = img.getRGB(x, y);
|
||||
int a = bitmapAlphaData.get(x + y * width) & 0xff;
|
||||
val = (val & 0xffffff) | (a << 24);
|
||||
img2.setRGB(x, y, multiplyAlpha(val));
|
||||
}
|
||||
int[] pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
int a = bitmapAlphaData.get(i) & 0xff;
|
||||
pixels[i] = multiplyAlpha((pixels[i] & 0xffffff) | (a << 24));
|
||||
}
|
||||
|
||||
cachedImage = img2;
|
||||
return img2;
|
||||
cachedImage = img;
|
||||
return img;
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -27,11 +27,12 @@ import com.jpexs.decompiler.flash.types.ALPHACOLORMAPDATA;
|
||||
import com.jpexs.decompiler.flash.types.ARGB;
|
||||
import com.jpexs.decompiler.flash.types.BasicType;
|
||||
import com.jpexs.decompiler.flash.types.annotations.Conditional;
|
||||
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.Helper;
|
||||
import com.jpexs.helpers.SerializableImage;
|
||||
import java.awt.Color;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -64,6 +65,13 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
public static final int FORMAT_8BIT_COLORMAPPED = 3;
|
||||
public static final int FORMAT_32BIT_ARGB = 5;
|
||||
|
||||
@Internal
|
||||
private ALPHACOLORMAPDATA colorMapData;
|
||||
@Internal
|
||||
private ALPHABITMAPDATA bitmapData;
|
||||
@Internal
|
||||
private boolean decompressed = false;
|
||||
|
||||
public static final int ID = 36;
|
||||
|
||||
@Override
|
||||
@@ -94,38 +102,39 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
public void setImage(byte[] data) throws IOException {
|
||||
SerializableImage image = new SerializableImage(ImageHelper.read(new ByteArrayInputStream(data)));
|
||||
ALPHABITMAPDATA bitmapData = new ALPHABITMAPDATA();
|
||||
bitmapFormat = FORMAT_32BIT_ARGB;
|
||||
bitmapWidth = image.getWidth();
|
||||
bitmapHeight = image.getHeight();
|
||||
bitmapData.bitmapPixelData = new ARGB[bitmapWidth * bitmapHeight];
|
||||
int pos = 0;
|
||||
for (int y = 0; y < bitmapHeight; y++) {
|
||||
for (int x = 0; x < bitmapWidth; x++) {
|
||||
int argb = image.getRGB(x, y);
|
||||
int a = (argb >> 24) & 0xff;
|
||||
int r = (argb >> 16) & 0xff;
|
||||
int g = (argb >> 8) & 0xff;
|
||||
int b = (argb) & 0xff;
|
||||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
bitmapData.bitmapPixelData = new ARGB[width * height];
|
||||
int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
|
||||
for (int pos = 0; pos < pixels.length; pos++) {
|
||||
int argb = pixels[pos];
|
||||
int a = (argb >> 24) & 0xff;
|
||||
int r = (argb >> 16) & 0xff;
|
||||
int g = (argb >> 8) & 0xff;
|
||||
int b = (argb) & 0xff;
|
||||
|
||||
r = r * a / 255;
|
||||
g = g * a / 255;
|
||||
b = b * a / 255;
|
||||
r = r * a / 255;
|
||||
g = g * a / 255;
|
||||
b = b * a / 255;
|
||||
|
||||
bitmapData.bitmapPixelData[pos] = new ARGB();
|
||||
bitmapData.bitmapPixelData[pos].alpha = a;
|
||||
bitmapData.bitmapPixelData[pos].red = r;
|
||||
bitmapData.bitmapPixelData[pos].green = g;
|
||||
bitmapData.bitmapPixelData[pos].blue = b;
|
||||
pos++;
|
||||
}
|
||||
bitmapData.bitmapPixelData[pos] = new ARGB();
|
||||
bitmapData.bitmapPixelData[pos].alpha = a;
|
||||
bitmapData.bitmapPixelData[pos].red = r;
|
||||
bitmapData.bitmapPixelData[pos].green = g;
|
||||
bitmapData.bitmapPixelData[pos].blue = b;
|
||||
}
|
||||
|
||||
int format = FORMAT_32BIT_ARGB;
|
||||
ByteArrayOutputStream bitmapDataOS = new ByteArrayOutputStream();
|
||||
SWFOutputStream sos = new SWFOutputStream(bitmapDataOS, getVersion());
|
||||
sos.writeALPHABITMAPDATA(bitmapData, bitmapFormat, bitmapWidth, bitmapHeight);
|
||||
sos.writeALPHABITMAPDATA(bitmapData, format, width, height);
|
||||
ByteArrayOutputStream zlibOS = new ByteArrayOutputStream();
|
||||
SWFOutputStream sos2 = new SWFOutputStream(zlibOS, getVersion());
|
||||
sos2.writeBytesZlib(bitmapDataOS.toByteArray());
|
||||
zlibBitmapData = new ByteArrayRange(zlibOS.toByteArray());
|
||||
bitmapFormat = format;
|
||||
bitmapWidth = width;
|
||||
bitmapHeight = height;
|
||||
decompressed = false;
|
||||
clearCache();
|
||||
setModified(true);
|
||||
@@ -156,10 +165,7 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
}
|
||||
zlibBitmapData = sis.readByteRangeEx(sis.available(), "zlibBitmapData");
|
||||
}
|
||||
private ALPHACOLORMAPDATA colorMapData;
|
||||
private ALPHABITMAPDATA bitmapData;
|
||||
private boolean decompressed = false;
|
||||
|
||||
|
||||
public ALPHACOLORMAPDATA getColorMapData() {
|
||||
if (!decompressed) {
|
||||
uncompressData();
|
||||
@@ -246,7 +252,7 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
c = multiplyAlpha(colorMapData.colorTableRGB[colorMapData.colorMapPixelData[pos32aligned] & 0xff].toInt());
|
||||
}
|
||||
if ((bitmapFormat == DefineBitsLossless2Tag.FORMAT_32BIT_ARGB)) {
|
||||
c = (multiplyAlpha(bitmapData.bitmapPixelData[pos].toInt()));
|
||||
c = multiplyAlpha(bitmapData.bitmapPixelData[pos].toInt());
|
||||
}
|
||||
bi.setRGB(x, y, c);
|
||||
pos32aligned++;
|
||||
|
||||
@@ -33,7 +33,7 @@ import com.jpexs.decompiler.flash.types.annotations.SWFType;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.SerializableImage;
|
||||
import java.awt.Color;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -97,34 +97,35 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
|
||||
@Override
|
||||
public void setImage(byte[] data) throws IOException {
|
||||
SerializableImage image = new SerializableImage(ImageHelper.read(new ByteArrayInputStream(data)));
|
||||
bitmapFormat = FORMAT_24BIT_RGB;
|
||||
bitmapWidth = image.getWidth();
|
||||
bitmapHeight = image.getHeight();
|
||||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
bitmapData = new BITMAPDATA();
|
||||
bitmapData.bitmapPixelDataPix24 = new PIX24[bitmapWidth * bitmapHeight];
|
||||
int pos = 0;
|
||||
for (int y = 0; y < bitmapHeight; y++) {
|
||||
for (int x = 0; x < bitmapWidth; x++) {
|
||||
int argb = image.getRGB(x, y);
|
||||
//int a = (argb >> 24) & 0xff;
|
||||
int r = (argb >> 16) & 0xff;
|
||||
int g = (argb >> 8) & 0xff;
|
||||
int b = (argb) & 0xff;
|
||||
bitmapData.bitmapPixelDataPix24[pos] = new PIX24();
|
||||
bitmapData.bitmapPixelDataPix24[pos].red = r;
|
||||
bitmapData.bitmapPixelDataPix24[pos].green = g;
|
||||
bitmapData.bitmapPixelDataPix24[pos].blue = b;
|
||||
bitmapData.bitmapPixelDataPix24[pos].reserved = 0xff; //documentation says 0, but image is sometimes broken with 0, so there is 0xff, which works (maybe alpha?)
|
||||
pos++;
|
||||
}
|
||||
bitmapData.bitmapPixelDataPix24 = new PIX24[width * height];
|
||||
int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
|
||||
for (int pos = 0; pos < pixels.length; pos++) {
|
||||
int argb = pixels[pos];
|
||||
//int a = (argb >> 24) & 0xff;
|
||||
int r = (argb >> 16) & 0xff;
|
||||
int g = (argb >> 8) & 0xff;
|
||||
int b = (argb) & 0xff;
|
||||
bitmapData.bitmapPixelDataPix24[pos] = new PIX24();
|
||||
bitmapData.bitmapPixelDataPix24[pos].red = r;
|
||||
bitmapData.bitmapPixelDataPix24[pos].green = g;
|
||||
bitmapData.bitmapPixelDataPix24[pos].blue = b;
|
||||
bitmapData.bitmapPixelDataPix24[pos].reserved = 0xff; //documentation says 0, but image is sometimes broken with 0, so there is 0xff, which works (maybe alpha?)
|
||||
}
|
||||
|
||||
int format = FORMAT_24BIT_RGB;
|
||||
ByteArrayOutputStream bitmapDataOS = new ByteArrayOutputStream();
|
||||
SWFOutputStream sos = new SWFOutputStream(bitmapDataOS, getVersion());
|
||||
sos.writeBITMAPDATA(bitmapData, bitmapFormat, bitmapWidth, bitmapHeight);
|
||||
sos.writeBITMAPDATA(bitmapData, format, width, height);
|
||||
ByteArrayOutputStream zlibOS = new ByteArrayOutputStream();
|
||||
SWFOutputStream sos2 = new SWFOutputStream(zlibOS, getVersion());
|
||||
sos2.writeBytesZlib(bitmapDataOS.toByteArray());
|
||||
zlibBitmapData = new ByteArrayRange(zlibOS.toByteArray());
|
||||
bitmapFormat = format;
|
||||
bitmapWidth = width;
|
||||
bitmapHeight = height;
|
||||
decompressed = false;
|
||||
clearCache();
|
||||
setModified(true);
|
||||
@@ -153,18 +154,18 @@ public class DefineBitsLosslessTag extends ImageTag implements AloneTag {
|
||||
int pos = 0;
|
||||
for (int y = 0; y < bitmapHeight; y++) {
|
||||
for (int x = 0; x < bitmapWidth; x++) {
|
||||
Color c = null;
|
||||
int c = 0;
|
||||
if (bitmapFormat == DefineBitsLosslessTag.FORMAT_8BIT_COLORMAPPED) {
|
||||
RGB color = colorMapData.colorTableRGB[colorMapData.colorMapPixelData[pos32aligned] & 0xff];
|
||||
c = (new Color(color.red, color.green, color.blue));
|
||||
c = color.toInt();
|
||||
}
|
||||
if (bitmapFormat == DefineBitsLosslessTag.FORMAT_15BIT_RGB) {
|
||||
c = (new Color(bitmapData.bitmapPixelDataPix15[pos].red * 8, bitmapData.bitmapPixelDataPix15[pos].green * 8, bitmapData.bitmapPixelDataPix15[pos].blue * 8));
|
||||
c = new RGB(bitmapData.bitmapPixelDataPix15[pos].red * 8, bitmapData.bitmapPixelDataPix15[pos].green * 8, bitmapData.bitmapPixelDataPix15[pos].blue * 8).toInt();
|
||||
}
|
||||
if (bitmapFormat == DefineBitsLosslessTag.FORMAT_24BIT_RGB) {
|
||||
c = (new Color(bitmapData.bitmapPixelDataPix24[pos].red, bitmapData.bitmapPixelDataPix24[pos].green, bitmapData.bitmapPixelDataPix24[pos].blue));
|
||||
c = new RGB(bitmapData.bitmapPixelDataPix24[pos].red, bitmapData.bitmapPixelDataPix24[pos].green, bitmapData.bitmapPixelDataPix24[pos].blue).toInt();
|
||||
}
|
||||
bi.setRGB(x, y, c.getRGB());
|
||||
bi.setRGB(x, y, c);
|
||||
pos32aligned++;
|
||||
pos++;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.jpexs.decompiler.flash.types.LINESTYLE;
|
||||
import com.jpexs.decompiler.flash.types.LINESTYLEARRAY;
|
||||
import com.jpexs.decompiler.flash.types.MATRIX;
|
||||
import com.jpexs.decompiler.flash.types.RECT;
|
||||
import com.jpexs.decompiler.flash.types.RGBA;
|
||||
import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE;
|
||||
import com.jpexs.decompiler.flash.types.shaperecords.EndShapeRecord;
|
||||
import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord;
|
||||
@@ -105,7 +106,7 @@ public abstract class ImageTag extends CharacterTag implements DrawableTag {
|
||||
r = max255(r * multiplier);
|
||||
g = max255(g * multiplier);
|
||||
b = max255(b * multiplier);
|
||||
return ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF);
|
||||
return RGBA.toInt(r, g, b, a);
|
||||
}
|
||||
|
||||
private SHAPEWITHSTYLE getShape() {
|
||||
|
||||
@@ -272,7 +272,7 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
|
||||
}
|
||||
|
||||
public static void staticTextToImage(SWF swf, List<TEXTRECORD> textRecords, int numText, SerializableImage image, MATRIX textMatrix, Matrix transformation, ColorTransform colorTransform) {
|
||||
Color textColor = new Color(0, 0, 0);
|
||||
int textColor = 0;
|
||||
FontTag font = null;
|
||||
int textHeight = 12;
|
||||
int x = 0;
|
||||
@@ -281,9 +281,9 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
|
||||
for (TEXTRECORD rec : textRecords) {
|
||||
if (rec.styleFlagsHasColor) {
|
||||
if (numText == 2) {
|
||||
textColor = colorTransform.apply(rec.textColorA.toColor());
|
||||
textColor = colorTransform.apply(rec.textColorA.toInt());
|
||||
} else {
|
||||
textColor = colorTransform.apply(rec.textColor.toColor());
|
||||
textColor = colorTransform.apply(rec.textColor.toInt());
|
||||
}
|
||||
}
|
||||
if (rec.styleFlagsHasFont) {
|
||||
@@ -300,6 +300,7 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
|
||||
|
||||
double rat = textHeight / 1024.0 / (font == null ? 1 : font.getDivider());
|
||||
|
||||
Color textColor2 = new Color(textColor);
|
||||
for (GLYPHENTRY entry : rec.glyphEntries) {
|
||||
Matrix mat = transformation.clone();
|
||||
mat = mat.concatenate(new Matrix(textMatrix));
|
||||
@@ -309,7 +310,7 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
|
||||
if (entry.glyphIndex != -1 && glyphs != null) {
|
||||
// shapeNum: 1
|
||||
SHAPE shape = glyphs.get(entry.glyphIndex);
|
||||
BitmapExporter.export(swf, shape, textColor, image, mat, colorTransform);
|
||||
BitmapExporter.export(swf, shape, textColor2, image, mat, colorTransform);
|
||||
x += entry.glyphAdvance;
|
||||
}
|
||||
}
|
||||
@@ -317,7 +318,7 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
|
||||
}
|
||||
|
||||
public static String staticTextToHtmlCanvas(double unitDivisor, SWF swf, List<TEXTRECORD> textRecords, int numText, RECT bounds, MATRIX textMatrix, ColorTransform colorTransform) {
|
||||
Color textColor = new Color(0, 0, 0);
|
||||
int textColor = 0;
|
||||
String ret = "";
|
||||
FontTag font = null;
|
||||
int fontId = -1;
|
||||
@@ -329,9 +330,9 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
|
||||
for (TEXTRECORD rec : textRecords) {
|
||||
if (rec.styleFlagsHasColor) {
|
||||
if (numText == 2) {
|
||||
textColor = colorTransform.apply(rec.textColorA.toColor());
|
||||
textColor = colorTransform.apply(rec.textColorA.toInt());
|
||||
} else {
|
||||
textColor = colorTransform.apply(rec.textColor.toColor());
|
||||
textColor = colorTransform.apply(rec.textColor.toInt());
|
||||
}
|
||||
}
|
||||
if (rec.styleFlagsHasFont) {
|
||||
@@ -366,7 +367,7 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
|
||||
}
|
||||
|
||||
public static void staticTextToSVG(SWF swf, List<TEXTRECORD> textRecords, int numText, SVGExporter exporter, RECT bounds, MATRIX textMatrix, ColorTransform colorTransform, double zoom) {
|
||||
Color textColor = new Color(0, 0, 0);
|
||||
int textColor = 0;
|
||||
FontTag font = null;
|
||||
int textHeight = 12;
|
||||
int x = 0;
|
||||
@@ -375,9 +376,9 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
|
||||
for (TEXTRECORD rec : textRecords) {
|
||||
if (rec.styleFlagsHasColor) {
|
||||
if (numText == 2) {
|
||||
textColor = colorTransform.apply(rec.textColorA.toColor());
|
||||
textColor = colorTransform.apply(rec.textColorA.toInt());
|
||||
} else {
|
||||
textColor = colorTransform.apply(rec.textColor.toColor());
|
||||
textColor = colorTransform.apply(rec.textColor.toInt());
|
||||
}
|
||||
}
|
||||
if (rec.styleFlagsHasFont) {
|
||||
@@ -422,12 +423,10 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
|
||||
textElement.setAttribute("lengthAdjust", "spacing");
|
||||
textElement.setTextContent(text.toString());
|
||||
|
||||
if (textColor != null) {
|
||||
RGBA colorA = new RGBA(textColor);
|
||||
textElement.setAttribute("fill", colorA.toHexRGB());
|
||||
if (colorA.alpha != 255) {
|
||||
textElement.setAttribute("fill-opacity", Float.toString(colorA.getAlphaFloat()));
|
||||
}
|
||||
RGBA colorA = new RGBA(textColor);
|
||||
textElement.setAttribute("fill", colorA.toHexRGB());
|
||||
if (colorA.alpha != 255) {
|
||||
textElement.setAttribute("fill-opacity", Float.toString(colorA.getAlphaFloat()));
|
||||
}
|
||||
|
||||
exporter.addToGroup(textElement);
|
||||
@@ -467,13 +466,12 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
|
||||
}
|
||||
|
||||
Element charImage = exporter.addUse(mat, bounds, charId);
|
||||
if (textColor != null) {
|
||||
RGBA colorA = new RGBA(textColor);
|
||||
charImage.setAttribute("fill", colorA.toHexRGB());
|
||||
if (colorA.alpha != 255) {
|
||||
charImage.setAttribute("fill-opacity", Float.toString(colorA.getAlphaFloat()));
|
||||
}
|
||||
RGBA colorA = new RGBA(textColor);
|
||||
charImage.setAttribute("fill", colorA.toHexRGB());
|
||||
if (colorA.alpha != 255) {
|
||||
charImage.setAttribute("fill-opacity", Float.toString(colorA.getAlphaFloat()));
|
||||
}
|
||||
|
||||
x += entry.glyphAdvance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,20 +58,10 @@ public class ARGB implements Serializable {
|
||||
}
|
||||
|
||||
public int toInt() {
|
||||
return ((alpha & 0xFF) << 24) |
|
||||
((red & 0xFF) << 16) |
|
||||
((green & 0xFF) << 8) |
|
||||
(blue & 0xFF);
|
||||
return RGBA.toInt(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
public ARGB() {
|
||||
|
||||
}
|
||||
|
||||
public ARGB(Color color) {
|
||||
this.alpha = color.getAlpha();
|
||||
this.red = color.getRed();
|
||||
this.green = color.getGreen();
|
||||
this.blue = color.getBlue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.jpexs.decompiler.flash.types;
|
||||
|
||||
import com.jpexs.decompiler.flash.types.filters.Filtering;
|
||||
import com.jpexs.helpers.SerializableImage;
|
||||
import java.awt.Color;
|
||||
import java.awt.image.RescaleOp;
|
||||
|
||||
/**
|
||||
@@ -36,7 +35,7 @@ public class ColorTransform implements Cloneable {
|
||||
return Filtering.colorEffect(src, getRedAdd(), getGreenAdd(), getBlueAdd(), getAlphaAdd(), getRedMulti(), getGreenMulti(), getBlueMulti(), getAlphaMulti());
|
||||
}
|
||||
|
||||
public Color apply(Color color) {
|
||||
public int apply(int color) {
|
||||
return Filtering.colorEffect(color, getRedAdd(), getGreenAdd(), getBlueAdd(), getAlphaAdd(), getRedMulti(), getGreenMulti(), getBlueMulti(), getAlphaMulti());
|
||||
}
|
||||
|
||||
@@ -44,14 +43,14 @@ public class ColorTransform implements Cloneable {
|
||||
if (color == null) {
|
||||
return null;
|
||||
}
|
||||
return new RGBA(Filtering.colorEffect(color.toColor(), getRedAdd(), getGreenAdd(), getBlueAdd(), getAlphaAdd(), getRedMulti(), getGreenMulti(), getBlueMulti(), getAlphaMulti()));
|
||||
return new RGBA(Filtering.colorEffect(color.toInt(), getRedAdd(), getGreenAdd(), getBlueAdd(), getAlphaAdd(), getRedMulti(), getGreenMulti(), getBlueMulti(), getAlphaMulti()));
|
||||
}
|
||||
|
||||
public RGBA apply(RGBA color) {
|
||||
if (color == null) {
|
||||
return null;
|
||||
}
|
||||
return new RGBA(Filtering.colorEffect(color.toColor(), getRedAdd(), getGreenAdd(), getBlueAdd(), getAlphaAdd(), getRedMulti(), getGreenMulti(), getBlueMulti(), getAlphaMulti()));
|
||||
return new RGBA(Filtering.colorEffect(color.toInt(), getRedAdd(), getGreenAdd(), getBlueAdd(), getAlphaAdd(), getRedMulti(), getGreenMulti(), getBlueMulti(), getAlphaMulti()));
|
||||
}
|
||||
|
||||
public GRADRECORD[] apply(GRADRECORD[] gradRecords) {
|
||||
@@ -84,19 +83,19 @@ public class ColorTransform implements Cloneable {
|
||||
}
|
||||
|
||||
public int getRedMulti() {
|
||||
return 255;
|
||||
return 256;
|
||||
}
|
||||
|
||||
public int getGreenMulti() {
|
||||
return 255;
|
||||
return 256;
|
||||
}
|
||||
|
||||
public int getBlueMulti() {
|
||||
return 255;
|
||||
return 256;
|
||||
}
|
||||
|
||||
public int getAlphaMulti() {
|
||||
return 255;
|
||||
return 256;
|
||||
}
|
||||
|
||||
public ColorTransform merge(final ColorTransform c) {
|
||||
|
||||
@@ -74,6 +74,10 @@ public class RGB implements Serializable {
|
||||
}
|
||||
|
||||
public int toInt() {
|
||||
return toInt(red, green, blue);
|
||||
}
|
||||
|
||||
public static int toInt(int red, int green, int blue) {
|
||||
return (0xFF << 24) |
|
||||
((red & 0xFF) << 16) |
|
||||
((green & 0xFF) << 8) |
|
||||
@@ -81,9 +85,15 @@ public class RGB implements Serializable {
|
||||
}
|
||||
|
||||
public RGB(Color color) {
|
||||
this.red = color.getRed();
|
||||
this.green = color.getGreen();
|
||||
this.blue = color.getBlue();
|
||||
red = color.getRed();
|
||||
green = color.getGreen();
|
||||
blue = color.getBlue();
|
||||
}
|
||||
|
||||
public RGB(int rgb) {
|
||||
red = (rgb >> 16) & 0xFF;
|
||||
green = (rgb >> 8) & 0xFF;
|
||||
blue = rgb & 0xFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -65,7 +65,12 @@ public class RGBA extends RGB implements Serializable {
|
||||
|
||||
public RGBA(Color color) {
|
||||
super(color);
|
||||
this.alpha = color.getAlpha();
|
||||
alpha = color.getAlpha();
|
||||
}
|
||||
|
||||
public RGBA(int rgb) {
|
||||
super(rgb);
|
||||
alpha = (rgb >> 24) & 0xFF;
|
||||
}
|
||||
|
||||
public RGBA() {
|
||||
@@ -78,6 +83,10 @@ public class RGBA extends RGB implements Serializable {
|
||||
|
||||
@Override
|
||||
public int toInt() {
|
||||
return toInt(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
public static int toInt(int red, int green, int blue, int alpha) {
|
||||
return ((alpha & 0xFF) << 24) |
|
||||
((red & 0xFF) << 16) |
|
||||
((green & 0xFF) << 8) |
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.types.filters;
|
||||
|
||||
import com.jpexs.decompiler.flash.types.RGBA;
|
||||
import com.jpexs.helpers.SerializableImage;
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
@@ -29,6 +30,7 @@ import java.awt.image.BandCombineOp;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.BufferedImageOp;
|
||||
import java.awt.image.ConvolveOp;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.awt.image.Kernel;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.WritableRaster;
|
||||
@@ -217,16 +219,17 @@ public class Filtering {
|
||||
}
|
||||
|
||||
public static SerializableImage blur(SerializableImage src, int hRadius, int vRadius, int iterations) {
|
||||
return new SerializableImage(blur(src.getBufferedImage(), hRadius, vRadius, iterations, null));
|
||||
}
|
||||
|
||||
private static BufferedImage blur(BufferedImage src, int hRadius, int vRadius, int iterations, int[] mask) {
|
||||
int[] pixels = (int[]) getRGB(src.getBufferedImage()).clone();
|
||||
int width = src.getWidth();
|
||||
int height = src.getHeight();
|
||||
blur(pixels, width, height, hRadius, vRadius, iterations, null);
|
||||
BufferedImage ret = new BufferedImage(width, height, src.getType());
|
||||
setRGB(ret, width, height, pixels);
|
||||
return new SerializableImage(ret);
|
||||
}
|
||||
|
||||
BufferedImage dst = new BufferedImage(width, height, src.getType());
|
||||
|
||||
int[] inPixels = getRGB(src, 0, 0, width, height);
|
||||
private static void blur(int[] src, int width, int height, int hRadius, int vRadius, int iterations, int[] mask) {
|
||||
int[] inPixels = src;
|
||||
premultiply(inPixels);
|
||||
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
@@ -234,8 +237,6 @@ public class Filtering {
|
||||
boxBlurVertical(inPixels, mask, width, height, vRadius / 2);
|
||||
}
|
||||
unpremultiply(inPixels);
|
||||
setRGB(dst, 0, 0, width, height, inPixels);
|
||||
return dst;
|
||||
}
|
||||
|
||||
public static SerializableImage bevel(SerializableImage src, int blurX, int blurY, float strength, int type, Color highlightColor, Color shadowColor, float angle, float distance, boolean knockout, int iterations) {
|
||||
@@ -255,7 +256,7 @@ public class Filtering {
|
||||
int width = src.getWidth();
|
||||
int height = src.getHeight();
|
||||
BufferedImage retImg = new BufferedImage(width, height, src.getType());
|
||||
int srcPixels[] = getRGB(src, 0, 0, width, height);
|
||||
int srcPixels[] = getRGB(src);
|
||||
|
||||
int revPixels[] = new int[srcPixels.length];
|
||||
for (int i = 0; i < srcPixels.length; i++) {
|
||||
@@ -269,7 +270,7 @@ public class Filtering {
|
||||
Point p2 = new Point(511, 0);
|
||||
gg.setPaint(new LinearGradientPaint(p1, p2, ratios, colors));
|
||||
gg.fill(new Rectangle(512, 1));
|
||||
int[] gradientPixels = getRGB(gradient, 0, 0, gradient.getWidth(), gradient.getHeight());
|
||||
int[] gradientPixels = getRGB(gradient);
|
||||
|
||||
BufferedImage shadowInner = null;
|
||||
BufferedImage hilightInner = null;
|
||||
@@ -290,6 +291,7 @@ public class Filtering {
|
||||
shadowInner = s2;
|
||||
hilightInner = h2;
|
||||
}
|
||||
|
||||
BufferedImage shadowOuter = null;
|
||||
BufferedImage hilightOuter = null;
|
||||
if (type != INNER) {
|
||||
@@ -348,11 +350,8 @@ public class Filtering {
|
||||
retc.drawImage(shadowIm, 0, 0, null);
|
||||
retc.drawImage(hilightIm, 0, 0, null);
|
||||
|
||||
/*if(true)
|
||||
return retImg;
|
||||
*/
|
||||
retImg = blur(retImg, blurX, blurY, iterations, mask);
|
||||
int ret[] = getRGB(retImg, 0, 0, width, height);
|
||||
int ret[] = getRGB(retImg);
|
||||
blur(ret, width, height, blurX, blurY, iterations, mask);
|
||||
|
||||
for (int i = 0; i < srcPixels.length; i++) {
|
||||
int ah = (int) (new Color(ret[i]).getRed() * strength);
|
||||
@@ -360,7 +359,8 @@ public class Filtering {
|
||||
int ra = cut(ah - as, -255, 255);
|
||||
ret[i] = gradientPixels[255 + ra];
|
||||
}
|
||||
setRGB(retImg, 0, 0, width, height, ret);
|
||||
|
||||
setRGB(retImg, width, height, ret);
|
||||
|
||||
if (!knockout) {
|
||||
Graphics2D g = retImg.createGraphics();
|
||||
@@ -391,7 +391,7 @@ public class Filtering {
|
||||
private static BufferedImage dropShadow(BufferedImage src, int blurX, int blurY, float angle, double distance, Color color, boolean inner, int iterations, float strength, boolean knockout) {
|
||||
int width = src.getWidth();
|
||||
int height = src.getHeight();
|
||||
int[] srcPixels = getRGB(src, 0, 0, width, height);
|
||||
int[] srcPixels = getRGB(src);
|
||||
int shadow[] = new int[srcPixels.length];
|
||||
for (int i = 0; i < srcPixels.length; i++) {
|
||||
int alpha = (srcPixels[i] >> 24) & 0xff;
|
||||
@@ -400,6 +400,7 @@ public class Filtering {
|
||||
}
|
||||
shadow[i] = new Color(color.getRed(), color.getGreen(), color.getBlue(), cut(color.getAlpha() * alpha / 255 * strength)).getRGB();
|
||||
}
|
||||
|
||||
Color colorFirst = Color.BLACK;
|
||||
Color colorAlpha = new Color(0, 0, 0, 0);
|
||||
double angleRad = angle / 180 * Math.PI;
|
||||
@@ -407,12 +408,9 @@ public class Filtering {
|
||||
double moveY = (distance * Math.sin(angleRad));
|
||||
shadow = moveRGB(width, height, shadow, moveX, moveY, inner ? colorFirst : colorAlpha);
|
||||
|
||||
BufferedImage retCanvas = new BufferedImage(width, height, src.getType());
|
||||
setRGB(retCanvas, 0, 0, width, height, shadow);
|
||||
if (blurX > 0 || blurY > 0) {
|
||||
retCanvas = blur(retCanvas, blurX, blurY, iterations, null);
|
||||
blur(shadow, width, height, blurX, blurY, iterations, null);
|
||||
}
|
||||
shadow = getRGB(retCanvas, 0, 0, width, height);
|
||||
|
||||
for (int i = 0; i < shadow.length; i++) {
|
||||
int mask = (srcPixels[i] >> 24) & 0xff;
|
||||
@@ -421,7 +419,9 @@ public class Filtering {
|
||||
}
|
||||
shadow[i] = shadow[i] & 0xffffff + ((mask * ((shadow[i] >> 24) & 0xff) / 255) << 24);
|
||||
}
|
||||
setRGB(retCanvas, 0, 0, width, height, shadow);
|
||||
|
||||
BufferedImage retCanvas = new BufferedImage(width, height, src.getType());
|
||||
setRGB(retCanvas, width, height, shadow);
|
||||
|
||||
if (!knockout) {
|
||||
Graphics2D g = retCanvas.createGraphics();
|
||||
@@ -440,36 +440,32 @@ public class Filtering {
|
||||
|
||||
int width = src.getWidth();
|
||||
int height = src.getHeight();
|
||||
BufferedImage retCanvas = new BufferedImage(width, height, src.getType());
|
||||
Graphics2D retImg = retCanvas.createGraphics();
|
||||
|
||||
BufferedImage gradCanvas = new BufferedImage(256, 1, src.getType());
|
||||
|
||||
Graphics2D gg = gradCanvas.createGraphics();
|
||||
|
||||
Point p1 = new Point(0, 0);
|
||||
Point p2 = new Point(255, 0);
|
||||
gg.setPaint(new LinearGradientPaint(p1, p2, ratios, colors));
|
||||
gg.fill(new Rectangle(256, 1));
|
||||
int[] gradientPixels = getRGB(gradCanvas, 0, 0, gradCanvas.getWidth(), gradCanvas.getHeight());
|
||||
int[] gradientPixels = getRGB(gradCanvas);
|
||||
|
||||
double angleRad = angle / 180 * Math.PI;
|
||||
double moveX = (distance * Math.cos(angleRad));
|
||||
double moveY = (distance * Math.sin(angleRad));
|
||||
int srcPixels[] = getRGB(src, 0, 0, width, height);
|
||||
int srcPixels[] = getRGB(src);
|
||||
int revPixels[] = new int[srcPixels.length];
|
||||
for (int i = 0; i < srcPixels.length; i++) {
|
||||
revPixels[i] = (srcPixels[i] & 0xffffff) + ((255 - ((srcPixels[i] >> 24) & 0xff)) << 24);
|
||||
}
|
||||
|
||||
int shadow[] = new int[srcPixels.length];
|
||||
for (int i = 0; i < srcPixels.length; i++) {
|
||||
shadow[i] = 0 + ((cut(strength * ((srcPixels[i] >> 24) & 0xff))) << 24);
|
||||
}
|
||||
|
||||
Color colorAlpha = new Color(0, 0, 0, 0);
|
||||
shadow = moveRGB(width, height, shadow, moveX, moveY, colorAlpha);
|
||||
|
||||
setRGB(retCanvas, 0, 0, width, height, shadow);
|
||||
|
||||
int mask[] = null;
|
||||
if (type == INNER) {
|
||||
mask = srcPixels;
|
||||
@@ -478,8 +474,7 @@ public class Filtering {
|
||||
mask = revPixels;
|
||||
}
|
||||
|
||||
retCanvas = blur(retCanvas, blurX, blurY, iterations, mask);
|
||||
shadow = getRGB(retCanvas, 0, 0, width, height);
|
||||
blur(shadow, width, height, blurX, blurY, iterations, mask);
|
||||
|
||||
if (mask != null) {
|
||||
for (int i = 0; i < mask.length; i++) {
|
||||
@@ -495,10 +490,11 @@ public class Filtering {
|
||||
shadow[i] = gradientPixels[a];
|
||||
}
|
||||
|
||||
setRGB(retCanvas, 0, 0, width, height, shadow);
|
||||
BufferedImage retCanvas = new BufferedImage(width, height, src.getType());
|
||||
setRGB(retCanvas, width, height, shadow);
|
||||
|
||||
if (!knockout) {
|
||||
retImg = retCanvas.createGraphics();
|
||||
Graphics2D retImg = retCanvas.createGraphics();
|
||||
retImg.setComposite(AlphaComposite.DstOver);
|
||||
retImg.drawImage(src, 0, 0, null);
|
||||
}
|
||||
@@ -506,26 +502,27 @@ public class Filtering {
|
||||
return retCanvas;
|
||||
}
|
||||
|
||||
private static int[] getRGB(BufferedImage image, int x, int y, int width, int height) {
|
||||
private static int[] getRGB(BufferedImage image) {
|
||||
int type = image.getType();
|
||||
if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB) {
|
||||
return (int[]) image.getRaster().getDataElements(x, y, width, height, null);
|
||||
return ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
|
||||
}
|
||||
return image.getRGB(x, y, width, height, null, 0, width);
|
||||
int width = image.getWidth();
|
||||
return image.getRGB(0, 0, width, image.getHeight(), null, 0, width);
|
||||
}
|
||||
|
||||
private static void setRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) {
|
||||
private static void setRGB(BufferedImage image, int width, int height, int[] pixels) {
|
||||
int type = image.getType();
|
||||
if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB) {
|
||||
image.getRaster().setDataElements(x, y, width, height, pixels);
|
||||
image.getRaster().setDataElements(0, 0, width, height, pixels);
|
||||
} else {
|
||||
image.setRGB(x, y, width, height, pixels, 0, width);
|
||||
image.setRGB(0, 0, width, height, pixels, 0, width);
|
||||
}
|
||||
}
|
||||
|
||||
private static int[] moveRGB(int width, int height, int[] rgb, double deltaX, double deltaY, Color fill) {
|
||||
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
setRGB(img, 0, 0, width, height, rgb);
|
||||
setRGB(img, width, height, rgb);
|
||||
BufferedImage retImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = (Graphics2D) retImg.getGraphics();
|
||||
g.setPaint(fill);
|
||||
@@ -537,7 +534,7 @@ public class Filtering {
|
||||
g.setTransform(AffineTransform.getTranslateInstance(deltaX, deltaY));
|
||||
g.setComposite(AlphaComposite.Src);
|
||||
g.drawImage(img, 0, 0, null);
|
||||
return getRGB(retImg, 0, 0, width, height);
|
||||
return getRGB(retImg);
|
||||
}
|
||||
|
||||
public static SerializableImage convolution(SerializableImage src, float[] matrix, int w, int h) {
|
||||
@@ -566,26 +563,25 @@ public class Filtering {
|
||||
return i;
|
||||
}
|
||||
|
||||
public static Color colorEffect(Color color,
|
||||
public static int colorEffect(int rgb,
|
||||
int redAddTerm, int greenAddTerm, int blueAddTerm, int alphaAddTerm,
|
||||
int redMultTerm, int greenMultTerm, int blueMultTerm, int alphaMultTerm) {
|
||||
int rgb = color.getRGB();
|
||||
int a = (rgb >> 24) & 0xff;
|
||||
int r = (rgb >> 16) & 0xff;
|
||||
int g = (rgb >> 8) & 0xff;
|
||||
int b = (rgb) & 0xff;
|
||||
r = Math.max(0, Math.min(((r * redMultTerm) / 255) + redAddTerm, 255));
|
||||
g = Math.max(0, Math.min(((g * greenMultTerm) / 255) + greenAddTerm, 255));
|
||||
b = Math.max(0, Math.min(((b * blueMultTerm) / 255) + blueAddTerm, 255));
|
||||
a = Math.max(0, Math.min(((a * alphaMultTerm) / 255) + alphaAddTerm, 255));
|
||||
return new Color(r, g, b, a);
|
||||
r = cut(((r * redMultTerm) / 255) + redAddTerm);
|
||||
g = cut(((g * greenMultTerm) / 255) + greenAddTerm);
|
||||
b = cut(((b * blueMultTerm) / 255) + blueAddTerm);
|
||||
a = cut(((a * alphaMultTerm) / 255) + alphaAddTerm);
|
||||
return RGBA.toInt(r, g, b, a);
|
||||
}
|
||||
|
||||
public static SerializableImage colorEffect(SerializableImage src,
|
||||
int redAddTerm, int greenAddTerm, int blueAddTerm, int alphaAddTerm,
|
||||
int redMultTerm, int greenMultTerm, int blueMultTerm, int alphaMultTerm) {
|
||||
BufferedImage dst = new BufferedImage(src.getWidth(), src.getHeight(), src.getType());
|
||||
int rgb[] = getRGB(src.getBufferedImage(), 0, 0, src.getWidth(), src.getHeight());
|
||||
int rgb[] = getRGB(src.getBufferedImage()).clone();
|
||||
for (int i = 0; i < rgb.length; i++) {
|
||||
int a = (rgb[i] >> 24) & 0xff;
|
||||
int r = (rgb[i] >> 16) & 0xff;
|
||||
@@ -597,7 +593,7 @@ public class Filtering {
|
||||
a = Math.max(0, Math.min(((a * alphaMultTerm) / 256) + alphaAddTerm, 255));
|
||||
rgb[i] = (a << 24) | (r << 16) | (g << 8) | (b);
|
||||
}
|
||||
setRGB(dst, 0, 0, src.getWidth(), src.getHeight(), rgb);
|
||||
setRGB(dst, src.getWidth(), src.getHeight(), rgb);
|
||||
return new SerializableImage(dst);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,18 +112,10 @@ public class SerializableImage implements Serializable {
|
||||
return image.getRGB(i, i1);
|
||||
}
|
||||
|
||||
public int[] getRGB(int i, int i1, int i2, int i3, int[] ints, int i4, int i5) {
|
||||
return image.getRGB(i, i1, i2, i3, ints, i4, i5);
|
||||
}
|
||||
|
||||
public synchronized void setRGB(int i, int i1, int i2) {
|
||||
image.setRGB(i, i1, i2);
|
||||
}
|
||||
|
||||
public void setRGB(int i, int i1, int i2, int i3, int[] ints, int i4, int i5) {
|
||||
image.setRGB(i, i1, i2, i3, ints, i4, i5);
|
||||
}
|
||||
|
||||
public ColorModel getColorModel() {
|
||||
return image.getColorModel();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user