aboutsummaryrefslogtreecommitdiff
path: root/src/render/composite.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2022-10-17 22:41:14 +0200
committermetamuffin <metamuffin@disroot.org>2022-10-17 22:41:14 +0200
commit3baa2e9cb8f00be594fb90a74acc9972e3477c72 (patch)
treecb12b918c93cfc8ae129c81d726989239812c383 /src/render/composite.rs
parent146ab6ff6d5ccfc83d2af8cb5df69c8caa02026f (diff)
downloadtrash-map-3baa2e9cb8f00be594fb90a74acc9972e3477c72.tar
trash-map-3baa2e9cb8f00be594fb90a74acc9972e3477c72.tar.bz2
trash-map-3baa2e9cb8f00be594fb90a74acc9972e3477c72.tar.zst
no margins
Diffstat (limited to 'src/render/composite.rs')
-rw-r--r--src/render/composite.rs30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/render/composite.rs b/src/render/composite.rs
index 99950f1..ea9cc29 100644
--- a/src/render/composite.rs
+++ b/src/render/composite.rs
@@ -7,21 +7,25 @@ pub const CHUNK_SIZE: usize = 16;
pub fn image_buffer_blit(
target: &mut ImageBuffer<Rgba<u8>, Vec<u8>>,
source: &ImageBuffer<Rgba<u8>, Vec<u8>>,
- offset: (u32, u32),
+ offset: (isize, isize),
) {
for (x, y, source_pixel) in source.enumerate_pixels() {
- let target_pixel = target.get_pixel_mut(x + offset.0, y + offset.1);
- let sa = source_pixel.0[3] as u16;
- let new_pixel = Rgba::from([
- ((target_pixel.0[0] as u16 * (255 - sa)) / 255 + (source_pixel.0[0] as u16 * sa) / 255)
- as u8,
- ((target_pixel.0[1] as u16 * (255 - sa)) / 255 + (source_pixel.0[1] as u16 * sa) / 255)
- as u8,
- ((target_pixel.0[2] as u16 * (255 - sa)) / 255 + (source_pixel.0[2] as u16 * sa) / 255)
- as u8,
- 255 - (((255 - target_pixel.0[3] as u16) * (255 - sa)) / 255) as u8,
- ]);
- *target_pixel = new_pixel;
+ let tx = x as isize + offset.0;
+ let ty = y as isize + offset.1;
+ if tx >= 0 && tx < target.width() as isize && ty >= 0 && ty < target.height() as isize {
+ let target_pixel = target.get_pixel_mut(tx as u32, ty as u32);
+ let sa = source_pixel.0[3] as u16;
+ let new_pixel = Rgba::from([
+ ((target_pixel.0[0] as u16 * (255 - sa)) / 255
+ + (source_pixel.0[0] as u16 * sa) / 255) as u8,
+ ((target_pixel.0[1] as u16 * (255 - sa)) / 255
+ + (source_pixel.0[1] as u16 * sa) / 255) as u8,
+ ((target_pixel.0[2] as u16 * (255 - sa)) / 255
+ + (source_pixel.0[2] as u16 * sa) / 255) as u8,
+ 255 - (((255 - target_pixel.0[3] as u16) * (255 - sa)) / 255) as u8,
+ ]);
+ *target_pixel = new_pixel;
+ }
}
}