From a84e5fedb1d7de9ebbffdd5aa6e357c6addf7a76 Mon Sep 17 00:00:00 2001 From: Xiaopeng Li Date: Thu, 12 Oct 2023 22:08:23 +0800 Subject: [PATCH] impl FT_PIXEL_MODE_LCD_V --- wezterm-font/src/rasterizer/freetype.rs | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/wezterm-font/src/rasterizer/freetype.rs b/wezterm-font/src/rasterizer/freetype.rs index cd60c4273..9f7f312c8 100644 --- a/wezterm-font/src/rasterizer/freetype.rs +++ b/wezterm-font/src/rasterizer/freetype.rs @@ -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)? } @@ -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,