16-bit RGB565, little-endian: red in the top 5 bits, green in the middle 6, blue in the low 5, low byte first. The usual depth of SPI LCDs and of Linux framebuffers configured with framebuffer_depth=16.
Cell colours resolve through a RasterExRatatui.Palette (named and indexed colours via its theme, :reset via its default foreground and background, :bold and :reversed applied); region pixels are packed as they come. Margins and skipped cells take the palette's default background.
Options
Every RasterExRatatui.Palette.new/1 option: :theme, :reset_fg, :reset_bg, :bold_bright.
Examples
iex> alias ExRatatui.CellSession.Cell
iex> alias RasterExRatatui.PixelFormat.RGB565
iex> config = RGB565.init([])
iex> RGB565.cell_paints(%Cell{fg: {:rgb, 255, 0, 0}, bg: {:rgb, 0, 255, 0}}, config)
{<<0, 248>>, <<224, 7>>}
Summary
Functions
The palette's default background.
2 bytes per pixel.
The cell's foreground and background, resolved through the palette and packed.
Builds the palette from opts.
:rgb565: regions are packed natively by ExRatatui.Pixels.pack_rgb8/5, which writes the same bytes as rgb_pixel/6.
Packs an RGB pixel; the position is ignored.
Packs a row of RGB pixels in one pass; the position is ignored.
Each 16-bit pixel as RGB8, the low bits filled from the high ones so full red is 255, not 248.
Functions
@spec blank(RasterExRatatui.Palette.t()) :: binary()
The palette's default background.
Examples
iex> RasterExRatatui.PixelFormat.RGB565.blank(RasterExRatatui.Palette.new(reset_bg: {0, 255, 0}))
<<224, 7>>
@spec bytes_per_pixel(RasterExRatatui.Palette.t()) :: 2
2 bytes per pixel.
Examples
iex> RasterExRatatui.PixelFormat.RGB565.bytes_per_pixel(RasterExRatatui.Palette.new())
2
@spec cell_paints(ExRatatui.CellSession.Cell.t(), RasterExRatatui.Palette.t()) :: {binary(), binary()}
The cell's foreground and background, resolved through the palette and packed.
Examples
iex> alias ExRatatui.CellSession.Cell
iex> RasterExRatatui.PixelFormat.RGB565.cell_paints(%Cell{fg: :reset, bg: :reset, modifiers: [:reversed]}, RasterExRatatui.Palette.new(reset_fg: {255, 0, 0}, reset_bg: {0, 255, 0}))
{<<224, 7>>, <<0, 248>>}
@spec init(keyword()) :: RasterExRatatui.Palette.t()
Builds the palette from opts.
Examples
iex> RasterExRatatui.PixelFormat.RGB565.init(reset_bg: {1, 2, 3}).reset_bg
{1, 2, 3}
@spec native_format(RasterExRatatui.Palette.t()) :: :rgb565
:rgb565: regions are packed natively by ExRatatui.Pixels.pack_rgb8/5, which writes the same bytes as rgb_pixel/6.
Examples
iex> RasterExRatatui.PixelFormat.RGB565.native_format(RasterExRatatui.Palette.new())
:rgb565
@spec rgb_pixel( 0..255, 0..255, 0..255, non_neg_integer(), non_neg_integer(), RasterExRatatui.Palette.t() ) :: binary()
Packs an RGB pixel; the position is ignored.
Examples
iex> RasterExRatatui.PixelFormat.RGB565.rgb_pixel(255, 0, 0, 0, 0, RasterExRatatui.Palette.new())
<<0, 248>>
@spec rgb_row( binary(), non_neg_integer(), non_neg_integer(), RasterExRatatui.Palette.t() ) :: binary()
Packs a row of RGB pixels in one pass; the position is ignored.
Examples
iex> RasterExRatatui.PixelFormat.RGB565.rgb_row(<<255, 0, 0, 0, 0, 255>>, 0, 0, RasterExRatatui.Palette.new())
<<0, 248, 31, 0>>
Each 16-bit pixel as RGB8, the low bits filled from the high ones so full red is 255, not 248.
Examples
iex> RasterExRatatui.PixelFormat.RGB565.unpack_row(<<0, 248, 224, 7, 31, 0>>, RasterExRatatui.Palette.new())
<<255, 0, 0, 0, 255, 0, 0, 0, 255>>