Added #2011, #2215 Option to ignore frame background color when exporting (make transparent)

This commit is contained in:
Jindra Petřík
2024-07-27 17:35:32 +02:00
parent 1e4d2511a2
commit 0b48eab7f7
13 changed files with 88 additions and 24 deletions

View File

@@ -3605,7 +3605,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
renderContext.cursorPosition = cursorPosition;
renderContext.mouseButton = mouseButton;
ExportRectangle viewRect = new ExportRectangle(rect);
timeline.toImage(frame, time, renderContext, image, image, false, m, new Matrix(), m, colorTransform, zoom, false, viewRect, m, true, Timeline.DRAW_MODE_ALL, 0, canUseSmoothing);
timeline.toImage(frame, time, renderContext, image, image, false, m, new Matrix(), m, colorTransform, zoom, true, viewRect, m, true, Timeline.DRAW_MODE_ALL, 0, canUseSmoothing);
return image;
}

View File

@@ -1001,6 +1001,10 @@ public final class Configuration {
@ConfigurationCategory("display")
public static ConfigurationItem<Boolean> previewResampleSound = null;
@ConfigurationDefaultBoolean(false)
@ConfigurationCategory("export")
public static ConfigurationItem<Boolean> lastExportTransparentBackground = null;
private enum OSId {
WINDOWS, OSX, UNIX
}

View File

@@ -128,7 +128,7 @@ public class FrameExporter {
frames.add(0); // todo: export all frames
}
FrameExportSettings fes = new FrameExportSettings(fem, settings.zoom);
FrameExportSettings fes = new FrameExportSettings(fem, settings.zoom, true);
return exportFrames(handler, outdir, swf, containerId, frames, fes, evl);
}
@@ -163,7 +163,7 @@ public class FrameExporter {
throw new Error("Unsupported sprite export mode");
}
FrameExportSettings fes = new FrameExportSettings(fem, settings.zoom);
FrameExportSettings fes = new FrameExportSettings(fem, settings.zoom, true);
return exportFrames(handler, outdir, swf, containerId, frames, fes, evl);
}
@@ -224,7 +224,7 @@ public class FrameExporter {
}
int fframe = fframes.get(pos++);
BufferedImage result = SWF.frameToImageGet(tim, fframe, 0, null, 0, tim.displayRect, new Matrix(), null, usesTransparency ? null : backgroundColor, settings.zoom, true).getBufferedImage();
BufferedImage result = SWF.frameToImageGet(tim, fframe, 0, null, 0, tim.displayRect, new Matrix(), null, backgroundColor == null && !usesTransparency ? Color.white : backgroundColor, settings.zoom, true).getBufferedImage();
if (Thread.currentThread().isInterrupted()) {
return null;
}
@@ -286,7 +286,7 @@ public class FrameExporter {
Color backgroundColor = null;
SetBackgroundColorTag setBgColorTag = swf.getBackgroundColor();
if (setBgColorTag != null) {
if (!settings.transparentBackground && setBgColorTag != null) {
backgroundColor = setBgColorTag.backgroundColor.toColor();
}
@@ -298,7 +298,7 @@ public class FrameExporter {
}
final int fi = i;
final Color fbackgroundColor = null;
final Color fbackgroundColor = backgroundColor;
for (File foutdir : foutdirs) {
new RetryTask(() -> {
int frame = fframes.get(fi);
@@ -309,11 +309,8 @@ public class FrameExporter {
rect.yMax *= settings.zoom;
rect.xMin *= settings.zoom;
rect.yMin *= settings.zoom;
SVGExporter exporter = new SVGExporter(rect, settings.zoom, "frame");
if (fbackgroundColor != null) {
exporter.setBackGroundColor(fbackgroundColor);
}
SVGExporter exporter = new SVGExporter(rect, settings.zoom, "frame", fbackgroundColor);
tim.toSVG(frame, 0, null, 0, exporter, null, 0);
fos.write(Utf8Helper.getBytes(exporter.getSVG()));
}
@@ -379,7 +376,7 @@ public class FrameExporter {
}
sb.append("\r\n");
RGB backgroundColor1 = new RGB(255, 255, 255);
if (setBgColorTag != null) {
if (!settings.transparentBackground && setBgColorTag != null) {
backgroundColor1 = setBgColorTag.backgroundColor;
}

View File

@@ -89,7 +89,10 @@ public class SVGExporter {
public boolean useTextTag = Configuration.textExportExportFontFace.get();
public SVGExporter(ExportRectangle bounds, double zoom, String objectType) {
this(bounds, zoom, objectType, null);
}
public SVGExporter(ExportRectangle bounds, double zoom, String objectType, Color backgroundColor) {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
@@ -109,8 +112,22 @@ public class SVGExporter {
svgRoot.setAttribute("height", (bounds.getHeight() / SWF.unitDivisor) + "px");
}
createDefGroup(bounds, null, zoom);
if (backgroundColor != null) {
Element rect = _svg.createElement("rect");
rect.setAttribute("fill", new RGBA(backgroundColor).toHexRGB());
if (Configuration.svgRetainBounds.get()) {
rect.setAttribute("width", (bounds.xMax / SWF.unitDivisor) + "px");
rect.setAttribute("height", (bounds.yMax / SWF.unitDivisor) + "px");
} else {
rect.setAttribute("width", (bounds.getWidth() / SWF.unitDivisor) + "px");
rect.setAttribute("height", (bounds.getHeight() / SWF.unitDivisor) + "px");
}
_svgGs.peek().appendChild(rect);
}
}
svgRoot.setAttribute("ffdec:objectType", objectType);
} catch (ParserConfigurationException ex) {
Logger.getLogger(SVGExporter.class.getName()).log(Level.SEVERE, null, ex);
}
@@ -227,10 +244,10 @@ public class SVGExporter {
return writer.toString();
}
public void setBackGroundColor(Color backGroundColor) {
/*public void setBackGroundColor(Color backGroundColor) {
Attr attr = _svg.createAttribute("style");
attr.setValue("background: " + new RGBA(backGroundColor).toHexARGB());
}
}*/
private String addClip(String path) {
lastClipId++;

View File

@@ -29,9 +29,12 @@ public class FrameExportSettings {
public FrameExportMode mode;
public double zoom;
public boolean transparentBackground;
public FrameExportSettings(FrameExportMode mode, double zoom) {
public FrameExportSettings(FrameExportMode mode, double zoom, boolean transparentBackground) {
this.mode = mode;
this.zoom = zoom;
this.transparentBackground = transparentBackground;
}
}