Skip to content

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

feat(scopes): waveform, RGB parade, vectorscope and histogram, counted on the GPU from the working space, in a pane of their own

Jareer00a9931caeab
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index c3344305..a71e3373 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -122,6 +122,12 @@ flowchart LR
the MaxCLL and MaxFALL measured as it is written. A clip with an FFmpeg
chain or a cutout keeps the eight-bit tone map in the decoder, and an HDR
export leaves an old package's FFmpeg chain out.
+- The scopes (`concat-render/src/scopes.rs`) count the monitor's canvas in
+ a compute pass as it is drawn (`WgpuCompositor::render_texture_scoped`),
+ its light before anything is clipped: the display level on an SDR
+ timeline, nits on PQ's scale on an HDR one. The counts come back without
+ the window waiting (`take_scope`, polled), are drawn on the CPU, and are
+ shown in the Scopes pane (`concat/ui/workspace/scopes-pane.slint`).
Effect packages written for
gamma-encoded `0..1` see that through the prelude's `legacy_in` and
`legacy_out` (`concat-effects/src/shader.rs`) until the GPU-only effects
diff --git a/src/crates/concat-host/src/preview.rs b/src/crates/concat-host/src/preview.rs
index f3a1dab7..ab288ad7 100644
--- a/src/crates/concat-host/src/preview.rs
+++ b/src/crates/concat-host/src/preview.rs
@@ -69,6 +69,11 @@ struct PlanEntry {
#[cfg(feature = "gpu")]
pub use concat_render::wgpu;
+/// The scopes the monitor counts as it draws; see
+/// [`Monitor::texture_of_scoped`].
+#[cfg(feature = "gpu")]
+pub use concat_render::scopes;
+
impl Default for Monitor {
fn default() -> Self {
Self::new()
@@ -184,6 +189,20 @@ impl Monitor {
&self,
sources: &concat_export::PreviewSources,
spec: FrameSpec,
+ ) -> Result<wgpu::Texture, String> {
+ self.texture_of_scoped(sources, spec, None)
+ }
+
+ /// [`Monitor::texture_of`], with `scope` counted from the frame's light
+ /// as it is drawn - a packaged transition's frame goes uncounted - for
+ /// [`Monitor::take_scope`] to hand over once its counts are back. The
+ /// same one thread, for the same reason.
+ #[cfg(feature = "gpu")]
+ pub fn texture_of_scoped(
+ &self,
+ sources: &concat_export::PreviewSources,
+ spec: FrameSpec,
+ scope: Option<concat_render::ScopeKind>,
) -> Result<wgpu::Texture, String> {
let gpu = self
.gpu
@@ -205,14 +224,22 @@ impl Monitor {
concat_render::detached_clip(),
Arc::new(frame),
));
+ plan.output = sources.plan().output;
return gpu
- .render_texture(&plan)
+ .render_texture_scoped(&plan, scope)
.ok_or_else(|| "the GPU device was lost".to_owned());
}
- gpu.render_texture(sources.plan())
+ gpu.render_texture_scoped(sources.plan(), scope)
.ok_or_else(|| "the GPU device was lost".to_owned())
}
+ /// The last scope [`Monitor::texture_of_scoped`] counted, once its
+ /// counts are back; never waits. From the device's thread.
+ #[cfg(feature = "gpu")]
+ pub fn take_scope(&self) -> Option<concat_render::ScopeData> {
+ self.gpu.as_ref()?.lock().ok()?.take_scope()
+ }
+
/// The plan for this clip list at this size and rate: the kept one
/// when it was built for the same list - the same allocation, or an
/// equal one - and a fresh one otherwise, kept in its place.
diff --git a/src/crates/concat-render/src/gpu.rs b/src/crates/concat-render/src/gpu.rs
index eb4f3fc7..b2362010 100644
--- a/src/crates/concat-render/src/gpu.rs
+++ b/src/crates/concat-render/src/gpu.rs
@@ -29,6 +29,7 @@
//! monitor with no copy anywhere.
use std::collections::HashMap;
+use std::sync::Arc;
use concat_core::frame::Frame;
use concat_core::shader::{Lut, RevealMap, ShaderPass, TransitionPass};
@@ -310,6 +311,102 @@ fn to_sdr(nits: vec3<f32>) -> vec3<f32> {
}
"#;
+/// The scopes' counting (see `crate::scopes`): every pixel of the working
+/// canvas, its light as it stands, added to the bins of the scope asked
+/// for. A level is the display encoding on an SDR timeline and PQ's signal
+/// for the nits on an HDR one; `TONE_MAP` is appended for `pq_signal`.
+const SCOPE_SHADER: &str = r#"
+struct Scope {
+ kind: u32,
+ hdr: u32,
+ width: u32,
+ height: u32,
+}
+
+@group(0) @binding(0) var picture: texture_2d<f32>;
+@group(0) @binding(1) var<storage, read_write> bins: array<atomic<u32>>;
+@group(0) @binding(2) var<uniform> scope: Scope;
+
+const COLUMNS: u32 = 256u;
+const LEVELS: u32 = 256u;
+const LUMA: vec3<f32> = vec3<f32>(0.2126, 0.7152, 0.0722);
+
+fn encoded(light: vec3<f32>) -> vec3<f32> {
+ if (scope.hdr == 1u) {
+ let nits = max(light, vec3<f32>(0.0)) * 203.0;
+ return vec3<f32>(pq_signal(nits.r), pq_signal(nits.g), pq_signal(nits.b));
+ }
+ return pow(clamp(light, vec3<f32>(0.0), vec3<f32>(1.0)), vec3<f32>(1.0 / 2.4));
+}
+
+// Luma as the scale reads it: of the encoded values on SDR (Y'), of the
+// light itself in nits on HDR.
+fn luma_of(light: vec3<f32>, e: vec3<f32>) -> f32 {
+ if (scope.hdr == 1u) {
+ return pq_signal(max(dot(light, LUMA), 0.0) * 203.0);
+ }
+ return dot(e, LUMA);
+}
+
+fn level_of(value: f32) -> u32 {
+ return min(u32(clamp(value, 0.0, 1.0) * f32(LEVELS - 1u) + 0.5), LEVELS - 1u);
+}
+
+@compute @workgroup_size(16, 16)
+fn scope_main(@builtin(global_invocation_id) id: vec3<u32>) {
+ if (id.x >= scope.width || id.y >= scope.height) {
+ return;
+ }
+ let light = textureLoad(picture, vec2<i32>(id.xy), 0).rgb;
+ let e = encoded(light);
+ let column = min(id.x * COLUMNS / scope.width, COLUMNS - 1u);
+ switch scope.kind {
+ case 0u: {
+ atomicAdd(&bins[column * LEVELS + level_of(luma_of(light, e))], 1u);
+ }
+ case 1u: {
+ atomicAdd(&bins[column * LEVELS + level_of(e.r)], 1u);
+ atomicAdd(&bins[(COLUMNS + column) * LEVELS + level_of(e.g)], 1u);
+ atomicAdd(&bins[(2u * COLUMNS + column) * LEVELS + level_of(e.b)], 1u);
+ }
+ case 2u: {
+ let y = dot(e, LUMA);
+ let cb = (e.b - y) / 1.8556;
+ let cr = (e.r - y) / 1.5748;
+ atomicAdd(&bins[level_of(0.5 - cr) * LEVELS + level_of(cb + 0.5)], 1u);
+ }
+ default: {
+ atomicAdd(&bins[level_of(e.r)], 1u);
+ atomicAdd(&bins[LEVELS + level_of(e.g)], 1u);
+ atomicAdd(&bins[2u * LEVELS + level_of(e.b)], 1u);
+ atomicAdd(&bins[3u * LEVELS + level_of(luma_of(light, e))], 1u);
+ }
+ }
+}
+"#;
+
+/// The scopes' pipeline and buffers, made on first use: the bins the
+/// shader counts into, and a buffer they are copied to and read back from
+/// without the window waiting on it.
+struct ScopeGpu {
+ pipeline: wgpu::ComputePipeline,
+ layout: wgpu::BindGroupLayout,
+ bins: wgpu::Buffer,
+ readback: wgpu::Buffer,
+ uniform: wgpu::Buffer,
+ /// A count on its way back.
+ pending: Option<PendingScope>,
+}
+
+/// A scope's counts on their way back: what they are of, and whether they
+/// have landed in the readback buffer.
+struct PendingScope {
+ kind: crate::scopes::ScopeKind,
+ hdr: bool,
+ size: (u32, u32),
+ landed: Arc<std::sync::atomic::AtomicBool>,
+}
+
/// A deep frame (sixteen bits a channel, Rec. 2020, its source's own signal)
/// copied into the working space: the upload of an HDR or wide-gamut clip.
/// One entry a signal (`concat_core::frame::Signal`): the transfer undone
@@ -530,6 +627,8 @@ pub struct WgpuCompositor {
/// The readback target an HDR frame is resolved into: sixteen-bit
/// integers, eight bytes a pixel.
deep_target: Option<Target>,
+ /// The scopes' counting, made the first time a scope is asked for.
+ scope: Option<ScopeGpu>,
/// The eight-bit textures frames are written into on their way to the
/// pool, one a size, each with its bind group.
staging: HashMap<(u32, u32), (wgpu::Texture, wgpu::BindGroup)>,
@@ -1032,6 +1131,7 @@ impl WgpuCompositor {
hdr_pipelines,
deliver_hdr: false,
deep_target: None,
+ scope: None,
staging: HashMap::new(),
deep_pipelines,
deep_layout,
@@ -1415,6 +1515,18 @@ impl WgpuCompositor {
/// is dead; the caller then falls back to [`Compositor::render`] on a
/// CPU compositor.
pub fn render_texture(&mut self, plan: &FramePlan) -> Option<wgpu::Texture> {
+ self.render_texture_scoped(plan, None)
+ }
+
+ /// [`WgpuCompositor::render_texture`], and `scope` counted from the
+ /// frame's light in the same submission - unless the last count is
+ /// still on its way back, when this frame goes uncounted rather than
+ /// wait for it. [`WgpuCompositor::take_scope`] hands the counts over.
+ pub fn render_texture_scoped(
+ &mut self,
+ plan: &FramePlan,
+ scope: Option<crate::scopes::ScopeKind>,
+ ) -> Option<wgpu::Texture> {
if self.dead {
return None;
}
@@ -1425,11 +1537,215 @@ impl WgpuCompositor {
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
let mut encoder = self.encode(&canvas_view, &canvas_texture, &draws, wgpu::Color::BLACK);
self.resolve(&mut encoder, (plan.width, plan.height), canvas, &view);
+ let counted = scope.and_then(|kind| {
+ self.count_scope(&mut encoder, &canvas_view, kind, (plan.width, plan.height))
+ });
self.queue.submit([encoder.finish()]);
+ if let Some(size) = counted {
+ self.read_scope(size);
+ }
self.retire();
Some(texture)
}
+ /// Records `kind` counted over `canvas`, `size` pixels, and its copy
+ /// into the readback buffer: the size of the copy when it was recorded,
+ /// none while a count is still on its way back.
+ fn count_scope(
+ &mut self,
+ encoder: &mut wgpu::CommandEncoder,
+ canvas: &wgpu::TextureView,
+ kind: crate::scopes::ScopeKind,
+ size: (u32, u32),
+ ) -> Option<u64> {
+ if self
+ .scope
+ .as_ref()
+ .is_some_and(|scope| scope.pending.is_some())
+ {
+ return None;
+ }
+ let hdr = self.output != concat_core::frame::Signal::Sdr;
+ let scope = self.scope.get_or_insert_with(|| {
+ let largest = (crate::scopes::ScopeKind::Parade.bins() * 4) as u64;
+ let module = self
+ .device
+ .create_shader_module(wgpu::ShaderModuleDescriptor {
+ label: Some("concat scopes"),
+ source: wgpu::ShaderSource::Wgsl(format!("{SCOPE_SHADER}{TONE_MAP}").into()),
+ });
+ let layout = self
+ .device
+ .create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
+ label: Some("concat scopes"),
+ entries: &[
+ wgpu::BindGroupLayoutEntry {
+ binding: 0,
+ visibility: wgpu::ShaderStages::COMPUTE,
+ ty: wgpu::BindingType::Texture {
+ sample_type: wgpu::TextureSampleType::Float { filterable: false },
+ view_dimension: wgpu::TextureViewDimension::D2,
+ multisampled: false,
+ },
+ count: None,
+ },
+ wgpu::BindGroupLayoutEntry {
+ binding: 1,
+ visibility: wgpu::ShaderStages::COMPUTE,
+ ty: wgpu::BindingType::Buffer {
+ ty: wgpu::BufferBindingType::Storage { read_only: false },
+ has_dynamic_offset: false,
+ min_binding_size: None,
+ },
+ count: None,
+ },
+ wgpu::BindGroupLayoutEntry {
+ binding: 2,
+ visibility: wgpu::ShaderStages::COMPUTE,
+ ty: wgpu::BindingType::Buffer {
+ ty: wgpu::BufferBindingType::Uniform,
+ has_dynamic_offset: false,
+ min_binding_size: None,
+ },
+ count: None,
+ },
+ ],
+ });
+ let pipeline_layout =
+ self.device
+ .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+ label: Some("concat scopes"),
+ bind_group_layouts: &[Some(&layout)],
+ immediate_size: 0,
+ });
+ let pipeline = self
+ .device
+ .create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
+ label: Some("concat scopes"),
+ layout: Some(&pipeline_layout),
+ module: &module,
+ entry_point: Some("scope_main"),
+ compilation_options: Default::default(),
+ cache: None,
+ });
+ let buffer = |label, usage| {
+ self.device.create_buffer(&wgpu::BufferDescriptor {
+ label: Some(label),
+ size: largest,
+ usage,
+ mapped_at_creation: false,
+ })
+ };
+ ScopeGpu {
+ pipeline,
+ layout,
+ bins: buffer(
+ "concat scope bins",
+ wgpu::BufferUsages::STORAGE
+ | wgpu::BufferUsages::COPY_SRC
+ | wgpu::BufferUsages::COPY_DST,
+ ),
+ readback: buffer(
+ "concat scope readback",
+ wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST,
+ ),
+ uniform: self.device.create_buffer(&wgpu::BufferDescriptor {
+ label: Some("concat scope"),
+ size: 16,
+ usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
+ mapped_at_creation: false,
+ }),
+ pending: None,
+ }
+ });
+ let bytes = (kind.bins() * 4) as u64;
+ let words = [kind.index(), u32::from(hdr), size.0, size.1];
+ let uniform: Vec<u8> = words.iter().flat_map(|word| word.to_le_bytes()).collect();
+ self.queue.write_buffer(&scope.uniform, 0, &uniform);
+ let group = self.device.create_bind_group(&wgpu::BindGroupDescriptor {
+ label: Some("concat scopes"),
+ layout: &scope.layout,
+ entries: &[
+ wgpu::BindGroupEntry {
+ binding: 0,
+ resource: wgpu::BindingResource::TextureView(canvas),
+ },
+ wgpu::BindGroupEntry {
+ binding: 1,
+ resource: scope.bins.as_entire_binding(),
+ },
+ wgpu::BindGroupEntry {
+ binding: 2,
+ resource: scope.uniform.as_entire_binding(),
+ },
+ ],
+ });
+ encoder.clear_buffer(&scope.bins, 0, Some(bytes));
+ {
+ let mut pass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor {
+ label: Some("concat scopes"),
+ timestamp_writes: None,
+ });
+ pass.set_pipeline(&scope.pipeline);
+ pass.set_bind_group(0, &group, &[]);
+ pass.dispatch_workgroups(size.0.div_ceil(16), size.1.div_ceil(16), 1);
+ }
+ encoder.copy_buffer_to_buffer(&scope.bins, 0, &scope.readback, 0, bytes);
+ scope.pending = Some(PendingScope {
+ kind,
+ hdr,
+ size,
+ landed: Arc::new(std::sync::atomic::AtomicBool::new(false)),
+ });
+ Some(bytes)
+ }
+
+ /// Asks for the counts just submitted to be mapped, without waiting.
+ fn read_scope(&mut self, bytes: u64) {
+ let Some(scope) = self.scope.as_ref() else {
+ return;
+ };
+ let Some(pending) = scope.pending.as_ref() else {
+ return;
+ };
+ let landed = Arc::clone(&pending.landed);
+ scope
+ .readback
+ .slice(..bytes)
+ .map_async(wgpu::MapMode::Read, move |result| {
+ if result.is_ok() {
+ landed.store(true, std::sync::atomic::Ordering::Release);
+ }
+ });
+ }
+
+ /// The last scope counted, once its counts have come back; none while
+ /// they are on their way, or when nothing was asked for. Never waits.
+ pub fn take_scope(&mut self) -> Option<crate::scopes::ScopeData> {
+ let _ = self.device.poll(wgpu::PollType::Poll);
+ let scope = self.scope.as_mut()?;
+ let pending = scope.pending.as_ref()?;
+ if !pending.landed.load(std::sync::atomic::Ordering::Acquire) {
+ return None;
+ }
+ let (kind, hdr, size) = (pending.kind, pending.hdr, pending.size);
+ let bytes = (kind.bins() * 4) as u64;
+ let counts = {
+ let data = scope.readback.slice(..bytes).get_mapped_range().ok()?;
+ data.chunks_exact(4)
+ .map(|word| u32::from_le_bytes([word[0], word[1], word[2], word[3]]))
+ .collect()
+ };
+ scope.readback.unmap();
+ scope.pending = None;
+ Some(crate::scopes::ScopeData {
+ kind,
+ hdr,
+ size,
+ counts,
+ })
+ }
+
/// Runs `pass` once over a sixteen-pixel-square picture and waits at
/// most `timeout` for the device: what a community package has to
/// survive before it is enabled. A pass the driver refuses is an
diff --git a/src/crates/concat-render/src/gpu/tests.rs b/src/crates/concat-render/src/gpu/tests.rs
index 43b063d9..27e10549 100644
--- a/src/crates/concat-render/src/gpu/tests.rs
+++ b/src/crates/concat-render/src/gpu/tests.rs
@@ -1028,6 +1028,94 @@ fn an_hdr_timeline_is_delivered_as_its_signal() {
assert_eq!(sdr.depth(), Depth::Eight, "an SDR timeline stays SDR");
}
+/// `kind` counted over `plan` as the monitor draws it, once the counts
+/// have come back.
+fn scoped(gpu: &mut WgpuCompositor, plan: &FramePlan, kind: crate::ScopeKind) -> crate::ScopeData {
+ gpu.render_texture_scoped(plan, Some(kind)).expect("draws");
+ for _ in 0..200 {
+ if let Some(data) = gpu.take_scope() {
+ return data;
+ }
+ let _ = gpu.device.poll(wgpu::PollType::wait_indefinitely());
+ }
+ panic!("the scope never came back");
+}
+
+/// The scopes count the monitor's picture where it is drawn: a flat grey
+/// is one level in every column it covers, at its display level on an SDR
+/// timeline; an HDR timeline's HLG peak sits at 1000 nits on PQ's scale;
+/// a histogram counts every pixel once a channel; pure red falls where the
+/// vectorscope's red target is.
+#[test]
+fn the_scopes_count_the_picture() {
+ use crate::ScopeKind;
+ use crate::scopes::{COLUMNS, LEVELS};
+ use concat_core::frame::Signal;
+ let Some(mut gpu) = gpu() else { return };
+ let (width, height) = (64u32, 32u32);
+ let grey = plan(
+ width,
+ height,
+ vec![layer(solid(width, height, [128, 128, 128, 255]))],
+ );
+ let waveform = scoped(&mut gpu, &grey, ScopeKind::Waveform);
+ assert_eq!(waveform.counts.iter().sum::<u32>(), width * height);
+ let level = |counts: &[u32]| counts.iter().position(|count| *count > 0);
+ for column in (0..COLUMNS).step_by((COLUMNS / width) as usize) {
+ let start = (column * LEVELS) as usize;
+ assert_eq!(
+ level(&waveform.counts[start..start + LEVELS as usize]),
+ Some(128),
+ "column {column}"
+ );
+ assert_eq!(waveform.counts[start + 128], height);
+ }
+
+ let peak = FramePlan {
+ output: Signal::Hlg,
+ ..plan(
+ width,
+ height,
+ vec![layer(deep(width, height, 1.0, Signal::Hlg))],
+ )
+ };
+ let hdr = scoped(&mut gpu, &peak, ScopeKind::Waveform);
+ assert!(hdr.hdr);
+ let at = level(&hdr.counts[..LEVELS as usize]).expect("counted");
+ let want = (crate::scopes::pq(1000.0) * 255.0).round() as usize;
+ assert!(
+ at.abs_diff(want) <= 1,
+ "the HLG peak at level {at}, not {want}"
+ );
+
+ let histogram = scoped(&mut gpu, &grey, ScopeKind::Histogram);
+ for channel in 0..4 {
+ let start = channel * LEVELS as usize;
+ assert_eq!(
+ histogram.counts[start..start + LEVELS as usize]
+ .iter()
+ .sum::<u32>(),
+ width * height,
+ "channel {channel}"
+ );
+ }
+
+ let red = plan(
+ width,
+ height,
+ vec![layer(solid(width, height, [255, 0, 0, 255]))],
+ );
+ let vectorscope = scoped(&mut gpu, &red, ScopeKind::Vectorscope);
+ let at = vectorscope
+ .counts
+ .iter()
+ .position(|count| *count > 0)
+ .expect("counted");
+ let cb = (0.0 - 0.2126) / 1.8556 + 0.5f32;
+ assert_eq!(at as u32 % LEVELS, (cb * 255.0 + 0.5) as u32, "Cb of red");
+ assert_eq!(at as u32 / LEVELS, 0, "Cr of red, at the top");
+}
+
/// A pass of a format 2 package - the scene-linear contract - with `body`
/// as its shader and no knobs, at `intensity`.
fn scene_linear(id: &str, body: &str, intensity: f32) -> ShaderPass {
diff --git a/src/crates/concat-render/src/lib.rs b/src/crates/concat-render/src/lib.rs
index b197cd2a..be0d3f5b 100644
--- a/src/crates/concat-render/src/lib.rs
+++ b/src/crates/concat-render/src/lib.rs
@@ -26,6 +26,7 @@ pub mod metrics;
pub mod plan;
#[cfg(test)]
mod reference;
+pub mod scopes;
#[cfg(test)]
mod transitions;
@@ -38,5 +39,6 @@ pub use plan::{
};
#[cfg(test)]
pub(crate) use reference::CpuCompositor;
+pub use scopes::{ScopeData, ScopeKind};
/// The wgpu the compositor is built on, for callers that share its device.
pub use wgpu;
diff --git a/src/crates/concat-render/src/scopes.rs b/src/crates/concat-render/src/scopes.rs
new file mode 100644
index 00000000..00d5e90a
--- /dev/null
+++ b/src/crates/concat-render/src/scopes.rs
@@ -0,0 +1,363 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// SPDX-FileCopyrightText: 2026 Jareer and Concat contributors
+
+//! The scopes: what the monitor's picture holds, counted on the GPU from
+//! the working space - its light before anything is clipped - and drawn
+//! here from the counts.
+//!
+//! On an SDR timeline a level is the display encoding, 0 to 100 %, as a
+//! Rec. 709 waveform reads. On an HDR one it is the light in nits on PQ's
+//! scale, so 100 nits, SDR white at 203 and a 1000-nit highlight each have
+//! their place however far apart they are (`WgpuCompositor::render_texture_scoped`
+//! counts; [`ScopeData::draw`] draws).
+
+/// Which scope.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum ScopeKind {
+ /// Luma across the picture: a column of levels for each column of it.
+ Waveform,
+ /// Red, green and blue as three waveforms side by side.
+ Parade,
+ /// The colour of every pixel as a point on the Cb-Cr plane.
+ Vectorscope,
+ /// How many pixels hold each level, a curve a channel.
+ Histogram,
+}
+
+/// The levels a waveform, a parade or a histogram tells apart, and the side
+/// of the vectorscope's plane.
+pub const LEVELS: u32 = 256;
+
+/// The columns a waveform counts the picture in, and a parade each channel.
+pub const COLUMNS: u32 = 256;
+
+impl ScopeKind {
+ /// Every kind, in the order the pane offers them.
+ pub const ALL: [ScopeKind; 4] = [
+ ScopeKind::Waveform,
+ ScopeKind::Parade,
+ ScopeKind::Vectorscope,
+ ScopeKind::Histogram,
+ ];
+
+ /// How many counts the scope takes.
+ pub const fn bins(self) -> usize {
+ (match self {
+ ScopeKind::Waveform => COLUMNS * LEVELS,
+ ScopeKind::Parade => 3 * COLUMNS * LEVELS,
+ ScopeKind::Vectorscope => LEVELS * LEVELS,
+ ScopeKind::Histogram => 4 * LEVELS,
+ }) as usize
+ }
+
+ /// The number the counting shader switches on.
+ pub(crate) const fn index(self) -> u32 {
+ match self {
+ ScopeKind::Waveform => 0,
+ ScopeKind::Parade => 1,
+ ScopeKind::Vectorscope => 2,
+ ScopeKind::Histogram => 3,
+ }
+ }
+}
+
+/// One frame's counts for a scope.
+#[derive(Clone, Debug, PartialEq)]
+pub struct ScopeData {
+ /// Which scope the counts are for.
+ pub kind: ScopeKind,
+ /// The timeline is HDR: a level is nits on PQ's scale, not the
+ /// display encoding.
+ pub hdr: bool,
+ /// The picture counted, in pixels.
+ pub size: (u32, u32),
+ /// The counts, laid out as the kind says: a waveform column by column,
+ /// each `LEVELS` from black up; a parade the same for red, green and
+ /// blue in turn; a vectorscope row by row from Cr's top; a histogram
+ /// red, green, blue and luma.
+ pub counts: Vec<u32>,
+}
+
+impl ScopeData {
+ /// The scope as a picture: its width, its height, and RGBA, eight bits
+ /// a channel, opaque, black where nothing fell.
+ pub fn draw(&self) -> (u32, u32, Vec<u8>) {
+ let pixels = (self.size.0 * self.size.1).max(1) as f32;
+ match self.kind {
+ ScopeKind::Waveform => {
+ let mut image = Image::new(COLUMNS, LEVELS);
+ self.traces(&mut image, 0, 0, [0.62, 1.0, 0.70], pixels);
+ image.finish()
+ }
+ ScopeKind::Parade => {
+ let mut image = Image::new(3 * COLUMNS, LEVELS);
+ for (channel, tint) in [[1.0, 0.36, 0.36], [0.36, 1.0, 0.46], [0.42, 0.56, 1.0]]
+ .into_iter()
+ .enumerate()
+ {
+ self.traces(
+ &mut image,
+ channel * (COLUMNS * LEVELS) as usize,
+ channel as u32 * COLUMNS,
+ tint,
+ pixels,
+ );
+ }
+ image.finish()
+ }
+ ScopeKind::Vectorscope => {
+ let mut image = Image::new(LEVELS, LEVELS);
+ // A point the square root of its share: a field of one
+ // colour is a bright spot, a scatter of many still shows.
+ let scale = (LEVELS * LEVELS) as f32 / 256.0 / pixels;
+ for (at, count) in self.counts.iter().enumerate() {
+ let level = ((*count as f32 * scale).sqrt()).min(1.0);
+ let (x, y) = (at as u32 % LEVELS, at as u32 / LEVELS);
+ image.add(x, y, [level * 0.9, level, level * 0.9]);
+ }
+ for target in TARGETS {
+ let (x, y) = plane(target);
+ image.square(x, y, 3, [0.55, 0.42, 0.20]);
+ }
+ image.cross(LEVELS / 2, LEVELS / 2, [0.35, 0.35, 0.35]);
+ image.finish()
+ }
+ ScopeKind::Histogram => {
+ const HEIGHT: u32 = 128;
+ let mut image = Image::new(LEVELS, HEIGHT);
+ // Scaled to the tallest bar short of the two ends, where a
+ // clipped or a black picture piles up and would flatten the
+ // rest.
+ let tallest = (0..4)
+ .flat_map(|channel| {
+ let start = channel * LEVELS as usize;
+ self.counts[start + 1..start + LEVELS as usize - 1]
+ .iter()
+ .copied()
+ })
+ .max()
+ .unwrap_or(0)
+ .max(1) as f32;
+ for (channel, tint) in [[0.9, 0.25, 0.25], [0.25, 0.85, 0.35], [0.30, 0.45, 1.0]]
+ .into_iter()
+ .enumerate()
+ {
+ for level in 0..LEVELS {
+ let count = self.counts[channel * LEVELS as usize + level as usize];
+ let bar = ((count as f32 / tallest).min(1.0) * HEIGHT as f32) as u32;
+ for y in HEIGHT - bar..HEIGHT {
+ image.add(level, y, tint.map(|c| c * 0.6));
+ }
+ }
+ }
+ let mut previous: Option<u32> = None;
+ for level in 0..LEVELS {
+ let count = self.counts[3 * LEVELS as usize + level as usize];
+ let top = HEIGHT
+ - 1
+ - ((count as f32 / tallest).min(1.0) * (HEIGHT - 1) as f32) as u32;
+ let from = previous.unwrap_or(top);
+ for y in from.min(top)..=from.max(top) {
+ image.set(level, y, [0.9, 0.9, 0.9]);
+ }
+ previous = Some(top);
+ }
+ image.finish()
+ }
+ }
+ }
+
+ /// A waveform's columns from `start` in the counts, drawn from `left`
+ /// in the image in `tint`: each level as bright as the square root of
+ /// the share of its column it holds.
+ fn traces(&self, image: &mut Image, start: usize, left: u32, tint: [f32; 3], pixels: f32) {
+ let per_column = (pixels / COLUMNS as f32).max(1.0);
+ let scale = LEVELS as f32 / 24.0 / per_column;
+ for column in 0..COLUMNS {
+ for level in 0..LEVELS {
+ let count = self.counts[start + (column * LEVELS + level) as usize];
+ if count == 0 {
+ continue;
+ }
+ let bright = ((count as f32 * scale).sqrt()).clamp(0.12, 1.0);
+ image.add(left + column, LEVELS - 1 - level, tint.map(|c| c * bright));
+ }
+ }
+ }
+}
+
+/// The colours of 75 % bars, which a vectorscope's targets mark: red,
+/// magenta, blue, cyan, green, yellow, as display-encoded RGB.
+const TARGETS: [[f32; 3]; 6] = [
+ [0.75, 0.0, 0.0],
+ [0.75, 0.0, 0.75],
+ [0.0, 0.0, 0.75],
+ [0.0, 0.75, 0.75],
+ [0.0, 0.75, 0.0],
+ [0.75, 0.75, 0.0],
+];
+
+/// Where an encoded colour falls on the vectorscope's plane, as the
+/// counting shader places it.
+fn plane(rgb: [f32; 3]) -> (u32, u32) {
+ let y = 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2];
+ let cb = (rgb[2] - y) / 1.8556;
+ let cr = (rgb[0] - y) / 1.5748;
+ (level_of(cb + 0.5), level_of(0.5 - cr))
+}
+
+/// The level a value `0..1` counts under, as the shader rounds it.
+fn level_of(value: f32) -> u32 {
+ ((value.clamp(0.0, 1.0) * (LEVELS - 1) as f32 + 0.5) as u32).min(LEVELS - 1)
+}
+
+/// SMPTE ST 2084's signal for `nits`: where a level sits on an HDR scope.
+pub fn pq(nits: f64) -> f64 {
+ let (m1, m2) = (0.159_301_757_812_5, 78.843_75);
+ let (c1, c2, c3) = (0.835_937_5, 18.851_562_5, 18.687_5);
+ let y = (nits / 10_000.0).clamp(0.0, 1.0).powf(m1);
+ ((c1 + c2 * y) / (1.0 + c3 * y)).powf(m2)
+}
+
+/// The scale's marks: where each sits, `0..1` from the bottom of a
+/// waveform or a parade or from the left of a histogram, and what it
+/// reads - a share of the display level on an SDR timeline, nits on an
+/// HDR one. None on a vectorscope, whose targets are drawn in it.
+pub fn marks(kind: ScopeKind, hdr: bool) -> Vec<(f32, String)> {
+ if kind == ScopeKind::Vectorscope {
+ return Vec::new();
+ }
+ if hdr {
+ [0.0, 1.0, 10.0, 100.0, 203.0, 1000.0, 4000.0]
+ .into_iter()
+ .map(|nits| (pq(nits) as f32, format!("{nits}")))
+ .collect()
+ } else {
+ [0, 25, 50, 75, 100]
+ .into_iter()
+ .map(|share| (share as f32 / 100.0, format!("{share}")))
+ .collect()
+ }
+}
+
+/// An RGB picture being drawn, in floats, added to where traces cross.
+struct Image {
+ width: u32,
+ height: u32,
+ pixels: Vec<[f32; 3]>,
+}
+
+impl Image {
+ fn new(width: u32, height: u32) -> Self {
+ Image {
+ width,
+ height,
+ pixels: vec![[0.0; 3]; (width * height) as usize],
+ }
+ }
+
+ fn add(&mut self, x: u32, y: u32, rgb: [f32; 3]) {
+ if x < self.width && y < self.height {
+ let pixel = &mut self.pixels[(y * self.width + x) as usize];
+ for (into, value) in pixel.iter_mut().zip(rgb) {
+ *into += value;
+ }
+ }
+ }
+
+ fn set(&mut self, x: u32, y: u32, rgb: [f32; 3]) {
+ if x < self.width && y < self.height {
+ self.pixels[(y * self.width + x) as usize] = rgb;
+ }
+ }
+
+ /// The outline of a square `2 * half + 1` across about `(x, y)`.
+ fn square(&mut self, x: u32, y: u32, half: u32, rgb: [f32; 3]) {
+ let (left, right) = (x.saturating_sub(half), x + half);
+ let (top, bottom) = (y.saturating_sub(half), y + half);
+ for across in left..=right {
+ self.add(across, top, rgb);
+ self.add(across, bottom, rgb);
+ }
+ for down in top..=bottom {
+ self.add(left, down, rgb);
+ self.add(right, down, rgb);
+ }
+ }
+
+ /// A small cross at `(x, y)`: the middle of the plane, colour none.
+ fn cross(&mut self, x: u32, y: u32, rgb: [f32; 3]) {
+ for offset in 0..9 {
+ self.add(x + offset - 4, y, rgb);
+ self.add(x, y + offset - 4, rgb);
+ }
+ }
+
+ fn finish(self) -> (u32, u32, Vec<u8>) {
+ let bytes = self
+ .pixels
+ .iter()
+ .flat_map(|[r, g, b]| {
+ let byte = |value: f32| (value.clamp(0.0, 1.0) * 255.0).round() as u8;
+ [byte(*r), byte(*g), byte(*b), 255]
+ })
+ .collect();
+ (self.width, self.height, bytes)
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// A waveform of a flat picture is one line across at its level; a
+ /// parade is three; every kind draws at its own size, opaque.
+ #[test]
+ fn a_flat_picture_draws_a_line() {
+ let mut counts = vec![0u32; ScopeKind::Waveform.bins()];
+ for column in 0..COLUMNS {
+ counts[(column * LEVELS + 128) as usize] = 100;
+ }
+ let waveform = ScopeData {
+ kind: ScopeKind::Waveform,
+ hdr: false,
+ size: (256, 100),
+ counts,
+ };
+ let (width, height, pixels) = waveform.draw();
+ assert_eq!((width, height), (COLUMNS, LEVELS));
+ let at = |x: u32, y: u32| pixels[((y * width + x) * 4 + 1) as usize];
+ assert!(at(10, LEVELS - 1 - 128) > 200, "the line is bright");
+ assert_eq!(at(10, 10), 0, "the rest is black");
+ assert!(pixels.chunks_exact(4).all(|pixel| pixel[3] == 255));
+ for kind in ScopeKind::ALL {
+ let data = ScopeData {
+ kind,
+ hdr: true,
+ size: (64, 36),
+ counts: vec![3; kind.bins()],
+ };
+ let (width, height, pixels) = data.draw();
+ assert_eq!(pixels.len(), (width * height * 4) as usize, "{kind:?}");
+ }
+ }
+
+ /// The marks read the display level on SDR and nits on HDR, where SDR
+ /// white sits at 58 % of PQ's scale and a 1000-nit highlight at 75 %.
+ #[test]
+ fn the_scale_reads_shares_or_nits() {
+ let sdr = marks(ScopeKind::Waveform, false);
+ assert_eq!(sdr.first(), Some(&(0.0, "0".to_owned())));
+ assert_eq!(sdr.last(), Some(&(1.0, "100".to_owned())));
+ let hdr = marks(ScopeKind::Parade, true);
+ let at = |label: &str| {
+ hdr.iter()
+ .find(|(_, text)| text == label)
+ .map(|(at, _)| *at)
+ };
+ assert!((at("203").expect("SDR white") - 0.5807).abs() < 0.001);
+ assert!((at("1000").expect("a highlight") - 0.7518).abs() < 0.001);
+ assert!(marks(ScopeKind::Vectorscope, true).is_empty());
+ assert_eq!(plane([0.5, 0.5, 0.5]), (level_of(0.5), level_of(0.5)));
+ }
+}
diff --git a/src/crates/concat/locales/de.json b/src/crates/concat/locales/de.json
index 88584bc0..5645211b 100644
--- a/src/crates/concat/locales/de.json
+++ b/src/crates/concat/locales/de.json
@@ -825,6 +825,13 @@
"relink.missingMedia": "Fehlende Medien",
"relink.relinkAll": "Alle neu verknüpfen…",
"relink.selectFolderContainingMedia": "Select folder containing media files",
+ "scopes.histogram": "Histogramm",
+ "scopes.nits": "Nits",
+ "scopes.parade": "Parade",
+ "scopes.scopes": "Scopes",
+ "scopes.vectorscope": "Vektorskop",
+ "scopes.waiting": "Die Scopes lesen das Bild des Monitors: abspielen oder scrubben, um es zu messen.",
+ "scopes.waveform": "Wellenform",
"settings.about": "Über",
"settings.accent": "Akzent",
"settings.address": "Adresse",
diff --git a/src/crates/concat/locales/en.json b/src/crates/concat/locales/en.json
index 0895b260..66cebb95 100644
--- a/src/crates/concat/locales/en.json
+++ b/src/crates/concat/locales/en.json
@@ -825,6 +825,13 @@
"relink.missingMedia": "Missing Media",
"relink.relinkAll": "Relink All…",
"relink.selectFolderContainingMedia": "Select folder containing media files",
+ "scopes.histogram": "Histogram",
+ "scopes.nits": "nits",
+ "scopes.parade": "Parade",
+ "scopes.scopes": "Scopes",
+ "scopes.vectorscope": "Vectorscope",
+ "scopes.waiting": "The scopes read the monitor's picture: play or scrub to count it.",
+ "scopes.waveform": "Waveform",
"settings.about": "About",
"settings.accent": "Accent",
"settings.address": "Address",
diff --git a/src/crates/concat/locales/es.json b/src/crates/concat/locales/es.json
index 132255fc..1e8c495b 100644
--- a/src/crates/concat/locales/es.json
+++ b/src/crates/concat/locales/es.json
@@ -825,6 +825,13 @@
"relink.missingMedia": "Medios faltantes",
"relink.relinkAll": "Vincular todo…",
"relink.selectFolderContainingMedia": "Select folder containing media files",
+ "scopes.histogram": "Histograma",
+ "scopes.nits": "nits",
+ "scopes.parade": "Parade",
+ "scopes.scopes": "Scopes",
+ "scopes.vectorscope": "Vectorscopio",
+ "scopes.waiting": "Los scopes leen la imagen del monitor: reproduce o arrastra para medirla.",
+ "scopes.waveform": "Forma de onda",
"settings.about": "Acerca de",
"settings.accent": "Acento",
"settings.address": "Dirección",
diff --git a/src/crates/concat/locales/fa.json b/src/crates/concat/locales/fa.json
index 8bda9c23..7f1d26d7 100644
--- a/src/crates/concat/locales/fa.json
+++ b/src/crates/concat/locales/fa.json
@@ -825,6 +825,13 @@
"relink.missingMedia": "رسانه گمشده",
"relink.relinkAll": "پیوند مجدد همه…",
"relink.selectFolderContainingMedia": "پوشه حاوی فایل رسانه‌ایها را انتخاب کنید",
+ "scopes.histogram": "هیستوگرام",
+ "scopes.nits": "نیت",
+ "scopes.parade": "پاراد",
+ "scopes.scopes": "اسکوپ‌ها",
+ "scopes.vectorscope": "وکتوراسکوپ",
+ "scopes.waiting": "اسکوپ‌ها تصویر مانیتور را می‌خوانند: برای اندازه‌گیری، پخش کنید یا جابه‌جا شوید.",
+ "scopes.waveform": "شکل موج",
"settings.about": "درباره",
"settings.accent": "رنگ تأکید",
"settings.address": "آدرس",
diff --git a/src/crates/concat/locales/fr.json b/src/crates/concat/locales/fr.json
index 15fff548..8da8eeb1 100644
--- a/src/crates/concat/locales/fr.json
+++ b/src/crates/concat/locales/fr.json
@@ -825,6 +825,13 @@
"relink.missingMedia": "Médias manquants",
"relink.relinkAll": "Tout relier…",
"relink.selectFolderContainingMedia": "Select folder containing media files",
+ "scopes.histogram": "Histogramme",
+ "scopes.nits": "nits",
+ "scopes.parade": "Parade",
+ "scopes.scopes": "Scopes",
+ "scopes.vectorscope": "Vectorscope",
+ "scopes.waiting": "Les scopes lisent l'image du moniteur : lisez ou déplacez la tête de lecture pour la mesurer.",
+ "scopes.waveform": "Forme d'onde",
"settings.about": "À propos",
"settings.accent": "Accent",
"settings.address": "Adresse",
diff --git a/src/crates/concat/locales/hr.json b/src/crates/concat/locales/hr.json
index d5989b18..af18e243 100644
--- a/src/crates/concat/locales/hr.json
+++ b/src/crates/concat/locales/hr.json
@@ -825,6 +825,13 @@
"relink.missingMedia": "Nedostajući mediji",
"relink.relinkAll": "Ponovno poveži sve…",
"relink.selectFolderContainingMedia": "Select folder containing media files",
+ "scopes.histogram": "Histogram",
+ "scopes.nits": "nita",
+ "scopes.parade": "Parada",
+ "scopes.scopes": "Mjerači",
+ "scopes.vectorscope": "Vektorskop",
+ "scopes.waiting": "Mjerači čitaju sliku monitora: reproducirajte ili pomičite da je izmjere.",
+ "scopes.waveform": "Valni oblik",
"settings.about": "O programu",
"settings.accent": "Naglasak",
"settings.address": "Adresa",
diff --git a/src/crates/concat/locales/it.json b/src/crates/concat/locales/it.json
index 067b69cc..5a950816 100644
--- a/src/crates/concat/locales/it.json
+++ b/src/crates/concat/locales/it.json
@@ -825,6 +825,13 @@
"relink.missingMedia": "Media mancanti",
"relink.relinkAll": "Ricollega tutto…",
"relink.selectFolderContainingMedia": "Select folder containing media files",
+ "scopes.histogram": "Istogramma",
+ "scopes.nits": "nit",
+ "scopes.parade": "Parade",
+ "scopes.scopes": "Scope",
+ "scopes.vectorscope": "Vettorscopio",
+ "scopes.waiting": "Gli scope leggono l'immagine del monitor: riproduci o scorri per misurarla.",
+ "scopes.waveform": "Forma d'onda",
"settings.about": "Informazioni",
"settings.accent": "Accento",
"settings.address": "Indirizzo",
diff --git a/src/crates/concat/locales/ja.json b/src/crates/concat/locales/ja.json
index 01a45d71..d0a819d6 100644
--- a/src/crates/concat/locales/ja.json
+++ b/src/crates/concat/locales/ja.json
@@ -825,6 +825,13 @@
"relink.missingMedia": "メディアが見つかりません",
"relink.relinkAll": "すべて再リンク…",
"relink.selectFolderContainingMedia": "Select folder containing media files",
+ "scopes.histogram": "ヒストグラム",
+ "scopes.nits": "nit",
+ "scopes.parade": "パレード",
+ "scopes.scopes": "スコープ",
+ "scopes.vectorscope": "ベクトルスコープ",
+ "scopes.waiting": "スコープはモニターの映像を読み取ります。再生かスクラブで計測されます。",
+ "scopes.waveform": "波形",
"settings.about": "情報",
"settings.accent": "アクセント",
"settings.address": "アドレス",
diff --git a/src/crates/concat/locales/ko.json b/src/crates/concat/locales/ko.json
index cdf14297..4ce18050 100644
--- a/src/crates/concat/locales/ko.json
+++ b/src/crates/concat/locales/ko.json
@@ -825,6 +825,13 @@
"relink.missingMedia": "미디어 없음",
"relink.relinkAll": "모두 다시 연결…",
"relink.selectFolderContainingMedia": "Select folder containing media files",
+ "scopes.histogram": "히스토그램",
+ "scopes.nits": "니트",
+ "scopes.parade": "퍼레이드",
+ "scopes.scopes": "스코프",
+ "scopes.vectorscope": "벡터스코프",
+ "scopes.waiting": "스코프는 모니터 화면을 읽습니다. 재생하거나 스크럽하면 측정됩니다.",
+ "scopes.waveform": "파형",
"settings.about": "정보",
"settings.accent": "강조색",
"settings.address": "주소",
diff --git a/src/crates/concat/locales/pt-BR.json b/src/crates/concat/locales/pt-BR.json
index 1c0aa2ea..00b6e483 100644
--- a/src/crates/concat/locales/pt-BR.json
+++ b/src/crates/concat/locales/pt-BR.json
@@ -825,6 +825,13 @@
"relink.missingMedia": "Mídia ausente",
"relink.relinkAll": "Vincular tudo…",
"relink.selectFolderContainingMedia": "Select folder containing media files",
+ "scopes.histogram": "Histograma",
+ "scopes.nits": "nits",
+ "scopes.parade": "Parade",
+ "scopes.scopes": "Scopes",
+ "scopes.vectorscope": "Vetorscópio",
+ "scopes.waiting": "Os scopes leem a imagem do monitor: reproduza ou arraste para medi-la.",
+ "scopes.waveform": "Forma de onda",
"settings.about": "Sobre",
"settings.accent": "Destaque",
"settings.address": "Endereço",
diff --git a/src/crates/concat/locales/ru.json b/src/crates/concat/locales/ru.json
index e400a4ba..ff3857c9 100644
--- a/src/crates/concat/locales/ru.json
+++ b/src/crates/concat/locales/ru.json
@@ -825,6 +825,13 @@
"relink.missingMedia": "Отсутствующие медиафайлы",
"relink.relinkAll": "Привязать все…",
"relink.selectFolderContainingMedia": "Выберите папку с медиафайлами",
+ "scopes.histogram": "Гистограмма",
+ "scopes.nits": "нит",
+ "scopes.parade": "Парад",
+ "scopes.scopes": "Скопы",
+ "scopes.vectorscope": "Вектороскоп",
+ "scopes.waiting": "Скопы читают изображение монитора: запустите или прокрутите, чтобы измерить.",
+ "scopes.waveform": "Осциллограмма",
"settings.about": "О программе",
"settings.accent": "Акцент",
"settings.address": "Адрес",
diff --git a/src/crates/concat/locales/tr.json b/src/crates/concat/locales/tr.json
index 71ee879b..e59d6965 100644
--- a/src/crates/concat/locales/tr.json
+++ b/src/crates/concat/locales/tr.json
@@ -825,6 +825,13 @@
"relink.missingMedia": "Eksik medya",
"relink.relinkAll": "Tümünü yeniden bağla…",
"relink.selectFolderContainingMedia": "Select folder containing media files",
+ "scopes.histogram": "Histogram",
+ "scopes.nits": "nit",
+ "scopes.parade": "Parade",
+ "scopes.scopes": "Skoplar",
+ "scopes.vectorscope": "Vektörskop",
+ "scopes.waiting": "Skoplar monitörün görüntüsünü okur: ölçmek için oynatın veya kaydırın.",
+ "scopes.waveform": "Dalga formu",
"settings.about": "Hakkında",
"settings.accent": "Vurgu",
"settings.address": "Adres",
diff --git a/src/crates/concat/locales/zh-Hans.json b/src/crates/concat/locales/zh-Hans.json
index 8b4035c2..69b7fd30 100644
--- a/src/crates/concat/locales/zh-Hans.json
+++ b/src/crates/concat/locales/zh-Hans.json
@@ -825,6 +825,13 @@
"relink.missingMedia": "媒体缺失",
"relink.relinkAll": "全部重新链接…",
"relink.selectFolderContainingMedia": "选择包含媒体文件的文件夹",
+ "scopes.histogram": "直方图",
+ "scopes.nits": "尼特",
+ "scopes.parade": "RGB 分量",
+ "scopes.scopes": "示波器",
+ "scopes.vectorscope": "矢量示波器",
+ "scopes.waiting": "示波器读取监视器的画面:播放或拖动时进行测量。",
+ "scopes.waveform": "波形图",
"settings.about": "关于",
"settings.accent": "强调色",
"settings.address": "地址",
diff --git a/src/crates/concat/locales/zh-TW.json b/src/crates/concat/locales/zh-TW.json
index 01547c43..0f6a1e3f 100644
--- a/src/crates/concat/locales/zh-TW.json
+++ b/src/crates/concat/locales/zh-TW.json
@@ -825,6 +825,13 @@
"relink.missingMedia": "媒體遺失",
"relink.relinkAll": "全部重新連結…",
"relink.selectFolderContainingMedia": "選取包含媒體檔案的資料夾",
+ "scopes.histogram": "直方圖",
+ "scopes.nits": "尼特",
+ "scopes.parade": "RGB 分量",
+ "scopes.scopes": "示波器",
+ "scopes.vectorscope": "向量示波器",
+ "scopes.waiting": "示波器讀取監看器的畫面:播放或拖曳時進行測量。",
+ "scopes.waveform": "波形圖",
"settings.about": "關於",
"settings.accent": "強調色",
"settings.address": "位址",
diff --git a/src/crates/concat/src/dock.rs b/src/crates/concat/src/dock.rs
index 01481a75..d6a59106 100644
--- a/src/crates/concat/src/dock.rs
+++ b/src/crates/concat/src/dock.rs
@@ -34,6 +34,14 @@ impl Dock {
Box::new(Dock::Leaf(kind))
}
+ /// Whether any seat shows `kind`.
+ pub fn holds(&self, kind: PaneKind) -> bool {
+ match self {
+ Dock::Leaf(leaf) => *leaf == kind,
+ Dock::Split { first, second, .. } => first.holds(kind) || second.holds(kind),
+ }
+ }
+
/// The node a path names, following each step into the first branch or the
/// second. A path that runs past a leaf stops there, which cannot happen
/// for a path this module produced.
@@ -317,3 +325,19 @@ pub fn nearest_row(heights: &[f32], y: f32) -> i32 {
}
best
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// A kind is on screen when any seat shows it, however deep the split.
+ #[test]
+ fn a_dock_knows_what_it_shows() {
+ let mut dock = default_dock();
+ assert!(dock.holds(PaneKind::Preview));
+ assert!(!dock.holds(PaneKind::Scopes));
+ let path = dock.leaf_path(0).expect("a first seat");
+ dock.split_leaf(&path, PaneKind::Scopes, DockSide::Right);
+ assert!(dock.holds(PaneKind::Scopes));
+ }
+}
diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rs
index 3abdb0e9..bfb26a20 100644
--- a/src/crates/concat/src/lib.rs
+++ b/src/crates/concat/src/lib.rs
@@ -217,6 +217,8 @@ pub fn run() -> Result<(), slint::PlatformError> {
editor.set_visual_wheels(ModelRc::from(models.visual_wheels.clone()));
editor.set_visual_curves(ModelRc::from(models.visual_curves.clone()));
editor.set_visual_colours(ModelRc::from(models.visual_colours.clone()));
+ app.global::<Scopes>()
+ .set_marks(ModelRc::from(models.scope_marks.clone()));
app.global::<Keyframes>()
.set_rows(ModelRc::from(models.key_rows.clone()));
app.global::<KeyEditor>()
@@ -1045,6 +1047,10 @@ pub fn run() -> Result<(), slint::PlatformError> {
editor.on_quality_changed(on_window!(|state, index: i32| {
state.handle(Msg::Monitor(MonitorMsg::QualityChanged(index)));
}));
+ app.global::<Scopes>()
+ .on_kind_changed(on_window!(|state, index: i32| {
+ state.handle(Msg::Monitor(MonitorMsg::ScopeKind(index)));
+ }));
editor.on_play_toggled(on_window!(|state| {
state.play_toggle();
}));
diff --git a/src/crates/concat/src/panes/monitor.rs b/src/crates/concat/src/panes/monitor.rs
index 5fbc4c7a..40b966ab 100644
--- a/src/crates/concat/src/panes/monitor.rs
+++ b/src/crates/concat/src/panes/monitor.rs
@@ -19,13 +19,14 @@
use std::collections::HashMap;
use std::sync::Arc;
-use concat_host::preview::FrameSpec;
+use concat_host::preview::{FrameSpec, scopes};
use concat_project::model::Project;
-use crate::host::{spawn_detached, spawn_in_project};
+use crate::host::{on_ui, spawn_detached, spawn_in_project};
use crate::i18n::tf;
use crate::panes::Msg;
use crate::studio::Studio;
+use crate::ui::{PaneKind, ScopeMarkData};
/// Everything that can happen to the monitor.
pub enum MonitorMsg {
@@ -39,6 +40,11 @@ pub enum MonitorMsg {
Opened,
/// The project closed: nothing to show.
Closed,
+ /// The Scopes pane's control: 0 waveform, 1 parade, 2 vectorscope,
+ /// 3 histogram.
+ ScopeKind(i32),
+ /// Look again for the scope counted with the last frame.
+ ScopePoll,
}
impl std::fmt::Debug for MonitorMsg {
@@ -57,6 +63,8 @@ impl std::fmt::Debug for MonitorMsg {
Self::QualityChanged(index) => write!(f, "QualityChanged({index})"),
Self::Opened => write!(f, "Opened"),
Self::Closed => write!(f, "Closed"),
+ Self::ScopeKind(index) => write!(f, "ScopeKind({index})"),
+ Self::ScopePoll => write!(f, "ScopePoll"),
}
}
}
@@ -87,9 +95,46 @@ pub struct MonitorPane {
/// it does not - and the trade is the window's, not the document's,
/// so it is remembered here and not saved.
quality: HashMap<String, usize>,
+ /// The scope the Scopes pane shows, by its control's index.
+ pub scope_kind: usize,
+ /// The last scope drawn: the picture, its scale's marks, and whether
+ /// its timeline was HDR.
+ pub scope: Option<(slint::Image, Vec<ScopeMarkData>, bool)>,
+ /// Looks left for a scope's counts on their way back.
+ scope_polls: u32,
}
impl MonitorPane {
+ /// The scope counted with the last frame, drawn once its counts are
+ /// back; until then, a look again in a few milliseconds, a few dozen
+ /// times at most. The window never waits on the device for it.
+ fn poll_scope(&mut self, studio: &mut Studio) {
+ match studio.host.monitor.take_scope() {
+ Some(data) => {
+ self.scope_polls = 0;
+ let (width, height, pixels) = data.draw();
+ let buffer = slint::SharedPixelBuffer::<slint::Rgba8Pixel>::clone_from_slice(
+ &pixels, width, height,
+ );
+ let marks = scopes::marks(data.kind, data.hdr)
+ .into_iter()
+ .map(|(at, label)| ScopeMarkData {
+ at,
+ label: label.into(),
+ })
+ .collect();
+ self.scope = Some((slint::Image::from_rgba8(buffer), marks, data.hdr));
+ }
+ None if self.scope_polls > 0 => {
+ self.scope_polls -= 1;
+ slint::Timer::single_shot(std::time::Duration::from_millis(8), || {
+ on_ui(|studio, _, _| studio.handle(Msg::Monitor(MonitorMsg::ScopePoll)));
+ });
+ }
+ None => {}
+ }
+ }
+
/// Applies one message. The studio is the rest of the window; while
/// this runs the studio's copy of the pane is a blank it must not read.
pub fn update(&mut self, msg: MonitorMsg, studio: &mut Studio) {
@@ -97,6 +142,12 @@ impl MonitorPane {
MonitorMsg::Request => self.request(studio),
MonitorMsg::Frame(result, spec) => {
self.busy = false;
+ // A Scopes pane on screen has the frame counted as it is
+ // drawn.
+ let scope = studio
+ .dock
+ .holds(PaneKind::Scopes)
+ .then(|| scopes::ScopeKind::ALL[self.scope_kind.min(3)]);
let picture = match result {
// Drawn here and not on the worker: this is the event
// loop, the one thread the window's renderer submits
@@ -105,7 +156,7 @@ impl MonitorPane {
Ok(Picture::Sources(sources)) => studio
.host
.monitor
- .texture_of(&sources, spec)
+ .texture_of_scoped(&sources, spec, scope)
.and_then(|texture| {
slint::Image::try_from(texture)
.map_err(|error| format!("preview texture: {error}"))
@@ -129,10 +180,20 @@ impl MonitorPane {
}
}
}
+ if scope.is_some() {
+ self.scope_polls = 60;
+ self.poll_scope(studio);
+ }
if self.wanted {
self.request(studio);
}
}
+ MonitorMsg::ScopeKind(index) => {
+ self.scope_kind = (index.max(0) as usize).min(3);
+ self.scope = None;
+ self.request(studio);
+ }
+ MonitorMsg::ScopePoll => self.poll_scope(studio),
MonitorMsg::QualityChanged(index) => {
let id = studio.project().active_timeline_id.clone();
self.quality.insert(id, (index.max(0) as usize).min(2));
diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rs
index 375effdc..de3eb514 100644
--- a/src/crates/concat/src/studio.rs
+++ b/src/crates/concat/src/studio.rs
@@ -581,6 +581,8 @@ pub struct Models {
pub visual_curves: Rc<VecModel<CurveGroupData>>,
/// The picture's chain's colour knobs, a row each.
pub visual_colours: Rc<VecModel<ColourKnobData>>,
+ /// The Scopes pane's scale.
+ pub scope_marks: Rc<VecModel<ScopeMarkData>>,
/// A link's wheels and curves, and a curve's points, by the link - -1
/// the colour panel - and the curve's key: kept like the rest, so a
/// wheel or a point being dragged is not dropped when it is published
@@ -645,6 +647,7 @@ impl Models {
adjust_curves: Rc::new(VecModel::default()),
visual_wheels: Rc::new(VecModel::default()),
visual_colours: Rc::new(VecModel::default()),
+ scope_marks: Rc::new(VecModel::default()),
visual_curves: Rc::new(VecModel::default()),
link_wheels: RefCell::new(HashMap::new()),
link_curves: RefCell::new(HashMap::new()),
@@ -6549,6 +6552,17 @@ impl Studio {
editor.set_playhead_free(!self.prefs.playhead_stops_at_end);
editor.set_playing(self.playing);
editor.set_preview_frame(self.monitor.image.clone());
+ let scopes = app.global::<Scopes>();
+ scopes.set_kind(self.monitor.scope_kind as i32);
+ match &self.monitor.scope {
+ Some((picture, marks, hdr)) => {
+ scopes.set_picture(picture.clone());
+ sync(&models.scope_marks, marks.clone());
+ scopes.set_hdr(*hdr);
+ scopes.set_ready(true);
+ }
+ None => scopes.set_ready(false),
+ }
sync(&models.stage, self.stage_items());
sync(&models.guides, self.stage_guides.clone());
let (path, width, erase) = self.stroke_overlay();
diff --git a/src/crates/concat/ui/app.slint b/src/crates/concat/ui/app.slint
index d6575417..91cced2f 100644
--- a/src/crates/concat/ui/app.slint
+++ b/src/crates/concat/ui/app.slint
@@ -47,6 +47,7 @@ import {
// Re-exported so main.rs can reach the globals and the struct.
import { KeyEditor, KeyMarkData, KeyRowData } from "workspace/keyframes-pane.slint";
+import { ScopeMarkData, Scopes } from "workspace/scopes-pane.slint";
export {
Curves, Fmt, Focus, Payload, Theme, Bezier, Editor, I18n,
@@ -54,7 +55,7 @@ export {
DockDivider, DockSide, PaneKind, SeatBox,
EffectData, MediaFilter, MediaItemData, MediaKind, TextPresetData,
ClipData, ClipField, ClipKeyData, ClipKind, ClipTextField, DropData, Keyframes,
- KeyEditor, KeyMarkData, KeyRowData,
+ KeyEditor, KeyMarkData, KeyRowData, ScopeMarkData, Scopes,
SelectedClipData, StageGuideData, StageItemData, TextAlignment, TimelineTabData,
TimelineTool, TrackData, TrackSize, MenuItemData, MenuRow, ExportData, ExportPhase, ModelData, SettingsData,
ChipOption, RecentProjectData, StartData, SystemFactData, ToastData, ProjectSheetData,
diff --git a/src/crates/concat/ui/workspace/pane-switcher.slint b/src/crates/concat/ui/workspace/pane-switcher.slint
index 88c0f8d9..79bb1f0d 100644
--- a/src/crates/concat/ui/workspace/pane-switcher.slint
+++ b/src/crates/concat/ui/workspace/pane-switcher.slint
@@ -39,6 +39,8 @@ export enum PaneKind {
timeline,
/// the selected clip's keys: a dopesheet and a curve editor
keyframes,
+ /// the monitor's picture as waveform, parade, vectorscope, histogram
+ scopes,
}
export global Panes {
@@ -60,6 +62,7 @@ export global Panes {
: kind == PaneKind.preview ? I18n.t("common.preview")
: kind == PaneKind.inspector ? I18n.t("paneSwitcher.inspector")
: kind == PaneKind.keyframes ? I18n.t("common.keyframes")
+ : kind == PaneKind.scopes ? I18n.t("scopes.scopes")
: I18n.t("paneSwitcher.timeline");
}
@@ -71,6 +74,7 @@ export global Panes {
: kind == PaneKind.preview ? "preview"
: kind == PaneKind.inspector ? "inspector"
: kind == PaneKind.keyframes ? "keyframes"
+ : kind == PaneKind.scopes ? "scopes"
: "timeline";
}
@@ -83,6 +87,7 @@ export global Panes {
: kind == PaneKind.preview ? Glyph.image
: kind == PaneKind.inspector ? Glyph.settings
: kind == PaneKind.keyframes ? Glyph.keyframe
+ : kind == PaneKind.scopes ? Glyph.waveform
: Glyph.rows;
}
}
@@ -394,6 +399,11 @@ export component PaneSwitcher inherits Rectangle {
current: root.kind == PaneKind.keyframes;
chosen => { menu.close(); root.picked(PaneKind.keyframes); }
}
+ SwitchRow {
+ kind: PaneKind.scopes;
+ current: root.kind == PaneKind.scopes;
+ chosen => { menu.close(); root.picked(PaneKind.scopes); }
+ }
SwitchRow {
kind: PaneKind.timeline;
current: root.kind == PaneKind.timeline;
@@ -497,6 +507,10 @@ export component AddPaneButton inherits Rectangle {
kind: PaneKind.keyframes;
chosen => { menu.close(); root.added(PaneKind.keyframes); }
}
+ SwitchRow {
+ kind: PaneKind.scopes;
+ chosen => { menu.close(); root.added(PaneKind.scopes); }
+ }
SwitchRow {
kind: PaneKind.timeline;
chosen => { menu.close(); root.added(PaneKind.timeline); }
diff --git a/src/crates/concat/ui/workspace/scopes-pane.slint b/src/crates/concat/ui/workspace/scopes-pane.slint
new file mode 100644
index 00000000..273f00db
--- /dev/null
+++ b/src/crates/concat/ui/workspace/scopes-pane.slint
@@ -0,0 +1,176 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// SPDX-FileCopyrightText: 2026 Jareer and Concat contributors
+
+// The Scopes pane: the monitor's picture as a colourist reads it. A
+// waveform (luma across the picture), a parade (red, green and blue side
+// by side), a vectorscope (every pixel's colour on the Cb-Cr plane, with
+// the 75 % bars' targets) or a histogram - counted on the GPU from the
+// frame's light before anything is clipped, and drawn by Rust. The scale
+// is the display level on an SDR timeline, and nits on PQ's scale on an
+// HDR one, so SDR white and a 1000-nit highlight each have their line.
+
+import { I18n } from "../i18n.slint";
+import { Theme } from "../theme/theme.slint";
+import { SegmentedControl } from "../primitives/segmented-control.slint";
+import { Pane, PaneHeader } from "pane.slint";
+import { PaneKind, PaneSwitcher } from "pane-switcher.slint";
+
+/// One mark of the scale: where it sits, `0..1` from the bottom of a
+/// waveform or a parade or from the left of a histogram, and what it reads.
+export struct ScopeMarkData {
+ at: float,
+ label: string,
+}
+
+/// The scope in view, published by Rust as the monitor draws.
+export global Scopes {
+ in property <image> picture;
+ in property <[ScopeMarkData]> marks;
+ /// 0 the waveform, 1 the parade, 2 the vectorscope, 3 the histogram.
+ in-out property <int> kind: 0;
+ /// The timeline is HDR: the marks read nits.
+ in property <bool> hdr;
+ /// A scope has been counted since the pane opened.
+ in property <bool> ready;
+ callback kind-changed(kind: int);
+}
+
+export component ScopesPane inherits Pane {
+ in property <int> pane-seat;
+ in property <bool> pane-removable;
+ callback pane-picked(kind: PaneKind);
+ callback pane-removed();
+
+ VerticalLayout {
+ PaneHeader {
+ title: I18n.t("scopes.scopes");
+
+ VerticalLayout {
+ alignment: center;
+ PaneSwitcher {
+ kind: PaneKind.scopes;
+ seat: root.pane-seat;
+ removable: root.pane-removable;
+ picked(kind) => { root.pane-picked(kind); }
+ removed => { root.pane-removed(); }
+ }
+ }
+ }
+
+ // Which scope, and what its scale reads.
+ Rectangle {
+ height: 40px;
+
+ Rectangle {
+ x: 0;
+ y: parent.height - 1px;
+ width: parent.width;
+ height: 1px;
+ background: Theme.line;
+ }
+
+ HorizontalLayout {
+ padding-left: Theme.pad;
+ padding-right: Theme.pad;
+ spacing: 8px;
+
+ VerticalLayout {
+ alignment: center;
+ SegmentedControl {
+ options: [
+ I18n.t("scopes.waveform"),
+ I18n.t("scopes.parade"),
+ I18n.t("scopes.vectorscope"),
+ I18n.t("scopes.histogram"),
+ ];
+ current: Scopes.kind;
+ changed(index) => { Scopes.kind-changed(index); }
+ }
+ }
+
+ Text {
+ horizontal-stretch: 0;
+ text: Scopes.kind == 2 ? "" : Scopes.hdr ? I18n.t("scopes.nits") : "%";
+ color: Theme.fg-dim;
+ font-size: Theme.fs-sm;
+ vertical-alignment: center;
+ }
+ }
+ }
+
+ // The scope, black, with its scale over it. A vectorscope keeps its
+ // plane square in the middle; the others fill the pane.
+ body := Rectangle {
+ background: #000000;
+ clip: true;
+
+ property <bool> square: Scopes.kind == 2;
+ property <length> side: Math.min(self.width, self.height) - 16px;
+
+ scope := Rectangle {
+ x: body.square ? (body.width - body.side) / 2 : 32px;
+ y: body.square ? (body.height - body.side) / 2 : 8px;
+ width: body.square ? body.side : body.width - 40px;
+ height: body.square ? body.side : body.height - (Scopes.kind == 3 ? 28px : 16px);
+
+ Image {
+ width: parent.width;
+ height: parent.height;
+ source: Scopes.picture;
+ image-fit: fill;
+ }
+
+ // A waveform's and a parade's marks are levels across.
+ if Scopes.kind < 2: Rectangle {
+ for mark in Scopes.marks: Rectangle {
+ y: (1 - mark.at) * scope.height;
+ width: scope.width;
+ height: 1px;
+ background: #ffffff26;
+
+ Text {
+ x: -30px;
+ y: -7px;
+ width: 26px;
+ text: mark.label;
+ color: Theme.fg-dim;
+ font-size: Theme.fs-xs;
+ horizontal-alignment: right;
+ }
+ }
+ }
+
+ // A histogram's are levels along.
+ if Scopes.kind == 3: Rectangle {
+ for mark in Scopes.marks: Rectangle {
+ x: mark.at * scope.width;
+ width: 1px;
+ height: scope.height;
+ background: #ffffff26;
+
+ Text {
+ x: -20px;
+ y: scope.height + 4px;
+ width: 40px;
+ text: mark.label;
+ color: Theme.fg-dim;
+ font-size: Theme.fs-xs;
+ horizontal-alignment: center;
+ }
+ }
+ }
+ }
+
+ if !Scopes.ready: Text {
+ width: parent.width;
+ height: parent.height;
+ text: I18n.t("scopes.waiting");
+ color: Theme.fg-dim;
+ font-size: Theme.fs;
+ horizontal-alignment: center;
+ vertical-alignment: center;
+ wrap: word-wrap;
+ }
+ }
+ }
+}
diff --git a/src/crates/concat/ui/workspace/seat.slint b/src/crates/concat/ui/workspace/seat.slint
index 67c4700e..828297f8 100644
--- a/src/crates/concat/ui/workspace/seat.slint
+++ b/src/crates/concat/ui/workspace/seat.slint
@@ -11,6 +11,7 @@ import { MediaPane } from "media-pane.slint";
import { PreviewPane } from "preview-pane.slint";
import { TimelinePane } from "timeline-pane.slint";
import { KeyframesPane } from "keyframes-pane.slint";
+import { ScopesPane } from "scopes-pane.slint";
// One box of the workspace, showing whichever view its `kind` names.
//
@@ -304,6 +305,18 @@ export component Seat inherits Rectangle {
}
}
+ if root.kind == PaneKind.scopes: ScopesPane {
+ x: 0;
+ y: 0;
+ width: root.width;
+ height: root.height;
+
+ pane-picked(kind) => { root.picked(kind); }
+ pane-seat: root.index;
+ pane-removable: Editor.seats.length > 1;
+ pane-removed => { root.removed(); }
+ }
+
if root.kind == PaneKind.keyframes: KeyframesPane {
x: 0;
y: 0;