libghostty-vt 0.0.0
Loading...
Searching...
No Matches
Kitty Graphics

Read the images that programs send with the Kitty graphics protocol. More...

Detailed Description

Read the images that programs send with the Kitty graphics protocol.

GhosttyKittyGraphics is a handle to the image storage of the active screen, where the terminal keeps every image a program sends with the Kitty graphics protocol.

Read it from a terminal with GHOSTTY_TERMINAL_DATA_KITTY_GRAPHICS. Use it to read pixels, play animations, and inspect what the storage holds. It doesn't tell you where to draw. The render state does that.

Example

/* The shortest time between two redraws. About 8 ms suits a 120 Hz display. */
#define MIN_FRAME_INTERVAL_MS 8
int64_t tick_animations(GhosttyKittyGraphics graphics, uint64_t now_ms) {
uint64_t next_ms = 0;
if (ghostty_kitty_graphics_animation_tick(graphics, now_ms, &next_ms) !=
return -1;
}
/* next_ms is an absolute time. Turn it into a delay from now. */
uint64_t delay_ms = next_ms > now_ms ? next_ms - now_ms : 0;
if (delay_ms < MIN_FRAME_INTERVAL_MS) delay_ms = MIN_FRAME_INTERVAL_MS;
return (int64_t)delay_ms;
}

Full program: c-vt-kitty-graphics/src/main.c

See Images for how to set up, decode PNGs, and draw images.

Typedefs

typedef struct GhosttyKittyGraphicsImpl * GhosttyKittyGraphics
typedef const struct GhosttyKittyGraphicsImageImpl * GhosttyKittyGraphicsImage
typedef struct GhosttyKittyGraphicsPlacementIteratorImpl * GhosttyKittyGraphicsPlacementIterator

Enumerations

enum  GhosttyKittyGraphicsData { GHOSTTY_KITTY_GRAPHICS_DATA_INVALID = 0 , GHOSTTY_KITTY_GRAPHICS_DATA_PLACEMENT_ITERATOR = 1 , GHOSTTY_KITTY_GRAPHICS_DATA_GENERATION = 2 , GHOSTTY_KITTY_GRAPHICS_DATA_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE }
enum  GhosttyKittyGraphicsPlacementData {
  GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_INVALID = 0 , GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_IMAGE_ID = 1 , GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_PLACEMENT_ID = 2 , GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_IS_VIRTUAL = 3 ,
  GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_X_OFFSET = 4 , GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_Y_OFFSET = 5 , GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_X = 6 , GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_Y = 7 ,
  GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_WIDTH = 8 , GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_HEIGHT = 9 , GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_COLUMNS = 10 , GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_ROWS = 11 ,
  GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_Z = 12 , GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE
}
enum  GhosttyKittyGraphicsPlacementIteratorOption { GHOSTTY_KITTY_GRAPHICS_PLACEMENT_ITERATOR_OPT_INVALID = 0 , GHOSTTY_KITTY_GRAPHICS_PLACEMENT_ITERATOR_OPT_LAYER = 1 , GHOSTTY_KITTY_GRAPHICS_PLACEMENT_ITERATOR_OPT_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE }
enum  GhosttyKittyImageFormat
enum  GhosttyKittyImageCompression
enum  GhosttyKittyGraphicsImageData {
  GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_INVALID = 0 , GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_ID = 1 , GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_NUMBER = 2 , GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_WIDTH = 3 ,
  GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_HEIGHT = 4 , GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_FORMAT = 5 , GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_COMPRESSION = 6 , GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_PIXELS = 7 ,
  GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_EXPECTED_LEN = 8 , GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_GENERATION = 9 , GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE
}

Data Structures

struct  GhosttyKittyGraphicsPlacementRenderInfo

Storage

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_get (GhosttyKittyGraphics graphics, GhosttyKittyGraphicsData data, void *out)
GHOSTTY_API GhosttyResult ghostty_kitty_graphics_animation_tick (GhosttyKittyGraphics graphics, uint64_t now_ms, uint64_t *next_ms)

Images

