mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-24 10:27:00 -06:00
M12: boards dot grid: blending a dot in a function of its own (Sonar)
This commit is contained in:
+19
-14
@@ -62,20 +62,25 @@ pub(crate) fn draw(pix: &mut Pixmap, view: &View, d: &Dots) {
|
|||||||
if xa >= xb {
|
if xa >= xb {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let [r, g, b, a] = if i % 2 == 0 && j % 2 == 0 { strong } else { faded };
|
let rgba = if i % 2 == 0 && j % 2 == 0 { strong } else { faded };
|
||||||
if a == 0 {
|
blend_square(data, row, (xa, xb), (ya, yb), rgba);
|
||||||
continue;
|
}
|
||||||
}
|
}
|
||||||
for y in ya..yb {
|
}
|
||||||
let start = y as usize * row;
|
|
||||||
let Some(line) = data.get_mut(start + xa as usize * 4..start + xb as usize * 4) else { continue };
|
/// Blend premultiplied `rgba` source-over into the pixels `xs` × `ys` of `data`, rows `row` bytes
|
||||||
for px in line.chunks_exact_mut(4) {
|
/// long.
|
||||||
// Source over, premultiplied.
|
fn blend_square(data: &mut [u8], row: usize, (xa, xb): (i64, i64), (ya, yb): (i64, i64), rgba: [u32; 4]) {
|
||||||
let keep = 255 - a;
|
let keep = 255 - rgba[3];
|
||||||
for (dst, src) in px.iter_mut().zip([r, g, b, a]) {
|
if rgba[3] == 0 {
|
||||||
*dst = (src + u32::from(*dst) * keep / 255).min(255) as u8;
|
return;
|
||||||
}
|
}
|
||||||
}
|
for y in ya..yb {
|
||||||
|
let start = y as usize * row;
|
||||||
|
let Some(line) = data.get_mut(start + xa as usize * 4..start + xb as usize * 4) else { continue };
|
||||||
|
for px in line.chunks_exact_mut(4) {
|
||||||
|
for (dst, src) in px.iter_mut().zip(rgba) {
|
||||||
|
*dst = (src + u32::from(*dst) * keep / 255).min(255) as u8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user