Skip to content

Commit 3b3ffb9

Browse files
committed
Add some tonecurve stuff that I'm about to remove in favour of the splines package
1 parent 2e73b22 commit 3b3ffb9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

‎blitz/src/render_settings.rs‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
use itertools::Itertools;
2+
use std::iter::once;
3+
4+
pub struct ToneCurve {
5+
x_vals: Vec<f32>,
6+
tangents: Vec<f32>,
7+
}
8+
9+
impl ToneCurve {
10+
pub fn new(points: &Vec<f32>) -> Self {
11+
// SPLINE TIME
12+
// https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Catmull%E2%80%93Rom_spline
13+
let x_inc = 1.0 / points.len() as f32;
14+
// for 4 points, this should be 12.5, 37.5, 62.5, 87.5, i.e. split into 4 even bands
15+
let x_vals = (0..points.len()).map(|x| (x as f32 + 0.5) * x_inc);
16+
let xs = once(0.0).chain(x_vals).chain(once(1.0)).collect_vec();
17+
let ys = once(0.0)
18+
.chain(points.iter().copied())
19+
.chain(once(1.0))
20+
.collect_vec();
21+
assert_eq!(xs.len(), ys.len());
22+
23+
let tangents = (1..(xs.len() - 1))
24+
.map(|k| {
25+
// as per wikipedia:
26+
// m_k =
27+
(ys[k + 1] - ys[k - 1]) / (xs[k + 1] - xs[k - 1])
28+
})
29+
.collect_vec();
30+
ToneCurve {
31+
x_vals: xs,
32+
tangents,
33+
}
34+
}
35+
36+
pub fn apply(val: f32) -> f32 {}
37+
}
38+
139
#[derive(Debug, Clone)]
240
pub struct RenderSettings {
341
pub tone_curve: Vec<f32>,

0 commit comments

Comments
 (0)