mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-05-24 18:14:36 +00:00
Added #1858 PDF export - JPEG with alpha channel exported as is
This commit is contained in:
@@ -15,10 +15,16 @@ import java.util.zip.DeflaterOutputStream;
|
||||
*/
|
||||
public class PDFMask extends PDFStream implements ImageObserver {
|
||||
|
||||
private final Image img;
|
||||
private byte[] alphaChannel;
|
||||
private Image img;
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
public PDFMask(byte alphaChannel[], int width, int height) {
|
||||
this.alphaChannel = alphaChannel;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
public PDFMask(Image img) {
|
||||
super("/XObject");
|
||||
this.img = img;
|
||||
@@ -51,23 +57,34 @@ public class PDFMask extends PDFStream implements ImageObserver {
|
||||
int h = height;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int[] pixels = new int[w * h];
|
||||
PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
|
||||
try {
|
||||
pg.grabPixels();
|
||||
} catch (InterruptedException e) {
|
||||
System.err.println("interrupted waiting for pixels!");
|
||||
return;
|
||||
}
|
||||
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
|
||||
System.err.println("image fetch aborted or errored");
|
||||
return;
|
||||
}
|
||||
for (int j = 0; j < h; j++) {
|
||||
for (int i = 0; i < w; i++) {
|
||||
int p = pixels[j * w + i];
|
||||
int alpha = 255 - (p >> 24) & 0xff;
|
||||
dos.write(alpha);
|
||||
if (img != null) {
|
||||
|
||||
int[] pixels = new int[w * h];
|
||||
PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
|
||||
try {
|
||||
pg.grabPixels();
|
||||
} catch (InterruptedException e) {
|
||||
System.err.println("interrupted waiting for pixels!");
|
||||
return;
|
||||
}
|
||||
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
|
||||
System.err.println("image fetch aborted or errored");
|
||||
return;
|
||||
}
|
||||
for (int j = 0; j < h; j++) {
|
||||
for (int i = 0; i < w; i++) {
|
||||
int p = pixels[j * w + i];
|
||||
int alpha = 255 - (p >> 24) & 0xff;
|
||||
dos.write(alpha);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int j = 0; j < h; j++) {
|
||||
for (int i = 0; i < w; i++) {
|
||||
int p = alphaChannel[j * w + i] & 0xff;
|
||||
int alpha = 255 - p;
|
||||
dos.write(alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user