Added #1858 PDF export - JPEG with alpha channel exported as is

This commit is contained in:
Jindra Petřík
2022-12-22 22:09:21 +01:00
parent 23404f85b6
commit 355df5899d
5 changed files with 54 additions and 21 deletions

View File

@@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file.
- [#1912] Persist selected item in the tree upon quick search (Ctrl+F)
- [#1901] Editor mode and autosave feature for header, raw editor, transform
- [#583] FlashPaper SWF to PDF with selectable text (commandline)
- [#1858] PDF export - JPEG with alpha channel exported as is
### Fixed
- [#1904] NullPointerException when renaming invalid identifiers in AS1/2 files caused by missing charset

Binary file not shown.

View File

@@ -16,6 +16,7 @@
*/
package com.jpexs.decompiler.flash.exporters;
import com.jpexs.decompiler.flash.tags.base.HasSeparateAlphaChannel;
import com.jpexs.decompiler.flash.tags.base.ImageTag;
import com.jpexs.decompiler.flash.tags.enums.ImageFormat;
import com.jpexs.helpers.Helper;
@@ -35,7 +36,10 @@ import java.awt.image.RenderedImage;
import java.awt.image.SampleModel;
import java.awt.image.TileObserver;
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* BufferedImage that has link to ImageTag. This is mainly used for PDF export coupling.
@@ -56,8 +60,19 @@ public class ImageTagBufferedImage extends BufferedImage {
return tag.getCharacterId();
}
public boolean isJpeg () {
return tag.getImageFormat() == ImageFormat.JPEG;
public boolean isJpeg() {
return tag.getOriginalImageFormat()== ImageFormat.JPEG;
}
public byte[] getAlphaChannel() {
if (tag instanceof HasSeparateAlphaChannel) {
HasSeparateAlphaChannel hsac = (HasSeparateAlphaChannel)tag;
try {
return hsac.getImageAlpha();
} catch (IOException ex) {
return null;
}
}
return null;
}
public byte[] getImageData() {

File diff suppressed because one or more lines are too long

View File

@@ -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);
}
}
}