Sixel Image Encoding and Graphics Standards

Sixel Image Encoding and Graphics Standards

Sixel is a specialized method of encoding bitmap images into a stream of ASCII characters. Developed primarily for DEC (Digital Equipment Corporation) hardware, it allows terminals and printers to render graphics by treating image data as a series of printable characters, bridging the gap between text-based communication and visual imagery.

How Sixel Encoding Works

The core of Sixel encoding involves breaking a bitmap image into horizontal strips that are exactly 6 pixels high. Each 1-pixel-wide vertical column within these strips is called a sixel. To convert these pixels into text, the system reads the six pixels in a column as binary data, where an "on" pixel is represented by a 1.

This binary sequence creates a 6-bit number ranging from 0 to 63 in decimal. To ensure these values remain within the printable ASCII range, the system applies an offset of 63. Consequently, an all-black sixel (0 decimal) is encoded as the character ?, while an all-white sixel is encoded as ~.

To manage the layout of the image, specific characters are used for cursor control: the dollar sign ($) represents a carriage return (CR), and the hyphen (-) represents a line feed (LF). Together, these form the CRLF sequence required to return the cursor to the start of a new line.

[ไม่มีภาพประกอบ]

Compression via Run-Length Encoding

To reduce the amount of data transmitted, Sixel employs a basic form of run-length encoding (RLE). This compression technique uses the exclamation mark (!) followed by a decimal number to indicate how many times the subsequent sixel character should be repeated. Because the ! character and decimal digits fall outside the valid encoded range for sixel data, software can easily identify and expand these sequences back into the full image.

Technical Implementation and Control

Entering "Sixel mode" requires a specific sequence: ESC P p1 ; p2 ; p3 ;q. In this sequence, ESC P is the standard DEC Device Control String (DCS), used to toggle special features on DEC equipment, and q serves as the sixel identifier. The parameters p1 through p3 are optional setup values: p1 defines the aspect ratio (though this is largely deprecated), p2 determines how the color of zeros is interpreted, and p3 sets the grid size parameters.

Once the image data is transmitted, the sequence ESC \ (the String Terminator) is sent to return the device to normal character mode.

Hardware Rendering: Printers vs. Terminals

The method of rendering Sixel data depends on the target hardware. For printers, the data is decoded back into binary and sent directly to six pins in the print head, with the primary complexity being the expansion of RLE data into the internal buffer.

Terminals face a more complex task. Those supporting graphics utilized the ReGIS (Remote Graphics Instruction Set) system to draw the sixel pattern into the screen's bitmap. This was achieved at high speeds by storing bitmap patterns as glyphs and then "blitting" (block transferring) them onto the screen.

Advanced Features: Custom Characters and Color

Sixel was also adapted for defining custom character sets. While the data format remained nearly identical, the escape codes changed, and the separate CR/LF characters were replaced by a single forward slash (/). For example, in the VT300 series, 80-column character glyphs measured 15 pixels wide by 12 pixels high, meaning a single character was defined by 30 sixels.

Color support is implemented using the hash character (#) followed by a number that refers to a specific color register. These registers, which vary by device, are defined using RGB or HLS values in a proprietary DEC format. On printers, color images are created by sending a line of sixels multiple times, with each pass representing a single bitplane (a layer of image data) from the register-based colors.

Because hardware capabilities vary, color Sixel drawings must be targeted to specific devices; non-graphics terminals typically ignore Sixel escape sequences entirely.

Key Facts

  • Sixel Height: Images are processed in horizontal strips 6 pixels high.
  • Encoding Range: 6-bit binary values (0-63) are offset by 63 to fit printable ASCII characters.
  • Compression: Uses Run-Length Encoding (RLE) initiated by the ! character.
  • Control Sequence: Uses the DEC Device Control String (DCS) ESC P to enter mode and ESC \ to exit.
  • Color Method: Utilizes color registers defined by RGB or HLS values, accessed via the # character.
Sixel Encoding Summary
Element Representation / Value Function
Sixel Unit 6-pixel vertical column Basic building block of the image
All-Black Sixel ? Decimal 0 offset by 63
All-White Sixel ~ Decimal 63 offset by 63
Carriage Return $ Moves cursor to start of line
Line Feed - Moves cursor to next line
RLE Trigger ! Indicates repeated sixel data
Color Trigger # References a color register

Frequently Asked Questions

What is a sixel?

A sixel is a vertical column of six pixels. In Sixel encoding, these columns are treated as 6-bit binary numbers and converted into ASCII characters for transmission.

How does Sixel compression work?

Sixel uses run-length encoding (RLE). When the system encounters an exclamation mark (!), it reads the following decimal number to determine how many times to repeat the next sixel character.

What is the purpose of the DCS sequence in Sixel?

The Device Control String (DCS), ESC P, is used to put the hardware into "Sixel mode," allowing it to interpret the subsequent stream of characters as image data rather than standard text.

How are colors handled in Sixel images?

Colors are managed through registers. The # character is followed by a register number, and the colors within those registers are defined using DEC's specific RGB or HLS formats.

Can any terminal display Sixel graphics?

No. Sixel requires specific hardware or software support. Terminals that do not support graphics generally ignore Sixel escape sequences silently.