aboutsummaryrefslogtreecommitdiff
path: root/src/render
diff options
context:
space:
mode:
Diffstat (limited to 'src/render')
-rw-r--r--src/render/composite.rs30
-rw-r--r--src/render/mod.rs9
2 files changed, 21 insertions, 18 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;
+ }
}
}
diff --git a/src/render/mod.rs b/src/render/mod.rs
index 6f5d5b4..9ae8b7a 100644
--- a/src/render/mod.rs
+++ b/src/render/mod.rs
@@ -52,16 +52,15 @@ impl Renderer {
.unwrap_or((true, true))
};
- let mut view: Texture =
- ImageBuffer::new(16 * (SEG_SIZE + 1) as u32, 16 * (SEG_SIZE + 1) as u32);
+ let mut view: Texture = ImageBuffer::new(16 * SEG_SIZE as u32, 16 * SEG_SIZE as u32);
let mut visible = Vec::<((isize, isize, isize), (isize, isize, isize))>::new();
let offx = sx * SEG_SIZE;
let offy = sy * SEG_SIZE * 2;
- for ix in 0..SEG_SIZE {
- for iy in 0..(SEG_SIZE * 2) {
+ for ix in -1..SEG_SIZE {
+ for iy in -1..(SEG_SIZE * 2) {
for off in 0..=1 {
let mut y = 319;
let mut x = -ix - offx + iy + offy;
@@ -94,7 +93,7 @@ impl Renderer {
let texture = &self.load_texture(name);
let ix = ix * 16 + off * 8;
let iy = iy * 8 + off * 4;
- image_buffer_blit(&mut view, texture, (ix as u32, iy as u32));
+ image_buffer_blit(&mut view, texture, (ix, iy));
}
let end_time = Instant::now();