From 63d923ad103dbdc40588dac17e116b858199582a Mon Sep 17 00:00:00 2001 From: Simon Gellis Date: Sat, 31 Oct 2026 12:35:03 -0400 Subject: [PATCH] Combine colors with saturation, not overflow --- src/images.rs | 6 +----- src/window/vip/framebuffer.rs | 6 +----- src/window/vip/world.rs | 13 ++----------- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/images.rs b/src/images.rs index 7f2a803..4e8689a 100644 --- a/src/images.rs +++ b/src/images.rs @@ -220,11 +220,7 @@ impl ImageBuffer { pub fn add(&mut self, coords: (usize, usize), pixel: Color32) { let index = coords.1 * self.size[0] + coords.0; let old = self.pixels[index]; - self.pixels[index] = Color32::from_rgb( - old.r() + pixel.r(), - old.g() + pixel.g(), - old.b() + pixel.b(), - ); + self.pixels[index] = old + pixel; } pub fn changed(&self, image: &ColorImage) -> bool { diff --git a/src/window/vip/framebuffer.rs b/src/window/vip/framebuffer.rs index 587b474..80e1952 100644 --- a/src/window/vip/framebuffer.rs +++ b/src/window/vip/framebuffer.rs @@ -266,11 +266,7 @@ impl ImageRenderer<1> for FrameBufferRenderer { } else { Color32::BLACK }; - Color32::from_rgb( - left.r() + right.r(), - left.g() + right.g(), - left.b() + right.b(), - ) + left + right }); let x = index / 64; for (i, pixel) in pixels.into_iter().enumerate() { diff --git a/src/window/vip/world.rs b/src/window/vip/world.rs index 88aadd7..afbc869 100644 --- a/src/window/vip/world.rs +++ b/src/window/vip/world.rs @@ -477,12 +477,7 @@ impl WorldWindow { let left_color = self.params.left_color; let right_color = self.params.right_color; - let both_color = Color32::from_rgb( - left_color.r() + right_color.r(), - left_color.g() + right_color.g(), - left_color.b() + right_color.b(), - ); - + let both_color = left_color + right_color; let painter = ui.painter(); let draw_rect = |x1: f32, x2: f32, color: Color32| { painter.line( @@ -702,11 +697,7 @@ impl WorldRenderer { for (dst, shades) in image.pixels.iter_mut().zip(self.buffer.iter()) { let left = colors[0][shades[0] as usize]; let right = colors[1][shades[1] as usize]; - *dst = Color32::from_rgb( - left.r() + right.r(), - left.g() + right.g(), - left.b() + right.b(), - ) + *dst = left + right; } }