mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-24 19:06:33 +00:00
Issue #259 Fixed images alpha channel (multiplying)
This commit is contained in:
@@ -523,7 +523,7 @@ public class Main {
|
||||
}
|
||||
|
||||
public static void initLang() {
|
||||
if (Configuration.containsConfig("locale")) {
|
||||
if (Configuration.containsConfig("locale")) {
|
||||
Locale.setDefault(Locale.forLanguageTag((String) Configuration.getConfig("locale", "en")));
|
||||
}
|
||||
UIManager.put("OptionPane.okButtonText", AppStrings.translate("button.ok"));
|
||||
|
||||
@@ -79,13 +79,16 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
public BufferedImage getImage(List<Tag> tags) {
|
||||
try {
|
||||
BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageData));
|
||||
BufferedImage img2 = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
if (bitmapAlphaData.length == 0) {
|
||||
return img;
|
||||
}
|
||||
BufferedImage img2 = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE);
|
||||
for (int y = 0; y < img.getHeight(); y++) {
|
||||
for (int x = 0; x < img.getWidth(); x++) {
|
||||
int val = img.getRGB(x, y);
|
||||
int a = bitmapAlphaData[x + y * img.getWidth()] & 0xff;
|
||||
val = (val & 0xffffff) | (a << 24);
|
||||
img2.setRGB(x, y, val);
|
||||
img2.setRGB(x, y, colorToInt(multiplyAlpha(intToColor(val))));
|
||||
}
|
||||
}
|
||||
return img2;
|
||||
|
||||
@@ -85,13 +85,16 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
|
||||
public BufferedImage getImage(List<Tag> tags) {
|
||||
try {
|
||||
BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageData));
|
||||
if (bitmapAlphaData.length == 0) {
|
||||
return img;
|
||||
}
|
||||
BufferedImage img2 = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
for (int y = 0; y < img.getHeight(); y++) {
|
||||
for (int x = 0; x < img.getWidth(); x++) {
|
||||
int val = img.getRGB(x, y);
|
||||
int a = bitmapAlphaData[x + y * img.getWidth()] & 0xff;
|
||||
val = (val & 0xffffff) | (a << 24);
|
||||
img2.setRGB(x, y, val);
|
||||
img2.setRGB(x, y, colorToInt(multiplyAlpha(intToColor(val))));
|
||||
}
|
||||
}
|
||||
return img2;
|
||||
@@ -125,8 +128,10 @@ public class DefineBitsJPEG4Tag extends ImageTag implements AloneTag {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param swf
|
||||
* @param data Data bytes
|
||||
* @param version SWF version
|
||||
* @param pos
|
||||
* @throws IOException
|
||||
*/
|
||||
public DefineBitsJPEG4Tag(SWF swf, byte data[], int version, long pos) throws IOException {
|
||||
|
||||
@@ -25,8 +25,10 @@ import com.jpexs.decompiler.flash.types.ALPHABITMAPDATA;
|
||||
import com.jpexs.decompiler.flash.types.ALPHACOLORMAPDATA;
|
||||
import com.jpexs.decompiler.flash.types.ARGB;
|
||||
import com.jpexs.decompiler.flash.types.RGBA;
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -69,6 +71,11 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
int r = (argb >> 16) & 0xff;
|
||||
int g = (argb >> 8) & 0xff;
|
||||
int b = (argb >> 0) & 0xff;
|
||||
|
||||
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;
|
||||
@@ -178,11 +185,10 @@ public class DefineBitsLossless2Tag extends ImageTag implements AloneTag {
|
||||
for (int y = 0; y < bitmapHeight; y++) {
|
||||
for (int x = 0; x < bitmapWidth; x++) {
|
||||
if ((bitmapFormat == DefineBitsLossless2Tag.FORMAT_8BIT_COLORMAPPED)) {
|
||||
RGBA color = colorMapData.colorTableRGB[colorMapData.colorMapPixelData[pos32aligned] & 0xff];
|
||||
g.setColor(new Color(color.red, color.green, color.blue, color.alpha));
|
||||
g.setColor(multiplyAlpha(colorMapData.colorTableRGB[colorMapData.colorMapPixelData[pos32aligned] & 0xff].toColor()));
|
||||
}
|
||||
if ((bitmapFormat == DefineBitsLossless2Tag.FORMAT_32BIT_ARGB)) {
|
||||
g.setColor(new Color(bitmapData.bitmapPixelData[pos].red, bitmapData.bitmapPixelData[pos].green, bitmapData.bitmapPixelData[pos].blue, bitmapData.bitmapPixelData[pos].alpha));
|
||||
g.setColor(multiplyAlpha(bitmapData.bitmapPixelData[pos].toColor()));
|
||||
}
|
||||
g.fillRect(x, y, 1, 1);
|
||||
pos32aligned++;
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.tags.base;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -59,4 +60,23 @@ public abstract class ImageTag extends CharacterTag {
|
||||
|
||||
return "unk";
|
||||
}
|
||||
|
||||
protected static int max255(float val){
|
||||
if(val>255){
|
||||
return 255;
|
||||
}
|
||||
return (int)val;
|
||||
}
|
||||
|
||||
protected static Color intToColor(int val){
|
||||
return new Color(val&0xff,(val>>8)&0xff,(val>>16)&0xff,(val>>24)&0xff);
|
||||
}
|
||||
protected static int colorToInt(Color c){
|
||||
return (c.getAlpha()<<24)|(c.getBlue()<<16)|(c.getGreen()<<8)|c.getRed();
|
||||
}
|
||||
|
||||
protected static Color multiplyAlpha(Color c){
|
||||
float multiplier = c.getAlpha()==0?0:255.0f/c.getAlpha();
|
||||
return new Color(max255(c.getRed()*multiplier), max255(c.getGreen()*multiplier), max255(c.getBlue()*multiplier), c.getAlpha());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.types;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
/**
|
||||
* Represents 32-bit alpha, red, green and blue value
|
||||
*
|
||||
@@ -44,4 +46,8 @@ public class ARGB {
|
||||
public String toString() {
|
||||
return "[ARGB a=" + alpha + ",r=" + red + ",g=" + green + ",b=" + blue + "]";
|
||||
}
|
||||
|
||||
public Color toColor() {
|
||||
return new Color(red, green, blue, alpha);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user