140 Commits

Author SHA1 Message Date
Tim Culverhouse
723d79c9de graphics: set default transmission format as .rgba
The default format for transmission is defined as RGBA (f=32) in the
Kitty Graphics specification. When no format is specified, this can
result in an error for length checking.

Fixes: #2212
Reference: https://sw.kovidgoyal.net/kitty/graphics-protocol/#control-data-reference
2024-09-10 11:03:51 -07:00
Mitchell Hashimoto
761bcfad50 kitty gfx: handle q with chunked transmissions properly
Fixes #2190

The `q` value with chunk transmissions is a bit complicated. The initial
transmission ("start" command) `q` value is used for all subsequent
chunks UNLESS a subsequent chunk specifies a `q >= 1`. If a chunk
specifies `q >= 1`, then that `q` value is subsequently used for all
future chunks unless another chunk specifies `q >= 1`. And so on.

This commit importantly also introduces the ability to test a full Kitty
command from string request to structured response. This will let us
prevent regressions in the future and ensure that we are correctly
handling the complex underspecified behavior of Kitty Graphics.
2024-09-04 10:24:25 -07:00
Mitchell Hashimoto
2acd7e8a42 kitty: respond OK with metadata on display transmissions 2024-09-03 11:05:16 -07:00
Mitchell Hashimoto
e9c83a5f64 kitty: ENOENT when image ID not found for placement 2024-09-03 10:38:10 -07:00
Mitchell Hashimoto
de612934a0 some tweaks for wuffs 2024-09-02 20:47:07 -07:00
Jeffrey C. Ollie
6edeb45e7e kitty graphics: address review comments
- move wuffs code from src/ to pkg/
- eliminate stray debug logs
- make logs a warning instead of an error
- remove initialization of some structs to zero
2024-09-02 20:47:07 -07:00
Jeffrey C. Ollie
6dbb82c259 kitty graphics: performance enhancements
Improve the performance of Kitty graphics by switching to the WUFFS
library for decoding PNG images and for "swizzling" G, GA, and RGB data
to RGBA formats needed by the renderers.

WUFFS claims 2-3x performance benefits over other implementations, as
well as memory-safe operations.

Although not thorougly benchmarked, performance is on par with Kitty's
graphics decoding.

https://github.com/google/wuffs
2024-09-02 20:45:08 -07:00
Jeffrey C. Ollie
5e925db521 kitty graphics: fix usage of "m" key for local-only transmission mediums
If the transmission medium is a local-only medium, ignore the "m"
key. The Kitty graphics protocol specification does not explicitly
call out this behavior (although the "m" key is only mentioned in
connection with remote clients) but that's how it's implemented in
Kitty and at least one client (mpv) relies on this behavior when
using the shared memory transmission medium.

https://sw.kovidgoyal.net/kitty/graphics-protocol/#the-transmission-medium
ccc3bee9af/kitty/graphics.c (L547-L592)
2024-09-01 21:10:08 -07:00
Mitchell Hashimoto
8e2d63b6fa small stylistic changes 2024-08-24 19:55:09 -07:00
Jeffrey C. Ollie
b8d4969fee Make the Kind parsing simpler 2024-08-21 15:28:00 -05:00
Jeffrey C. Ollie
54e2ea05a5 Use switch and not if to format Kind 2024-08-21 12:37:18 -05:00
Jeffrey C. Ollie
571988bf99 Clean up Kitty color protocol by using a union
Non-exhaustive enums should be avoided, use a union to
make the code cleaner and safer.
2024-08-21 11:57:27 -05:00
Mitchell Hashimoto
140d1dde5a typos 2024-08-21 09:45:47 -04:00
Mitchell Hashimoto
6bf1acc5a2 terminal: move kitty color structs out to kitty package 2024-08-21 09:18:42 -04:00
Mitchell Hashimoto
d8f43b34ba terminal: yeet usingnamespace 2024-08-16 10:32:43 -07:00
Qwerasd
37872afbce kitty graphics: support loading 1 channel grayscale images 2024-08-15 21:38:46 -04:00
Qwerasd
10b8ca3c69 spelling: normalize grey -> gray 2024-08-11 18:31:01 -04:00
Mitchell Hashimoto
b368702a9d terminal/kitty: shared memory size may be larger than expected for pages
The shared memory segment size must be a multiple of page size. This
means that it may be larger than our expected image size. In this case,
we trim the padding at the end.
2024-08-09 20:33:39 -07:00
Mitchell Hashimoto
c114979ee3 terminal/kitty: minor stylistic changes to shm 2024-08-08 14:35:30 -07:00
Jeffrey C. Ollie
e2fe6bf74b kitty graphics: add support for shared memory transfer medium
Adds support for using shared memory to transfer images between
the CLI and Ghostty using the Kitty image protocol. This should be
the fastest way to transfer images if the CLI program and Ghostty are
running on the same system.