GHOSTTY_API GhosttyKittyGraphicsImage ghostty_kitty_graphics_image (GhosttyKittyGraphics graphics, uint32_t image_id)
GHOSTTY_API GhosttyResult ghostty_kitty_graphics_image_get (GhosttyKittyGraphicsImage image, GhosttyKittyGraphicsImageData data, void *out)
GHOSTTY_API GhosttyResult ghostty_kitty_graphics_image_get_multi (GhosttyKittyGraphicsImage image, size_t count, const GhosttyKittyGraphicsImageData *keys, void **values, size_t *out_written)

Placements

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_iterator_new (const GhosttyAllocator *allocator, GhosttyKittyGraphicsPlacementIterator *out_iterator)
GHOSTTY_API void ghostty_kitty_graphics_placement_iterator_free (GhosttyKittyGraphicsPlacementIterator iterator)
GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_iterator_set (GhosttyKittyGraphicsPlacementIterator iterator, GhosttyKittyGraphicsPlacementIteratorOption option, const void *value)
GHOSTTY_API bool ghostty_kitty_graphics_placement_next (GhosttyKittyGraphicsPlacementIterator iterator)
GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_get (GhosttyKittyGraphicsPlacementIterator iterator, GhosttyKittyGraphicsPlacementData data, void *out)
GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_get_multi (GhosttyKittyGraphicsPlacementIterator iterator, size_t count, const GhosttyKittyGraphicsPlacementData *keys, void **values, size_t *out_written)

Placement Geometry

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_rect (GhosttyKittyGraphicsPlacementIterator iterator, GhosttyKittyGraphicsImage image, GhosttyTerminal terminal, GhosttySelection *out_selection)
GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_pixel_size (GhosttyKittyGraphicsPlacementIterator iterator, GhosttyKittyGraphicsImage image, GhosttyTerminal terminal, uint32_t *out_width, uint32_t *out_height)
GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_grid_size (GhosttyKittyGraphicsPlacementIterator iterator, GhosttyKittyGraphicsImage image, GhosttyTerminal terminal, uint32_t *out_cols, uint32_t *out_rows)
GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_viewport_pos (GhosttyKittyGraphicsPlacementIterator iterator, GhosttyKittyGraphicsImage image, GhosttyTerminal terminal, int32_t *out_col, int32_t *out_row)
GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_source_rect (GhosttyKittyGraphicsPlacementIterator iterator, GhosttyKittyGraphicsImage image, uint32_t *out_x, uint32_t *out_y, uint32_t *out_width, uint32_t *out_height)
GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_render_info (GhosttyKittyGraphicsPlacementIterator iterator, GhosttyKittyGraphicsImage image, GhosttyTerminal terminal, GhosttyKittyGraphicsPlacementRenderInfo *out_info)

Typedef Documentation

◆ GhosttyKittyGraphics

typedef struct GhosttyKittyGraphicsImpl* GhosttyKittyGraphics

Opaque handle to a Kitty graphics image storage.

Obtained via ghostty_terminal_get() with GHOSTTY_TERMINAL_DATA_KITTY_GRAPHICS. The pointer is borrowed from the terminal and remains valid until the next mutating terminal call (e.g. ghostty_terminal_vt_write() or ghostty_terminal_reset()).

Examples
c-vt-kitty-graphics/src/main.c.

Definition at line 227 of file types.h.

◆ GhosttyKittyGraphicsImage

typedef const struct GhosttyKittyGraphicsImageImpl* GhosttyKittyGraphicsImage

Opaque handle to a Kitty graphics image.

Obtained via ghostty_kitty_graphics_image() with an image ID. The pointer is borrowed from the storage and remains valid until the next mutating terminal call.

Examples
c-vt-kitty-graphics/src/main.c.

Definition at line 238 of file types.h.

◆ GhosttyKittyGraphicsPlacementIterator

typedef struct GhosttyKittyGraphicsPlacementIteratorImpl* GhosttyKittyGraphicsPlacementIterator

Opaque handle to a Kitty graphics placement iterator.

Definition at line 245 of file types.h.

Enumeration Type Documentation

◆ GhosttyKittyGraphicsData

