Skip to content

Commit

Permalink
impl FT_PIXEL_MODE_LCD_V
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaopengli89 committed Oct 12, 2023
1 parent 11dec45 commit 9285051
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions wezterm-font/src/rasterizer/freetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ impl FontRasterizer for FreeTypeRasterizer {
ftwrap::FT_Pixel_Mode::FT_PIXEL_MODE_LCD => {
self.rasterize_lcd(pitch, ft_glyph, data, is_scaled)
}
ftwrap::FT_Pixel_Mode::FT_PIXEL_MODE_LCD_V => {
self.rasterize_lcd_v(pitch, ft_glyph, data, is_scaled)
}
ftwrap::FT_Pixel_Mode::FT_PIXEL_MODE_BGRA => {
self.rasterize_bgra(pitch, ft_glyph, data, is_scaled)?
}
Expand Down Expand Up @@ -257,6 +260,59 @@ impl FreeTypeRasterizer {
}
}

fn rasterize_lcd_v(
&self,
pitch: usize,
ft_glyph: &FT_GlyphSlotRec_,
data: &[u8],
is_scaled: bool,
) -> RasterizedGlyph {
let width = ft_glyph.bitmap.width as usize;
let height = ft_glyph.bitmap.rows as usize / 3;
let size = width * height * 4;
let mut rgba = vec![0u8; size];
for y in 0..height {
let src_offset = y * pitch * 3;
let dest_offset = y * width * 4;
for x in 0..width {
let red = data[src_offset + x];
let green = data[src_offset + x + pitch];
let blue = data[src_offset + x + 2 * pitch];

let linear_alpha = red.max(green).max(blue);

// Texture is SRGBA, which in OpenGL means
// that the RGB values are gamma adjusted
// non-linear values, but the A value is
// linear!

let red = linear_u8_to_srgb8(red);
let green = linear_u8_to_srgb8(green);
let blue = linear_u8_to_srgb8(blue);

let (red, blue) = match self.display_pixel_geometry {
DisplayPixelGeometry::RGB => (red, blue),
DisplayPixelGeometry::BGR => (blue, red),
};

rgba[dest_offset + (x * 4)] = red;
rgba[dest_offset + (x * 4) + 1] = green;
rgba[dest_offset + (x * 4) + 2] = blue;
rgba[dest_offset + (x * 4) + 3] = linear_alpha;
}
}

RasterizedGlyph {
data: rgba,
height,
width,
bearing_x: PixelLength::new(ft_glyph.bitmap_left as f64),
bearing_y: PixelLength::new(ft_glyph.bitmap_top as f64),
has_color: self.has_color,
is_scaled,
}
}

fn rasterize_bgra(
&self,
pitch: usize,
Expand Down

0 comments on commit 9285051

Please sign in to comment.