Skip to content

Reimplement Kitty graphics rendering - #815

Merged
emil-e merged 1 commit into
dakra:mainfrom
emil-e:emil-e/kitty-placeholder-transparency
Nov 16, 2026
Merged

emil-e merged 1 commit into
dakra:mainfrom
emil-e:emil-e/kitty-placeholder-transparency

Conversation

@emil-e

@emil-e emil-e commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

Replace the overlay/PPM renderer with native row-local image composition integrated into the normal text renderer.

  • Preserve alpha, clipping, image-layer ordering, source cropping, and Unicode placeholder fragments, including wide characters and style/link boundaries.
  • Separate placement planning from lazy raster realization. Emacs owns the bounded PNG/visibility-mask cache; native composition and resize scratch retain their high-water capacities.
  • Keep image handling out of text-only cell loops through row-level comptime specialization.
  • Add bounded resampling, allocation-safe PNG compression, regression coverage, and tools/kitty-graphics-stress.py for visual testing.

PNG support in Emacs is required; ImageMagick is not. Negative-z placements retain image-to-image ordering but render in the foreground. Animation and relative placements rooted in placeholders remain outside this implementation's scope.

Verification

Rebased onto current upstream main (75e4bd2), retaining its libghostty-vt 1.0.0 update and adapting the cursor-after-shrink regression test to the new renderer.

  • Debug and ReleaseFast builds passed.
  • 62 Debug Zig unit tests passed.
  • 53 Debug Kitty ERT tests passed; 3 graphical cases skipped in batch.
  • 222 native ERT tests passed with ReleaseFast; 3 graphical cases skipped in batch.
  • All 3 graphical ERT cases passed separately.
  • All 8 Kitty Elate groups / 53 steps passed.
  • A final independent source review of the rebased contribution found no actionable findings.

All Emacs validation used disposable isolated sessions. Windows and whole-repository test coverage were not verified.

@emil-e
emil-e force-pushed the emil-e/kitty-placeholder-transparency branch from 1dc0e03 to 5a73382 Compare November 13, 2026 15:51
@dakra

dakra commented Nov 13, 2026

Copy link
Copy Markdown
Owner

@claude review

@claude

claude Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Claude finished @dakra's task in 5m 21s —— View job


Review of PR #815: Reimplement Kitty graphics rendering

  • Read CLAUDE.md / src/CLAUDE.md
  • Review Zig changes (KittyRenderer, image_composition, Renderer, emacs, png, ppm, stb glue)
  • Review Elisp/tests/docs
  • Post findings

I found no verified bugs. There are two questions, posted as inline comments, and no NITs worth raising.

Overall: this is a strong redesign. The old approach used Lisp overlays plus scrollback debris cleanup (kitty-clear, strip-orphan-top, the overlay-stack heuristics). The new one composes images into ordinary row text properties, so eviction and re-rendering clean up naturally through delete-region. That removes about 300 lines of fragile Elisp.

The parts I checked and found sound:

  • Where dirty state lives: row dirtiness stays inside the Renderer, so it follows src/CLAUDE.md.
  • Row specialisation: the comptime with_images split keeps the text-only cell loop as it was.
  • Bounds checking: sizes use checked arithmetic, and the 64 MiB scratch cap is enforced before any allocation.

Questions (inline)

  1. QUESTION (perf), src/KittyRenderer.zig:198-205: prepare rebuilds plans for every row of every pinned placement in retained history on every redraw. The renderer only visits rows from the previous active_pin downward, so plans for scrollback rows are only read after a full clear. Building them lazily in prepareRow, or limiting them to rows at or after rendered_from, would bound the cost to what is actually rendered.
  2. QUESTION (robustness), src/Renderer.zig:1034: kitty.prepare swaps frames before render runs. If a row raster fails mid-render (OOM, ImageCreationFailed, or a quit during create-image), the next redraw compares against the plan that never rendered. Text-dirty rows still re-render. A row whose only change was its image is treated as clean and keeps a stale image. Swapping frames only after render succeeds, or discarding the new frame with an errdefer, would avoid this.

Things I checked that hold up

  • ghostel_png_compress / stb free(): I read the current Zig std/heap.zig CAllocator. Byte-aligned allocations take the .raw path, which calls plain malloc, and realloc is used for growth, so stb's free() is valid. That includes the MinGW Windows build, where the manual-align header path is not taken for alignment 1.
  • makeUnibyteString returning non-optional: make_unibyte_string is part of the Emacs 28 module API, which matches the project's 28.1+ minimum.
  • Letterboxing maths in addVirtual: fitted_width <= grid_width (and the same for height) holds after rounding, so (grid - fitted) / 2 cannot underflow.
  • finishPlan wide-character widening: end_col >= 1 is guaranteed because addSlice rejects empty intersections, so the cells[...] indexing is in bounds.
  • Display-property runs across style/link boundaries: the same display list is reused within a span, and Emacs treats consecutive eq display values as one replacement. The image is not split when the face changes under it.
  • Single-allocation scratch for stb resize: stb's v0.97 resizer requests its working memory in one STBIR_MALLOC call (stb_image_resize.h:2446), which is what ResizeContext.acquire / no-op STBIR_FREE assume.
  • Leftover references: nothing in lisp/, extensions/ or tests still uses the removed Elisp (ghostel--kitty-active, ghostel--kitty-clear, ghostel--kitty-display-*).

Not done

  • I did not build or run any tests: there is no Zig toolchain in this runner, and the project requires Zig 0.17.
  • I did not review the 4.3k lines of vendored stb headers beyond the hooks they expose.
  • I did not review tools/kitty-graphics-stress.py in depth (it is a dev-only tool).

Comment thread src/KittyRenderer.zig Resolved
Comment thread src/Renderer.zig Resolved
@emil-e
emil-e force-pushed the emil-e/kitty-placeholder-transparency branch 2 times, most recently from aa500f4 to fd4bc7f Compare November 15, 2026 20:40
Render Kitty images through native row-local composition with Lisp-owned image caching. Support PNG and PPM output, backing-resolution pixels, and lazy row planning alongside ordinary text projection.

Add graphics protocol, composition, rendering, and integration coverage plus a manual stress tool.
@emil-e
emil-e force-pushed the emil-e/kitty-placeholder-transparency branch from fd4bc7f to e0fb9f1 Compare November 15, 2026 21:03
@emil-e
emil-e merged commit d72b3b2 into dakra:main Nov 16, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants