Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

fix(engine): default transparent to true in queue_frame

Kushagra Kumar59b564326e60
diff --git a/crates/engine/src/commands/comp_more.rs b/crates/engine/src/commands/comp_more.rs
index 1014b1992..0a1f63cb4 100644
--- a/crates/engine/src/commands/comp_more.rs
+++ b/crates/engine/src/commands/comp_more.rs
@@ -91,14 +91,13 @@ fn queue_frame(s: &mut Session, p: &Value) -> Result<Value> {
it.settings = s.project.render_templates.default_render_settings(TemplateSlot::Still);
it.settings.time_span = TimeSpan::Custom { start: t, end: t + comp.frame_duration() };
it.output = s.project.render_templates.default_output_module(TemplateSlot::Still);
- if let Some(transparent) = b_p(p, "transparent") {
- if !transparent {
- it.output.channels = Channels::Rgb;
- } else if it.output.supports_alpha() {
- it.output.channels = Channels::Rgba;
- } else {
- return Err(bad("comp.saveFrameAs", format!("{} doesn't support an alpha channel", it.output.format.label())));
- }
+ let transparent = b_p(p, "transparent").unwrap_or(true);
+ if !transparent {
+ it.output.channels = Channels::Rgb;
+ } else if it.output.supports_alpha() {
+ it.output.channels = Channels::Rgba;
+ } else {
+ return Err(bad("comp.saveFrameAs", format!("{} doesn't support an alpha channel", it.output.format.label())));
}
if let Some(path) = str_p(p, "path") {
it.output.output = path.to_string();
diff --git a/crates/engine/src/tests_frame_export.rs b/crates/engine/src/tests_frame_export.rs
index c6b0847ec..d4273bc6c 100644
--- a/crates/engine/src/tests_frame_export.rs
+++ b/crates/engine/src/tests_frame_export.rs
@@ -219,3 +219,22 @@ fn save_frame_as_defaults_to_png_sequence_with_alpha() {
assert_eq!(it.output.name, "PNG Sequence with Alpha");
assert_eq!(it.output.channels, effectcraft_project::render_queue::Channels::Rgba);
}
+
+#[test]
+fn save_frame_as_defaults_to_transparent_even_with_rgb_frame_template() {
+ let mut s = Session::default();
+ s.execute("comp.new", json!({"name": "Comp", "width": 32, "height": 32, "frameRate": 24, "duration": 1})).unwrap();
+
+ // Set Frame Default to an RGB output template ("PNG Sequence")
+ s.execute_checked("renderQueue.setTemplateDefault", json!({"kind": "outputModule", "slot": "still", "name": "PNG Sequence"})).unwrap();
+
+ // Omitting `transparent` must default to true and promote to Channels::Rgba
+ s.execute_checked("comp.saveFrameAs", json!({"queue": true})).unwrap();
+ let it = s.project.render_queue.last().unwrap();
+ assert_eq!(it.output.channels, effectcraft_project::render_queue::Channels::Rgba);
+
+ // Explicit `transparent: false` respects the request and stays Channels::Rgb
+ s.execute_checked("comp.saveFrameAs", json!({"queue": true, "transparent": false})).unwrap();
+ let it = s.project.render_queue.last().unwrap();
+ assert_eq!(it.output.channels, effectcraft_project::render_queue::Channels::Rgb);
+}