Works for single image transfer using `kitten icat`:

```
kitten icat --transfer-mode=memory images/icons/icon_256x256.png
```

However trying to play a movie with `mpv` fails in Ghostty (although it
works in Kitty):

```
mpv --vo=kitty --vo-kitty-use-shm=yes --profile=sw-fast --really-quiet video.mp4
```

`mpv` appears to be sending frames using the normal image transfer
commands but always setting `more_chunks` to `true` which results in an
image never being shown by Ghostty.

Shared memory transfer on Windows remains to be implemented.
2024-08-08 15:38:54 -05:00
Mitchell Hashimoto
a1276b3cc3 terminal/kitty: delete all images ignores virtual placements 2024-07-29 19:37:47 -07:00
Mitchell Hashimoto
bf30753657 terminal/kitty: handle case where both offsets are in one grid cell 2024-07-29 18:57:31 -07:00
Mitchell Hashimoto
d510bb4497 terminal/kitty: adjust middle rows for image offsets 2024-07-29 17:26:57 -07:00
Mitchell Hashimoto
0c81ca44b8 terminal/kitty: do not render blank virtual placement cells 2024-07-29 14:52:09 -07:00
Mitchell Hashimoto
39b915ac25 terminal/kitty: handle width-stretched 2024-07-29 14:42:27 -07:00
Mitchell Hashimoto
5e9b871028 terminal/kitty: unit tests for unicode placements 2024-07-29 14:15:51 -07:00
Mitchell Hashimoto
359458b96a terminal/kitty: switch to new placement math 2024-07-29 10:52:10 -07:00
Mitchell Hashimoto
0ebf14fd44 terminal/kitty: working on moving placement math here for testing 2024-07-29 10:39:18 -07:00
Mitchell Hashimoto
266033670d terminal/kitty: support cells with no diacritics 2024-07-25 21:32:45 -07:00
Mitchell Hashimoto
91a6e70d1b terminal/kitty: extra placement tests 2024-07-25 21:32:45 -07:00
Mitchell Hashimoto
1786502f15 terminal/kitty: working runs 2024-07-25 21:32:45 -07:00
Mitchell Hashimoto
cf6463fec0 terminal/kitty: preparing to build runs of placements 2024-07-25 21:32:44 -07:00
Mitchell Hashimoto
7c6ae90300 terminal/kitty: implement high bit image id parsing 2024-07-25 21:32:44 -07:00
Mitchell Hashimoto
578bfc8d23 terminal/kitty: parse image/placement id from style 2024-07-25 21:32:44 -07:00
Mitchell Hashimoto
13df93a1d0 temrinal/kitty: really basic row/col diacritic decoding 2024-07-25 21:32:44 -07:00
Mitchell Hashimoto
e656fe3b79 terminal/kitty: starting virtual placement iterator 2024-07-25 21:32:44 -07:00
Mitchell Hashimoto
bb1a9bf532 terminal/kitty: rename diacritics to unicode 2024-07-25 21:32:44 -07:00
Mitchell Hashimoto
f71afcab95 terminal/kitty: diacritic small tests 2024-07-25 21:32:44 -07:00
Mitchell Hashimoto
358b4ca896 terminal/kitty: parse relative placement fields 2024-07-25 21:32:44 -07:00
Mitchell Hashimoto
2c0f9bfc28 terminal: cell returns empty for Kitty placeholder
So we don't render the replacement char
2024-07-25 21:32:44 -07:00
Mitchell Hashimoto
7d9e50353b terminal/kitty: add virtual placeholders placements 2024-07-25 21:32:44 -07:00
Mitchell Hashimoto
a5c382633f terminal/kitty: placements support location enum (only pin for now) 2024-07-25 21:32:43 -07:00
Mitchell Hashimoto
d29073d999 terminal/kitty: add graphics diacritics file 2024-07-25 21:32:43 -07:00
multifred
72c672adb7 Fix multiple deprecated names for zig lib/std 2024-07-22 00:07:17 +02:00
Mitchell Hashimoto
360e4f690f terminal/kitty: change graphics base64 decode to use simdutf 2024-07-16 20:21:09 -07:00
Mitchell Hashimoto
3fc08aa660 terminal/kitty: intersect cell deletion is 1-based 2024-07-05 19:08:33 -07:00
Mitchell Hashimoto
44c95cbf7d terminal/kitty: delete by column/row is one-indexed 2024-07-05 18:59:21 -07:00
Mitchell Hashimoto
f4eea71859 terminal/kitty: image dimensions off by one fix
We weren't counting the original x/y as width 1.
2024-07-05 18:58:56 -07:00
Mitchell Hashimoto
53423f1071 0.13 conversions 2024-06-24 15:16:24 -07:00
Mitchell Hashimoto
3f16234f72 terminal: Coordinate uses CellCountInt 2024-04-26 20:52:08 -07:00