From 149dba53fa308278befca700953ed9a45a2aae7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Thu, 8 Dec 2022 23:04:52 +0100 Subject: [PATCH] Added Option to fix conflation artifacts in antialising (Default off - it is slow) --- CHANGELOG.md | 1 + .../flash/configuration/Configuration.java | 4 ++ .../flash/exporters/shape/BitmapExporter.java | 35 ++++++++-- .../exporters/shape/CanvasShapeExporter.java | 8 +++ .../shape/DefaultSVGShapeExporter.java | 22 +++++++ .../flash/exporters/shape/IShapeExporter.java | 4 +- .../flash/exporters/shape/PathExporter.java | 9 ++- .../exporters/shape/SVGShapeExporter.java | 13 +++- .../exporters/shape/ShapeExportData.java | 2 + .../exporters/shape/ShapeExporterBase.java | 64 ++++++++++++++++--- .../locales/AdvancedSettingsDialog.properties | 4 ++ .../AdvancedSettingsDialog_cs.properties | 5 +- 12 files changed, 151 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6588bfc72..f46cdd059 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file. - List of treenode subitems on otherwise empty panel (with 32x32 icons) - DefineVideoStream codecId and videoFlagsDeblocking handled as enums in raw editation - Option to mute frame sounds +- Option to fix conflation artifacts in antialising (Default off - it is slow) ### Fixed - [#1897] Close menu button without selecting specific item diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java index 87770cb7d..f2a4224fb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -827,6 +827,10 @@ public final class Configuration { @ConfigurationCategory("display") public static ConfigurationItem playFrameSounds = null; + @ConfigurationDefaultBoolean(false) + @ConfigurationCategory("display") + public static ConfigurationItem fixAntialiasConflation = null; + private enum OSId { WINDOWS, OSX, UNIX } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/BitmapExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/BitmapExporter.java index 4c4c13b1a..679677b95 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/BitmapExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/BitmapExporter.java @@ -45,6 +45,7 @@ import java.awt.Shape; import java.awt.Stroke; import java.awt.TexturePaint; import java.awt.geom.AffineTransform; +import java.awt.geom.Area; import java.awt.geom.GeneralPath; import java.awt.geom.NoninvertibleTransformException; import java.awt.image.BufferedImage; @@ -74,6 +75,8 @@ public class BitmapExporter extends ShapeExporterBase { private final SWF swf; private final GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD); //For correct intersections display; + + private Shape aliasedShape; private Paint fillPaint; @@ -104,6 +107,13 @@ public class BitmapExporter extends ShapeExporterBase { private static boolean linearGradientColorWarnignShown = false; private boolean scaleStrokes; + + private boolean aliasedFill = false; + + @Override + public void beginAliasedFills() { + aliasedFill = true; + } private class TransformedStroke implements Stroke { @@ -211,6 +221,7 @@ public class BitmapExporter extends ShapeExporterBase { @Override public void beginFills() { + aliasedFill = false; } @Override @@ -597,12 +608,21 @@ public class BitmapExporter extends ShapeExporterBase { } protected void finalizePath() { - if (fillPaint != null) { + if (fillPaint != null) { + Shape shp = path; + if (aliasedFill) { + aliasedShape = new BasicStroke((float)(SWF.unitDivisor / unzoom / 2), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND).createStrokedShape(shp); + return; + } else if (aliasedShape != null) { + Area a = new Area(shp); + a.add(new Area(aliasedShape)); + shp = a; + } graphics.setComposite(AlphaComposite.SrcOver); if (fillPaint instanceof MultipleGradientPaint) { AffineTransform oldAf = graphics.getTransform(); Shape prevClip = graphics.getClip(); - graphics.clip(path); + graphics.clip(shp); Matrix inverse = null; try { double scx = fillTransform.getScaleX(); @@ -627,7 +647,7 @@ public class BitmapExporter extends ShapeExporterBase { graphics.setPaint(fillPaint); if (inverse != null) { - ExportRectangle rect = inverse.transform(new ExportRectangle(path.getBounds2D())); + ExportRectangle rect = inverse.transform(new ExportRectangle(shp.getBounds2D())); double minX = rect.xMin; double minY = rect.yMin; graphics.fill(new java.awt.Rectangle((int) minX, (int) minY, (int) (rect.xMax - minX), (int) (rect.yMax - minY))); @@ -638,7 +658,7 @@ public class BitmapExporter extends ShapeExporterBase { } else if (fillPaint instanceof TexturePaint) { AffineTransform oldAf = graphics.getTransform(); Shape prevClip = graphics.getClip(); - graphics.clip(path); + graphics.clip(shp); Matrix inverse = null; if (fillRepeat) { try { @@ -671,7 +691,7 @@ public class BitmapExporter extends ShapeExporterBase { if (fillRepeat) { if (inverse != null) { - ExportRectangle rect = inverse.transform(new ExportRectangle(path.getBounds2D())); + ExportRectangle rect = inverse.transform(new ExportRectangle(shp.getBounds2D())); double minX = rect.xMin; double minY = rect.yMin; graphics.fill(new Rectangle((int) minX, (int) minY, (int) (rect.xMax - minX), (int) (rect.yMax - minY))); @@ -685,10 +705,13 @@ public class BitmapExporter extends ShapeExporterBase { graphics.setClip(prevClip); } else { graphics.setPaint(fillPaint); - graphics.fill(path); + graphics.fill(shp); } } if (linePaint != null && lineStroke != null) { + if(true) { + //return; + } Shape strokedShape = lineStroke.createStrokedShape(path); graphics.setComposite(AlphaComposite.SrcOver); if (linePaint instanceof MultipleGradientPaint) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/CanvasShapeExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/CanvasShapeExporter.java index 3481fdc6e..e733cfda7 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/CanvasShapeExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/CanvasShapeExporter.java @@ -81,6 +81,8 @@ public class CanvasShapeExporter extends ShapeExporterBase { protected int fillWidth = 0; protected int fillHeight = 0; + + protected boolean aliasedFill = false; public static String getJsPrefix() { return "