Fixed: filters zooming

This commit is contained in:
Jindra Petřík
2021-03-14 23:56:04 +01:00
parent 4065bb363e
commit b4d97d60d7
30 changed files with 210 additions and 91 deletions

View File

@@ -2903,7 +2903,7 @@ public final class SWF implements SWFContainerItem, Timelined {
RenderContext renderContext = new RenderContext();
renderContext.cursorPosition = cursorPosition;
renderContext.mouseButton = mouseButton;
timeline.toImage(frame, time, renderContext, image, false, m, new Matrix(), m, colorTransform);
timeline.toImage(frame, time, renderContext, image, false, m, new Matrix(), m, colorTransform, zoom);
return image;
}

View File

@@ -62,7 +62,7 @@ import java.util.logging.Logger;
*/
public class ShapeExporter {
public List<File> exportShapes(AbortRetryIgnoreHandler handler, final String outdir, final SWF swf, ReadOnlyTagList tags, final ShapeExportSettings settings, EventListener evl) throws IOException, InterruptedException {
public List<File> exportShapes(AbortRetryIgnoreHandler handler, final String outdir, final SWF swf, ReadOnlyTagList tags, final ShapeExportSettings settings, EventListener evl, double unzoom) throws IOException, InterruptedException {
List<File> ret = new ArrayList<>();
if (tags.isEmpty()) {
return ret;
@@ -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, new CXFORMWITHALPHA());
st.toImage(0, 0, 0, new RenderContext(), img, false, m, m, m, new CXFORMWITHALPHA(), unzoom);
if (settings.mode == ShapeExportMode.PNG) {
ImageHelper.write(img.getBufferedImage(), ImageFormat.PNG, file);
} else {

View File

@@ -1159,7 +1159,7 @@ public class SvgImporter {
swf.assignExportNamesToSymbols();
st.shapeBounds.Xmax = (int) (si.getWidth() * SWF.unitDivisor);
st.shapeBounds.Ymax = (int) (si.getHeight() * SWF.unitDivisor);
new ShapeExporter().exportShapes(null, "./outex/", swf, new ReadOnlyTagList(li), new ShapeExportSettings(ShapeExportMode.SVG, 1), null);
new ShapeExporter().exportShapes(null, "./outex/", swf, new ReadOnlyTagList(li), new ShapeExportSettings(ShapeExportMode.SVG, 1), null, 1);
}
//Test for SVG

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, ColorTransform colorTransform) {
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, ColorTransform colorTransform, double unzoom) {
render(TextRenderMode.BITMAP, image, null, null, transformation, colorTransform, 1);
}

View File

@@ -368,8 +368,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, ColorTransform colorTransform) {
getTimeline().toImage(frame, time, renderContext, image, isClip, transformation, strokeTransformation, absoluteTransformation, colorTransform);
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, ColorTransform colorTransform, double unzoom) {
getTimeline().toImage(frame, time, renderContext, image, isClip, transformation, strokeTransformation, absoluteTransformation, colorTransform, unzoom);
}
@Override

View File

@@ -97,8 +97,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, ColorTransform colorTransform) {
getTimeline().toImage(frame, time, renderContext, image, isClip, transformation, strokeTransformation, absoluteTransformation, colorTransform);
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, ColorTransform colorTransform, double unzoom) {
getTimeline().toImage(frame, time, renderContext, image, isClip, transformation, strokeTransformation, absoluteTransformation, colorTransform, unzoom);
}
@Override

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.tags.base;
import com.jpexs.decompiler.flash.SWF;
@@ -44,7 +45,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, ColorTransform colorTransform, double unzoom);
public abstract void toSVG(SVGExporter exporter, int ratio, ColorTransform colorTransform, int level) throws IOException;

View File

@@ -417,7 +417,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, ColorTransform colorTransform) {
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, ColorTransform colorTransform, double unzoom) {
SHAPERECORD.shapeListToImage(swf, getGlyphShapeTable(), image, frame, Color.black, colorTransform);
}

View File

@@ -230,7 +230,7 @@ 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, ColorTransform colorTransform) {
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, ColorTransform colorTransform, double unzoom) {
BitmapExporter.export(swf, getShape(), null, image, transformation, strokeTransformation, colorTransform);
}

View File

