6 Bring your own decoder🔗ℹ

tui/kitty deliberately contains no image decoder. Kitty itself accepts only the following payloads, and this library forwards them unchanged, so whatever your image library produces can be handed over directly if it fits one of these shapes:

format

 

kitty key

 

payload layout

 

size keys

'rgb

 

f=24

 

3 bytes per pixel, R,G,B, row-major

 

s, v required

'rgba

 

f=32

 

4 bytes per pixel, R,G,B,A, row-major, straight (non-premultiplied) alpha

 

s, v required

'indexed

 

f=8

 

1 byte palette index per pixel

 

s, v required

'indexed-alpha

 

f=16

 

1 byte index + 1 byte alpha per pixel

 

s, v required

'png

 

f=100

 

a complete PNG file

 

s, v optional

Rules for a zero-conversion hand-off:

  • No stride or row padding: exactly width x height x bytes-per-pixel bytes, packed. Crop or repack yourself if the source buffer is padded.

  • Rows go top to bottom, pixels left to right; there is no flip.

  • Colors are sRGB, and alpha is straight, not premultiplied.

  • Bytes are in RGB/RGBA order. Buffers in ARGB, BGRA, BGR or float form must be reordered by the caller.

  • Pixels are 8 bits per channel; HDR/float content must be converted before it reaches this API.

Racket libraries that decode into one of these shapes:

library

 

what it gives you

 

hand-off

racket/draw

 

read-bitmap decodes PNG, JPEG, GIF, BMP, XBM and XPM; get-argb-pixels on a bitmap% returns ARGB with straight alpha by default; save-file writes PNG

 

pass a PNG path as 'png; or move A behind RGB and pass 'rgba

pict

 

pict->argb-pixels returns four bytes per pixel (A, R, G, B)

 

rotate A to the end and pass 'rgba

images/flomap

 

bitmap->flomap returns ARGB floats with the color channels multiplied by alpha

 

unpremultiply and quantize to 8 bits yourself, or pass a PNG file

2htdp/image

 

bitmap/file loads an image file; image->color-list gives per-pixel color objects

 

pass the PNG file path as 'png

tiff (catalog package)

 

FFI to libtiff; decodes any TIFF to RGBA pixels

 

pass the RGBA buffer as 'rgba

riff (catalog package)

 

FFI to libFLIF

 

pass decoded pixels as 'rgba

opencv (catalog package)

 

FFI to OpenCV (cv::Mat pixel buffers)

 

pass RGB/RGBA buffers directly

png-image (catalog package)

 

inspects and edits PNG chunks (not a pixel decoder)

 

pass the PNG bytes as 'png

Nothing in this list is a dependency of tui. The zero-conversion paths cover most cases:

(put-kitty-image
 (kitty-image 1 #f #f 'png
              (make-kitty-payload "/tmp/frame.png" #:medium 'file)))
 
 
(put-kitty-image
 (kitty-image 2 640 480 'rgba rgba-bytes))
 
 
(put-kitty-image
 (kitty-image 3 640 480 'rgba
              (make-kitty-payload zlib-bytes #:compression 'zlib)))

o=z means RFC 1950 ZLIB (two-byte header plus an Adler-32 trailer), not raw RFC 1951 deflate. In the main distribution, file/gzip’s deflate produces raw deflate without the ZLIB wrapper, so it cannot be passed directly; use a ZLIB-capable library. This library does not add, strip or verify the wrapper.

'indexed and 'indexed-alpha require kitty 0.50.0 or newer; probe-kitty-graphics! only checks the basic graphics query, so treat these formats as opt-in for recent terminals.