Sixel
Sixel, short for "six pixels", is a bitmap graphics format supported by terminals and printers from DEC. It consists of a pattern six pixels high and one wide, resulting in 64 possible patterns. Each possible pattern is assigned an ASCII character, making the sixels easy to transmit on 7-bit serial links.
Sixel was first introduced as a way of sending bitmap graphics to DEC
The system was later re-used as a way to send bitmap data to the
Description
Sixel encodes images by breaking up the bitmap into a series of 6-pixel high horizontal strips. Each 1-pixel-wide vertical column in a particular strip forms a single sixel. Each sixel's pixels are read as binary and encoded into a single 6-bit number, with "on" pixels encoded as a 1. This number, from 0 to 63 decimal, is then converted into a single ASCII character, offset by 63 so that an all-black sixel, 0 decimal, is encoded as ?. This ensures that the sixels remain within the
Sixel also includes a rudimentary form of compression, using run-length encoding (RLE). This is accomplished with the ! character followed by a decimal number of the times to repeat, and then a single sixel character to be repeated. Since the ! and decimal digits cannot be valid sixel data, lying outside the encoded range, the encoding is easy to identify and expand back out in software.
"Sixel mode" is entered by sending the sequence ESC+Pp1;p2;p3;q. The p1 through p3 were optional setup parameters, with p1 defining an
For printing, sixels are sent to the printer, decoded back into binary, and sent directly to six pins in the print head. The only complexity involved expanding the RLEs into the internal print buffer. Display on a terminal is somewhat more difficult. On terminals supporting graphics, the ReGIS graphics system was used to directly draw the sixel pattern into the screen's bitmap. This was done at high speed by storing the bitmap patterns as a glyph and then blitting them.
When used for defining custom character sets the format was almost identical, although the escape codes changed. In terms of the data, the only major difference is the replacement of the separate CR/LF with a single /
. In the VT300 series for instance, 80-column character glyphs were 15 pixels wide by 12 high, meaning that a character could be defined by sending a total of 30 sixels.
Color is also supported using the # character, followed by a number referring to one of a number of
Sample
<ESC>Pq #0;2;0;0;0#1;2;100;100;0#2;2;0;100;0 #1~~@@vv@@~~@@~~$ #2??}}GG}}??}}??- #1!14@ <ESC>\
The example above enters sixel mode, sets up three color registers, and then uses those registers to draw sixels in those colors. The #0;2;0;0;0
is interpreted as "set color register 0, use mode 2 (RGB mode), set R, G and B to 0%". This sets color 0 to black, and the following commands set register 1 to yellow (100%, 100%, 0%) and 2 to green (0%, 100%, 0%). Unlike most modern systems which assign an 8-bit value (0–255) to each color channel, RGB mode is based on "intensity" of each channel from 0% to 100%.
The data lines following select a color, yellow for the first and third and green for the middle, then draw sixels. The last line shows the RLE in use, meaning "repeat @
(0b100000
) 14 times". The final output is 14 pixels by 7 pixels, so the last line simply repeats 0b100000
14 times to fill the last line. $
at the end of a line means that the next line will overprint the current line, while -
means that the next line represents a new line of sixels.
Notes
- ^ Lower-case "p" was the ReGIS identifier.
See also
- ReGIS – a means of displaying vector graphics on later DEC VT-series terminals
- Semigraphics – text-based graphics, including "squot" sub-character square blocks
References
- "VT330/VT340 Programmer Reference Manual, Volume 2: Graphics Programming", Digital, EK-VT3XX-GP-002, May 1988
- Chris Chiesa, All About SIXELs, 29 September 1990
- Moy, Edward; Gildea, Stephen; Dickey, Thomas (31 December 2023). "XTerm Control Sequences". XTerm manual.