@@ -313,7 +313,7 @@ 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, ColorTransform colorTransform) {
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, ColorTransform colorTransform, double unzoom) {
SHAPEWITHSTYLE shape = getShapeAtRatio(ratio);
// morphShape using shapeNum=3, morphShape2 using shapeNum=4
// todo: Currently the generated image is not cached, because the cache

View File

@@ -171,7 +171,7 @@ 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, ColorTransform colorTransform) {
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, ColorTransform colorTransform, double unzoom) {
BitmapExporter.export(swf, getShapes(), null, image, transformation, strokeTransformation, colorTransform);
if (Configuration._debugMode.get()) { // show control points
List<GeneralPath> paths = PathExporter.export(swf, getShapes());

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.tags.base;
import com.jpexs.decompiler.flash.AppResources;
@@ -651,7 +652,7 @@ public abstract class StaticTextTag extends TextTag {
}
@Override
@Override
public void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, ColorTransform colorTransform, double unzoom) {
staticTextToImage(swf, textRecords, getTextNum(), image, textMatrix, transformation, colorTransform);
/*try {
TextTag originalTag = (TextTag) getOriginalTag();

View File

@@ -659,23 +659,23 @@ public class Timeline {
deltaXMax = Math.max(x, deltaXMax);
deltaYMax = Math.max(y, deltaYMax);
}
rect.xMin -= deltaXMax * unzoom;
rect.xMax += deltaXMax * unzoom;
rect.yMin -= deltaYMax * unzoom;
rect.yMax += deltaYMax * unzoom;
rect.xMin -= deltaXMax * unzoom * SWF.unitDivisor;
rect.xMax += deltaXMax * unzoom * SWF.unitDivisor;
rect.yMin -= deltaYMax * unzoom * SWF.unitDivisor;
rect.yMax += deltaYMax * unzoom * SWF.unitDivisor;
}
rect.xMin -= unzoom;
rect.yMin -= unzoom;
rect.xMin -= SWF.unitDivisor;
rect.yMin -= SWF.unitDivisor;
rect.xMin = Math.max(0, rect.xMin);
rect.yMin = Math.max(0, rect.yMin);
drawMatrix.translate(rect.xMin, rect.yMin);
if (img == null) {
int newWidth = (int) (rect.getWidth() / unzoom);
int newHeight = (int) (rect.getHeight() / unzoom);
int deltaX = (int) (rect.xMin / unzoom);
int deltaY = (int) (rect.yMin / unzoom);
int newWidth = (int) (rect.getWidth() / SWF.unitDivisor);
int newHeight = (int) (rect.getHeight() / SWF.unitDivisor);
int deltaX = (int) (rect.xMin / SWF.unitDivisor);
int deltaY = (int) (rect.yMin / SWF.unitDivisor);
newWidth = Math.min(image.getWidth() - deltaX, newWidth) + 1;
newHeight = Math.min(image.getHeight() - deltaY, newHeight) + 1;
@@ -721,14 +721,14 @@ public class Timeline {
}
if (!(drawable instanceof ImageTag) || (swf.isAS3() && layer.hasImage)) {
drawable.toImage(dframe, time, ratio, renderContext, img, isClip || clipDepth > -1, m, strokeTransform, absMat, clrTrans2);
drawable.toImage(dframe, time, ratio, renderContext, img, isClip || clipDepth > -1, m, strokeTransform, absMat, clrTrans2, unzoom);
} else {
// todo: show one time warning
}
if (filters != null) {
for (FILTER filter : filters) {
img = filter.apply(img);
img = filter.apply(img, unzoom);
}
}
if (blendMode > 1) {
@@ -742,8 +742,8 @@ public class Timeline {
}
}
drawMatrix.translateX /= unzoom;
drawMatrix.translateY /= unzoom;
drawMatrix.translateX /= SWF.unitDivisor;
drawMatrix.translateY /= SWF.unitDivisor;
AffineTransform trans = drawMatrix.toTransform();
switch (blendMode) {
@@ -835,8 +835,9 @@ 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 = SWF.unitDivisor;
public void toImage(int frame, int time, RenderContext renderContext, SerializableImage image, boolean isClip, Matrix transformation, Matrix strokeTransformation, Matrix absoluteTransformation, ColorTransform colorTransform, double unzoom) {
//double unzoom = SWF.unitDivisor;
//unzoom = SWF.unitDivisor;
if (getFrameCount() <= frame) {
return;
}

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.filters;
import com.jpexs.decompiler.flash.types.BasicType;
@@ -101,14 +102,14 @@ public class BEVELFILTER extends FILTER {
}
@Override
@Override
public SerializableImage apply(SerializableImage src, double zoom) {
int type = Filtering.INNER;
if (onTop && !innerShadow) {
type = Filtering.FULL;
} else if (!innerShadow) {
type = Filtering.OUTER;
}
}
return Filtering.bevel(src, (int) Math.round(blurX * zoom), (int) Math.round(blurY * zoom), strength, type, highlightColor.toInt(), shadowColor.toInt(), (int) (angle * 180 / Math.PI), (float) (distance * zoom), knockout, passes);
}
@Override

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.filters;
import com.jpexs.decompiler.flash.types.BasicType;
@@ -54,8 +55,8 @@ public class BLURFILTER extends FILTER {
}
@Override
@Override
public SerializableImage apply(SerializableImage src) {
public SerializableImage apply(SerializableImage src, double zoom) {
return Filtering.blur(src, (int) Math.round(blurX * zoom), (int) Math.round(blurY * zoom), passes);
}
@Override

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.filters;
import com.jpexs.decompiler.flash.types.BasicType;
@@ -40,7 +41,7 @@ public class COLORMATRIXFILTER extends FILTER {
}
@Override
@Override
public SerializableImage apply(SerializableImage src, double zoom) {
float[][] matrix2 = new float[4][5];
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 5; x++) {

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.filters;
import com.jpexs.decompiler.flash.types.BasicType;
@@ -85,7 +86,7 @@ public class CONVOLUTIONFILTER extends FILTER {
}
@Override
@Override
public SerializableImage apply(SerializableImage src, double zoom) {
int height = matrix.length;
int width = matrix[0].length;
float[] matrix2 = new float[width * height];

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.filters;
import com.jpexs.decompiler.flash.types.BasicType;
@@ -91,8 +92,8 @@ public class DROPSHADOWFILTER extends FILTER {
}
@Override
@Override
public SerializableImage apply(SerializableImage src) {
public SerializableImage apply(SerializableImage src, double zoom) {
return Filtering.dropShadow(src, (int) Math.round(blurX * zoom), (int) Math.round(blurY * zoom), (int) (angle * 180 / Math.PI), distance * zoom, dropShadowColor.toColor(), innerShadow, passes, strength, knockout);
}
@Override

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.filters;
import com.jpexs.decompiler.flash.types.BasicType;
@@ -44,7 +45,7 @@ public abstract class FILTER implements Serializable {
this.id = id;
}
public abstract SerializableImage apply(SerializableImage src, double zoom);
public abstract double getDeltaX();

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.filters;
import com.jpexs.decompiler.flash.types.BasicType;
@@ -79,8 +80,8 @@ public class GLOWFILTER extends FILTER {
}
@Override
@Override
public SerializableImage apply(SerializableImage src) {
public SerializableImage apply(SerializableImage src, double zoom) {
return Filtering.glow(src, (int) Math.round(blurX * zoom), (int) Math.round(blurY * zoom), strength, glowColor.toColor(), innerGlow, knockout, passes);
}
@Override

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.filters;
import com.jpexs.decompiler.flash.types.BasicType;
@@ -103,7 +104,7 @@ public class GRADIENTBEVELFILTER extends FILTER {
}
@Override
@Override
public SerializableImage apply(SerializableImage src, double zoom) {
List<Color> colors = new ArrayList<>();
List<Float> ratios = new ArrayList<>();
for (int i = 0; i < gradientColors.length; i++) {
@@ -126,7 +127,7 @@ public class GRADIENTBEVELFILTER extends FILTER {
type = Filtering.OUTER;
}
return Filtering.gradientBevel(src, colorsArr, ratiosArr, (int) Math.round(blurX * zoom), (int) Math.round(blurY * zoom), strength, type, (int) (angle * 180 / Math.PI), (float) (distance * zoom), knockout, passes);
}
@Override

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.filters;
import com.jpexs.decompiler.flash.types.BasicType;
@@ -106,7 +107,7 @@ public class GRADIENTGLOWFILTER extends FILTER {
}
@Override
@Override
public SerializableImage apply(SerializableImage src, double zoom) {
List<Color> colors = new ArrayList<>();
List<Float> ratios = new ArrayList<>();
for (int i = 0; i < gradientColors.length; i++) {
@@ -127,7 +128,7 @@ public class GRADIENTGLOWFILTER extends FILTER {
for (int i = 0; i < ratios.size(); i++) {
ratiosAr[i] = ratios.get(i);
}
}
return Filtering.gradientGlow(src, (int) Math.round(blurX * zoom), (int) Math.round(blurY * zoom), (int) (angle * 180 / Math.PI), distance * zoom, colors.toArray(new Color[colors.size()]), ratiosAr, type, passes, strength, knockout);
}
@Override