mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-19 16:45:28 +00:00
#3464: raster: an unbounded blur is exactly 0 where it doesn't reach
Outside the boxes' combined reach of the moved line the result is 0, but boxes_unbounded still evaluated the prefix-sum polynomials there, and far past the line their cancelling terms left a rounding residue (about 5 for a one-pixel line moved a billion pixels). Those positions are now 0 without evaluating anything. Also wraps the raster re-export line rustfmt asks for.
This commit is contained in:
2 files changed
+24
-1
No files matched your search
@@ -297,7 +297,15 @@ fn boxes_unbounded(line: &[Px], r: &[i64], shift: i64, out: &mut [Px]) {
|
||||
})
|
||||
.collect();
|
||||
let norm: f64 = r.iter().map(|&ri| 2.0 * ri as f64 + 1.0).product();
|
||||
// The boxes read the line within `reach` of `x − shift`. Outside that the result is 0, and
|
||||
// the polynomials far past the line would only cancel to their rounding error.
|
||||
let reach = r.iter().fold(0i64, |s, &ri| s.saturating_add(ri));
|
||||
for (x, o) in (0i64..).zip(out.iter_mut()) {
|
||||
let c = x.saturating_sub(shift);
|
||||
if c.saturating_add(reach) < 0 || c.saturating_sub(reach) >= n_i {
|
||||
*o = [0.0; 4];
|
||||
continue;
|
||||
}
|
||||
let mut v = [0.0f64; 4];
|
||||
for &(offset, sign) in &terms {
|
||||
let s = at(x.saturating_add(offset));
|
||||
@@ -678,6 +686,19 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// #3464: a window the blur doesn't reach stays exactly transparent, however far the move
|
||||
/// (far past the line, the cancelling polynomials left a rounding residue of about 5).
|
||||
#[test]
|
||||
fn unbounded_gaussian_at_a_far_shift_is_exactly_transparent() {
|
||||
let img = Image::filled(1, 1, [1.0, 1.0, 1.0, 1.0]);
|
||||
for shift in [[-1_000_000_030i64, 0i64], [0, 1_000_000_030], [i64::MIN, i64::MAX]] {
|
||||
let out = gaussian_blur_unbounded_at(&img, 1.5, 1.5, shift, 4, 3);
|
||||
assert!(out.data.iter().flatten().all(|v| *v == 0.0), "{shift:?}");
|
||||
}
|
||||
// Next to the window the tail still reaches in.
|
||||
assert!(gaussian_blur_unbounded_at(&img, 1.5, 1.5, [-1, 0], 4, 3).get(0, 0)[3] > 0.0);
|
||||
}
|
||||
|
||||
/// #3464: a sigma past any buffer, or infinite, blurs as the widest one does: finite, no
|
||||
/// overflow in the radii. A NaN sigma leaves the axis alone.
|
||||
#[test]
|
||||
|
||||
@@ -17,7 +17,9 @@ pub mod yuv;
|
||||
use effectcraft_color::{BlendMode, blend_pixel};
|
||||
use rayon::prelude::*;
|
||||
|
||||
pub use blur::{box_blur, directional_blur, gaussian_blur, gaussian_blur_exact, gaussian_blur_unbounded, gaussian_blur_unbounded_at, gaussian_is_exact, radial_blur};
|
||||
pub use blur::{
|
||||
box_blur, directional_blur, gaussian_blur, gaussian_blur_exact, gaussian_blur_unbounded, gaussian_blur_unbounded_at, gaussian_is_exact, radial_blur,
|
||||
};
|
||||
pub use channels3d::AuxChannels;
|
||||
pub use warp::{Sampling, WarpOpts, accumulate_warp, composite_warp, composite_warp_changed, composite_warp_reference, resample};
|
||||
|
||||
|
||||
Reference in new issue
Block a user