#1199 Automatically import alpha channel do JPEG3 and JPEG4 tags from PNG.

This commit is contained in:
honfika@gmail.com
2016-03-12 21:41:58 +01:00
parent bc647dda7c
commit 12c8ee3da5
2 changed files with 21 additions and 1 deletions

View File

@@ -106,6 +106,24 @@ public class ImageImporter extends TagImporter {
public Tag importImageAlpha(ImageTag it, byte[] newData) throws IOException {
try {
BufferedImage img = ImageHelper.read(newData);
int width = img.getWidth();
int height = img.getHeight();
byte[] data = new byte[width * height];
int[] imgData = img.getRGB(0, 0, width, height, null, 0, width);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int alpha = (imgData[y * width + x] >> 24) & 0xff;
data[y * width + x] = (byte) alpha;
}
}
newData = data;
} catch (IOException ex) {
}
if (it instanceof DefineBitsJPEG3Tag) {
((DefineBitsJPEG3Tag) it).setImageAlpha(newData);
} else if (it instanceof DefineBitsJPEG4Tag) {