Queryable data kinds for ghostty_kitty_graphics_get().

Enumerator
GHOSTTY_KITTY_GRAPHICS_DATA_INVALID 

Invalid / sentinel value.

GHOSTTY_KITTY_GRAPHICS_DATA_PLACEMENT_ITERATOR 

Populate a pre-allocated placement iterator with placement data from the storage. Iterator data is only valid as long as the underlying terminal is not mutated.

Output type: GhosttyKittyGraphicsPlacementIterator *

GHOSTTY_KITTY_GRAPHICS_DATA_GENERATION 

A value that changes whenever a program sends, replaces, places or deletes an image. It is 0 if nothing has changed the storage yet, which means the storage is empty.

If the value matches the last one you read, the storage holds the same images and placements as before. The placements may still have moved on screen, because scrolling and resizing move them without changing the storage. So this value can't tell you when to read the render state's image list again. For that, use GHOSTTY_RENDER_STATE_DATA_IMAGE_PLACEMENTS_GENERATION. See Knowing what changed.

A value is never reused, not even by another screen, after a reset, or by another terminal. You can use it as a cache key on its own.

Output type: uint64_t *

Definition at line 48 of file kitty_graphics.h.

◆ GhosttyKittyGraphicsImageData

Queryable data kinds for ghostty_kitty_graphics_image_get().

Enumerator
GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_INVALID 

Invalid / sentinel value.

GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_ID 

The image ID.

Output type: uint32_t *

GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_NUMBER 

The image number.

Output type: uint32_t *

GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_WIDTH 

Image width in pixels.

Output type: uint32_t *

GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_HEIGHT 

Image height in pixels.

Output type: uint32_t *

GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_FORMAT 

Pixel format of the image. Never GHOSTTY_KITTY_IMAGE_FORMAT_PNG; PNG payloads are decoded to RGBA before storage.

Output type: GhosttyKittyImageFormat *

GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_COMPRESSION 

Compression of the image. Always GHOSTTY_KITTY_IMAGE_COMPRESSION_NONE; compressed payloads are inflated before storage.

Output type: GhosttyKittyImageCompression *

GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_PIXELS 

The image's pixel data. The string points into memory owned by the terminal and stays valid until the terminal is next modified. Its length is always width * height * bytes per pixel for the reported format.

Returns GHOSTTY_NO_VALUE if the image's pixels have not arrived yet. The expected size is still available through GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_EXPECTED_LEN.

The data is always fully decoded, uncompressed pixels in the format reported by GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_FORMAT: zlib payloads are inflated and PNG payloads are decoded to RGBA at transmission time, before the image is stored. Consumers can upload this directly to the GPU without any decode step.

For an animated image (Kitty graphics animation, actions a=f/a=a) this is the pixel data of the current animation frame. The image's GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_GENERATION changes whenever the current frame changes, so generation-keyed caches remain coherent.

upload_texture(pixels.ptr, pixels.len);
}
@ GHOSTTY_SUCCESS
Definition types.h:145
GHOSTTY_API GhosttyResult ghostty_kitty_graphics_image_get(GhosttyKittyGraphicsImage image, GhosttyKittyGraphicsImageData data, void *out)
@ GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_PIXELS
size_t len
Definition types.h:444
const uint8_t * ptr
Definition types.h:441

Output type: GhosttyString *

GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_EXPECTED_LEN 

The size of the image's pixel data in bytes, which is width * height * bytes per pixel for the reported format.

This is available even before the pixels arrive, when GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_PIXELS still returns GHOSTTY_NO_VALUE. In that case the image already counts this many bytes against the storage limit. Once the pixels arrive, this equals the length of GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_PIXELS.

Output type: size_t *

GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_GENERATION 

A value that changes whenever this image's pixels may have changed: when a program sends the image or replaces it, and when an animation moves to a new frame. Use it as part of your texture cache key. If it matches the texture you have, you don't need to read the pixels again. The render state reports the same value for each of its entries as GHOSTTY_RENDER_STATE_IMAGE_DATA_IMAGE_GENERATION.

Don't use the image's size or data length to detect changes instead. A program can send new pixels of the same size under the same ID.

