Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

feat(project): a background colour for the frame, picked on the New Project screen and in Project settings (#456)

Jareer643bbe1fabc3
diff --git a/src/crates/concat-api/src/lib.rs b/src/crates/concat-api/src/lib.rs
index c34673f0..b170d35b 100644
--- a/src/crates/concat-api/src/lib.rs
+++ b/src/crates/concat-api/src/lib.rs
@@ -527,6 +527,7 @@ impl Api {
video.height,
video.rate_num,
video.rate_den,
+ [0, 0, 0],
)
.map_err(ApiError::failed)?;
self.adopt(info)
@@ -861,6 +862,7 @@ impl Api {
moving: false,
proxy: false,
color_space: session.video().color_space,
+ canvas: session.video().canvas,
},
)
.map_err(ApiError::failed)?;
@@ -1320,6 +1322,7 @@ mod tests {
location: location.clone(),
name: "Round trip".to_owned(),
video: Some(VideoSettings {
+ canvas: [0, 0, 0],
width: 1080,
height: 1920,
rate_num: 60,
diff --git a/src/crates/concat-core/src/timeline.rs b/src/crates/concat-core/src/timeline.rs
index a761b943..7f737766 100644
--- a/src/crates/concat-core/src/timeline.rs
+++ b/src/crates/concat-core/src/timeline.rs
@@ -380,6 +380,10 @@ pub struct Timeline {
pub width: u32,
/// Output height in pixels.
pub height: u32,
+ /// What shows where no picture covers the frame, as eight-bit
+ /// `[r, g, b]`: the project's canvas colour, black unless it was given
+ /// another. A transition to black still goes to black.
+ pub canvas: [u8; 3],
tracks: Arena<Track>,
clips: Arena<Clip>,
order: Vec<TrackId>,
@@ -392,6 +396,7 @@ impl Timeline {
frame_rate,
width,
height,
+ canvas: [0, 0, 0],
tracks: Arena::new(),
clips: Arena::new(),
order: Vec::new(),
diff --git a/src/crates/concat-export/src/lib.rs b/src/crates/concat-export/src/lib.rs
index 18be3a86..8455e6fe 100644
--- a/src/crates/concat-export/src/lib.rs
+++ b/src/crates/concat-export/src/lib.rs
@@ -468,6 +468,10 @@ pub struct ExportRequest {
/// clocks and keyframe fractions keep their local timing.
#[serde(default)]
pub effect_time_offset: f64,
+ /// What shows where no picture covers the frame, `[r, g, b]`; black
+ /// when a request does not say. See `VideoSettings::canvas`.
+ #[serde(default)]
+ pub canvas: [u8; 3],
/// The flattened clip list to render.
pub clips: Vec<ExportClip>,
}
@@ -1920,6 +1924,7 @@ fn render_picture(
time,
width: request.width,
height: request.height,
+ canvas: plan.canvas,
layers: with_backdrops(
layers,
&backdrops,
@@ -2164,6 +2169,7 @@ fn transition_stages(plan: &FramePlan, span: &TransitionSpan) -> (FramePlan, Fra
time: plan.time,
width: plan.width,
height: plan.height,
+ canvas: plan.canvas,
layers,
treatments: Vec::new(),
output: plan.output,
@@ -2207,6 +2213,7 @@ fn combine_transition(
time,
width,
height,
+ canvas: plan.canvas,
layers,
treatments,
output,
@@ -2260,6 +2267,10 @@ pub struct PreviewFrameRequest {
/// What the timeline is output in; SDR when a request does not say.
#[serde(default)]
pub color_space: ColorSpace,
+ /// What shows where no picture covers the frame; black when a request
+ /// does not say.
+ #[serde(default)]
+ pub canvas: [u8; 3],
}
/// The signal a timeline of `space` is drawn for (`FramePlan::output`).
@@ -2489,6 +2500,7 @@ pub fn preview_sources_of(
time,
width: plan.width,
height: plan.height,
+ canvas: plan_at.canvas,
layers: with_backdrops(
layers,
backdrops,
@@ -2544,6 +2556,7 @@ pub fn preview_plan(
rate_num: i64,
rate_den: i64,
color_space: ColorSpace,
+ canvas: [u8; 3],
) -> PreviewPlan {
// A preview has no error to give, and a picture at the wrong pace beats
// none; the document opens with a sane rate (VideoSettings::or) anyway.
@@ -2573,6 +2586,7 @@ pub fn preview_plan(
color_space,
hdr: false,
effect_time_offset: 0.0,
+ canvas,
clips: Vec::new(),
};
PreviewPlan {
@@ -2593,6 +2607,7 @@ fn preview_timeline(request: &PreviewFrameRequest) -> PreviewPlan {
request.rate_num,
request.rate_den,
request.color_space,
+ request.canvas,
)
}
@@ -2705,6 +2720,7 @@ mod tests {
time,
width: 8,
height: 8,
+ canvas: [0, 0, 0],
layers: vec![ground, top],
treatments: Vec::new(),
output: concat_core::frame::Signal::Sdr,
@@ -2793,6 +2809,7 @@ mod tests {
time,
width: 16,
height: 8,
+ canvas: [0, 0, 0],
layers: vec![ground_layer(solid([255, 0, 0, 255])), incoming],
treatments: Vec::new(),
output: concat_core::frame::Signal::Sdr,
@@ -2917,6 +2934,7 @@ mod tests {
one.media_height = Some(height);
}
let request = PreviewFrameRequest {
+ canvas: [0, 0, 0],
time,
width,
height,
@@ -3032,6 +3050,7 @@ mod tests {
let pool = concat_media::ReaderPool::new(16 * 1024 * 1024, 2);
let pixel = |clips: &[ExportClip], time: f64, x: u32, y: u32| -> [u8; 3] {
let request = PreviewFrameRequest {
+ canvas: [0, 0, 0],
time,
width,
height,
@@ -3129,6 +3148,7 @@ mod tests {
request_clip.crop = Some([0.0, 0.5, 0.0, 0.0]);
request_clip.flip_h = true;
let request = PreviewFrameRequest {
+ canvas: [0, 0, 0],
time: 0.5,
width,
height,
@@ -3194,6 +3214,7 @@ mod tests {
request_clip.media_width = Some(64);
request_clip.media_height = Some(64);
let request = PreviewFrameRequest {
+ canvas: [0, 0, 0],
time: 0.5,
width: 64,
height: 64,
@@ -3219,6 +3240,7 @@ mod tests {
let mut outliving = clip("video", 0, 0.0, 3.0, 0.0);
outliving.path = path.to_string_lossy().into_owned();
let late = PreviewFrameRequest {
+ canvas: [0, 0, 0],
time: 2.5,
width: 64,
height: 64,
@@ -3243,6 +3265,7 @@ mod tests {
effected.media_height = Some(64);
effected.effects = vec![AppliedFilter::new("concat.mono")];
let filtered = PreviewFrameRequest {
+ canvas: [0, 0, 0],
time: 0.5,
width: 64,
height: 64,
@@ -3364,6 +3387,7 @@ mod tests {
let pool = concat_media::ReaderPool::new(16 * 1024 * 1024, 2);
let request = |clips: Vec<ExportClip>| PreviewFrameRequest {
+ canvas: [0, 0, 0],
time: 1.0,
width,
height,
@@ -3453,6 +3477,7 @@ mod tests {
still.media_width = Some(32);
still.media_height = Some(64);
let request = PreviewFrameRequest {
+ canvas: [0, 0, 0],
time: 0.5,
width: 64,
height: 64,
@@ -3519,6 +3544,7 @@ mod tests {
footage.media_height = Some(64);
let nested = root.join("Movies").join("Concat");
let request = ExportRequest {
+ canvas: [0, 0, 0],
output: nested.join("out.mp4").to_string_lossy().into_owned(),
width: 64,
height: 64,
@@ -3600,6 +3626,7 @@ mod tests {
footage.media_height = Some(64);
let output = dir.join("out.mp4");
let request = ExportRequest {
+ canvas: [0, 0, 0],
output: output.to_string_lossy().into_owned(),
width: 64,
height: 64,
diff --git a/src/crates/concat-export/src/resolve.rs b/src/crates/concat-export/src/resolve.rs
index 29e9c77b..6d723240 100644
--- a/src/crates/concat-export/src/resolve.rs
+++ b/src/crates/concat-export/src/resolve.rs
@@ -265,6 +265,7 @@ pub(crate) fn build_timeline(
transitions: Vec<TransitionSpan>,
) -> BuiltTimeline {
let mut timeline = Timeline::new(request.width, request.height, rate);
+ timeline.canvas = request.canvas;
let mut stills = std::collections::HashSet::new();
let mut decode_sizes: HashMap<ClipId, (u32, u32)> = HashMap::new();
let mut tracks_of: HashMap<ClipId, usize> = HashMap::new();
diff --git a/src/crates/concat-host/src/consolidate.rs b/src/crates/concat-host/src/consolidate.rs
index 5f978dc1..891d4728 100644
--- a/src/crates/concat-host/src/consolidate.rs
+++ b/src/crates/concat-host/src/consolidate.rs
@@ -113,6 +113,7 @@ impl Consolidation {
let hdr = self.video.color_space.is_hdr();
ExportRequest {
output: output.to_string_lossy().into_owned(),
+ canvas: self.video.canvas,
width: self.video.width,
height: self.video.height,
rate_num: self.video.rate_num,
diff --git a/src/crates/concat-host/src/export.rs b/src/crates/concat-host/src/export.rs
index 67aae9d9..90a6c2bd 100644
--- a/src/crates/concat-host/src/export.rs
+++ b/src/crates/concat-host/src/export.rs
@@ -83,6 +83,7 @@ pub fn request(session: &Session, spec: &ExportSpec, titles: Vec<ExportClip>) ->
color_space: session.video().color_space,
hdr: spec.hdr,
effect_time_offset: 0.0,
+ canvas: session.video().canvas,
clips,
}
}
diff --git a/src/crates/concat-host/src/media.rs b/src/crates/concat-host/src/media.rs
index 28129edc..9a18ed18 100644
--- a/src/crates/concat-host/src/media.rs
+++ b/src/crates/concat-host/src/media.rs
@@ -1342,6 +1342,7 @@ mod tests {
})
.expect("places");
let settings = DocumentSettings {
+ canvas: [0, 0, 0],
name: name.to_owned(),
width: 64,
height: 32,
diff --git a/src/crates/concat-host/src/preview.rs b/src/crates/concat-host/src/preview.rs
index 49e441c4..f60ff645 100644
--- a/src/crates/concat-host/src/preview.rs
+++ b/src/crates/concat-host/src/preview.rs
@@ -50,6 +50,9 @@ pub struct FrameSpec {
/// What the timeline is output in: an HDR one keeps its clips' light
/// above white and is rolled off for the SDR screen.
pub color_space: ColorSpace,
+ /// What shows where no picture covers the frame; see
+ /// `VideoSettings::canvas`.
+ pub canvas: [u8; 3],
}
/// The reader pool behind the monitor, shareable across threads.
@@ -74,6 +77,7 @@ struct PlanEntry {
height: u32,
rate: (i64, i64),
color_space: ColorSpace,
+ canvas: [u8; 3],
plan: Arc<concat_export::PreviewPlan>,
}
@@ -228,6 +232,7 @@ impl Monitor {
// layer of its own.
let frame = sources.composite(&mut *gpu);
let mut plan = concat_render::FramePlan::empty(spec.width, spec.height);
+ plan.canvas = spec.canvas;
plan.layers.push(concat_render::PlannedLayer::picture(
concat_render::detached_clip(),
Arc::new(frame),
@@ -260,6 +265,7 @@ impl Monitor {
&& entry.height == spec.height
&& entry.rate == rate
&& entry.color_space == spec.color_space
+ && entry.canvas == spec.canvas
&& (Arc::ptr_eq(&entry.clips, &clips) || *entry.clips == *clips)
{
return Arc::clone(&entry.plan);
@@ -271,6 +277,7 @@ impl Monitor {
rate.0,
rate.1,
spec.color_space,
+ spec.canvas,
));
*slot = Some(PlanEntry {
clips,
@@ -278,6 +285,7 @@ impl Monitor {
height: spec.height,
rate,
color_space: spec.color_space,
+ canvas: spec.canvas,
plan: Arc::clone(&plan),
});
plan
diff --git a/src/crates/concat-host/src/projects.rs b/src/crates/concat-host/src/projects.rs
index 98984eed..0e050f70 100644
--- a/src/crates/concat-host/src/projects.rs
+++ b/src/crates/concat-host/src/projects.rs
@@ -69,6 +69,11 @@ pub struct ProjectInfo {
pub rate_num: i64,
/// Denominator of the frame rate.
pub rate_den: i64,
+ /// What shows where no picture covers the frame, for a project's first
+ /// timeline; see `VideoSettings::canvas`. Black for a recents entry
+ /// written before there was one.
+ #[serde(default)]
+ pub canvas: [u8; 3],
/// Milliseconds since the epoch.
pub opened_at: u64,
}
@@ -96,6 +101,17 @@ struct Video {
height: u32,
rate_num: i64,
rate_den: i64,
+ /// `#rrggbb`, left out while black; see `VideoSettings::canvas`.
+ #[serde(
+ default,
+ skip_serializing_if = "is_black",
+ with = "concat_project::model::hex_rgb"
+ )]
+ canvas: [u8; 3],
+}
+
+fn is_black(rgb: &[u8; 3]) -> bool {
+ *rgb == [0, 0, 0]
}
fn now_millis() -> u64 {
@@ -116,6 +132,7 @@ pub fn create(
height: u32,
rate_num: i64,
rate_den: i64,
+ canvas: [u8; 3],
) -> Result<ProjectInfo, String> {
let root = Path::new(location).join(folder_name(name));
let manifest = root.join(MANIFEST);
@@ -143,6 +160,7 @@ pub fn create(
height,
rate_num,
rate_den,
+ canvas,
},
rest: serde_json::Map::new(),
};
@@ -159,6 +177,7 @@ pub fn create(
height,
rate_num,
rate_den,
+ canvas,
opened_at: now_millis(),
})
}
@@ -459,6 +478,7 @@ pub fn open(path: &str) -> Result<ProjectInfo, String> {
name: document.name,
width: document.video.width,
height: document.video.height,
+ canvas: document.video.canvas,
rate_num: document.video.rate_num,
rate_den: document.video.rate_den,
opened_at: now_millis(),
@@ -666,7 +686,7 @@ mod tests {
#[test]
fn a_project_named_nul_is_created_and_reads_back() {
let location = scratch("device-name");
- let info = create(&location, "nul", 1920, 1080, 30, 1).expect("creates");
+ let info = create(&location, "nul", 1920, 1080, 30, 1, [0, 0, 0]).expect("creates");
assert!(is_project(Path::new(&info.path)));
assert_eq!(info.name, "nul");
}
diff --git a/src/crates/concat-host/src/session.rs b/src/crates/concat-host/src/session.rs
index ee53ba54..7cca1baf 100644
--- a/src/crates/concat-host/src/session.rs
+++ b/src/crates/concat-host/src/session.rs
@@ -144,6 +144,7 @@ impl Session {
height: info.height,
rate_num: info.rate_num,
rate_den: info.rate_den,
+ canvas: info.canvas,
},
)
}
@@ -182,6 +183,7 @@ impl Session {
height: video.height,
rate_num: video.rate_num,
rate_den: video.rate_den,
+ canvas: video.canvas,
}
}
@@ -318,6 +320,7 @@ mod tests {
fn settings() -> DocumentSettings {
DocumentSettings {
+ canvas: [0, 0, 0],
name: "Test".to_owned(),
width: 1920,
height: 1080,
@@ -332,8 +335,16 @@ mod tests {
std::env::temp_dir().join(format!("concat-session-test-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&scratch);
std::fs::create_dir_all(&scratch).expect("scratch dir");
- let info = projects::create(&scratch.to_string_lossy(), "Fresh", 1920, 1080, 30, 1)
- .expect("creates");
+ let info = projects::create(
+ &scratch.to_string_lossy(),
+ "Fresh",
+ 1920,
+ 1080,
+ 30,
+ 1,
+ [0, 0, 0],
+ )
+ .expect("creates");
let mut session = Session::open_info(&info).expect("opens the settings-only manifest");
assert!(!session.can_undo());
@@ -348,6 +359,7 @@ mod tests {
assert!(view.can_undo);
session
.set_video(VideoSettings {
+ canvas: [0, 0, 0],
width: 1280,
height: 720,
rate_num: 25,
diff --git a/src/crates/concat-host/src/templates.rs b/src/crates/concat-host/src/templates.rs
index a2b39f9c..6d0cda79 100644
--- a/src/crates/concat-host/src/templates.rs
+++ b/src/crates/concat-host/src/templates.rs
@@ -299,6 +299,7 @@ pub fn instantiate(
info.height,
info.rate_num,
info.rate_den,
+ [0, 0, 0],
)?;
let root = PathBuf::from(&project.path);
@@ -347,6 +348,7 @@ pub fn instantiate(
height: info.height,
rate_num: info.rate_num,
rate_den: info.rate_den,
+ canvas: editor.project().active().video.canvas,
};
projects::save(&project.path, &editor.to_document(&settings))?;
@@ -487,6 +489,7 @@ mod tests {
}
let settings = DocumentSettings {
+ canvas: [0, 0, 0],
name: "Beat Intro".to_owned(),
width: 1920,
height: 1080,
diff --git a/src/crates/concat-host/tests/export.rs b/src/crates/concat-host/tests/export.rs
index 50085936..85b927e7 100644
--- a/src/crates/concat-host/tests/export.rs
+++ b/src/crates/concat-host/tests/export.rs
@@ -476,6 +476,7 @@ impl Studio {
video.height,
video.rate_num,
video.rate_den,
+ [0, 0, 0],
)
.expect("creates the project");
let session = Session::open_info(&info).expect("opens the project");
@@ -652,6 +653,7 @@ fn effect(id: &str) -> AppliedFilter {
fn video(width: u32, height: u32, rate_num: i64, rate_den: i64) -> VideoSettings {
VideoSettings {
+ canvas: [0, 0, 0],
width,
height,
rate_num,
@@ -896,6 +898,7 @@ fn a_background_fills_the_bars_in_the_export_and_the_monitor() {
];
let monitor = |studio: &Studio| {
let request = concat_export::PreviewFrameRequest {
+ canvas: [0, 0, 0],
time: 1.0,
width,
height,
diff --git a/src/crates/concat-host/tests/stabilize.rs b/src/crates/concat-host/tests/stabilize.rs
index 3cb02c08..1b28da7d 100644
--- a/src/crates/concat-host/tests/stabilize.rs
+++ b/src/crates/concat-host/tests/stabilize.rs
@@ -175,6 +175,7 @@ fn a_shaky_shot_is_measured_and_held_still() {
HEIGHT,
30,
1,
+ [0, 0, 0],
)
.expect("creates the project");
let mut session = Session::open_info(&info).expect("opens the project");
@@ -291,6 +292,7 @@ fn a_shaky_shot_is_measured_and_held_still() {
Arc::clone(&clips),
&session.settings(),
FrameSpec {
+ canvas: [0, 0, 0],
time: k as f64 / 30.0,
width: WIDTH,
height: HEIGHT,
diff --git a/src/crates/concat-mobile/src/lib.rs b/src/crates/concat-mobile/src/lib.rs
index 977ac8ce..ea221f18 100644
--- a/src/crates/concat-mobile/src/lib.rs
+++ b/src/crates/concat-mobile/src/lib.rs
@@ -153,7 +153,15 @@ impl Engine {
let info = if concat_host::projects::is_project(&folder) {
concat_host::projects::open(&folder.to_string_lossy())?
} else {
- concat_host::projects::create(&projects.to_string_lossy(), "Spike", 1080, 1920, 30, 1)?
+ concat_host::projects::create(
+ &projects.to_string_lossy(),
+ "Spike",
+ 1080,
+ 1920,
+ 30,
+ 1,
+ [0, 0, 0],
+ )?
};
let session = Session::open_info(&info)?;
let clock = Arc::new(Clock {
diff --git a/src/crates/concat-mobile/src/render.rs b/src/crates/concat-mobile/src/render.rs
index e84ae2ad..bbdd2e3c 100644
--- a/src/crates/concat-mobile/src/render.rs
+++ b/src/crates/concat-mobile/src/render.rs
@@ -389,6 +389,7 @@ fn spec(doc: &Doc, at: f64, size: (u32, u32), moving: bool) -> concat_host::prev
moving,
proxy: false,
color_space: doc.color,
+ canvas: doc.settings.canvas,
}
}
diff --git a/src/crates/concat-project/src/doc.rs b/src/crates/concat-project/src/doc.rs
index 34d5b4d2..79ea5dbb 100644
--- a/src/crates/concat-project/src/doc.rs
+++ b/src/crates/concat-project/src/doc.rs
@@ -299,6 +299,9 @@ pub struct DocumentSettings {
pub rate_num: i64,
/// Denominator of the output frame rate, e.g. 1001 for 29.97fps.
pub rate_den: i64,
+ /// What shows where no picture covers the frame; see
+ /// `VideoSettings::canvas`.
+ pub canvas: [u8; 3],
}
impl DocumentSettings {
@@ -311,6 +314,7 @@ impl DocumentSettings {
rate_num: self.rate_num,
rate_den: self.rate_den,
color_space: ColorSpace::Sdr,
+ canvas: self.canvas,
}
}
}
diff --git a/src/crates/concat-project/src/lib.rs b/src/crates/concat-project/src/lib.rs
index 379dd01e..5b566912 100644
--- a/src/crates/concat-project/src/lib.rs
+++ b/src/crates/concat-project/src/lib.rs
@@ -164,6 +164,29 @@ mod tests {
);
}
+ /// A timeline's canvas colour is written as `#rrggbb` and read back;
+ /// black is not written at all, so a document without one is the
+ /// document it always was, and junk reads as black (#456).
+ #[test]
+ fn a_canvas_colour_is_written_only_when_it_is_not_black() {
+ use crate::model::VideoSettings;
+ let black = serde_json::to_value(VideoSettings::default()).unwrap();
+ assert!(black.get("canvas").is_none(), "{black}");
+ let green = VideoSettings {
+ canvas: [0, 177, 64],
+ ..VideoSettings::default()
+ };
+ let written = serde_json::to_value(green).unwrap();
+ assert_eq!(written["canvas"], "#00b140");
+ let read: VideoSettings = serde_json::from_value(written).unwrap();
+ assert_eq!(read, green);
+ let junk: VideoSettings = serde_json::from_value(json!({
+ "width": 1920, "height": 1080, "rateNum": 30, "rateDen": 1, "canvas": "teal"
+ }))
+ .unwrap();
+ assert_eq!(junk.canvas, [0, 0, 0]);
+ }
+
#[test]
fn old_styles_keep_their_original_appearance() {
use crate::model::{TextCase, TextStyle};
@@ -242,6 +265,7 @@ mod tests {
height: 1080,
rate_num: 30,
rate_den: 1,
+ canvas: [0, 0, 0],
}
}
diff --git a/src/crates/concat-project/src/model.rs b/src/crates/concat-project/src/model.rs
index 0c631748..7b40ee62 100644
--- a/src/crates/concat-project/src/model.rs
+++ b/src/crates/concat-project/src/model.rs
@@ -2630,6 +2630,35 @@ pub struct VideoSettings {
#[serde(default, skip_serializing_if = "ColorSpace::is_sdr")]
#[serde(deserialize_with = "wire::color_space")]
pub color_space: ColorSpace,
+ /// What shows where no picture covers the frame - a gap, the space
+ /// around a title, a clip fading in - as `#rrggbb` in the document:
+ /// black unless the project was given another (#456). Left out of the
+ /// document while it is black, so those documents stay as they were.
+ #[serde(default, skip_serializing_if = "is_black", with = "hex_rgb")]
+ #[cfg_attr(feature = "schema", schemars(with = "String"))]
+ pub canvas: [u8; 3],
+}
+
+fn is_black(rgb: &[u8; 3]) -> bool {
+ *rgb == [0, 0, 0]
+}
+
+/// A colour kept as three channels and written as `#rrggbb`, the way the
+/// document writes every colour. One that does not read is black.
+pub mod hex_rgb {
+ use serde::{Deserialize, Deserializer, Serializer};
+
+ /// `#rrggbb`, lower case.
+ pub fn serialize<S: Serializer>(rgb: &[u8; 3], serializer: S) -> Result<S::Ok, S::Error> {
+ serializer.serialize_str(&format!("#{:02x}{:02x}{:02x}", rgb[0], rgb[1], rgb[2]))
+ }
+
+ /// `#rrggbb` or `#rrggbbaa`, its alpha ignored; black for anything
+ /// else.
+ pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<[u8; 3], D::Error> {
+ let value = serde_json::Value::deserialize(deserializer)?;
+ Ok(value.as_str().and_then(super::rgb_of).unwrap_or([0, 0, 0]))
+ }
}
impl Default for VideoSettings {
@@ -2642,6 +2671,7 @@ impl Default for VideoSettings {
rate_num: 30,
rate_den: 1,
color_space: ColorSpace::Sdr,
+ canvas: [0, 0, 0],
}
}
}
@@ -2693,6 +2723,7 @@ impl VideoSettings {
fallback.rate_den
},
color_space: self.color_space,
+ canvas: self.canvas,
}
}
diff --git a/src/crates/concat-render/src/gpu.rs b/src/crates/concat-render/src/gpu.rs
index b250652d..237ddd78 100644
--- a/src/crates/concat-render/src/gpu.rs
+++ b/src/crates/concat-render/src/gpu.rs
@@ -1518,7 +1518,7 @@ impl WgpuCompositor {
self.push_layer(&mut draws, &mut vertices, plan, &plan.layers[next]);
next += 1;
}
- let below = self.render_pooled(width, height, &draws, &vertices, wgpu::Color::BLACK);
+ let below = self.render_pooled(width, height, &draws, &vertices, clear_of(plan.canvas));
let strength = treatment.strength.clamp(0.0, 1.0);
if strength <= 0.0 || treatment.effects.is_empty() {
ground = Some(below);
@@ -1536,7 +1536,7 @@ impl WgpuCompositor {
let mut vertices = Vec::new();
self.push_pooled(&mut draws, &mut vertices, width, height, below, 1.0);
self.push_pooled(&mut draws, &mut vertices, width, height, treated, strength);
- self.render_pooled(width, height, &draws, &vertices, wgpu::Color::BLACK)
+ self.render_pooled(width, height, &draws, &vertices, clear_of(plan.canvas))
});
}
let mut draws = Vec::new();
@@ -1791,7 +1791,7 @@ impl WgpuCompositor {
let (canvas, canvas_texture, canvas_view) = self.canvas(plan.width, plan.height);
let texture = self.presentable(plan.width, plan.height);
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
- let mut encoder = self.encode(&canvas_view, &canvas_texture, &draws, wgpu::Color::BLACK);
+ let mut encoder = self.encode(&canvas_view, &canvas_texture, &draws, clear_of(plan.canvas));
self.resolve(&mut encoder, (plan.width, plan.height), canvas, &view);
self.queue.submit([encoder.finish()]);
self.retire();
@@ -2963,7 +2963,7 @@ impl WgpuCompositor {
let (draws, vertices) = self.prepare(plan);
self.write_vertices(&vertices);
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
- let encoder = self.encode(&view, texture, &draws, wgpu::Color::BLACK);
+ let encoder = self.encode(&view, texture, &draws, clear_of(plan.canvas));
self.queue.submit([encoder.finish()]);
}
let from_view = from_texture.create_view(&wgpu::TextureViewDescriptor::default());
@@ -3530,6 +3530,19 @@ impl WgpuCompositor {
}
}
+/// A plan's canvas colour as the working space holds it: each eight-bit
+/// level through the 2.4 gamma every picture is uploaded through, so the
+/// canvas and a still of the same colour come out the same, 1.0 SDR white.
+fn clear_of([r, g, b]: [u8; 3]) -> wgpu::Color {
+ let light = |level: u8| (f64::from(level) / 255.0).powf(2.4);
+ wgpu::Color {
+ r: light(r),
+ g: light(g),
+ b: light(b),
+ a: 1.0,
+ }
+}
+
impl Compositor for WgpuCompositor {
fn render(&mut self, plan: &FramePlan) -> Frame {
// A dead device never comes back for this instance. What it hands
@@ -3552,7 +3565,7 @@ impl Compositor for WgpuCompositor {
let validation = self.device.push_error_scope(wgpu::ErrorFilter::Validation);
let (draws, vertices) = self.prepare(plan);
self.write_vertices(&vertices);
- let frame = self.render_and_read(plan.width, plan.height, &draws);
+ let frame = self.render_and_read(plan.width, plan.height, &draws, clear_of(plan.canvas));
let refused = pollster::block_on(validation.pop());
let exhausted = pollster::block_on(memory.pop());
let errors = [exhausted, refused].into_iter().flatten();
@@ -3662,14 +3675,20 @@ impl Compositor for WgpuCompositor {
impl WgpuCompositor {
/// Draws into the readback target and copies it out: one submit, one
/// wait. `None` when the device did not deliver the pixels.
- fn render_and_read(&mut self, width: u32, height: u32, draws: &[Draw]) -> Option<Frame> {
+ fn render_and_read(
+ &mut self,
+ width: u32,
+ height: u32,
+ draws: &[Draw],
+ clear: wgpu::Color,
+ ) -> Option<Frame> {
let (canvas, canvas_texture, canvas_view) = self.canvas(width, height);
self.target(width, height);
let target = self.current_target();
let view = target
.texture
.create_view(&wgpu::TextureViewDescriptor::default());
- let mut encoder = self.encode(&canvas_view, &canvas_texture, draws, wgpu::Color::BLACK);
+ let mut encoder = self.encode(&canvas_view, &canvas_texture, draws, clear);
self.resolve(&mut encoder, (width, height), canvas, &view);
encoder.copy_texture_to_buffer(
wgpu::TexelCopyTextureInfo {
diff --git a/src/crates/concat-render/src/gpu/tests.rs b/src/crates/concat-render/src/gpu/tests.rs
index 059e7ec3..9e85bf6c 100644
--- a/src/crates/concat-render/src/gpu/tests.rs
+++ b/src/crates/concat-render/src/gpu/tests.rs
@@ -130,6 +130,27 @@ fn empty_output_is_opaque_black() {
assert_eq!(frame.pixel(3, 3), Some([0, 0, 0, 255]));
}
+/// The canvas colour comes back out as it went in: cleared in linear
+/// light through the upload's gamma and resolved back, within a level.
+#[test]
+fn an_empty_frame_is_the_canvas_colour() {
+ let Some(mut gpu) = gpu() else { return };
+ for canvas in [[0, 177, 64], [255, 255, 255], [0, 71, 187], [31, 31, 31]] {
+ let frame = gpu.render(&FramePlan {
+ canvas,
+ ..FramePlan::empty(4, 4)
+ });
+ let pixel = frame.pixel(2, 2).expect("a pixel");
+ for channel in 0..3 {
+ assert!(
+ pixel[channel].abs_diff(canvas[channel]) <= 1,
+ "{canvas:?} came back {pixel:?}"
+ );
+ }
+ assert_eq!(pixel[3], 255);
+ }
+}
+
#[test]
fn plain_layers_match_the_cpu_reference_to_the_pixel() {
let Some(mut gpu) = gpu() else { return };
@@ -925,6 +946,7 @@ fn a_transition_kept_on_the_device_matches_the_read_back_one() {
time: concat_core::time::Rational::new(1, 2),
width,
height,
+ canvas: [0, 0, 0],
layers: vec![PlannedLayer::picture(
detached_clip(),
Arc::new(solid(width, height, colour)),
@@ -982,6 +1004,7 @@ fn a_frame_drawn_before_is_not_uploaded_again() {
time: concat_core::time::Rational::new(0, 1),
width: 64,
height: 36,
+ canvas: [0, 0, 0],
layers: vec![PlannedLayer::picture(detached_clip(), Arc::clone(frame))],
treatments: Vec::new(),
output: concat_core::frame::Signal::Sdr,
@@ -1022,6 +1045,7 @@ fn the_pool_stays_within_its_limits() {
time: concat_core::time::Rational::new(0, 1),
width: 4,
height: 4,
+ canvas: [0, 0, 0],
layers: vec![PlannedLayer::picture(detached_clip(), frame)],
treatments: Vec::new(),
output: concat_core::frame::Signal::Sdr,
diff --git a/src/crates/concat-render/src/plan.rs b/src/crates/concat-render/src/plan.rs
index 6cb7d2a3..76fe7fc5 100644
--- a/src/crates/concat-render/src/plan.rs
+++ b/src/crates/concat-render/src/plan.rs
@@ -733,6 +733,9 @@ pub struct FramePlan {
pub width: u32,
/// Output height.
pub height: u32,
+ /// What is drawn under the bottom layer, where no picture covers the
+ /// frame: the timeline's canvas colour, eight-bit `[r, g, b]`.
+ pub canvas: [u8; 3],
/// Visible layers, bottom-most first.
pub layers: Vec<PlannedLayer>,
/// The treatments live at this instant, in ascending track order.
@@ -750,14 +753,15 @@ impl FramePlan {
time: Rational::ZERO,
width,
height,
+ canvas: [0, 0, 0],
layers: Vec::new(),
treatments: Vec::new(),
output: Signal::Sdr,
}
}
- /// True if nothing is on screen. The result is a black frame, not an error:
- /// gaps in a timeline are ordinary.
+ /// True if nothing is on screen. The result is the canvas, not an
+ /// error: gaps in a timeline are ordinary.
pub fn is_empty(&self) -> bool {
self.layers.is_empty()
}
@@ -835,6 +839,7 @@ pub fn plan_frame(timeline: &Timeline, time: Rational) -> FramePlan {
time,
width: timeline.width,
height: timeline.height,
+ canvas: timeline.canvas,
layers,
treatments: Vec::new(),
output: Signal::Sdr,
diff --git a/src/crates/concat-render/src/reference.rs b/src/crates/concat-render/src/reference.rs
index 3b963bca..4f666698 100644
--- a/src/crates/concat-render/src/reference.rs
+++ b/src/crates/concat-render/src/reference.rs
@@ -48,6 +48,8 @@ impl Compositor for CpuCompositor {
// besides its effects, which are the GPU's alone and are held to
// their packages' probes instead.
let mut ground = Frame::black(plan.width, plan.height);
+ let [r, g, b] = plan.canvas;
+ ground.fill([r, g, b, 255]);
let next = 0;
for layer in &plan.layers[next..] {
draw(&mut ground, plan, layer);
@@ -357,6 +359,39 @@ fn blend_aligned(output: &mut Frame, picture: &Frame, geometry: &Geometry, weigh
#[cfg(test)]
mod tests {
+ /// A frame with nothing on it is the canvas, and a picture that does
+ /// not cover the frame sits on the canvas, not on black (#456).
+ #[test]
+ fn the_canvas_shows_where_no_picture_covers_the_frame() {
+ use crate::Compositor;
+ use crate::plan::{FramePlan, PlannedLayer, detached_clip};
+ let gap = FramePlan {
+ canvas: [0, 177, 64],
+ ..FramePlan::empty(8, 4)
+ };
+ let frame = super::CpuCompositor.render(&gap);
+ assert!(
+ frame
+ .pixels()
+ .chunks_exact(4)
+ .all(|p| p == [0, 177, 64, 255])
+ );
+
+ let mut half = concat_core::Frame::black(4, 4);
+ half.fill([255, 255, 255, 255]);
+ let plan = FramePlan {
+ layers: vec![PlannedLayer::picture(
+ detached_clip(),
+ std::sync::Arc::new(half),
+ )],
+ ..gap
+ };
+ let frame = super::CpuCompositor.render(&plan);
+ // Fitted into an 8x4 frame, the 4x4 square leaves the sides bare.
+ assert_eq!(frame.pixel(0, 2), Some([0, 177, 64, 255]));
+ assert_eq!(frame.pixel(4, 2), Some([255, 255, 255, 255]));
+ }
+
#[test]
fn lighten_and_darken_weigh_the_layer_in_by_its_alpha() {
use super::{Blend, mix};
diff --git a/src/crates/concat/locales/ar.json b/src/crates/concat/locales/ar.json
index 37c034de..2e99bec1 100644
--- a/src/crates/concat/locales/ar.json
+++ b/src/crates/concat/locales/ar.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "الأبطأ",
"speedRamp.smooth": "ناعم",
"speedRamp.straight": "مستقيم",
+ "start.background": "الخلفية",
"start.choose": "اختيار…",
"start.chooseAFolder": "اختيار مجلد",
"start.chooseWhereProjectFolder": "اختر مكان مجلد المشروع",
diff --git a/src/crates/concat/locales/az.json b/src/crates/concat/locales/az.json
index 811a9cef..db3c7baa 100644
--- a/src/crates/concat/locales/az.json
+++ b/src/crates/concat/locales/az.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "Ən yavaş",
"speedRamp.smooth": "Hamar",
"speedRamp.straight": "Düz",
+ "start.background": "Fon",
"start.choose": "Seç…",
"start.chooseAFolder": "Qovluq seçin",
"start.chooseWhereProjectFolder": "Layihə qovluğunun harada olacağını seçin",
diff --git a/src/crates/concat/locales/bn.json b/src/crates/concat/locales/bn.json
index b6db5787..a9060f90 100644
--- a/src/crates/concat/locales/bn.json
+++ b/src/crates/concat/locales/bn.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "ধীরতম",
"speedRamp.smooth": "মসৃণ",
"speedRamp.straight": "সোজা",
+ "start.background": "পটভূমি",
"start.choose": "বেছে নিন…",
"start.chooseAFolder": "একটি ফোল্ডার বেছে নিন",
"start.chooseWhereProjectFolder": "প্রকল্প ফোল্ডার কোথায় যাবে তা বেছে নিন",
diff --git a/src/crates/concat/locales/de.json b/src/crates/concat/locales/de.json
index 70bc000d..4f210f71 100644
--- a/src/crates/concat/locales/de.json
+++ b/src/crates/concat/locales/de.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "Langsamste Stelle",
"speedRamp.smooth": "Weich",
"speedRamp.straight": "Gerade",
+ "start.background": "Hintergrund",
"start.choose": "Wählen…",
"start.chooseAFolder": "Ordner wählen",
"start.chooseWhereProjectFolder": "Wähle, wohin der Projektordner soll",
diff --git a/src/crates/concat/locales/en.json b/src/crates/concat/locales/en.json
index ffbc2b4b..7cc761ff 100644
--- a/src/crates/concat/locales/en.json
+++ b/src/crates/concat/locales/en.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "Slowest",
"speedRamp.smooth": "Smooth",
"speedRamp.straight": "Straight",
+ "start.background": "Background",
"start.choose": "Choose…",
"start.chooseAFolder": "Choose a folder",
"start.chooseWhereProjectFolder": "Choose where the project folder should go",
diff --git a/src/crates/concat/locales/es.json b/src/crates/concat/locales/es.json
index e15761bd..9b84d33d 100644
--- a/src/crates/concat/locales/es.json
+++ b/src/crates/concat/locales/es.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "Lo más lento",
"speedRamp.smooth": "Suave",
"speedRamp.straight": "Recta",
+ "start.background": "Fondo",
"start.choose": "Elegir…",
"start.chooseAFolder": "Elige una carpeta",
"start.chooseWhereProjectFolder": "Elige dónde irá la carpeta del proyecto",
diff --git a/src/crates/concat/locales/fa.json b/src/crates/concat/locales/fa.json
index 21cb319b..988d0259 100644
--- a/src/crates/concat/locales/fa.json
+++ b/src/crates/concat/locales/fa.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "کندترین",
"speedRamp.smooth": "نرم",
"speedRamp.straight": "مستقیم",
+ "start.background": "پس‌زمینه",
"start.choose": "انتخاب…",
"start.chooseAFolder": "انتخاب پوشه",
"start.chooseWhereProjectFolder": "محل ذخیره پوشه پروژه را انتخاب کنید",
diff --git a/src/crates/concat/locales/fr.json b/src/crates/concat/locales/fr.json
index 6ae82f92..3bf71b76 100644
--- a/src/crates/concat/locales/fr.json
+++ b/src/crates/concat/locales/fr.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "Le plus lent",
"speedRamp.smooth": "Douce",
"speedRamp.straight": "Droite",
+ "start.background": "Arrière-plan",
"start.choose": "Choisir…",
"start.chooseAFolder": "Choisir un dossier",
"start.chooseWhereProjectFolder": "Choisissez où placer le dossier du projet",
diff --git a/src/crates/concat/locales/he.json b/src/crates/concat/locales/he.json
index d72e6404..20dacf26 100644
--- a/src/crates/concat/locales/he.json
+++ b/src/crates/concat/locales/he.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "האיטי ביותר",
"speedRamp.smooth": "חלק",
"speedRamp.straight": "ישר",
+ "start.background": "רקע",
"start.choose": "בחירה…",
"start.chooseAFolder": "בחירת תיקייה",
"start.chooseWhereProjectFolder": "בחירת המיקום של תיקיית הפרויקט",
diff --git a/src/crates/concat/locales/hi.json b/src/crates/concat/locales/hi.json
index 035446db..5dde091a 100644
--- a/src/crates/concat/locales/hi.json
+++ b/src/crates/concat/locales/hi.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "सबसे धीमा",
"speedRamp.smooth": "सहज",
"speedRamp.straight": "सीधा",
+ "start.background": "पृष्ठभूमि",
"start.choose": "चुनें…",
"start.chooseAFolder": "फ़ोल्डर चुनें",
"start.chooseWhereProjectFolder": "चुनें कि प्रोजेक्ट फ़ोल्डर कहां रखा जाए",
diff --git a/src/crates/concat/locales/hr.json b/src/crates/concat/locales/hr.json
index 1d2c1362..05b39348 100644
--- a/src/crates/concat/locales/hr.json
+++ b/src/crates/concat/locales/hr.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "Najsporije",
"speedRamp.smooth": "Glatko",
"speedRamp.straight": "Ravno",
+ "start.background": "Pozadina",
"start.choose": "Odaberi…",
"start.chooseAFolder": "Odaberite mapu",
"start.chooseWhereProjectFolder": "Odaberite kamo će mapa projekta",
diff --git a/src/crates/concat/locales/id.json b/src/crates/concat/locales/id.json
index cbb4ff7c..a4dfd8bb 100644
--- a/src/crates/concat/locales/id.json
+++ b/src/crates/concat/locales/id.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "Paling lambat",
"speedRamp.smooth": "Halus",
"speedRamp.straight": "Lurus",
+ "start.background": "Latar",
"start.choose": "Pilih…",
"start.chooseAFolder": "Pilih folder",
"start.chooseWhereProjectFolder": "Pilih lokasi folder proyek",
diff --git a/src/crates/concat/locales/it.json b/src/crates/concat/locales/it.json
index f75f34ac..192b457d 100644
--- a/src/crates/concat/locales/it.json
+++ b/src/crates/concat/locales/it.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "Più lento",
"speedRamp.smooth": "Morbida",
"speedRamp.straight": "Dritta",
+ "start.background": "Sfondo",
"start.choose": "Scegli…",
"start.chooseAFolder": "Scegli una cartella",
"start.chooseWhereProjectFolder": "Scegli dove mettere la cartella del progetto",
diff --git a/src/crates/concat/locales/ja.json b/src/crates/concat/locales/ja.json
index e87af22c..46ae060a 100644
--- a/src/crates/concat/locales/ja.json
+++ b/src/crates/concat/locales/ja.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "最遅",
"speedRamp.smooth": "なめらか",
"speedRamp.straight": "直線",
+ "start.background": "背景",
"start.choose": "選択…",
"start.chooseAFolder": "フォルダーを選択",
"start.chooseWhereProjectFolder": "プロジェクトフォルダーの保存先を選んでください",
diff --git a/src/crates/concat/locales/ko.json b/src/crates/concat/locales/ko.json
index 4e4bd78d..0f153da5 100644
--- a/src/crates/concat/locales/ko.json
+++ b/src/crates/concat/locales/ko.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "가장 느리게",
"speedRamp.smooth": "부드럽게",
"speedRamp.straight": "직선",
+ "start.background": "배경",
"start.choose": "선택…",
"start.chooseAFolder": "폴더 선택",
"start.chooseWhereProjectFolder": "프로젝트 폴더를 둘 위치를 선택하세요",
diff --git a/src/crates/concat/locales/nl.json b/src/crates/concat/locales/nl.json
index 74201189..d0a1ae40 100644
--- a/src/crates/concat/locales/nl.json
+++ b/src/crates/concat/locales/nl.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "Traagst",
"speedRamp.smooth": "Vloeiend",
"speedRamp.straight": "Recht",
+ "start.background": "Achtergrond",
"start.choose": "Kiezen…",
"start.chooseAFolder": "Kies een map",
"start.chooseWhereProjectFolder": "Kies waar de projectmap moet komen",
diff --git a/src/crates/concat/locales/pl.json b/src/crates/concat/locales/pl.json
index a825650e..a6ef3988 100644
--- a/src/crates/concat/locales/pl.json
+++ b/src/crates/concat/locales/pl.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "Najwolniej",
"speedRamp.smooth": "Płynna",
"speedRamp.straight": "Prosta",
+ "start.background": "Tło",
"start.choose": "Wybierz…",
"start.chooseAFolder": "Wybierz folder",
"start.chooseWhereProjectFolder": "Wybierz, gdzie ma się znaleźć folder projektu",
diff --git a/src/crates/concat/locales/pt-BR.json b/src/crates/concat/locales/pt-BR.json
index 12d7ffcf..1f62c4e0 100644
--- a/src/crates/concat/locales/pt-BR.json
+++ b/src/crates/concat/locales/pt-BR.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "Mais lento",
"speedRamp.smooth": "Suave",
"speedRamp.straight": "Reta",
+ "start.background": "Fundo",
"start.choose": "Escolher…",
"start.chooseAFolder": "Escolha uma pasta",
"start.chooseWhereProjectFolder": "Escolha onde a pasta do projeto deve ficar",
diff --git a/src/crates/concat/locales/ru.json b/src/crates/concat/locales/ru.json
index 4d65e10a..29cbeb35 100644
--- a/src/crates/concat/locales/ru.json
+++ b/src/crates/concat/locales/ru.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "Медленнее всего",
"speedRamp.smooth": "Плавно",
"speedRamp.straight": "Прямо",
+ "start.background": "Фон",
"start.choose": "Выбрать…",
"start.chooseAFolder": "Выберите папку",
"start.chooseWhereProjectFolder": "Выберите, где будет папка проекта",
diff --git a/src/crates/concat/locales/th.json b/src/crates/concat/locales/th.json
index 9e16f522..cca1bdaf 100644
--- a/src/crates/concat/locales/th.json
+++ b/src/crates/concat/locales/th.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "ช้าที่สุด",
"speedRamp.smooth": "นุ่มนวล",
"speedRamp.straight": "ตรง",
+ "start.background": "พื้นหลัง",
"start.choose": "เลือก…",
"start.chooseAFolder": "เลือกโฟลเดอร์",
"start.chooseWhereProjectFolder": "เลือกตำแหน่งของโฟลเดอร์โปรเจกต์",
diff --git a/src/crates/concat/locales/tr.json b/src/crates/concat/locales/tr.json
index c4d9d856..3a41e678 100644
--- a/src/crates/concat/locales/tr.json
+++ b/src/crates/concat/locales/tr.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "En yavaş",
"speedRamp.smooth": "Yumuşak",
"speedRamp.straight": "Düz",
+ "start.background": "Arka plan",
"start.choose": "Seç…",
"start.chooseAFolder": "Bir klasör seçin",
"start.chooseWhereProjectFolder": "Proje klasörünün nereye gideceğini seçin",
diff --git a/src/crates/concat/locales/uk.json b/src/crates/concat/locales/uk.json
index dbdb3526..5d0e45c1 100644
--- a/src/crates/concat/locales/uk.json
+++ b/src/crates/concat/locales/uk.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "Найповільніше",
"speedRamp.smooth": "Плавно",
"speedRamp.straight": "Прямо",
+ "start.background": "Тло",
"start.choose": "Вибрати…",
"start.chooseAFolder": "Виберіть папку",
"start.chooseWhereProjectFolder": "Виберіть, де розмістити папку проєкту",
diff --git a/src/crates/concat/locales/ur.json b/src/crates/concat/locales/ur.json
index 70c38ae5..8dc3f840 100644
--- a/src/crates/concat/locales/ur.json
+++ b/src/crates/concat/locales/ur.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "سب سے سست",
"speedRamp.smooth": "ہموار",
"speedRamp.straight": "سیدھا",
+ "start.background": "پس منظر",
"start.choose": "چنیں…",
"start.chooseAFolder": "فولڈر چنیں",
"start.chooseWhereProjectFolder": "چنیں کہ پروجیکٹ فولڈر کہاں جائے",
diff --git a/src/crates/concat/locales/vi.json b/src/crates/concat/locales/vi.json
index 64b274c6..8bbc6c2f 100644
--- a/src/crates/concat/locales/vi.json
+++ b/src/crates/concat/locales/vi.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "Chậm nhất",
"speedRamp.smooth": "Mượt",
"speedRamp.straight": "Thẳng",
+ "start.background": "Nền",
"start.choose": "Chọn…",
"start.chooseAFolder": "Chọn thư mục",
"start.chooseWhereProjectFolder": "Chọn nơi lưu thư mục dự án",
diff --git a/src/crates/concat/locales/zh-Hans.json b/src/crates/concat/locales/zh-Hans.json
index 08721e95..e47f5675 100644
--- a/src/crates/concat/locales/zh-Hans.json
+++ b/src/crates/concat/locales/zh-Hans.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "最慢",
"speedRamp.smooth": "平滑",
"speedRamp.straight": "直线",
+ "start.background": "背景",
"start.choose": "选择…",
"start.chooseAFolder": "选择文件夹",
"start.chooseWhereProjectFolder": "选择项目文件夹的存放位置",
diff --git a/src/crates/concat/locales/zh-TW.json b/src/crates/concat/locales/zh-TW.json
index eea53067..393c8138 100644
--- a/src/crates/concat/locales/zh-TW.json
+++ b/src/crates/concat/locales/zh-TW.json
@@ -618,6 +618,7 @@
"speedRamp.slowest": "最慢",
"speedRamp.smooth": "平滑",
"speedRamp.straight": "直線",
+ "start.background": "背景",
"start.choose": "選擇…",
"start.chooseAFolder": "選擇資料夾",
"start.chooseWhereProjectFolder": "選擇專案資料夾的存放位置",
diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rs
index 38c97aed..08713082 100644
--- a/src/crates/concat/src/lib.rs
+++ b/src/crates/concat/src/lib.rs
@@ -717,6 +717,13 @@ fn start(project: Option<std::path::PathBuf>, smoke: bool) -> Result<(), slint::
app.on_start_browse(on_window!(|state| {
state.handle(Msg::Start(StartMsg::Browse));
}));
+ app.on_start_canvas_changed(on_window!(|state, colour: slint::Color| {
+ state.handle(Msg::Start(StartMsg::CanvasChanged([
+ colour.red(),
+ colour.green(),
+ colour.blue(),
+ ])));
+ }));
app.on_start_create(on_window!(|state| {
state.handle(Msg::Start(StartMsg::Create));
}));
@@ -1785,6 +1792,13 @@ fn start(project: Option<std::path::PathBuf>, smoke: bool) -> Result<(), slint::
app.on_project_color_space_changed(on_window!(|state, index: i32| {
state.handle(Msg::Project(ProjectMsg::ColorSpaceChanged(index)));
}));
+ app.on_project_canvas_changed(on_window!(|state, colour: slint::Color| {
+ state.handle(Msg::Project(ProjectMsg::CanvasChanged([
+ colour.red(),
+ colour.green(),
+ colour.blue(),
+ ])));
+ }));
app.on_project_custom_width_edited(on_window!(|state, width: f32| {
state.handle(Msg::Project(ProjectMsg::CustomWidth(width)));
}));
@@ -2800,7 +2814,7 @@ mod tests {
#[test]
fn a_failed_save_keeps_the_real_session_and_its_edit() {
let scratch = Scratch::new("session");
- let info = projects::create(&scratch.location(), "Closing", 1920, 1080, 30, 1)
+ let info = projects::create(&scratch.location(), "Closing", 1920, 1080, 30, 1, [0, 0, 0])
.expect("creates the project");
let manifest = projects::manifest_path(Path::new(&info.path));
@@ -2878,7 +2892,7 @@ mod tests {
#[test]
fn a_delayed_autosave_cannot_replace_the_close_snapshot() {
let scratch = Scratch::new("ordered-close");
- let info = projects::create(&scratch.location(), "Ordered", 1920, 1080, 30, 1)
+ let info = projects::create(&scratch.location(), "Ordered", 1920, 1080, 30, 1, [0, 0, 0])
.expect("creates the project");
let mut session = Session::open_info(&info).expect("opens the session");
let (old_path, old_document) = session.prepare_save(None);
diff --git a/src/crates/concat/src/panes/monitor.rs b/src/crates/concat/src/panes/monitor.rs
index 29db6d74..7de849b3 100644
--- a/src/crates/concat/src/panes/monitor.rs
+++ b/src/crates/concat/src/panes/monitor.rs
@@ -250,6 +250,7 @@ impl MonitorPane {
&& (studio.playing || studio.source.as_ref().is_some_and(|source| source.playing))
&& quality > 0,
color_space: studio.project().active().video.color_space,
+ canvas: studio.project().active().video.canvas,
};
if !studio.playing {
self.cadence.report(studio.project().active().video.rate());
diff --git a/src/crates/concat/src/panes/project.rs b/src/crates/concat/src/panes/project.rs
index 0e2cc8f2..bbd9aa09 100644
--- a/src/crates/concat/src/panes/project.rs
+++ b/src/crates/concat/src/panes/project.rs
@@ -25,6 +25,8 @@ pub enum ProjectMsg {
CustomFps(f32),
/// A row of the colour list: SDR, HDR HLG, HDR PQ.
ColorSpaceChanged(i32),
+ /// What shows where no picture covers the frame, `[r, g, b]` (#456).
+ CanvasChanged([u8; 3]),
Apply,
}
@@ -43,6 +45,8 @@ pub struct ProjectPane {
pub custom_rate: (i64, i64),
/// What the timeline is output in.
pub color_space: ColorSpace,
+ /// What shows where no picture covers the frame.
+ pub canvas: [u8; 3],
}
/// The colour list's rows, in the sheet's order.
@@ -76,6 +80,7 @@ impl ProjectPane {
custom_size: (width, height),
custom_rate: (num, den),
color_space: video.color_space,
+ canvas: video.canvas,
};
}
ProjectMsg::Close => self.open = false,
@@ -105,6 +110,7 @@ impl ProjectPane {
self.color_space =
COLOR_SPACES[(index.max(0) as usize).min(COLOR_SPACES.len() - 1)];
}
+ ProjectMsg::CanvasChanged(canvas) => self.canvas = canvas,
ProjectMsg::Apply => self.apply(studio),
}
}
@@ -127,6 +133,7 @@ impl ProjectPane {
video.rate_num = num;
video.rate_den = den;
video.color_space = sheet.color_space;
+ video.canvas = sheet.canvas;
session.prepare_save((!name.is_empty()).then_some(name.as_str()));
if !name.is_empty() {
studio.project_name = name;
@@ -177,6 +184,7 @@ impl ProjectPane {
.iter()
.position(|space| *space == self.color_space)
.unwrap_or(0) as i32,
+ canvas: slint::Color::from_rgb_u8(self.canvas[0], self.canvas[1], self.canvas[2]),
}
}
}
diff --git a/src/crates/concat/src/panes/start.rs b/src/crates/concat/src/panes/start.rs
index 4ffa304c..c293ccaf 100644
--- a/src/crates/concat/src/panes/start.rs
+++ b/src/crates/concat/src/panes/start.rs
@@ -34,6 +34,8 @@ pub enum StartMsg {
CustomWidth(f32),
CustomHeight(f32),
CustomFps(f32),
+ /// What shows where no picture covers the frame, `[r, g, b]`.
+ CanvasChanged([u8; 3]),
DismissError,
/// Pick where the project folder goes.
Browse,
@@ -134,6 +136,9 @@ pub struct StartPane {
pub custom_size: (u32, u32),
/// The custom rate, as an exact fraction.
pub custom_rate: (i64, i64),
+ /// What shows where no picture covers the frame (#456): black, as
+ /// every project before it had.
+ pub canvas: [u8; 3],
pub busy: bool,
pub error: String,
/// The projects' search, as typed; empty shows them all.
@@ -159,6 +164,7 @@ impl Default for StartPane {
rate: 3,
custom_size: (1920, 1080),
custom_rate: (30, 1),
+ canvas: [0, 0, 0],
busy: false,
error: String::new(),
query: String::new(),
@@ -283,6 +289,7 @@ impl StartPane {
self.custom_size = custom_frame(self.custom_size.0 as f32, height);
}
StartMsg::CustomFps(fps) => self.custom_rate = custom_rate(f64::from(fps)),
+ StartMsg::CanvasChanged(canvas) => self.canvas = canvas,
StartMsg::DismissError => self.error.clear(),
// The picker runs with the studio unborrowed and answers as a
// message of its own; see `host::after_dialog`.
@@ -404,7 +411,7 @@ impl StartPane {
self.error = t("start.chooseWhereProjectFolder");
return;
}
- let opened = projects::create(&self.location, &name, width, height, num, den)
+ let opened = projects::create(&self.location, &name, width, height, num, den, self.canvas)
.and_then(|info| studio.open_project(info));
self.busy = false;
match opened {
@@ -518,6 +525,7 @@ impl StartPane {
size: self.size as i32,
rate: self.rate as i32,
size_readout: format!("{width} x {height}").into(),
+ canvas: slint::Color::from_rgb_u8(self.canvas[0], self.canvas[1], self.canvas[2]),
custom_width: width as f32,
custom_height: height as f32,
custom_fps: fps_of(num, den) as f32,
@@ -588,6 +596,7 @@ mod tests {
fn the_projects_search_and_sort() {
let recent = |name: &str, path: &str| projects::Recent {
info: projects::ProjectInfo {
+ canvas: [0, 0, 0],
path: path.into(),
name: name.into(),
width: 1920,
diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rs
index 01dccd52..ed7c631a 100644
--- a/src/crates/concat/src/studio.rs
+++ b/src/crates/concat/src/studio.rs
@@ -8015,6 +8015,7 @@ impl Studio {
moving: false,
proxy: false,
color_space: self.project().active().video.color_space,
+ canvas: self.project().active().video.canvas,
};
let monitor = self.host.monitor.clone();
let out_dir = project_dir.join("frames");
diff --git a/src/crates/concat/ui/app.slint b/src/crates/concat/ui/app.slint
index 0b2a28a9..a95c7a0d 100644
--- a/src/crates/concat/ui/app.slint
+++ b/src/crates/concat/ui/app.slint
@@ -266,6 +266,7 @@ export component App inherits Window {
callback settings-accent-changed(index: int);
callback settings-accent-custom-changed(colour: color);
callback settings-playhead-changed(colour: color);
+ callback start-canvas-changed(value: color);
callback settings-playhead-reset();
callback settings-scale-changed(index: int);
callback settings-playhead-stops-changed(on: bool);
@@ -413,6 +414,7 @@ export component App inherits Window {
// The window's keyboard, and the thing focus falls back to.
//
+ callback project-canvas-changed(value: color);
// It wraps the content rather than sitting beside it, and both of its jobs
// come out of that:
//
@@ -922,6 +924,7 @@ export component App inherits Window {
data: root.project-sheet;
closed => { root.project-closed(); }
+ canvas-changed(value) => { root.start-canvas-changed(value); }
name-edited(name) => { root.project-name-edited(name); }
size-changed(index) => { root.project-size-changed(index); }
rate-changed(index) => { root.project-rate-changed(index); }
@@ -1006,3 +1009,4 @@ export component App inherits Window {
data: root.toast;
}
}
+ canvas-changed(value) => { root.project-canvas-changed(value); }
diff --git a/src/crates/concat/ui/dialogs/project.slint b/src/crates/concat/ui/dialogs/project.slint
index 56de17df..feeb447c 100644
--- a/src/crates/concat/ui/dialogs/project.slint
+++ b/src/crates/concat/ui/dialogs/project.slint
@@ -7,6 +7,7 @@ import { Glyph } from "../icons.slint";
import { Button, DialogRow, DialogSection, Field, Modal } from "../primitives/modal.slint";
import { Select } from "../primitives/select.slint";
import { NumberField } from "../primitives/number-field.slint";
+import { ColourField } from "../inspector/controls.slint";
// The project sheet: what the Details panel's Modify button opens.
//
@@ -34,6 +35,8 @@ export struct ProjectSheetData {
rate-readout: string,
/// Row in the colour list: SDR, HDR HLG, HDR PQ.
color-space: int,
+ /// What shows where no picture covers the frame (#456).
+ canvas: color,
}
export component ProjectDialog inherits Modal {
@@ -46,6 +49,7 @@ export component ProjectDialog inherits Modal {
callback custom-height-edited(height: float);
callback custom-fps-edited(fps: float);
callback color-space-changed(index: int);
+ callback canvas-changed(value: color);
callback apply();
open: root.data.open;
@@ -186,6 +190,18 @@ export component ProjectDialog inherits Modal {
font-size: Theme.fs-sm;
wrap: word-wrap;
}
+
+ // What shows where no picture covers the frame: the gaps, the
+ // space around a title. The timeline's, like the frame above.
+ DialogRow {
+ label: I18n.t("start.background");
+ ColourField {
+ padding-left: 0;
+ padding-right: 0;
+ value: root.data.canvas;
+ changed(value) => { root.canvas-changed(value); }
+ }
+ }
}
Rectangle {
diff --git a/src/crates/concat/ui/start.slint b/src/crates/concat/ui/start.slint
index 2feb16ea..b6b81c5a 100644
--- a/src/crates/concat/ui/start.slint
+++ b/src/crates/concat/ui/start.slint
@@ -11,6 +11,7 @@ import { Tip } from "primitives/tooltip.slint";
import { Focus } from "util.slint";
import { NumberField } from "primitives/number-field.slint";
import { Select } from "primitives/select.slint";
+import { ColourField } from "inspector/controls.slint";
import { SegmentedControl } from "primitives/segmented-control.slint";
// The launch screen: the app's home, and the window's own ground under all
@@ -139,6 +140,8 @@ export struct StartData {
/// "30/1 fps" — the exact fraction, because 29.97 is 30000/1001 and
/// never anything else.
rate-readout: string,
+ /// What shows where no picture covers the frame (#456).
+ canvas: color,
/// Creating. The button says so and everything is refused meanwhile.
busy: bool,
/// Non-empty puts up the notice above the button.
@@ -2155,6 +2158,7 @@ export component NewProjectDialog inherits Modal {
callback custom-width-edited(width: float);
callback custom-height-edited(height: float);
callback custom-fps-edited(fps: float);
+ callback canvas-changed(value: color);
callback create();
callback dismiss-error();
@@ -2394,7 +2398,6 @@ export component NewProjectDialog inherits Modal {
FormRow {
label: I18n.upper("common.frameRate");
- last: true;
stacked: root.narrow;
VerticalLayout {
@@ -2448,6 +2451,51 @@ export component NewProjectDialog inherits Modal {
}
}
+ // What shows where no picture covers the frame - the gaps, the
+ // space around a title. Four to pick at a press - black, white and
+ // the two keying colours, for a picture that is cut out later - and
+ // any other typed or picked on the right. Transparent comes with
+ // an export that keeps it (#456).
+ FormRow {
+ label: I18n.upper("start.background");
+ last: true;
+ stacked: root.narrow;
+
+ HorizontalLayout {
+ spacing: 8px;
+
+ for preset in [#000000, #ffffff, #00b140, #0047bb]: VerticalLayout {
+ alignment: center;
+
+ Rectangle {
+ width: 24px;
+ height: 24px;
+ border-radius: Theme.r-sm;
+ border-width: root.data.canvas == preset ? 2px : 1px;
+ border-color: root.data.canvas == preset ? Theme.accent
+ : pick.has-hover ? Theme.line-strong : Theme.line;
+ background: preset;
+
+ pick := TouchArea {
+ mouse-cursor: pointer;
+ enabled: !root.data.busy;
+ clicked => { root.canvas-changed(preset); }
+ }
+ }
+ }
+
+ Rectangle { horizontal-stretch: 1; }
+
+ ColourField {
+ horizontal-stretch: 0;
+ padding-left: 0;
+ padding-right: 0;
+ value: root.data.canvas;
+ changed(value) => { root.canvas-changed(value); }
+ }
+ }
+ }
+
// The notice, above the button, wrapping to as many lines as the
// error takes: an elided error is half an error, and on a phone
// that is most of it.