Raxol.Terminal.ANSI.SixelGraphics (Raxol v0.5.0)

View Source

Sixel graphics support for terminal rendering.

This module handles:

  • Sixel image encoding and decoding
  • Color palette management
  • Image scaling and positioning
  • Terminal compatibility checks

Summary

Functions

Decodes an ANSI escape sequence into a Sixel image.

Encodes a Sixel image to ANSI escape sequence.

Gets the current image data.

Gets the current color palette.

Gets the current position.

Gets the current scale factors.

Creates a new Sixel image with default values.

Creates a new Sixel image with specified dimensions.

Processes a sequence of Sixel data.

Sets the image data for a Sixel image.

Sets the color palette for a Sixel image.

Sets the position for a Sixel image.

Sets the scale factor for a Sixel image.

Checks if the terminal supports Sixel graphics.

Types

t()

@type t() :: %Raxol.Terminal.ANSI.SixelGraphics{
  attributes: map(),
  current_color: non_neg_integer(),
  data: binary(),
  height: non_neg_integer(),
  palette: map(),
  pixel_buffer: map(),
  position: {non_neg_integer(), non_neg_integer()},
  scale: {non_neg_integer(), non_neg_integer()},
  sixel_cursor_pos: {non_neg_integer(), non_neg_integer()},
  width: non_neg_integer()
}

Functions

decode(data)

@spec decode(binary()) :: t()

Decodes an ANSI escape sequence into a Sixel image.

Parameters

  • data - The ANSI escape sequence to decode

Returns

A new Raxol.Terminal.ANSI.SixelGraphics.t/0 struct with the decoded image data.

encode(image)

@spec encode(t()) :: binary()

Encodes a Sixel image to ANSI escape sequence.

Parameters

  • image - The image to encode

Returns

A binary containing the ANSI escape sequence for the Sixel image.

get_data(image)

@spec get_data(t()) :: binary()

Gets the current image data.

Parameters

  • image - The current image

Returns

The binary image data.

get_palette(image)

@spec get_palette(t()) :: map()

Gets the current color palette.

Parameters

  • image - The current image

Returns

A map containing the current color palette.

get_position(image)

@spec get_position(t()) :: {non_neg_integer(), non_neg_integer()}

Gets the current position.

Parameters

  • image - The current image

Returns

A tuple {x, y} with the current position.

get_scale(image)

@spec get_scale(t()) :: {non_neg_integer(), non_neg_integer()}

Gets the current scale factors.

Parameters

  • image - The current image

Returns

A tuple {x_scale, y_scale} with the current scale factors.

new()

@spec new() :: t()

Creates a new Sixel image with default values.

Returns

A new Raxol.Terminal.ANSI.SixelGraphics.t/0 struct with default values.

new(width, height)

@spec new(non_neg_integer(), non_neg_integer()) :: t()

Creates a new Sixel image with specified dimensions.

Parameters

  • width - The image width in pixels
  • height - The image height in pixels

Returns

A new Raxol.Terminal.ANSI.SixelGraphics.t/0 struct with the specified dimensions.

process_sequence(state, data)

@spec process_sequence(t(), binary()) :: {t(), :ok | {:error, atom()}}

Processes a sequence of Sixel data.

Parameters

  • state - The current Sixel state
  • data - The Sixel data to process

Returns

A tuple containing the updated state and a response.

set_data(image, data)

@spec set_data(t(), binary()) :: t()

Sets the image data for a Sixel image.

Parameters

  • image - The current image
  • data - The binary image data

Returns

The updated image with new data.

set_palette(image, palette)

@spec set_palette(t(), map()) :: t()

Sets the color palette for a Sixel image.

Parameters

  • image - The current image
  • palette - A map of color indices to RGB values

Returns

The updated image with new palette.

set_position(image, x, y)

@spec set_position(t(), non_neg_integer(), non_neg_integer()) :: t()

Sets the position for a Sixel image.

Parameters

  • image - The current image
  • x - The horizontal position
  • y - The vertical position

Returns

The updated image with new position.

set_scale(image, x_scale, y_scale)

@spec set_scale(t(), non_neg_integer(), non_neg_integer()) :: t()

Sets the scale factor for a Sixel image.

Parameters

  • image - The current image
  • x_scale - The horizontal scale factor
  • y_scale - The vertical scale factor

Returns

The updated image with new scale factors.

supported?()

@spec supported?() :: boolean()

Checks if the terminal supports Sixel graphics.

Returns

true if Sixel graphics are supported, false otherwise.