# `RasterExRatatui.PixelFormat.XRGB8888`
[🔗](https://github.com/mcass19/raster_ex_ratatui/blob/v0.4.0/lib/raster_ex_ratatui/pixel_format/xrgb8888.ex#L1)

32-bit XRGB8888, little-endian: bytes are blue, green, red, then an unused byte written as `255`. A common Linux framebuffer depth; `RasterExRatatui.Framebuffer.format_for/1` picks it from the device instead of assuming it.

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.XRGB8888
    iex> config = XRGB8888.init([])
    iex> XRGB8888.cell_paints(%Cell{fg: {:rgb, 255, 0, 0}, bg: {:rgb, 0, 255, 0}}, config)
    {<<0, 0, 255, 255>>, <<0, 255, 0, 255>>}

# `blank`

```elixir
@spec blank(RasterExRatatui.Palette.t()) :: binary()
```

The palette's default background.

## Examples

    iex> RasterExRatatui.PixelFormat.XRGB8888.blank(RasterExRatatui.Palette.new(reset_bg: {0, 255, 0}))
    <<0, 255, 0, 255>>

# `bytes_per_pixel`

```elixir
@spec bytes_per_pixel(RasterExRatatui.Palette.t()) :: 4
```

4 bytes per pixel.

## Examples

    iex> RasterExRatatui.PixelFormat.XRGB8888.bytes_per_pixel(RasterExRatatui.Palette.new())
    4

# `cell_paints`

```elixir
@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.XRGB8888.cell_paints(%Cell{fg: :reset, bg: :reset, modifiers: [:reversed]}, RasterExRatatui.Palette.new(reset_fg: {255, 0, 0}, reset_bg: {0, 255, 0}))
    {<<0, 255, 0, 255>>, <<0, 0, 255, 255>>}

# `init`

```elixir
@spec init(keyword()) :: RasterExRatatui.Palette.t()
```

Builds the palette from `opts`.

## Examples

    iex> RasterExRatatui.PixelFormat.XRGB8888.init(reset_bg: {1, 2, 3}).reset_bg
    {1, 2, 3}

# `native_format`

```elixir
@spec native_format(RasterExRatatui.Palette.t()) :: :xrgb8888
```

`:xrgb8888`: regions are packed natively by `ExRatatui.Pixels.pack_rgb8/5`, which writes the same bytes as `rgb_pixel/6`.

## Examples

    iex> RasterExRatatui.PixelFormat.XRGB8888.native_format(RasterExRatatui.Palette.new())
    :xrgb8888

# `rgb_pixel`

```elixir
@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.XRGB8888.rgb_pixel(255, 0, 0, 0, 0, RasterExRatatui.Palette.new())
    <<0, 0, 255, 255>>

# `rgb_row`

```elixir
@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.XRGB8888.rgb_row(<<255, 0, 0, 0, 0, 255>>, 0, 0, RasterExRatatui.Palette.new())
    <<0, 0, 255, 255, 255, 0, 0, 255>>

# `unpack_row`

```elixir
@spec unpack_row(binary(), term()) :: binary()
```

Each 32-bit pixel as RGB8.

## Examples

    iex> RasterExRatatui.PixelFormat.XRGB8888.unpack_row(<<0, 128, 255, 255>>, RasterExRatatui.Palette.new())
    <<255, 128, 0>>

---

*Consult [api-reference.md](api-reference.md) for complete listing*
