mirror of
https://github.com/anomalyco/opentui.git
synced 2026-04-25 04:55:58 +03:00
[PR #633] Add ImageRenderable for pixel based images #673
Labels
No labels
bug
core
documentation
feature
good first issue
help wanted
pull-request
question
react
solid
tmux
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/opentui#673
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/anomalyco/opentui/pull/633
Author: @iamlemec
Created: 2/5/2026
Status: 🔄 Open
Base:
main← Head:image-renderable📝 Commits (1)
7a5a40badd ImageRenderable element to render images with the kitty graphics protocol📊 Changes
16 files changed (+483 additions, -4 deletions)
View changed files
📝
bun.lock(+16 -0)📝
packages/core/package.json(+2 -0)📝
packages/core/src/Renderable.ts(+19 -1)📝
packages/core/src/buffer.ts(+14 -0)➕
packages/core/src/examples/assets/blue.png(+0 -0)➕
packages/core/src/examples/assets/snake.png(+0 -0)➕
packages/core/src/examples/image.ts(+99 -0)➕
packages/core/src/renderables/Image.ts(+85 -0)📝
packages/core/src/renderables/composition/constructs.ts(+6 -0)📝
packages/core/src/renderables/index.ts(+1 -0)📝
packages/core/src/renderer.ts(+6 -1)📝
packages/core/src/zig.ts(+37 -1)📝
packages/core/src/zig/buffer.zig(+91 -0)➕
packages/core/src/zig/kitty.zig(+48 -0)📝
packages/core/src/zig/lib.zig(+12 -0)📝
packages/core/src/zig/renderer.zig(+47 -1)📄 Description
This adds an
ImageRenderableelement to render pixel images. The rendering closely mirrors the current/next buffer approach fromOptimizedBufferbut usingPixelBuffer, which is basically a collection ofPixelPatchobjects. This allows for flicker-free, non-reduntant rendering.The main interface is a new
renderPixelsfunction onRenderablesthat allows any renderable (not justImageRenderable) to display arbitrary numbers of images. Images are hashed to prevent redundant writes. The actual output is buffered with regular text output on the native side to prevent flicker.I tried to keep the changes as minimal as possible. I did need to increase the size of the output buffer from 2MB to 8MB to accomodate images. The only additional dependency is
pngjsfor decoding PNG files. There is an example with animated images calledimage.ts. This currently only outputs kitty format, but other formats should not be difficult. The data input is just aUint8Arrayof RGBA pixels, but could push file loading from example to core library.In terms of z-index issues, so far as I can tell, images are always placed above text, even if the text is written afterwards (at least in kitty/ghostty). So doing truly interleaved text and pixels would be non-trivial, but not impossible. You'd basically have to go in and transparent blit out parts of the images if they are occluded. This doesn't do that, so the pixel images are always just an overlay on top.
See issue #92 for more discussion.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.