Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ _Avoid_: Cache, library
A change of shot from one frame to the next, found in a Track when it loads; the Look can fade cuts longer than the rest.
_Avoid_: Scene change, transition

**Flash**:
A few frames (an explosion, lightning, a camera flash) much brighter than the frames around them, found in a Track when it loads; the Look's Flash guard tones them down.
_Avoid_: Spike, strobe

**Black threshold**:
The darkness under which the Look fades colors out instead of showing them dim and muddy; the opposite of the minimum brightness.
_Avoid_: Black level, cutoff

**Look**:
The user's color tuning applied at playback: brightness, saturation, smoothing, and how much of the screen each light reads.
_Avoid_: Settings, profile
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ fn run(video: &Path, opts: &Options, hw: HwAccel) -> Result<(Track, Stats)> {
edges,
exposure: 1.0,
cuts: Vec::new(),
flash_gains: Vec::new(),
};
Ok((track, Stats { elapsed: start.elapsed().as_secs_f64(), hwaccel: hw }))
}
Expand Down
35 changes: 35 additions & 0 deletions apps/server/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ pub struct Look {
pub auto_exposure: bool,
/// How much grey, washed-out colors lean to a warm white (0 = none, 1 = fully).
pub warm_greys: f32,
/// How much Flashes (a few frames much brighter than around them) are
/// toned down: 0 = as they are, 1 = back to the level around them.
pub flash_guard: f32,
/// Colors darker than this (luminance, linear light, after exposure) fade
/// out instead of showing dim and muddy (0 = off).
pub black_threshold: f32,
/// How fast they fade under the threshold: 1 is linear, higher is darker sooner.
pub black_falloff: f32,
}

impl Default for Look {
Expand All @@ -81,6 +89,9 @@ impl Default for Look {
centered_smoothing: true,
auto_exposure: true,
warm_greys: 0.5,
flash_guard: 0.5,
black_threshold: 0.0,
black_falloff: 2.0,
}
}
}
Expand Down Expand Up @@ -110,6 +121,14 @@ impl Look {
for v in &mut c {
*v = (l + (*v - l) * self.saturation).max(0.0) * self.brightness;
}
// Under the Black threshold, fade out along a curve: 1 at the threshold, 0 at black.
let dim = luminance(c);
if self.black_threshold > 0.0 && dim < self.black_threshold {
let k = (dim / self.black_threshold).powf(self.black_falloff.max(0.1));
for v in &mut c {
*v *= k;
}
}
let max = c[0].max(c[1]).max(c[2]);
if max > 1.0 {
// Keep the hue instead of clipping each channel separately.
Expand Down Expand Up @@ -160,4 +179,20 @@ mod tests {
let c = look.apply([0.8, 0.4, 0.0]);
assert!((c[0] - 1.0).abs() < 1e-6 && (c[1] - 0.5).abs() < 1e-6);
}

#[test]
fn under_the_black_threshold_colors_fade_out_with_no_step() {
let look =
Look { saturation: 1.0, warm_greys: 0.0, black_threshold: 0.02, black_falloff: 2.0, ..Default::default() };
// Above: untouched.
assert_eq!(look.apply([0.1, 0.05, 0.02]), [0.1, 0.05, 0.02]);
// Across the threshold, no step; under it, darker and darker, down to black.
let lum = |v: f32| luminance(look.apply([v; 3]));
assert!((lum(0.0201) - lum(0.0199)).abs() < 1e-3);
assert!((lum(0.01) - 0.01 * 0.25).abs() < 1e-5, "{}", lum(0.01));
assert!(lum(0.005) < lum(0.01) && lum(0.0) == 0.0);
// Off: dim colors pass.
let off = Look { black_threshold: 0.0, ..look };
assert_eq!(off.apply([0.01; 3]), [0.01; 3]);
}
}
10 changes: 3 additions & 7 deletions apps/server/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,8 @@ impl Renderer {
Mapping::new(&self.channels, track.cols, track.rows, look)
});
}
let half = smoothing_at(track, t, look);
match (edges, look.centered_smoothing) {
(false, true) => track.sample_centered(t, half, &mut self.grid),
(false, false) => track.sample(t, &mut self.grid),
(true, true) => track.sample_edges_centered(t, half, &mut self.grid),
(true, false) => track.sample_edges(t, &mut self.grid),
}
let half = look.centered_smoothing.then(|| smoothing_at(track, t, look));
track.sample_for_lights(t, half, edges, look.flash_guard, &mut self.grid);
self.mapping.as_ref().unwrap().colors(&self.grid, &mut self.colors);
for c in self.colors.iter_mut() {
c.1 = look.apply(c.1);
Expand Down Expand Up @@ -241,6 +236,7 @@ mod tests {
edges: Vec::new(),
exposure: 1.0,
cuts: Vec::new(),
flash_gains: Vec::new(),
}
}

Expand Down
Loading
Loading