1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-11 13:51:01 -05:00

Add support for LCD-V pixel mode

This commit is contained in:
yshui 2018-07-21 18:05:14 +00:00 committed by Christian Duerr
parent a6e8974a06
commit 0d5edb7a7a

View file

@ -348,14 +348,14 @@ impl FreeTypeRasterizer {
let glyph = face.ft_face.glyph(); let glyph = face.ft_face.glyph();
glyph.render_glyph(face.render_mode)?; glyph.render_glyph(face.render_mode)?;
let (pixel_width, buf) = Self::normalize_buffer(&glyph.bitmap())?; let (pixel_height, pixel_width, buf) = Self::normalize_buffer(&glyph.bitmap())?;
Ok(RasterizedGlyph { Ok(RasterizedGlyph {
c: glyph_key.c, c: glyph_key.c,
top: glyph.bitmap_top(), top: glyph.bitmap_top(),
left: glyph.bitmap_left(), left: glyph.bitmap_left(),
width: pixel_width, width: pixel_width,
height: glyph.bitmap().rows(), height: pixel_height,
buf, buf,
}) })
} }
@ -427,7 +427,7 @@ impl FreeTypeRasterizer {
/// Given a FreeType `Bitmap`, returns packed buffer with 1 byte per LCD channel. /// Given a FreeType `Bitmap`, returns packed buffer with 1 byte per LCD channel.
/// ///
/// The i32 value in the return type is the number of pixels per row. /// The i32 value in the return type is the number of pixels per row.
fn normalize_buffer(bitmap: &freetype::bitmap::Bitmap) -> freetype::FtResult<(i32, Vec<u8>)> { fn normalize_buffer(bitmap: &freetype::bitmap::Bitmap) -> freetype::FtResult<(i32, i32, Vec<u8>)> {
use freetype::bitmap::PixelMode; use freetype::bitmap::PixelMode;
let buf = bitmap.buffer(); let buf = bitmap.buffer();
@ -440,7 +440,18 @@ impl FreeTypeRasterizer {
let stop = start + bitmap.width() as usize; let stop = start + bitmap.width() as usize;
packed.extend_from_slice(&buf[start..stop]); packed.extend_from_slice(&buf[start..stop]);
} }
Ok((bitmap.width() / 3, packed)) Ok((bitmap.rows(), bitmap.width() / 3, packed))
},
PixelMode::LcdV => {
for i in 0..bitmap.rows()/3 {
for j in 0..bitmap.width() {
for k in 0..3 {
let offset = ((i as usize) * 3 + k) * pitch + (j as usize);
packed.push(buf[offset]);
}
}
}
Ok((bitmap.rows() / 3, bitmap.width(), packed))
}, },
// Mono data is stored in a packed format using 1 bit per pixel. // Mono data is stored in a packed format using 1 bit per pixel.
PixelMode::Mono => { PixelMode::Mono => {
@ -471,7 +482,7 @@ impl FreeTypeRasterizer {
byte += 1; byte += 1;
} }
} }
Ok((bitmap.width(), packed)) Ok((bitmap.rows(), bitmap.width(), packed))
}, },
// Gray data is stored as a value between 0 and 255 using 1 byte per pixel. // Gray data is stored as a value between 0 and 255 using 1 byte per pixel.
PixelMode::Gray => { PixelMode::Gray => {
@ -484,7 +495,7 @@ impl FreeTypeRasterizer {
packed.push(*byte); packed.push(*byte);
} }
} }
Ok((bitmap.width(), packed)) Ok((bitmap.rows(), bitmap.width(), packed))
}, },
mode => panic!("unhandled pixel mode: {:?}", mode) mode => panic!("unhandled pixel mode: {:?}", mode)
} }