1 hosho_sixel
liquibyte edited this page 2026-11-19 16:23:30 -06:00

hosho_sixel.h

Sixel Pictures: the Data a Program Sends, as Pixels.

Copyright (c) 2016-2026 Michael Grey (liquibyte) liquibyte@gmail.com SPDX-License-Identifier: Artistic-2.0 Distributed under the Artistic License 2.0; see LICENSE for terms.

A sixel picture is text: each character is a column of six pixels in one color. This reads the data of a sixel device control string and gives the picture as pixels.

Features:

  • Color definitions in RGB and in HLS, 256 color registers
  • Repeat counts, raster attributes, carriage return and new line
  • A background that is transparent or filled

Internal design notes:

  • The format is that of the VT330 and VT340, as xterm's ctlseqs and the DEC manuals describe it
  • The color registers are the caller's: a program can define colors in one picture and use them in the next
  • A picture is not larger than HOSHO_SIXEL_SIZE_LIMIT in each direction; pixels beyond that are dropped
#include "hosho_sixel.h"

Constants: HOSHO_SIXEL_COLORS, HOSHO_SIXEL_SIZE_LIMIT

Functions: hosho_sixel_default_colors, hosho_sixel_decode

Constants

HOSHO_SIXEL_COLORS

#define HOSHO_SIXEL_COLORS 256

The number of color registers.

HOSHO_SIXEL_SIZE_LIMIT

#define HOSHO_SIXEL_SIZE_LIMIT 4096

The most pixels a picture has in each direction.

Functions

hosho_sixel_default_colors

void hosho_sixel_default_colors(uint32_t *colors);

Give color registers the colors a VT340 starts with.

Parameter Description
colors HOSHO_SIXEL_COLORS registers, each 0xRRGGBB

hosho_sixel_decode

uint32_t *hosho_sixel_decode(
    const char *data,
    size_t length,
    uint32_t *colors,
    int fill_background,
    int *width,
    int *height);

Read sixel data.

Parameter Description
data The data of the device control string (after its final byte q)
length Its bytes
colors HOSHO_SIXEL_COLORS color registers, each 0xRRGGBB; the data's color definitions change them
fill_background 1 to give pixels the data did not draw the color of register 0; 0 to leave them transparent
width Gets the picture's width in pixels
height Gets its height

Returns: width times height pixels from malloc(), each 0xAARRGGBB (alpha 0 or 255), which the caller must free(); NULL when the data has no pixel or memory ran out