diff options
author | Daniel Schadt <kingdread@gmx.de> | 2019-12-07 17:29:12 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2019-12-07 17:29:12 +0100 |
commit | 3522b9ee1906dc36d04ee3ef9eab99305dcac5c4 (patch) | |
tree | 8ba1e07f2ef7769d78743ae49c05ce9b05aec527 /src | |
parent | 17f3c1a5023ff0457299b272a608ba45875841c7 (diff) | |
download | kondou-3522b9ee1906dc36d04ee3ef9eab99305dcac5c4.tar.gz kondou-3522b9ee1906dc36d04ee3ef9eab99305dcac5c4.tar.bz2 kondou-3522b9ee1906dc36d04ee3ef9eab99305dcac5c4.zip |
improve grayscale rendering
Apparently, turning the picture to grayscale also messes with the alpha
channel. A lot of trait icons have a small transparent border though.
Therefore, we want to preserve the alpha channel by copying it back from
the original trait icon. This improves render quality and removes some
of the artifacts.
Diffstat (limited to 'src')
-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]) + }) +} |