diff options
Diffstat (limited to 'src/render.rs')
-rw-r--r-- | src/render.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/render.rs b/src/render.rs index 77a847f..927782c 100644 --- a/src/render.rs +++ b/src/render.rs @@ -112,10 +112,7 @@ impl<'r> Renderer<'r> { self.options.trait_size, imageops::FilterType::CatmullRom, ); - let minor_img = imageproc::map::map_pixels(&minor_img, |x, y, p| { - let alpha = self.minor_mask.get_pixel(x, y)[3]; - Rgba([p[0], p[1], p[2], alpha]) - }); + let minor_img = with_mask(&minor_img, &self.minor_mask); let y_pos = (buffer.height() - minor_img.height()) / 2; let x_slice = (buffer.width() - self.options.traitline_x_offset) / 6; let x_pos = 2 * (minor.tier - 1) * x_slice @@ -138,9 +135,9 @@ impl<'r> Renderer<'r> { imageops::FilterType::CatmullRom, ); let major_img = if !chosen { - major_img.grayscale() + with_mask(&major_img.grayscale(), &major_img) } else { - major_img + major_img.to_rgba() }; let y_slice = buffer.height() / 3; let y_pos = vertical_pos as u32 * y_slice + (y_slice - major_img.height()) / 2; @@ -323,3 +320,14 @@ impl<'r> Renderer<'r> { Ok(buffer) } } + +fn with_mask<I, J>(input: &I, mask: &J) -> RgbaImage +where + I: GenericImage<Pixel = Rgba<u8>>, + J: GenericImage<Pixel = Rgba<u8>>, +{ + imageproc::map::map_pixels(input, |x, y, p| { + let alpha = mask.get_pixel(x, y)[3]; + Rgba([p[0], p[1], p[2], alpha]) + }) +} |