JFLib

text/lcd.rs#

Source: lib/text/lcd.rs

lcd -- subpixel (LCD, ClearType-like) glyph smoothing

  set_subpixel(SUBPIXEL_*) / subpixel()   the order of the display's subpixels; NONE (the
       default) keeps greyscale masks.  RGB / BGR: three columns per pixel, VRGB / VBGR:
       three rows (rotated panels)

A glyph is rasterized at three times the resolution across the subpixels (x for RGB / BGR,
y for VRGB / VBGR), FreeType's default 5-tap FIR filter (08 4D 56 4D 08, sum 256) spreads
every subpixel's coverage over its neighbours (fewer colour fringes, the energy of each
pixel kept), and each colour channel is blended with its own coverage.  The cache entry
holds 3 bytes per pixel in the physical order of the subpixels (left to right, or top to
bottom), so RGB and BGR share it; the mask is one pixel wider (taller) on each side than
the greyscale one.

Blending is gamma-correct-ish: target and text colour go to linear light (gamma 1.6, a
256-entry table), each channel is mixed there and comes back through a 2 x 4096-entry
table.  Linear light makes dark text thinner and light text bolder, so the coverage is
adjusted first by the text colour's luminance (DirectWrite's "enhanced contrast",
c' = c (1 + k) / (1 + k c), k = LCD_DARK for black text down to -LCD_LIGHT for white):
black, white and grey text keep the weight of greyscale text within a few per cent
(fonttest --selftest measures it).

Used only where it is safe: an opaque target (FMT_XRGB, the window framebuffer) and a
glyph from the cache.  A8 and PARGB targets (layers, images, anything composited later),
colour glyphs (COLR layers, CBDT bitmaps), the icon font, glyphs too large for the cache
(filled as paths) and black-and-white masks (set_antialias(false)) stay greyscale.  The
text colour's alpha and the global opacity scale the coverage (the target stays opaque).
Mirrored (RTL) windows mirror the command lists, not the pixels: text keeps the physical
subpixel order.
/// set_subpixel: greyscale smoothing (no subpixels)
SUBPIXEL_NONE: u8 = 0
/// set_subpixel: red, green, blue from left to right
SUBPIXEL_RGB: u8 = 1
/// set_subpixel: blue, green, red from left to right
SUBPIXEL_BGR: u8 = 2
/// set_subpixel: red, green, blue from top to bottom
SUBPIXEL_VRGB: u8 = 3
/// set_subpixel: blue, green, red from top to bottom
SUBPIXEL_VBGR: u8 = 4

impl Text

  • fn set_subpixel(&mut self, order: u8) the subpixel order of the display (SUBPIXEL_*): RGB / BGR / VRGB / VBGR draw glyphs on opaque (FMT_XRGB) targets with subpixel smoothing, NONE (the default) in greyscale; see lcd.rs for where it applies
  • fn subpixel(&self) -> u8 the subpixel order in use (SUBPIXEL_*)
  • fn lcd_tables_exact(&mut self) -> bool (tests) every byte survives the trip through linear light unchanged

Source: docs/API.md in the JFLib repository.