A value is never reused, not even by another image, another screen, or another terminal. It is never 0 for a stored image, so you can use 0 to mean "no texture yet".

One case doesn't change this value. When a program finishes sending an image whose pixels were still on the way, the image keeps its value, and GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_PIXELS starts returning the pixels. GHOSTTY_KITTY_GRAPHICS_DATA_GENERATION changes when that happens, so read PIXELS again then.

Output type: uint64_t *

Examples
c-vt-kitty-graphics/src/main.c.

Definition at line 273 of file kitty_graphics.h.

◆ GhosttyKittyGraphicsPlacementData

Queryable data kinds for ghostty_kitty_graphics_placement_get().

Enumerator
GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_INVALID 

Invalid / sentinel value.

GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_IMAGE_ID 

The image ID this placement belongs to.

Output type: uint32_t *

GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_PLACEMENT_ID 

The placement ID.

Output type: uint32_t *

GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_IS_VIRTUAL 

Whether this is a virtual placement, which a program shows with Unicode placeholder cells.

A virtual placement appears wherever its placeholder cells are, so the storage has no position for it. The render state's image list positions it from its cells like any other placement, so a renderer doesn't need to check this. See Placeholders.

Output type: bool *

GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_X_OFFSET 

Pixel offset from the left edge of the cell.

Output type: uint32_t *

GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_Y_OFFSET 

Pixel offset from the top edge of the cell.

Output type: uint32_t *

GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_X 

Source rectangle x origin in pixels.

Output type: uint32_t *

GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_Y 

Source rectangle y origin in pixels.

Output type: uint32_t *

GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_WIDTH 

Source rectangle width in pixels (0 = full image width).

Output type: uint32_t *

GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_SOURCE_HEIGHT 

Source rectangle height in pixels (0 = full image height).

Output type: uint32_t *

GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_COLUMNS 

Number of columns this placement occupies.

Output type: uint32_t *

GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_ROWS 

Number of rows this placement occupies.

Output type: uint32_t *

GHOSTTY_KITTY_GRAPHICS_PLACEMENT_DATA_Z 

Z-index for this placement.

Output type: int32_t *

Definition at line 88 of file kitty_graphics.h.

◆ GhosttyKittyGraphicsPlacementIteratorOption

Settable options for ghostty_kitty_graphics_placement_iterator_set().

Enumerator
GHOSTTY_KITTY_GRAPHICS_PLACEMENT_ITERATOR_OPT_INVALID 

Not a real option. ghostty_kitty_graphics_placement_iterator_set() returns GHOSTTY_INVALID_VALUE for it. Its value is 0, so a zeroed or uninitialized variable is never mistaken for a real option.

GHOSTTY_KITTY_GRAPHICS_PLACEMENT_ITERATOR_OPT_LAYER 

Only visit placements in the chosen layers.

The value is a mask with one bit for each GhosttyImageLayer. Combine the GHOSTTY_IMAGE_LAYER_MASK_* macros with | to choose layers. For example, this visits every placement except the ones drawn below the cell backgrounds:

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_iterator_set(GhosttyKittyGraphicsPlacementIterator iterator, GhosttyKittyGraphicsPlacementIteratorOption option, const void *value)
@ GHOSTTY_KITTY_GRAPHICS_PLACEMENT_ITERATOR_OPT_LAYER
#define GHOSTTY_IMAGE_LAYER_MASK_BELOW_TEXT
Definition types.h:422
#define GHOSTTY_IMAGE_LAYER_MASK_ABOVE_TEXT
Definition types.h:426

A mask of 0 or a NULL value turns the filter off, and the iterator visits every placement. This is the default. A mask with a bit that matches no layer returns GHOSTTY_INVALID_VALUE and keeps the current filter.

Each placement's layer comes from its z-index, using the ranges listed in GhosttyImageLayer. This filter only applies to the storage iterator. To draw images, use the layer the render state reports for each entry (GHOSTTY_RENDER_STATE_IMAGE_DATA_LAYER). The render state uses the same ranges and also includes virtual placements, which are always drawn below the text.

