1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-29 21:44:24 +03:00

font: add helper to swap red/blue channels in an image

This commit is contained in:
Wez Furlong 2023-08-16 11:49:43 -07:00
parent 847b1b7ab9
commit 25697d406e
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
2 changed files with 17 additions and 3 deletions

View File

@ -230,9 +230,12 @@ impl FreeTypeRasterizer {
// emoji glyphs don't always fill the bitmap size, so we compute
// the non-transparent bounds
let cropped = crate::rasterizer::crop_to_non_transparent(&mut source_image).to_image();
let mut cropped = crate::rasterizer::crop_to_non_transparent(&mut source_image).to_image();
crate::rasterizer::swap_red_and_blue(&mut cropped);
let dest_width = cropped.width() as usize;
let dest_height = cropped.height() as usize;
RasterizedGlyph {
data: cropped.into_vec(),
height: dest_height,

View File

@ -1,6 +1,7 @@
use crate::parser::ParsedFont;
use crate::units::*;
use config::FontRasterizerSelection;
use image::{ImageBuffer, Rgba};
/// The amount, as a number in [0,1], to horizontally skew a glyph when rendering synthetic
/// italics
@ -47,9 +48,19 @@ pub fn new_rasterizer(
}
}
pub(crate) fn swap_red_and_blue<Container: std::ops::Deref<Target = [u8]> + std::ops::DerefMut>(
image: &mut ImageBuffer<Rgba<u8>, Container>,
) {
for pixel in image.pixels_mut() {
let red = pixel[0];
pixel[0] = pixel[2];
pixel[2] = red;
}
}
pub(crate) fn crop_to_non_transparent<'a, Container>(
image: &'a mut image::ImageBuffer<image::Rgba<u8>, Container>,
) -> image::SubImage<&'a mut image::ImageBuffer<image::Rgba<u8>, Container>>
image: &'a mut image::ImageBuffer<Rgba<u8>, Container>,
) -> image::SubImage<&'a mut ImageBuffer<Rgba<u8>, Container>>
where
Container: std::ops::Deref<Target = [u8]>,
{