Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Merge PR #1320

Brandon Thomas372f39f8f7ae
diff --cc crates/raw/src/demosaic/ahd.rs
index d97b56215,a75c395aa..d9fc27d76
--- a/crates/raw/src/demosaic/ahd.rs
+++ b/crates/raw/src/demosaic/ahd.rs
@@@ -20,17 -23,18 +23,22 @@@ const MARGIN: usize = 6
pub(crate) fn ahd(m: &Mosaic) -> Rgb32f {
let (w, h) = (m.w, m.h);
let mut out = Rgb32f::new(w, h);
+ if w == 0 || h == 0 {
+ return out;
+ }
- // one row of tiles per task, written straight into the picture (collecting the tiles first held a second copy)
- out.data.par_chunks_mut(w * TILE).enumerate().for_each(|(ty, band)| {
- let (y0, th) = (ty * TILE, band.len() / w);
- for x0 in (0..w).step_by(TILE) {
- let tw = TILE.min(w - x0);
- let px = tile(m, x0, y0, tw, th);
- for y in 0..th {
- band[y * w + x0..y * w + x0 + tw].copy_from_slice(&px[y * tw..(y + 1) * tw]);
++ // one row of tiles per task, its tiles in parallel too, written straight into the picture
+ out.data.par_chunks_mut((w * TILE).max(1)).enumerate().for_each(|(ty, band)| {
+ let (y0, th) = (ty * TILE, band.len() / w.max(1));
+ let tiles: Vec<(usize, usize, Vec<[f32; 3]>)> = (0..w.div_ceil(TILE))
+ .into_par_iter()
+ .map(|tx| {
+ let (x0, tw) = (tx * TILE, TILE.min(w - tx * TILE));
+ (x0, tw, tile(m, x0, y0, tw, th))
+ })
+ .collect();
+ for (x0, tw, px) in tiles {
+ for (row, src) in band.chunks_exact_mut(w).zip(px.chunks_exact(tw)) {
+ row[x0..x0 + tw].copy_from_slice(src);
}
}
});