Input type: const uint32_t *

Definition at line 190 of file kitty_graphics.h.

◆ GhosttyKittyImageCompression

Compression of a Kitty graphics image.

Note that stored images are always decompressed: GHOSTTY_KITTY_IMAGE_COMPRESSION_ZLIB_DEFLATE payloads are inflated before storage, so ghostty_kitty_graphics_image_get() always reports GHOSTTY_KITTY_IMAGE_COMPRESSION_NONE. Consumers never need to inflate image data themselves.

Definition at line 262 of file kitty_graphics.h.

◆ GhosttyKittyImageFormat

Pixel format of a Kitty graphics image.

Note that stored images are always fully decoded: GHOSTTY_KITTY_IMAGE_FORMAT_PNG is never returned by ghostty_kitty_graphics_image_get() because PNG payloads are decoded to GHOSTTY_KITTY_IMAGE_FORMAT_RGBA before storage. The PNG value exists only for protocol-level completeness.

Examples
c-vt-kitty-graphics/src/main.c.

Definition at line 242 of file kitty_graphics.h.

Function Documentation

◆ ghostty_kitty_graphics_animation_tick()

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_animation_tick ( GhosttyKittyGraphics graphics,
uint64_t now_ms,
uint64_t * next_ms )

Advance playing animations and get the time of the next frame.

Every playing animation moves to the frame that is due at now_ms. An animation moves forward at most one frame per call. If calls arrive late, playback slows down rather than skipping frames.

Images that moved to a new frame get a new GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_GENERATION, and their GHOSTTY_KITTY_GRAPHICS_IMAGE_DATA_PIXELS returns the new frame's pixels.

Time is measured in milliseconds on a clock you choose, such as the time since your application started. The clock must only move forward, and you must keep using the same clock with the same starting point for as long as the terminal exists. The time written to next_ms uses the same clock.

This call changes the image storage. Like ghostty_terminal_vt_write(), it invalidates any GhosttyKittyGraphicsImage handles and image data pointers you are holding, so look images up again afterwards. The GhosttyKittyGraphics handle itself stays valid.

Call this once each time you prepare a frame to draw, not in a loop. Animation explains how to schedule redraws with the returned time and includes an example.

Parameters
graphicsThe kitty graphics handle
now_msThe current time in milliseconds
[out]next_msSet to the time the next frame is due, in milliseconds on the same clock as now_ms. Only written when the function returns GHOSTTY_SUCCESS.
Returns
GHOSTTY_SUCCESS if an animation is playing and next_ms was set, GHOSTTY_NO_VALUE if nothing is playing, GHOSTTY_UNSUPPORTED if Kitty graphics are disabled at build time, GHOSTTY_INVALID_VALUE if next_ms is NULL
Examples
c-vt-kitty-graphics/src/main.c.

◆ ghostty_kitty_graphics_get()

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_get ( GhosttyKittyGraphics graphics,
GhosttyKittyGraphicsData data,
void * out )

Get data from a kitty graphics storage instance.

The output pointer must be of the appropriate type for the requested data kind.

Returns GHOSTTY_UNSUPPORTED when Kitty graphics are disabled at build time.

Parameters
graphicsThe kitty graphics handle
dataThe type of data to extract
[out]outPointer to store the extracted data
Returns
GHOSTTY_SUCCESS on success, or GHOSTTY_UNSUPPORTED if data is not known to this version of the library or Kitty graphics are disabled at build time
Examples
c-vt-kitty-graphics/src/main.c.

◆ ghostty_kitty_graphics_image()

GHOSTTY_API GhosttyKittyGraphicsImage ghostty_kitty_graphics_image ( GhosttyKittyGraphics graphics,
uint32_t image_id )

Look up a Kitty graphics image by its image ID.

Returns NULL if no image with the given ID exists or if Kitty graphics are disabled at build time.

Parameters
graphicsThe kitty graphics handle
image_idThe image ID to look up
Returns
An opaque image handle, or NULL if not found
Examples
c-vt-kitty-graphics/src/main.c.

