WIP - scaling matrix fix

This commit is contained in:
Jindra Petřík
2021-03-31 14:25:52 +02:00
parent fd8b624845
commit 82b5062771
17 changed files with 71 additions and 48 deletions

View File

@@ -558,7 +558,7 @@ public class FrameExporter {
renderContext.stateUnderCursor = new ArrayList<>();
try {
tim.toImage(fframe, fframe, renderContext, image, false, m, new Matrix(), m, null, zoom, true, new ExportRectangle(rect), m);
tim.toImage(fframe, fframe, renderContext, image, false, m, new Matrix(), m, null, zoom, true, new ExportRectangle(rect), m, true);
} catch (Exception ex) {
ex.printStackTrace();
}

View File

@@ -122,7 +122,7 @@ public class ShapeExporter {
}
Matrix m = Matrix.getScaleInstance(settings.zoom);
m.translate(-rect.Xmin, -rect.Ymin);
st.toImage(0, 0, 0, new RenderContext(), img, false, m, m, m, m, new CXFORMWITHALPHA(), unzoom, false, new ExportRectangle(rect));
st.toImage(0, 0, 0, new RenderContext(), img, false, m, m, m, m, new CXFORMWITHALPHA(), unzoom, false, new ExportRectangle(rect), true);
if (settings.mode == ShapeExportMode.PNG) {
ImageHelper.write(img.getBufferedImage(), ImageFormat.PNG, file);
} else {

View File

@@ -97,6 +97,8 @@ public class BitmapExporter extends ShapeExporterBase {
private static boolean linearGradientColorWarnignShown = false;
private boolean scaleStrokes;
private class TransformedStroke implements Stroke {
/**
@@ -148,9 +150,9 @@ public class BitmapExporter extends ShapeExporterBase {
}
}
public static void export(SWF swf, SHAPE shape, Color defaultColor, SerializableImage image, Matrix transformation, Matrix strokeTransformation, ColorTransform colorTransform) {
public static void export(SWF swf, SHAPE shape, Color defaultColor, SerializableImage image, Matrix transformation, Matrix strokeTransformation, ColorTransform colorTransform, boolean scaleStrokes) {
BitmapExporter exporter = new BitmapExporter(swf, shape, defaultColor, colorTransform);
exporter.exportTo(image, transformation, strokeTransformation);
exporter.exportTo(image, transformation, strokeTransformation, scaleStrokes);
}
private BitmapExporter(SWF swf, SHAPE shape, Color defaultColor, ColorTransform colorTransform) {
@@ -159,8 +161,9 @@ public class BitmapExporter extends ShapeExporterBase {
this.defaultColor = defaultColor;
}
private void exportTo(SerializableImage image, Matrix transformation, Matrix strokeTransformation) {
private void exportTo(SerializableImage image, Matrix transformation, Matrix strokeTransformation, boolean scaleStrokes) {
this.image = image;
this.scaleStrokes = scaleStrokes;
ExportRectangle bounds = new ExportRectangle(shape.getBounds());
ExportRectangle transformedBounds = strokeTransformation.transform(bounds);
@@ -392,18 +395,20 @@ public class BitmapExporter extends ShapeExporterBase {
joinStyle = BasicStroke.JOIN_ROUND;
break;
}
switch (scaleMode) {
case "VERTICAL":
thickness *= strokeTransformation.scaleY;
break;
case "HORIZONTAL":
thickness *= strokeTransformation.scaleX;
break;
case "NORMAL":
thickness *= Math.max(strokeTransformation.scaleX, strokeTransformation.scaleY);
break;
case "NONE":
break;
if (scaleStrokes) {
switch (scaleMode) {
case "VERTICAL":
thickness *= strokeTransformation.scaleY;
break;
case "HORIZONTAL":
thickness *= strokeTransformation.scaleX;
break;
case "NORMAL":
thickness *= Math.max(strokeTransformation.scaleX, strokeTransformation.scaleY);
break;
case "NONE":
break;
}
}
if (thickness < 0) {

View File

@@ -1148,7 +1148,7 @@ public class SvgImporter {
st = (DefineShape4Tag) (new SvgImporter().importSvg(st, svgDataS, false));
swf.addTag(st);
SerializableImage si = new SerializableImage(480, 360, BufferedImage.TYPE_4BYTE_ABGR);
BitmapExporter.export(swf, st.shapes, Color.yellow, si, new Matrix(), new Matrix(), null);
BitmapExporter.export(swf, st.shapes, Color.yellow, si, new Matrix(), new Matrix(), null, true);
List<Tag> li = new ArrayList<>();
li.add(st);
ImageIO.write(si.getBufferedImage(), "PNG", new File(name + ".imported.png"));

View File

@@ -961,7 +961,7 @@ public class DefineEditTextTag extends TextTag {
}
@Override
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect) {
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect, boolean scaleStrokes) {
render(TextRenderMode.BITMAP, image, null, null, transformation, colorTransform, 1);
}

View File

@@ -369,8 +369,8 @@ public class DefineSpriteTag extends DrawableTag implements Timelined {
}
@Override
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect) {
getTimeline().toImage(frame, time, renderContext, image, isClip, transformation, strokeTransformation, absoluteTransformation, colorTransform, unzoom, sameImage, viewRect, fullTransformation);
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect, boolean scaleStrokes) {
getTimeline().toImage(frame, time, renderContext, image, isClip, transformation, strokeTransformation, absoluteTransformation, colorTransform, unzoom, sameImage, viewRect, fullTransformation, scaleStrokes);
}
@Override

View File

@@ -98,8 +98,8 @@ public abstract class ButtonTag extends DrawableTag implements Timelined {
}
@Override
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect) {
getTimeline().toImage(frame, time, renderContext, image, isClip, transformation, strokeTransformation, absoluteTransformation, colorTransform, unzoom, sameImage, viewRect, fullTransformation);
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect, boolean scaleStrokes) {
getTimeline().toImage(frame, time, renderContext, image, isClip, transformation, strokeTransformation, absoluteTransformation, colorTransform, unzoom, sameImage, viewRect, fullTransformation, scaleStrokes);
}
@Override

View File

@@ -46,7 +46,7 @@ public abstract class DrawableTag extends CharacterTag implements BoundedTag {
public abstract Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked);
public abstract void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix prevTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect);
public abstract void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix prevTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect, boolean scaleStrokes);
public abstract void toSVG(SVGExporter exporter, int ratio, ColorTransform colorTransform, int level) throws IOException;

View File

@@ -433,7 +433,7 @@ public abstract class FontTag extends DrawableTag implements AloneTag {
}
@Override
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect) {
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect, boolean scaleStrokes) {
SHAPERECORD.shapeListToImage(swf, getGlyphShapeTable(), image, frame, Color.black, colorTransform);
}

View File

@@ -231,8 +231,8 @@ public abstract class ImageTag extends DrawableTag {
}
@Override
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect) {
BitmapExporter.export(swf, getShape(), null, image, transformation, strokeTransformation, colorTransform);
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect, boolean scaleStrokes) {
BitmapExporter.export(swf, getShape(), null, image, transformation, strokeTransformation, colorTransform, true);
}
@Override

View File

@@ -314,13 +314,13 @@ public abstract class MorphShapeTag extends DrawableTag {
}
@Override
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect) {
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect, boolean scaleStrokes) {
SHAPEWITHSTYLE shape = getShapeAtRatio(ratio);
// morphShape using shapeNum=3, morphShape2 using shapeNum=4
// todo: Currently the generated image is not cached, because the cache
// key contains the hashCode of the finalRecord object, and it is always
// recreated
BitmapExporter.export(swf, shape, null, image, transformation, strokeTransformation, colorTransform);
BitmapExporter.export(swf, shape, null, image, transformation, strokeTransformation, colorTransform, scaleStrokes);
}
@Override

View File

@@ -172,8 +172,8 @@ public abstract class ShapeTag extends DrawableTag implements LazyObject {
}
@Override
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect) {
BitmapExporter.export(swf, getShapes(), null, image, transformation, strokeTransformation, colorTransform);
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect, boolean scaleStrokes) {
BitmapExporter.export(swf, getShapes(), null, image, transformation, strokeTransformation, colorTransform, scaleStrokes);
if (Configuration._debugMode.get()) { // show control points
List<GeneralPath> paths = PathExporter.export(swf, getShapes());
double[] coords = new double[6];

View File

@@ -652,7 +652,7 @@ public abstract class StaticTextTag extends TextTag {
}
@Override
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect) {
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect, boolean scaleStrokes) {
staticTextToImage(swf, textRecords, getTextNum(), image, textMatrix, transformation, colorTransform);
/*try {
TextTag originalTag = (TextTag) getOriginalTag();

View File

@@ -422,7 +422,7 @@ public abstract class TextTag extends DrawableTag {
Graphics2D g = (Graphics2D) image.getGraphics();
Matrix mat = transformation.clone();
mat = mat.concatenate(new Matrix(textMatrix));
BitmapExporter.export(swf, getBorderShape(borderColor, fillColor, rect), null, image, mat, mat, colorTransform);
BitmapExporter.export(swf, getBorderShape(borderColor, fillColor, rect), null, image, mat, mat, colorTransform, true);
}
public static void drawBorderHtmlCanvas(SWF swf, StringBuilder result, RGB borderColor, RGB fillColor, RECT rect, MATRIX textMatrix, ColorTransform colorTransform, double unitDivisor) {
@@ -512,7 +512,7 @@ public abstract class TextTag extends DrawableTag {
}
if (shape != null) {
BitmapExporter.export(swf, shape, textColor2, image, mat, mat, colorTransform);
BitmapExporter.export(swf, shape, textColor2, image, mat, mat, colorTransform, true);
if (SHAPERECORD.DRAW_BOUNDING_BOX) {
RGB borderColor = new RGBA(Color.black);
RGB fillColor = new RGBA(new Color(255, 255, 255, 0));

View File

@@ -72,6 +72,7 @@ import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -79,6 +80,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import org.w3c.dom.Element;
/**
@@ -617,7 +621,7 @@ public class Timeline {
toImage(frame, time, renderContext, image, isClip, transforms[i], absoluteTransformation, colorTransform, targetRect[i]);
}
}*/
private void drawDrawable(Matrix strokeTransform, DepthState layer, Matrix layerMatrix, Graphics2D g, ColorTransform colorTransForm, int blendMode, List<Clip> clips, Matrix transformation, boolean isClip, int clipDepth, Matrix absMat, int time, int ratio, RenderContext renderContext, SerializableImage image, DrawableTag drawable, List<FILTER> filters, double unzoom, ColorTransform clrTrans, boolean sameImage, ExportRectangle viewRect, Matrix fullTransformation) {
private void drawDrawable(Matrix strokeTransform, DepthState layer, Matrix layerMatrix, Graphics2D g, ColorTransform colorTransForm, int blendMode, List<Clip> clips, Matrix transformation, boolean isClip, int clipDepth, Matrix absMat, int time, int ratio, RenderContext renderContext, SerializableImage image, DrawableTag drawable, List<FILTER> filters, double unzoom, ColorTransform clrTrans, boolean sameImage, ExportRectangle viewRect, Matrix fullTransformation, boolean scaleStrokes) {
Matrix drawMatrix = new Matrix();
int drawableFrameCount = drawable.getNumFrames();
if (drawableFrameCount == 0) {
@@ -792,7 +796,7 @@ public class Timeline {
}
if (!(drawable instanceof ImageTag) || (swf.isAS3() && layer.hasImage)) {
drawable.toImage(dframe, time, ratio, renderContext, img, isClip || clipDepth > -1, m, strokeTransform, absMat, mfull, clrTrans2, unzoom, sameImage, viewRect);
drawable.toImage(dframe, time, ratio, renderContext, img, isClip || clipDepth > -1, m, strokeTransform, absMat, mfull, clrTrans2, unzoom, sameImage, viewRect, scaleStrokes);
} else {
// todo: show one time warning
}
@@ -913,6 +917,11 @@ public class Timeline {
if (!(sameImage && canUseSameImage)) {
g.setTransform(drawMatrix.toTransform());
g.drawImage(img.getBufferedImage(), 0, 0, null);
/*try {
ImageIO.write(img.getBufferedImage(), "PNG", new File("out.png"));
} catch (IOException ex) {
Logger.getLogger(Timeline.class.getName()).log(Level.SEVERE, null, ex);
}*/
}
if (g instanceof BlendModeSetable) {
((BlendModeSetable) g).setBlendMode(0);
@@ -920,7 +929,7 @@ public class Timeline {
}
}
public void toImage(int frame, int time, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect, Matrix fullTransformation) {
public void toImage(int frame, int time, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect, Matrix fullTransformation, boolean scaleStrokes) {
//double unzoom = SWF.unitDivisor;
//unzoom = SWF.unitDivisor;
if (getFrameCount() <= frame) {
@@ -1035,22 +1044,26 @@ public class Timeline {
g.setTransform(new AffineTransform());
ExportRectangle p1 = transformation.transform(targetRect[s]);
if (sx == 0) {
p1.xMin = 0;
p1.xMin = viewRect.xMin;
}
if (sy == 0) {
p1.yMin = 0;
p1.yMin = viewRect.yMin;
}
if (sx == 2) {
p1.xMax = unzoom * swf.getRect().getWidth() / SWF.unitDivisor;
p1.xMax = unzoom * viewRect.getWidth() / SWF.unitDivisor;
}
if (sy == 2) {
p1.yMax = unzoom * swf.getRect().getHeight() / SWF.unitDivisor;
p1.yMax = unzoom * viewRect.getHeight() / SWF.unitDivisor;
}
Rectangle2D r = new Rectangle2D.Double(p1.xMin, p1.yMin, p1.getWidth(), p1.getHeight());
g.setClip(r);
drawDrawable(strokeTransformation.preConcatenate(layerMatrix), layer, transforms[s], g, colorTransform, layer.blendMode, clips, transformation, isClip, layer.clipDepth, absMat, time, layer.ratio, renderContext, image, (DrawableTag) character, layer.filters, unzoom, clrTrans, sameImage, viewRect, fullTransformation);
if (sx == 1 && sy == 1) {
//System.err.println("xxx");
}
//Matrix.getScaleInstance(SWF.unitDivisor).concatenate(strokeTransformation).concatenate(transforms[s].inverse())
drawDrawable(strokeTransformation.concatenate(layerMatrix).concatenate(transforms[s].inverse()), layer, transforms[s], g, colorTransform, layer.blendMode, clips, transformation, isClip, layer.clipDepth, absMat, time, layer.ratio, renderContext, image, (DrawableTag) character, layer.filters, unzoom, clrTrans, sameImage, viewRect, fullTransformation, false);
s++;
}
}
@@ -1058,7 +1071,11 @@ public class Timeline {
g.setTransform(origTransform);
} else {
drawDrawable(strokeTransformation, layer, layerMatrix, g, colorTransform, layer.blendMode, clips, transformation, isClip, layer.clipDepth, absMat, time, layer.ratio, renderContext, image, (DrawableTag) character, layer.filters, unzoom, clrTrans, sameImage, viewRect, fullTransformation);
boolean subScaleStrokes = scaleStrokes;
if (character instanceof DefineSpriteTag) {
subScaleStrokes = true;
}
drawDrawable(strokeTransformation, layer, layerMatrix, g, colorTransform, layer.blendMode, clips, transformation, isClip, layer.clipDepth, absMat, time, layer.ratio, renderContext, image, (DrawableTag) character, layer.filters, unzoom, clrTrans, sameImage, viewRect, fullTransformation, subScaleStrokes);
}
} else if (character instanceof BoundedTag) {
showPlaceholder = true;

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.types.shaperecords;
import com.jpexs.decompiler.flash.SWF;
@@ -218,7 +219,7 @@ public abstract class SHAPERECORD implements Cloneable, NeedsCharacters, Seriali
Matrix transformation = Matrix.getTranslateInstance(px, py);
transformation.scale(ratio);
transformation.scale(ratio);
BitmapExporter.export(swf, shape, color, image, transformation, transformation, colorTransform, true);
// draw bounding boxes
if (DRAW_BOUNDING_BOX) {