Compare commits
4 Commits
00e91a709f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
99faa4cd3d
|
|||
|
61f0408bad
|
|||
|
9199791f51
|
|||
|
b6fbc99dac
|
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -739,9 +739,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.2"
|
||||
version = "1.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2806eaa3524762875e21c3dcd057bc4b7bfa01ce4da8d46be1cd43649e1cc6b"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "oorandom"
|
||||
|
||||
19
src/blur.rs
19
src/blur.rs
@@ -30,18 +30,17 @@ impl Blur {
|
||||
|
||||
/// Approximate 1D Gaussian filter of standard deviation sigma with N box filter passes. Each element in the output array contains the radius of the box filter for the corresponding pass.
|
||||
fn boxes_for_gaussian<const N: usize>(sigma: f32) -> [usize; N] {
|
||||
let w_ideal = (12.0 * sigma * sigma / N as f32 + 1.0).sqrt();
|
||||
let sigma_sq = sigma.powi(2);
|
||||
let w_ideal = (12.0 * sigma_sq / N as f32 + 1.0).sqrt();
|
||||
let mut w = w_ideal as usize;
|
||||
w -= 1 - (w & 1);
|
||||
let mut m = 0.25 * (N * (w + 3)) as f32;
|
||||
m -= 3.0 * sigma * sigma / (w + 1) as f32;
|
||||
let m = m.round() as usize;
|
||||
let m = (0.25 * (N * (w + 3)) as f32 - 3.0 * sigma_sq / (w + 1) as f32).round() as usize;
|
||||
|
||||
let mut result = [0; N];
|
||||
for (i, value) in result.iter_mut().enumerate() {
|
||||
*value = (if i < m { w - 1 } else { w + 1 }) / 2;
|
||||
}
|
||||
result
|
||||
(0..N)
|
||||
.map(|i| (w + 1 - 2 * (i < m) as usize) / 2)
|
||||
.collect::<Vec<_>>()
|
||||
.try_into()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// Perform one pass of the 2D box filter of the given radius. The result will be written to the src slice, while the buf slice is used as a scratch space.
|
||||
@@ -67,7 +66,7 @@ impl Blur {
|
||||
.for_each(|(src_row, dst_row)| {
|
||||
// First we build a value for the beginning of each row. We assume periodic boundary conditions, so we need to push the left index to the opposite side of the row.
|
||||
let width_sub_radius = width - radius;
|
||||
let mut value = src_row[width - radius - 1];
|
||||
let mut value = src_row[width_sub_radius - 1];
|
||||
for j in 0..radius {
|
||||
value += src_row[width_sub_radius + j] + src_row[j];
|
||||
}
|
||||
|
||||
@@ -29,9 +29,7 @@ fn main() {
|
||||
"-i",
|
||||
"-",
|
||||
"-c:v",
|
||||
"libx264",
|
||||
"-preset",
|
||||
"fast",
|
||||
"libsvtav1",
|
||||
"output.mp4",
|
||||
])
|
||||
.stdin(std::process::Stdio::piped())
|
||||
|
||||
Reference in New Issue
Block a user