◆ ghostty_kitty_graphics_image_get()

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_image_get ( GhosttyKittyGraphicsImage image,
GhosttyKittyGraphicsImageData data,
void * out )

Get data from a Kitty graphics image.

The output pointer must be of the appropriate type for the requested data kind.

Parameters
imageThe image handle (NULL returns GHOSTTY_INVALID_VALUE)
dataThe data kind to query
[out]outPointer to receive the queried value
Returns
GHOSTTY_SUCCESS on success, or GHOSTTY_UNSUPPORTED if data is not known to this version of the library or Kitty graphics are disabled at build time
Examples
c-vt-kitty-graphics/src/main.c.

◆ ghostty_kitty_graphics_image_get_multi()

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_image_get_multi ( GhosttyKittyGraphicsImage image,
size_t count,
const GhosttyKittyGraphicsImageData * keys,
void ** values,
size_t * out_written )

Get multiple data fields from a Kitty graphics image in a single call.

Use this when each call into the library is expensive, for example from WebAssembly or from another language through its foreign function interface. It reads every key in one call. From C in the same process it costs the same as calling ghostty_kitty_graphics_image_get() once per key, so use whichever reads better.

Each element in the keys array specifies a data kind, and the corresponding element in the values array receives the result. The type of each values[i] pointer must match the output type documented for keys[i].

Processing stops at the first error; on success out_written is set to count, on error it is set to the index of the failing key (i.e. the number of values successfully written).

