internal renderer transparency fix

This commit is contained in:
Jindra Petk
2014-03-01 07:59:16 +01:00
parent 69cf07b3b4
commit 2a7b93acff
6 changed files with 66 additions and 10 deletions

View File

@@ -2220,6 +2220,14 @@ public final class SWF implements TreeItem {
RECT rect = displayRect;
image = new SerializableImage((int) (rect.getWidth() / SWF.unitDivisor) + 1,
(int) (rect.getHeight() / SWF.unitDivisor) + 1, SerializableImage.TYPE_INT_ARGB);
//Make all pixels transparent
Graphics2D g = (Graphics2D)image.getGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setComposite(AlphaComposite.Src);
g.setColor(new Color(0,0,0,0f));
g.fillRect(0, 0, image.getWidth(), image.getHeight());
Matrix m = new Matrix();
m.translate(-rect.Xmin, -rect.Ymin);
frameToImage(containerId, fi.maxDepth, fi.layers, fi.backgroundColor, fi.characters, fi.frame, allTags, controlTags, displayRect, visited, image, m);
@@ -2357,6 +2365,14 @@ public final class SWF implements TreeItem {
for (FrameInfo fi : frameInfos) {
SerializableImage image = new SerializableImage((int) (rect.getWidth() / SWF.unitDivisor) + 1,
(int) (rect.getHeight() / SWF.unitDivisor) + 1, SerializableImage.TYPE_INT_ARGB);
//Make all pixels transparent
Graphics2D g = (Graphics2D)image.getGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setComposite(AlphaComposite.Src);
g.setColor(new Color(0,0,0,0f));
g.fillRect(0, 0, image.getWidth(), image.getHeight());
Matrix m = new Matrix();
m.translate(-rect.Xmin, -rect.Ymin);
frameToImage(containerId, fi.maxDepth, fi.layers, fi.backgroundColor, fi.characters, fi.frame, allTags, controlTags, displayRect, visited, image, m);
@@ -2410,6 +2426,14 @@ public final class SWF implements TreeItem {
m.translate(-rect.xMin, -rect.yMin);
drawMatrix.translate(rect.xMin, rect.yMin);
}
//Make all pixels transparent
Graphics2D gr = (Graphics2D)img.getGraphics();
gr.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
gr.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gr.setComposite(AlphaComposite.Src);
gr.setColor(new Color(0,0,0,0f));
gr.fillRect(0, 0, img.getWidth(), image.getHeight());
drawable.toImage(layer.ratio < 0 ? 0 : layer.ratio/*layer.duration*/, allTags, characters, visited, img, m);
} else {
// only DefineFont tags

View File

@@ -109,6 +109,11 @@ public class BitmapExporter extends ShapeExporterBase implements IShapeExporter
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setComposite(AlphaComposite.Src);
//Make all pixels transparent
graphics.setColor(new Color(0, 0, 0, 0f));
graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
defaultStroke = graphics.getStroke();
super.export();
}
@@ -116,10 +121,6 @@ public class BitmapExporter extends ShapeExporterBase implements IShapeExporter
private void exportTo(SerializableImage image, Matrix transformation) {
this.image = image;
graphics = (Graphics2D) image.getGraphics();
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setComposite(AlphaComposite.Src);
AffineTransform at = transformation.toTransform();
at.preConcatenate(AffineTransform.getScaleInstance(1 / SWF.unitDivisor, 1 / SWF.unitDivisor));
unitDivisor = 1;

View File

@@ -25,9 +25,14 @@ import com.jpexs.decompiler.flash.tags.base.CharacterTag;
import com.jpexs.decompiler.flash.tags.base.DrawableTag;
import com.jpexs.decompiler.flash.types.RECT;
import com.jpexs.helpers.SerializableImage;
import java.awt.AlphaComposite;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Composite;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
@@ -134,6 +139,14 @@ public final class ImagePanel extends JPanel implements ActionListener, FlashDis
RECT rect = bounded.getRect(characters, new Stack<Integer>());
SerializableImage image = new SerializableImage((int) (rect.getWidth() / SWF.unitDivisor) + 1,
(int) (rect.getHeight() / SWF.unitDivisor) + 1, SerializableImage.TYPE_INT_ARGB);
//Make all pixels transparent
Graphics2D g = (Graphics2D) image.getGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setComposite(AlphaComposite.Src);
g.setColor(new Color(0, 0, 0, 0f));
g.fillRect(0, 0, image.getWidth(), image.getHeight());
Matrix m = new Matrix();
m.translate(-rect.Xmin, -rect.Ymin);
drawable.toImage(0, swf.tags, characters, new Stack<Integer>(), image, m);
@@ -204,6 +217,14 @@ public final class ImagePanel extends JPanel implements ActionListener, FlashDis
RECT rect = bounded.getRect(characters, new Stack<Integer>());
SerializableImage image = new SerializableImage((int) (rect.getWidth() / SWF.unitDivisor) + 1,
(int) (rect.getHeight() / SWF.unitDivisor) + 1, SerializableImage.TYPE_INT_ARGB);
//Make all pixels transparent
Graphics2D g = (Graphics2D) image.getGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setComposite(AlphaComposite.Src);
g.setColor(new Color(0, 0, 0, 0f));
g.fillRect(0, 0, image.getWidth(), image.getHeight());
Matrix m = new Matrix();
m.translate(-rect.Xmin, -rect.Ymin);
drawable.toImage(nframe, swf.tags, characters, new Stack<Integer>(), image, m);

View File

@@ -198,10 +198,7 @@ public abstract class TextTag extends CharacterTag implements BoundedTag {
int textHeight = 12;
int x = 0;
int y = 0;
Graphics2D g = (Graphics2D) image.getGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Graphics2D g = (Graphics2D) image.getGraphics();
List<SHAPE> glyphs = new ArrayList<>();
for (TEXTRECORD rec : textRecords) {
if (rec.styleFlagsHasColor) {

View File

@@ -25,9 +25,11 @@ import com.jpexs.decompiler.flash.types.RECT;
import com.jpexs.decompiler.flash.types.SHAPE;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.SerializableImage;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.font.GlyphVector;
import java.awt.geom.PathIterator;
@@ -124,7 +126,13 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali
public static SerializableImage shapeListToImage(SWF swf, List<SHAPE> shapes, int prevWidth, int prevHeight, Color color) {
if (shapes.isEmpty()) {
return new SerializableImage(1, 1, BufferedImage.TYPE_INT_RGB);
SerializableImage image = new SerializableImage(1, 1, BufferedImage.TYPE_INT_RGB);
//Make all pixels transparent
Graphics2D g = (Graphics2D)image.getGraphics();
g.setComposite(AlphaComposite.Src);
g.setColor(new Color(0, 0, 0, 0f));
g.fillRect(0, 0, image.getWidth(), image.getHeight());
return image;
}
SerializableImage ret = new SerializableImage(prevWidth, prevHeight, SerializableImage.TYPE_INT_ARGB);
Graphics g = ret.getGraphics();

View File

@@ -41,6 +41,7 @@ public class SerializableImage implements Serializable {
static int imageid = 0;
private BufferedImage image;
private transient Graphics graphics;
public SerializableImage() {
}
@@ -77,7 +78,11 @@ public class SerializableImage implements Serializable {
}
public Graphics getGraphics() {
return image.getGraphics();
//One graphics rule them all
if (graphics != null) {
return graphics;
}
return graphics = image.getGraphics();
}
public int getType() {