1package clib
2
3import (
4 "bytes"
5 "image/png"
6
7 "github.com/mattn/go-sixel"
8)
9
10// EncodePNGToSixel converts PNG bytes to Sixel format
11// Returns Sixel sequence and row count needed for terminal spacing
12func EncodePNGToSixel(pngData []byte, cellHeightPx int) (string, int, error) {
13 // Decode PNG
14 img, err := png.Decode(bytes.NewReader(pngData))
15 if err != nil {
16 return "", 0, err
17 }
18
19 // Encode to Sixel
20 var buf bytes.Buffer
21 enc := sixel.NewEncoder(&buf)
22 if err := enc.Encode(img); err != nil {
23 return "", 0, err
24 }
25
26 // Calculate rows: image height / cell height
27 bounds := img.Bounds()
28 rows := (bounds.Dy() + cellHeightPx - 1) / cellHeightPx
29
30 return buf.String(), rows, nil
31}