Parameters
imageThe image handle (NULL returns GHOSTTY_INVALID_VALUE)
countNumber of key/value pairs
keysArray of data kinds to query
valuesArray of output pointers (types must match each key's documented output type)
[out]out_writtenOn return, receives the number of values successfully written (may be NULL)
Returns
GHOSTTY_SUCCESS if every key succeeds. Otherwise the result of the first key that failed, for example GHOSTTY_UNSUPPORTED for a key that is not known to this version of the library.
Examples
c-vt-kitty-graphics/src/main.c.

◆ ghostty_kitty_graphics_placement_get()

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_get ( GhosttyKittyGraphicsPlacementIterator iterator,
GhosttyKittyGraphicsPlacementData data,
void * out )

Get data from the current placement in a placement iterator.

Call ghostty_kitty_graphics_placement_next() at least once before calling this function.

Parameters
iteratorThe iterator handle (NULL returns GHOSTTY_INVALID_VALUE)
dataThe data kind to query
[out]outPointer to receive the queried value
Returns
GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the iterator is NULL or not positioned on a placement, or GHOSTTY_UNSUPPORTED if data is not known to this version of the library

◆ ghostty_kitty_graphics_placement_get_multi()

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_get_multi ( GhosttyKittyGraphicsPlacementIterator iterator,
size_t count,
const GhosttyKittyGraphicsPlacementData * keys,
void ** values,
size_t * out_written )

Get multiple data fields from the current placement in a single call.

Use this when each call into the library is expensive, for example from WebAssembly or from another language through its foreign function interface. It reads every key in one call. From C in the same process it costs the same as calling ghostty_kitty_graphics_placement_get() once per key, so use whichever reads better.

Each element in the keys array specifies a data kind, and the corresponding element in the values array receives the result. The type of each values[i] pointer must match the output type documented for keys[i].

Processing stops at the first error; on success out_written is set to count, on error it is set to the index of the failing key (i.e. the number of values successfully written).

Parameters
iteratorThe iterator handle (NULL returns GHOSTTY_INVALID_VALUE)
countNumber of key/value pairs
keysArray of data kinds to query
valuesArray of output pointers (types must match each key's documented output type)
[out]out_writtenOn return, receives the number of values successfully written (may be NULL)
Returns
GHOSTTY_SUCCESS if every key succeeds. Otherwise the result of the first key that failed, for example GHOSTTY_UNSUPPORTED for a key that is not known to this version of the library.

◆ ghostty_kitty_graphics_placement_grid_size()

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_grid_size ( GhosttyKittyGraphicsPlacementIterator iterator,
GhosttyKittyGraphicsImage image,
GhosttyTerminal terminal,
uint32_t * out_cols,
uint32_t * out_rows )

Compute the grid cell size of the current placement.

Returns the number of columns and rows that the placement occupies in the terminal grid. If the placement specifies explicit columns and rows, those are returned directly; otherwise they are calculated from the pixel size and cell dimensions.

Parameters
iteratorThe placement iterator positioned on a placement
imageThe image handle for this placement's image
terminalThe terminal handle
[out]out_colsOn success, receives the number of columns
[out]out_rowsOn success, receives the number of rows
Returns
GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if any handle is NULL or the iterator is not positioned, GHOSTTY_UNSUPPORTED when Kitty graphics are disabled at build time

◆ ghostty_kitty_graphics_placement_iterator_free()

GHOSTTY_API void ghostty_kitty_graphics_placement_iterator_free ( GhosttyKittyGraphicsPlacementIterator iterator)

Free a placement iterator.

Parameters
iteratorThe iterator handle to free (may be NULL)

◆ ghostty_kitty_graphics_placement_iterator_new()

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_iterator_new ( const GhosttyAllocator * allocator,
GhosttyKittyGraphicsPlacementIterator * out_iterator )

Create a new placement iterator instance.

All fields except the allocator are left undefined until populated via ghostty_kitty_graphics_get() with GHOSTTY_KITTY_GRAPHICS_DATA_PLACEMENT_ITERATOR.

Parameters
allocatorPointer to allocator, or NULL to use the default allocator
[out]out_iteratorOn success, receives the created iterator handle
Returns
GHOSTTY_SUCCESS on success, GHOSTTY_OUT_OF_MEMORY on allocation failure

◆ ghostty_kitty_graphics_placement_iterator_set()

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_iterator_set ( GhosttyKittyGraphicsPlacementIterator iterator,
GhosttyKittyGraphicsPlacementIteratorOption option,
const void * value )

Set an option on a placement iterator.

Use GHOSTTY_KITTY_GRAPHICS_PLACEMENT_ITERATOR_OPT_LAYER to visit only the placements in some layers. ghostty_kitty_graphics_placement_next() then skips every placement outside those layers. By default, the iterator visits every placement.

Parameters
iteratorThe iterator handle (NULL returns GHOSTTY_INVALID_VALUE)
optionThe option to set
valuePointer to the value. Its type depends on the option. NULL resets the option to its default.
Returns
GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the value is out of range, or GHOSTTY_UNSUPPORTED if option is not known to this version of the library or Kitty graphics are disabled at build time

◆ ghostty_kitty_graphics_placement_next()

GHOSTTY_API bool ghostty_kitty_graphics_placement_next ( GhosttyKittyGraphicsPlacementIterator iterator)

Advance the placement iterator to the next placement.

If a layer filter has been set via ghostty_kitty_graphics_placement_iterator_set(), only placements matching that layer are returned.

Parameters
iteratorThe iterator handle (may be NULL)
Returns
true if advanced to the next placement, false if at the end

◆ ghostty_kitty_graphics_placement_pixel_size()

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_pixel_size ( GhosttyKittyGraphicsPlacementIterator iterator,
GhosttyKittyGraphicsImage image,
GhosttyTerminal terminal,
uint32_t * out_width,
uint32_t * out_height )

Compute the rendered pixel size of the current placement.

Takes into account the placement's source rectangle, specified columns/rows, and aspect ratio to calculate the final rendered pixel dimensions.

Parameters
iteratorThe placement iterator positioned on a placement
imageThe image handle for this placement's image
terminalThe terminal handle
[out]out_widthOn success, receives the width in pixels
[out]out_heightOn success, receives the height in pixels
Returns
GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if any handle is NULL or the iterator is not positioned, GHOSTTY_UNSUPPORTED when Kitty graphics are disabled at build time

◆ ghostty_kitty_graphics_placement_rect()

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_rect ( GhosttyKittyGraphicsPlacementIterator iterator,
GhosttyKittyGraphicsImage image,
GhosttyTerminal terminal,
GhosttySelection * out_selection )

Compute the grid rectangle occupied by the current placement.

Uses the placement's pin, the image dimensions, and the terminal's cell/pixel geometry to calculate the bounding rectangle. Virtual placements (unicode placeholders) return GHOSTTY_NO_VALUE.

Parameters
terminalThe terminal handle
imageThe image handle for this placement's image
iteratorThe placement iterator positioned on a placement
[out]out_selectionOn success, receives the bounding rectangle as a selection with rectangle=true
Returns
GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if any handle is NULL or the iterator is not positioned, GHOSTTY_NO_VALUE for virtual placements, GHOSTTY_UNSUPPORTED when Kitty graphics are disabled at build time

◆ ghostty_kitty_graphics_placement_render_info()

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_render_info ( GhosttyKittyGraphicsPlacementIterator iterator,
GhosttyKittyGraphicsImage image,
GhosttyTerminal terminal,
GhosttyKittyGraphicsPlacementRenderInfo * out_info )

Get all of the geometry of the current placement in one call.

This fills in a GhosttyKittyGraphicsPlacementRenderInfo with the pixel size, grid size, viewport position and source rectangle. Set its size with GHOSTTY_INIT_SIZED first.

This is for inspecting the storage. To draw, use the render state's image list instead. It gives the same values for every image on screen, including virtual placements and placements relative to them. If you draw from both, images are drawn twice. See Drawing images.

The call succeeds even when the placement isn't in the viewport. Check viewport_visible before using viewport_col and viewport_row.

Parameters
iteratorThe placement iterator, moved to a placement
imageThe image of this placement
terminalThe terminal the storage belongs to
[out]out_infoReceives the geometry
Returns
GHOSTTY_SUCCESS on success. GHOSTTY_INVALID_VALUE if any handle or out_info is NULL, the iterator is not on a placement, or out_info->size is too small. GHOSTTY_UNSUPPORTED if Kitty graphics are disabled at build time.

◆ ghostty_kitty_graphics_placement_source_rect()

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_source_rect ( GhosttyKittyGraphicsPlacementIterator iterator,
GhosttyKittyGraphicsImage image,
uint32_t * out_x,
uint32_t * out_y,
uint32_t * out_width,
uint32_t * out_height )

Get the resolved source rectangle for the current placement.

Applies kitty protocol semantics: a width or height of 0 in the placement means "use the full image dimension", and the resulting rectangle is clamped to the actual image bounds. The returned values are in pixels and are ready to use for texture sampling.

Parameters
iteratorThe placement iterator positioned on a placement
imageThe image handle for this placement's image
[out]out_xSource rect x origin in pixels
[out]out_ySource rect y origin in pixels
[out]out_widthSource rect width in pixels
[out]out_heightSource rect height in pixels
Returns
GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if any handle is NULL or the iterator is not positioned

◆ ghostty_kitty_graphics_placement_viewport_pos()

GHOSTTY_API GhosttyResult ghostty_kitty_graphics_placement_viewport_pos ( GhosttyKittyGraphicsPlacementIterator iterator,
GhosttyKittyGraphicsImage image,
GhosttyTerminal terminal,
int32_t * out_col,
int32_t * out_row )

Get the top-left cell of the current placement, relative to the viewport.

This is for inspecting the storage. To draw, use the render state's image list instead. It positions every image on screen, including virtual placements and placements relative to them, and covers overscan rows. If you draw from both, images are drawn twice. See Drawing images.

The row is negative when the top of the placement scrolled above the viewport. For example, an image 4 rows tall that scrolled up by 2 rows has a row of -2. Its top 2 rows are above the viewport and its bottom 2 rows are still visible.

Parameters
iteratorThe placement iterator, moved to a placement
imageThe image of this placement
terminalThe terminal the storage belongs to
[out]out_colOn success, receives the column
[out]out_rowOn success, receives the row, which can be negative
Returns
GHOSTTY_SUCCESS if any part of the placement is in the viewport. GHOSTTY_NO_VALUE if it is entirely outside the viewport or if it is a virtual placement or relative to one. GHOSTTY_UNSUPPORTED if Kitty graphics are disabled at build time. GHOSTTY_INVALID_VALUE if any handle is NULL or the iterator is not on a placement.