From 2aef95f62788163b789fae92b5a6546b2413d9e4 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 14 Dec 2019 01:45:23 +0100 Subject: correctly render transparent backgrounds Previously, some areas were "double exposed" to the transparency, making them a bit darker than the rest. The solution is to make sure that each part is drawn with the correct background color, and then only copying pixels instead of blending them to the final canvas. --- src/render.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/render.rs b/src/render.rs index e3f2d31..cbfd54f 100644 --- a/src/render.rs +++ b/src/render.rs @@ -135,9 +135,10 @@ impl<'r> Renderer<'r> { } pub fn render_skills(&mut self, skills: &[Option]) -> Result { - let mut buffer = ImageBuffer::new( + let mut buffer = ImageBuffer::from_pixel( skills.len() as u32 * self.options.skill_size, self.options.skill_size, + self.options.background_color, ); for (i, skill) in skills.iter().enumerate() { if let Some(skill) = skill { @@ -294,7 +295,11 @@ impl<'r> Renderer<'r> { specialization: &Specialization, ) -> Result { let scale = self.options.text_size; - let mut buffer = ImageBuffer::new(self.options.traitline_width, scale); + let mut buffer = ImageBuffer::from_pixel( + self.options.traitline_width, + scale, + self.options.background_color, + ); drawing::draw_text_mut( &mut buffer, self.options.text_color, @@ -367,7 +372,7 @@ impl<'r> Renderer<'r> { Alignment::Center => half(width - image.width()), Alignment::Right => width - image.width(), }; - imageops::overlay(&mut buffer, image, pos_x, pos_y); + buffer.copy_from(image, pos_x, pos_y); pos_y += image.height(); } -- cgit v1.2.3