mirror of
https://github.com/db9979/sshtermy.git
synced 2026-12-06 12:44:08 +01:00
* Leistungsanzeige verständlicher, Zeichnen etwa doppelt so schnell - Anzeige bewertet die Zeichenzeit in Worten (flüssig/gut/etwas träge/ruckelt), zwei Zeilen Balken je Bild statt Braille-Punkte, "möglich"-Bildrate, 1 Bild/s im Leerlauf wird erklärt; im Terminal links neben der F6-Leiste, Toasts weichen darunter aus - Overlays (Toasts, Tooltip, Ausblenden, Leistungsanzeige) ohne Compositor: stamp() fasst nur die überdeckten Zeilen an - Terminalbild wird gemerkt, solange keine neue Ausgabe kam (Term.Gen) - Seitenleiste ohne lipgloss-Umbruch anfügen (beside), Verläufe in einem Render - ViewHL misst bereits aufgefüllte Zeilen nicht noch einmal - Benchmarks: Terminal 2,9 → 0,9 ms, mit F6 + Anzeige 6,5 → 2,3 ms, mit laufender Ausgabe 6,9 → 3,5 ms je Bild Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUk5KxaHH89KrFPon9n * Zeichnen noch einmal fast doppelt so schnell - x/ansi als Fork (third_party/ansi): ASCII-Schnellweg in FirstGraphemeCluster, lipgloss misst jede Zeile jedes Bildes - Terminal-Zeilen unter einer Sperre holen (vt LineCopy), Farbregeln aus denselben Zellen statt jede Zelle zweimal einzeln - Seitenleiste (F6, Ziel, …) gemerkt, solange ihr Inhalt gleich bleibt - Balken der Leistungsanzeige je Farbe in einem Render - Benchmark mit F6, Anzeige und laufender Ausgabe: 3,5 → 1,8 ms je Bild Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUk5KxaHH89KrFPon9n --------- Co-authored-by: Claude <noreply@anthropic.com>
87 lines
1.9 KiB
Go
87 lines
1.9 KiB
Go
// Package kitty provides Kitty terminal graphics protocol functionality.
|
|
package kitty
|
|
|
|
import (
|
|
"compress/zlib"
|
|
"fmt"
|
|
"image"
|
|
"image/color"
|
|
"image/png"
|
|
"io"
|
|
)
|
|
|
|
// Decoder is a decoder for the Kitty graphics protocol. It supports decoding
|
|
// images in the 24-bit [RGB], 32-bit [RGBA], and [PNG] formats. It can also
|
|
// decompress data using zlib.
|
|
// The default format is 32-bit [RGBA].
|
|
type Decoder struct {
|
|
// Uses zlib decompression.
|
|
Decompress bool
|
|
|
|
// Can be one of [RGB], [RGBA], or [PNG].
|
|
Format int
|
|
|
|
// Width of the image in pixels. This can be omitted if the image is [PNG]
|
|
// formatted.
|
|
Width int
|
|
|
|
// Height of the image in pixels. This can be omitted if the image is [PNG]
|
|
// formatted.
|
|
Height int
|
|
}
|
|
|
|
// Decode decodes the image data from r in the specified format.
|
|
func (d *Decoder) Decode(r io.Reader) (image.Image, error) {
|
|
if d.Decompress {
|
|
zr, err := zlib.NewReader(r)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create zlib reader: %w", err)
|
|
}
|
|
|
|
defer zr.Close() //nolint:errcheck
|
|
r = zr
|
|
}
|
|
|
|
if d.Format == 0 {
|
|
d.Format = RGBA
|
|
}
|
|
|
|
switch d.Format {
|
|
case RGBA, RGB:
|
|
return d.decodeRGBA(r, d.Format == RGBA)
|
|
|
|
case PNG:
|
|
return png.Decode(r) //nolint:wrapcheck
|
|
|
|
default:
|
|
return nil, fmt.Errorf("unsupported format: %d", d.Format)
|
|
}
|
|
}
|
|
|
|
// decodeRGBA decodes the image data in 32-bit RGBA or 24-bit RGB formats.
|
|
func (d *Decoder) decodeRGBA(r io.Reader, alpha bool) (image.Image, error) {
|
|
m := image.NewRGBA(image.Rect(0, 0, d.Width, d.Height))
|
|
|
|
var buf []byte
|
|
if alpha {
|
|
buf = make([]byte, 4)
|
|
} else {
|
|
buf = make([]byte, 3)
|
|
}
|
|
|
|
for y := range d.Height {
|
|
for x := range d.Width {
|
|
if _, err := io.ReadFull(r, buf[:]); err != nil {
|
|
return nil, fmt.Errorf("failed to read pixel data: %w", err)
|
|
}
|
|
if alpha {
|
|
m.SetRGBA(x, y, color.RGBA{buf[0], buf[1], buf[2], buf[3]})
|
|
} else {
|
|
m.SetRGBA(x, y, color.RGBA{buf[0], buf[1], buf[2], 0xff})
|
|
}
|
|
}
|
|
}
|
|
|
|
return m, nil
|
|
}
|