ansi/image
src/ansi/image.tur
inline image protocols (Kitty / iTerm2 / sixel) + placeholder.
defn
image-placeholder
(image-placeholder [path :cstr])
write a bracketed "[image: path]" string to stdout.
Parameters
| path | the path string to embed in the placeholder. May be empty. |
Since: tur-ansi AN4
defn
image-display-base64
(image-display-base64 [b64 :cstr])
emit a Kitty inline-image sequence from base64 PNG data.
Parameters
| b64 | ASCII base64-encoded PNG bytes (no whitespace, no '=' stripping) | |
| Chunks the payload into 4096-character APC blocks per the Kitty protocol, | ||
| with m=1 on every chunk except the last (m=0). Outputs nothing if b64 | ||
| is empty or null. |
Since: tur-ansi AN4
defn
image-display-protocol
(image-display-protocol [proto :int path :cstr])
display a PNG file using a specific protocol.
Parameters
| proto | 0 = placeholder, 1 = kitty, 2 = iterm2, 3 = sixel | |
| (matches the encoding used by (term-image-protocol)) | ||
| path | filesystem path to a PNG (or other supported image format) | |
| Sixel (proto=3) is deferred to v0.2; the call falls back to the | ||
| bracketed placeholder so callers wired to (term-image-protocol) keep | ||
| working without a special-case branch. Any unknown proto also falls | ||
| back to the placeholder. A missing file always falls back too. |
Since: tur-ansi AN4
defn
image-display
(image-display [path :cstr])
display a PNG file inline using the best available protocol.
Parameters
| path | filesystem path to a PNG file | |
| Calls (term-image-protocol) internally to pick the protocol; when none | ||
| is detected (or sixel, which is deferred), falls back to the bracketed | ||
| placeholder. |
Example
(image-display "logo.png") ; => emits Kitty/iTerm2 APC/OSC or [image: logo.png]
Since: tur-ansi AN4
defn
image-display-rgba
(image-display-rgba [w :int h :int rgba :cstr])
emit a sixel sequence from a raw RGBA pixel buffer.
Parameters
| w | pixel width (must be >= 1) | |
| h | pixel height (must be >= 1) | |
| rgba | pointer to w*h*4 bytes in tightly-packed RGBA order | |
| (no row padding; alpha is currently ignored) | ||
| Uses a fixed 6x6x6 color cube (216 colors) for quantization: each | ||
| channel is mapped to 0-5 via byte/51. The encoder emits palette | ||
| declarations only for the colors that actually appear in the image, | ||
| then writes one 6-row sixel band at a time with run-length encoding | ||
| for repeated columns. | ||
| No protocol detection is performed; the caller is expected to have | ||
| verified (term-image-protocol) == 3 first. Out-of-range w or h are | ||
| treated as no-ops. A null rgba pointer is also a no-op. |
Since: tur-ansi v0.1.2
Internal definitions
__image-init