Sixel Graphics

Sixel Graphics

May 4, 2021
graphics

Reading time: 1 minutes and 7 seconds.

What are Sixels?

VT330/VT340 Programmer Reference Manual, Ch. 14 Sixel Graphics.

Escape Character

DCS (Device Control String): 0x90

OR

ESC+P: 0x1B + 0x50

Termination

ST (String Terminator) 0x0

OR

ESC+\: 0x1B + 0x5C

Control Functions

LSB (least-significant bit) at the top.

>>> 0x90 0x40 = 0x90 0b000001
■
□
□
□
□
□

>>> 0x90 0x74 = 0x90 0b110100
■
□
■
□
■
■

>>> sixel2str = lambda i : '\n'.join(['■' if (((i-0x3F) >> j) & 1) else '□' for j in range(6)])
>>> sixels2str = lambda il : '\n'.join([' '.join(l) for l in zip(*[[c for c in sixel2str(i) if c != '\n'] for i in il])])
>>> print(sixel2str(0x74))






# Brian Kernighan's algo.
def count_bits(n):
    count = 0
    while n:
        n &= (n-1)
        count += 1

    return count

countbits = lambda n : (count := 0, (while n: (n &= (n-1)), count += 1), count)[-1]
for i, c in enumerate(range(ord('?'), ord('?')+64)):
    print(f"|`{bin(i).replace('0b','').rjust(6, '0')}`|`{chr(c)}`|`{hex(c).upper().replace('X','x')}`|")
SixelCharHex
000000?0x3F
000001@0x40
000010A0x41
000011B0x42
000100C0x43
000101D0x44
000110E0x45
000111F0x46
001000G0x47
001001H0x48
001010I0x49
001011J0x4A
001100K0x4B
001101L0x4C
001110M0x4D
001111N0x4E
010000O0x4F
010001P0x50
010010Q0x51
010011R0x52
010100S0x53
010101T0x54
010110U0x55
010111V0x56
011000W0x57
011001X0x58
011010Y0x59
011011Z0x5A
011100[0x5B
011101\|0x5C|
011110]0x5D
011111^0x5E
100000_0x5F
100001`0x60
100010a0x61
100011b0x62
100100c0x63
100101d0x64
100110e0x65
100111f0x66
101000g0x67
101001h0x68
101010i0x69
101011j0x6A
101100k0x6B
101101l0x6C
101110m0x6D
101111n0x6E
110000o0x6F
110001p0x70
110010q0x71
110011r0x72
110100s0x73
110101t0x74
110110u0x75
110111v0x76
111000w0x77
111001x0x78
111010y0x79
111011z0x7A
111100{0x7B
111101\|0x7C
111110}0x7D
111111~0x7E