EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Merge origin/main into fix/issue-2092-camera-focus-crash
Christopher Linnett280a400be471
diff --cc crates/effects/src/lib.rsindex f83c7eff0,204e651ec..54ce880bc--- a/crates/effects/src/lib.rs+++ b/crates/effects/src/lib.rs@@@ -287,15 -290,35 +290,36 @@@ impl Bufself.offset[0] += origin[0] * self.scale;self.offset[1] += origin[1] * self.scale;}+ /// Grow by transparent pixels: `sides` = left, top, right, bottom. Content keeps its place.+ pub fn pad_sides(&mut self, sides: [u32; 4]) {+ let [l, t, r, b] = sides;+ if l == 0 && t == 0 && r == 0 && b == 0 {+ return;+ }+ let (Some(w), Some(h)) = (self.img.width.checked_add(l).and_then(|v| v.checked_add(r)), self.img.height.checked_add(t).and_then(|v| v.checked_add(b)))+ else {+ return;+ };+ let mut out = Image::new(w, h);+ let (sw, ow) = (self.img.width as usize, w as usize);+ for y in 0..self.img.height as usize {+ let at = (y + t as usize) * ow + l as usize;+ let (Some(src), Some(dst)) = (self.img.data.get(y * sw..(y + 1) * sw), out.data.get_mut(at..at + sw)) else { continue };+ dst.copy_from_slice(src);+ }+ self.img = out;+ self.offset[0] += l as f64;+ self.offset[1] += t as f64;+ }- /// Grow by `pad` transparent pixels on every side.+ /// Grow by `pad` transparent pixels on every side (as clamped by [`Image::effective_pad`]).pub fn pad(&mut self, pad: u32) {- if pad == 0 {+ let eff = self.img.effective_pad(pad);+ if eff == 0 {return;}- self.img = self.img.padded(pad);- self.offset[0] += pad as f64;- self.offset[1] += pad as f64;+ self.img = self.img.padded(eff);+ self.offset[0] += eff as f64;+ self.offset[1] += eff as f64;}}diff --cc crates/raster/src/lib.rsindex c9e44cb25,9f2e4e755..01960b66b--- a/crates/raster/src/lib.rs+++ b/crates/raster/src/lib.rs@@@ -22,11 -23,28 +23,33 @@@ pub use warp::{Sampling, WarpOpts, accupub type Px = [f32; 4];+/// Maximum padded side in pixels — mirrors the project crate's `limits::MAX_SIZE` (30 000;+/// raster sits below it in the layering and may not depend on it, so the two must stay equal).+/// A padded side beyond the largest supported comp side has no render use.+pub const MAX_PADDED_SIDE: u32 = 30_000;++ /// Clamp (colour ≤ alpha ≤ 1, NaN → 0) and round half up to `levels` steps (`inv` = 1 / levels):+ /// one pixel of an 8/16 bpc buffer. Values are non-negative after the clamp, so the integer+ /// conversion rounds like `round()` and vectorises.+ #[allow(clippy::manual_clamp)] // max/min map NaN to 0; clamp would keep NaN+ #[inline(always)]+ pub fn quantize_px(p: &mut Px, levels: f32, inv: f32) {+ let a = round_half_up(p[3].max(0.0).min(1.0) * levels) * inv;+ let hi = [a, a, a, a];+ for c in 0..3 {+ p[c] = round_half_up(p[c].max(0.0).min(hi[c]) * levels) * inv;+ }+ p[3] = a;+ }++ /// `v` (0..=65 535) rounded half up. The same either way; the fastest on each target: x86-64's+ /// baseline converts to integers in one instruction but has no `floor` (SSE4.1), while in wasm+ /// `floor` is one instruction and converting back from `u32` several (about 1.5× faster there).+ #[inline(always)]+ fn round_half_up(v: f32) -> f32 {+ if cfg!(target_arch = "wasm32") { (v + 0.5).floor() } else { (v + 0.5) as u32 as f32 }+ }+#[derive(Clone, Debug, Default, PartialEq)]pub struct Image {pub width: u32,