| 1 |
package vaxisscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/ |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytesscip-go gomod github.com/golang/go/src go1.18 bytes/" |
| 5 |
"encoding/base64scip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/" |
| 6 |
"fmtscip-go gomod github.com/golang/go/src go1.18 fmt/" |
| 7 |
"imagescip-go gomod github.com/golang/go/src go1.18 image/" |
| 8 |
"image/colorscip-go gomod github.com/golang/go/src go1.18 `image/color`/" |
| 9 |
"image/pngscip-go gomod github.com/golang/go/src go1.18 `image/png`/" |
| 10 |
"ioscip-go gomod github.com/golang/go/src go1.18 io/" |
| 11 |
|
| 12 |
"git.sr.ht/~rockorager/vaxis/logscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/" |
| 13 |
"git.sr.ht/~rockorager/vaxis/octreequantscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/octreequant`/" |
| 14 |
|
| •15 |
"git.sr.ht/~rockorager/vaxis/sixelscip-go gomod github.com/golang/go/src go1.18 `git.sr.ht/~rockorager/vaxis/sixel`/" |
| 16 |
"golang.org/x/image/drawscip-go gomod golang.org/x/image v0.9.0 `golang.org/x/image/draw`/" |
| 17 |
) |
| 18 |
|
| 19 |
// Alpha value that we consider to be transparent enough to use default |
| 20 |
// background color |
| 21 |
const transparentEnoughscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/transparentEnough. = 50 |
| 22 |
|
| 23 |
const ( |
| 24 |
noGraphicsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/noGraphics. = iota |
| 25 |
fullBlockscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/fullBlock. |
| 26 |
halfBlockscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/halfBlock. |
| 27 |
sixelGraphicsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/sixelGraphics. |
| 28 |
kittyscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/kitty. |
| 29 |
) |
| 30 |
|
| 31 |
// Image is a static image on the screen |
| 32 |
type Imagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Image# interface { |
| 33 |
// Draw draws the [Image] to the [Window]. The image will not be drawn |
| 34 |
// if it is larger than the window |
| 35 |
Drawscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Image#Draw.(Windowscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Window#) |
| 36 |
// Destroy removes an image from memory. Call when done with this image |
| 37 |
Destroyscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Image#Destroy.() |
| 38 |
// Resizes the image to fit within the provided area. The image will not |
| 39 |
// be upscaled, nor will it's aspect ratio be changed |
| 40 |
Resizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Image#Resize.(w int, h int) |
| 41 |
// CellSize is the current cell size of the encoded image |
| 42 |
CellSizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Image#CellSize.() (w int, h int) |
| 43 |
} |
| 44 |
|
| 45 |
// NewImage creates a new image using the highest quality renderer the terminal |
| 46 |
// is capable of |
| 47 |
func (vx *Vaxisscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#) NewImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#NewImage().(img imagescip-go gomod github.com/golang/go/src go1.18 image/.Imagescip-go gomod github.com/golang/go/src go1.18 image/Image#) (Imagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Image#, error) { |
| 48 |
switch vx.graphicsProtocolscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#graphicsProtocol. { |
| 49 |
case fullBlockscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/fullBlock.: |
| 50 |
return vx.NewFullBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#NewFullBlockImage().(img), nil |
| 51 |
case halfBlockscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/halfBlock.: |
| 52 |
return vx.NewHalfBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#NewHalfBlockImage().(img), nil |
| 53 |
case sixelGraphicsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/sixelGraphics.: |
| 54 |
return vx.NewSixelscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#NewSixel().(img), nil |
| 55 |
case kittyscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/kitty.: |
| 56 |
return vx.NewKittyGraphicscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#NewKittyGraphic().(img), nil |
| 57 |
default: |
| 58 |
return nil, fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.18 fmt/Errorf().("no supported image protocol") |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
type KittyImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage# struct { |
| 63 |
vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#vx. *Vaxisscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis# |
| 64 |
imgscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#img. imagescip-go gomod github.com/golang/go/src go1.18 image/.Imagescip-go gomod github.com/golang/go/src go1.18 image/Image# |
| 65 |
idscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#id. uint64 |
| 66 |
wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#w. int |
| 67 |
hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#h. int |
| 68 |
uploadedscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#uploaded. int32 |
| 69 |
encodingscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#encoding. int32 |
| 70 |
bufscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#buf. *bytesscip-go gomod github.com/golang/go/src go1.18 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.18 bytes/Buffer# |
| 71 |
} |
| 72 |
|
| 73 |
func (vx *Vaxisscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#) NewKittyGraphicscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#NewKittyGraphic().(img imagescip-go gomod github.com/golang/go/src go1.18 image/.Imagescip-go gomod github.com/golang/go/src go1.18 image/Image#) *KittyImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage# { |
| 74 |
logscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/.Tracescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/Trace().("new kitty image") |
| 75 |
k := &KittyImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#{ |
| 76 |
vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#vx.: vx, |
| 77 |
imgscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#img.: img, |
| 78 |
idscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#id.: vx.nextGraphicIDscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#nextGraphicID().(), |
| 79 |
bufscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#buf.: bytesscip-go gomod github.com/golang/go/src go1.18 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.18 bytes/NewBuffer().(nil), |
| 80 |
} |
| 81 |
return k |
| 82 |
} |
| 83 |
|
| 84 |
// Draw draws the [Image] to the [Window]. |
| 85 |
func (k *KittyImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#) Drawscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#Draw().(win Windowscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Window#) { |
| 86 |
if atomicLoadscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/atomicLoad().(&k.encodingscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#encoding.) { |
| 87 |
return |
| 88 |
} |
| 89 |
col, row := win.Originscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Window#Origin().() |
| 90 |
logscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/.Tracescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/Trace().("placing kitty image at cell %d,%d", col, row) |
| 91 |
// the pid is a 32 bit number where the high 16bits are the width and |
| 92 |
// the low 16 are the height |
| 93 |
pid := uint(col)<<16 | uint(row) |
| 94 |
writeFunc := func(w ioscip-go gomod github.com/golang/go/src go1.18 io/.Writerscip-go gomod github.com/golang/go/src go1.18 io/Writer#) { |
| 95 |
if !atomicLoadscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/atomicLoad().(&k.uploadedscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#uploaded.) { |
| 96 |
w.Writescip-go gomod github.com/golang/go/src go1.18 io/Writer#Write().(k.bufscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#buf..Bytesscip-go gomod github.com/golang/go/src go1.18 bytes/Buffer#Bytes().()) |
| 97 |
atomicStorescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/atomicStore().(&k.uploadedscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#uploaded., true) |
| 98 |
k.bufscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#buf..Resetscip-go gomod github.com/golang/go/src go1.18 bytes/Buffer#Reset().() |
| 99 |
} |
| 100 |
fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Fprintf().(w, "\x1B_Ga=p,i=%d,p=%d,C=1\x1B\\", k.idscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#id., pid) |
| 101 |
} |
| 102 |
deleteFunc := func(w ioscip-go gomod github.com/golang/go/src go1.18 io/.Writerscip-go gomod github.com/golang/go/src go1.18 io/Writer#) { |
| 103 |
fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Fprintf().(w, "\x1B_Ga=d,d=i,i=%d,p=%d\x1B\\", k.idscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#id., pid) |
| 104 |
} |
| 105 |
placement := &placementscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#{ |
| 106 |
colscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#col.: col, |
| 107 |
rowscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#row.: row, |
| 108 |
idscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#id.: k.idscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#id., |
| 109 |
wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#w.: k.wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#w., |
| 110 |
hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#h.: k.hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#h., |
| 111 |
writeToscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#writeTo.: writeFunc, |
| 112 |
deleteFnscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#deleteFn.: deleteFunc, |
| 113 |
} |
| 114 |
k.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#vx..graphicsNextscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#graphicsNext. = append(k.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#vx..graphicsNextscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#graphicsNext., placement) |
| 115 |
} |
| 116 |
|
| 117 |
// Destroy deletes this image from memory |
| 118 |
func (k *KittyImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#) Destroyscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#Destroy().() { |
| 119 |
fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Fprintf().(k.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#vx..consolescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#console., "\x1B_Ga=d,d=I,i=%d\x1B\\", k.idscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#id.) |
| 120 |
} |
| 121 |
|
| 122 |
func (k *KittyImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#) CellSizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#CellSize().() (w int, h int) { |
| 123 |
return k.wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#w., k.hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#h. |
| 124 |
} |
| 125 |
|
| 126 |
// Resizes the image to fit within the wxh area. The image will not be |
| 127 |
// upscaled, nor will it's aspect ratio be changed. Resizing will be done in a |
| 128 |
// separate goroutine. A [Redraw] event will be posted when complete |
| 129 |
func (k *KittyImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#) Resizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#Resize().(w int, h int) { |
| 130 |
// Resize the image |
| 131 |
cellPixW := k.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#vx..winSizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#winSize..XPixelscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Resize#XPixel. / k.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#vx..winSizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#winSize..Colsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Resize#Cols. |
| 132 |
cellPixH := k.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#vx..winSizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#winSize..YPixelscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Resize#YPixel. / k.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#vx..winSizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#winSize..Rowsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Resize#Rows. |
| 133 |
img := resizeImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/resizeImage().(k.imgscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#img., w, h, cellPixW, cellPixH) |
| 134 |
|
| 135 |
// Reupload the image |
| 136 |
max := img.Boundsscip-go gomod github.com/golang/go/src go1.18 image/Image#Bounds().().Maxscip-go gomod github.com/golang/go/src go1.18 image/Rectangle#Max. |
| 137 |
k.wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#w. = max.Xscip-go gomod github.com/golang/go/src go1.18 image/Point#X. / cellPixW |
| 138 |
if max.Xscip-go gomod github.com/golang/go/src go1.18 image/Point#X.%cellPixW != 0 { |
| 139 |
k.wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#w. += 1 |
| 140 |
} |
| 141 |
k.hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#h. = max.Yscip-go gomod github.com/golang/go/src go1.18 image/Point#Y. / cellPixH |
| 142 |
if max.Yscip-go gomod github.com/golang/go/src go1.18 image/Point#Y.%cellPixH != 0 { |
| 143 |
k.hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#h. += 1 |
| 144 |
} |
| 145 |
|
| 146 |
atomicStorescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/atomicStore().(&k.encodingscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#encoding., true) |
| 147 |
go func() { |
| 148 |
defer atomicStorescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/atomicStore().(&k.encodingscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#encoding., false) |
| 149 |
// Encode it to base64 |
| 150 |
buf := bytesscip-go gomod github.com/golang/go/src go1.18 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.18 bytes/NewBuffer().(nil) |
| 151 |
wc := base64scip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/.NewEncoderscip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/NewEncoder().(base64scip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.18 `encoding/base64`/StdEncoding., buf) |
| 152 |
err := pngscip-go gomod github.com/golang/go/src go1.18 `image/png`/.Encodescip-go gomod github.com/golang/go/src go1.18 `image/png`/Encode().(wc, img) |
| 153 |
if err != nil { |
| 154 |
logscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/.Errorscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/Error().("couldn't encode kitty image: %v", err) |
| 155 |
return |
| 156 |
} |
| 157 |
wc.Closescip-go gomod github.com/golang/go/src go1.18 io/Closer#Close().() |
| 158 |
b := make([]byte, 4096) |
| 159 |
atomicStorescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/atomicStore().(&k.uploadedscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#uploaded., false) |
| 160 |
for buf.Lenscip-go gomod github.com/golang/go/src go1.18 bytes/Buffer#Len().() > 0 { |
| 161 |
n, err := buf.Readscip-go gomod github.com/golang/go/src go1.18 bytes/Buffer#Read().(b) |
| 162 |
if err == ioscip-go gomod github.com/golang/go/src go1.18 io/.EOFscip-go gomod github.com/golang/go/src go1.18 io/EOF. { |
| 163 |
break |
| 164 |
} |
| 165 |
m := 1 |
| 166 |
if buf.Lenscip-go gomod github.com/golang/go/src go1.18 bytes/Buffer#Len().() == 0 { |
| 167 |
m = 0 |
| 168 |
} |
| 169 |
fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Fprintf().(k.bufscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#buf., "\x1B_Gf=100,i=%d,m=%d;%s\x1B\\", k.idscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#id., m, string(b[:n])) |
| 170 |
} |
| 171 |
k.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/KittyImage#vx..PostEventBlockingscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#PostEventBlocking().(Redrawscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Redraw#{}) |
| 172 |
}() |
| 173 |
} |
| 174 |
|
| 175 |
type Sixelscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel# struct { |
| 176 |
vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#vx. *Vaxisscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis# |
| 177 |
imgscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#img. imagescip-go gomod github.com/golang/go/src go1.18 image/.Imagescip-go gomod github.com/golang/go/src go1.18 image/Image# |
| 178 |
bufscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#buf. *bytesscip-go gomod github.com/golang/go/src go1.18 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.18 bytes/Buffer# |
| 179 |
idscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#id. uint64 |
| 180 |
wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#w. int |
| 181 |
hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#h. int |
| 182 |
encodingscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#encoding. int32 |
| 183 |
} |
| 184 |
|
| 185 |
// Draw draws the [Image] to the [Window]. The image will not be drawn |
| 186 |
// if it is larger than the window |
| 187 |
func (s *Sixelscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#) Drawscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#Draw().(win Windowscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Window#) { |
| 188 |
if s.bufscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#buf..Lenscip-go gomod github.com/golang/go/src go1.18 bytes/Buffer#Len().() == 0 { |
| 189 |
return |
| 190 |
} |
| 191 |
if atomicLoadscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/atomicLoad().(&s.encodingscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#encoding.) { |
| 192 |
return |
| 193 |
} |
| 194 |
w, h := win.Sizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Window#Size().() |
| 195 |
if s.wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#w. > w || s.hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#h. > h { |
| 196 |
return |
| 197 |
} |
| 198 |
for y := 0; y < s.hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#h.; y += 1 { |
| 199 |
for x := 0; x < s.wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#w.; x += 1 { |
| 200 |
win.SetCellscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Window#SetCell().(x, y, Cellscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#{ |
| 201 |
sixelscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#sixel.: true, |
| 202 |
}) |
| 203 |
} |
| 204 |
} |
| 205 |
writeFunc := func(w ioscip-go gomod github.com/golang/go/src go1.18 io/.Writerscip-go gomod github.com/golang/go/src go1.18 io/Writer#) { |
| 206 |
// Also need to set sixel value in here for Refresh cycles |
| 207 |
for y := 0; y < s.hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#h.; y += 1 { |
| 208 |
for x := 0; x < s.wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#w.; x += 1 { |
| 209 |
win.SetCellscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Window#SetCell().(x, y, Cellscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#{ |
| 210 |
sixelscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#sixel.: true, |
| 211 |
}) |
| 212 |
} |
| 213 |
} |
| 214 |
w.Writescip-go gomod github.com/golang/go/src go1.18 io/Writer#Write().(s.bufscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#buf..Bytesscip-go gomod github.com/golang/go/src go1.18 bytes/Buffer#Bytes().()) |
| 215 |
} |
| 216 |
deleteFunc := func(_ ioscip-go gomod github.com/golang/go/src go1.18 io/.Writerscip-go gomod github.com/golang/go/src go1.18 io/Writer#) { |
| 217 |
// no-op. we expect users to Clear the screen or just print |
| 218 |
// cells, which will have the effect of clearing the sixel |
| 219 |
} |
| 220 |
col, row := win.Originscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Window#Origin().() |
| 221 |
logscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/.Tracescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/Trace().("placing sixel image at cell %d,%d", col, row) |
| 222 |
placement := &placementscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#{ |
| 223 |
colscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#col.: col, |
| 224 |
rowscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#row.: row, |
| 225 |
writeToscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#writeTo.: writeFunc, |
| 226 |
deleteFnscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#deleteFn.: deleteFunc, |
| 227 |
idscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#id.: s.idscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#id., |
| 228 |
wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#w.: s.wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#w., |
| 229 |
hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#h.: s.hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#h., |
| 230 |
} |
| 231 |
s.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#vx..graphicsNextscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#graphicsNext. = append(s.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#vx..graphicsNextscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#graphicsNext., placement) |
| 232 |
} |
| 233 |
|
| 234 |
// Destroy removes an image from memory. Call when done with this image |
| 235 |
func (s *Sixelscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#) Destroyscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#Destroy().() { |
| 236 |
s.bufscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#buf..Resetscip-go gomod github.com/golang/go/src go1.18 bytes/Buffer#Reset().() |
| 237 |
} |
| 238 |
|
| 239 |
// Resizes the image to fit within the wxh area. The image will not be |
| 240 |
// upscaled, nor will it's aspect ratio be changed. Resize will be done in a |
| 241 |
// separate gorotuine. A Redraw event will be posted when complete |
| 242 |
func (s *Sixelscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#) Resizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#Resize().(w int, h int) { |
| 243 |
atomicStorescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/atomicStore().(&s.encodingscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#encoding., true) |
| 244 |
go func() { |
| 245 |
defer atomicStorescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/atomicStore().(&s.encodingscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#encoding., false) |
| 246 |
// Resize the image |
| 247 |
cellPixW := s.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#vx..winSizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#winSize..XPixelscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Resize#XPixel. / s.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#vx..winSizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#winSize..Colsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Resize#Cols. |
| 248 |
cellPixH := s.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#vx..winSizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#winSize..YPixelscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Resize#YPixel. / s.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#vx..winSizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#winSize..Rowsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Resize#Rows. |
| 249 |
img := resizeImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/resizeImage().(s.imgscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#img., w, h, cellPixW, cellPixH) |
| 250 |
max := img.Boundsscip-go gomod github.com/golang/go/src go1.18 image/Image#Bounds().().Maxscip-go gomod github.com/golang/go/src go1.18 image/Rectangle#Max. |
| 251 |
s.wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#w. = max.Xscip-go gomod github.com/golang/go/src go1.18 image/Point#X. / cellPixW |
| 252 |
if max.Xscip-go gomod github.com/golang/go/src go1.18 image/Point#X.%cellPixW != 0 { |
| 253 |
s.wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#w. += 1 |
| 254 |
} |
| 255 |
s.hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#h. = max.Yscip-go gomod github.com/golang/go/src go1.18 image/Point#Y. / cellPixH |
| 256 |
if max.Yscip-go gomod github.com/golang/go/src go1.18 image/Point#Y.%cellPixH != 0 { |
| 257 |
s.hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#h. += 1 |
| 258 |
} |
| 259 |
// Re-encode the image |
| 260 |
s.bufscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#buf..Resetscip-go gomod github.com/golang/go/src go1.18 bytes/Buffer#Reset().() |
| 261 |
var paletted imagescip-go gomod github.com/golang/go/src go1.18 image/.Imagescip-go gomod github.com/golang/go/src go1.18 image/Image# |
| 262 |
if p, ok := img.(*imagescip-go gomod github.com/golang/go/src go1.18 image/.Palettedscip-go gomod github.com/golang/go/src go1.18 image/Paletted#); ok && len(p.Palettescip-go gomod github.com/golang/go/src go1.18 image/Paletted#Palette.) < 255 { |
| 263 |
// fast-path for paletted images: pass through to sixel |
| 264 |
paletted = p |
| 265 |
} else { |
| 266 |
paletted = octreequantscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/octreequant`/.Palettedscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/octreequant`/Paletted().(img, 254) |
| 267 |
} |
| 268 |
err := sixelscip-go gomod github.com/golang/go/src go1.18 `git.sr.ht/~rockorager/vaxis/sixel`/.NewEncoder(s.bufscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#buf.).Encode(paletted) |
| 269 |
if err != nil { |
| 270 |
logscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/.Errorscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/Error().("couldn't encode sixel: %v", err) |
| 271 |
return |
| 272 |
} |
| 273 |
|
| 274 |
// Foot requires that we set the P2 parameter = 1 in order to |
| 275 |
// enable transparency. This doesn't seem to affect other sixel |
| 276 |
// based terminals |
| 277 |
b := s.bufscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#buf..Bytesscip-go gomod github.com/golang/go/src go1.18 bytes/Buffer#Bytes().() |
| 278 |
b[4] = 0x31 |
| 279 |
|
| 280 |
s.vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#vx..PostEventBlockingscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#PostEventBlocking().(Redrawscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Redraw#{}) |
| 281 |
}() |
| 282 |
} |
| 283 |
|
| 284 |
// CellSize is the current cell size of the encoded image |
| 285 |
func (s *Sixelscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#) CellSizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#CellSize().() (w int, h int) { |
| 286 |
if atomicLoadscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/atomicLoad().(&s.encodingscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#encoding.) { |
| 287 |
return |
| 288 |
} |
| 289 |
return s.wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#w., s.hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#h. |
| 290 |
} |
| 291 |
|
| 292 |
func (vx *Vaxisscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#) NewSixelscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#NewSixel().(img imagescip-go gomod github.com/golang/go/src go1.18 image/.Imagescip-go gomod github.com/golang/go/src go1.18 image/Image#) *Sixelscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel# { |
| 293 |
logscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/.Tracescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/Trace().("new sixel image") |
| 294 |
s := &Sixelscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#{ |
| 295 |
vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#vx.: vx, |
| 296 |
imgscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#img.: img, |
| 297 |
idscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#id.: vx.nextGraphicIDscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#nextGraphicID().(), |
| 298 |
bufscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Sixel#buf.: bytesscip-go gomod github.com/golang/go/src go1.18 bytes/.NewBufferscip-go gomod github.com/golang/go/src go1.18 bytes/NewBuffer().(nil), |
| 299 |
} |
| 300 |
return s |
| 301 |
} |
| 302 |
|
| 303 |
// placement is an image placement. If two placements are identical, the |
| 304 |
// image will not be redrawn |
| 305 |
type placementscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement# struct { |
| 306 |
writeToscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#writeTo. func(w ioscip-go gomod github.com/golang/go/src go1.18 io/.Writerscip-go gomod github.com/golang/go/src go1.18 io/Writer#) |
| 307 |
deleteFnscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#deleteFn. func(w ioscip-go gomod github.com/golang/go/src go1.18 io/.Writerscip-go gomod github.com/golang/go/src go1.18 io/Writer#) |
| 308 |
colscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#col. int |
| 309 |
rowscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#row. int |
| 310 |
idscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#id. uint64 |
| 311 |
wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#w. int |
| 312 |
hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#h. int |
| 313 |
} |
| 314 |
|
| 315 |
// samePlacement compares two placements for equality. Two placements are |
| 316 |
// considered equal if it is the same image, with the same size, at the same |
| 317 |
// location |
| 318 |
func samePlacementscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/samePlacement().(p1, p2 *placementscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#) bool { |
| 319 |
if p1.idscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#id. != p2.idscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#id. { |
| 320 |
return false |
| 321 |
} |
| 322 |
if p1.colscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#col. != p2.colscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#col. { |
| 323 |
return false |
| 324 |
} |
| 325 |
if p1.rowscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#row. != p2.rowscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#row. { |
| 326 |
return false |
| 327 |
} |
| 328 |
if p1.wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#w. != p2.wscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#w. { |
| 329 |
return false |
| 330 |
} |
| 331 |
if p1.hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#h. != p2.hscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/placement#h. { |
| 332 |
return false |
| 333 |
} |
| 334 |
return true |
| 335 |
} |
| 336 |
|
| 337 |
// Resizes an image to fit within the provided rectangle (as cells). If the |
| 338 |
// image already fits, it won't be resized |
| 339 |
func resizeImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/resizeImage().(img imagescip-go gomod github.com/golang/go/src go1.18 image/.Imagescip-go gomod github.com/golang/go/src go1.18 image/Image#, w int, h int, cellPixW int, cellPixH int) imagescip-go gomod github.com/golang/go/src go1.18 image/.Imagescip-go gomod github.com/golang/go/src go1.18 image/Image# { |
| 340 |
wPix := img.Boundsscip-go gomod github.com/golang/go/src go1.18 image/Image#Bounds().().Maxscip-go gomod github.com/golang/go/src go1.18 image/Rectangle#Max..Xscip-go gomod github.com/golang/go/src go1.18 image/Point#X. |
| 341 |
hPix := img.Boundsscip-go gomod github.com/golang/go/src go1.18 image/Image#Bounds().().Maxscip-go gomod github.com/golang/go/src go1.18 image/Rectangle#Max..Yscip-go gomod github.com/golang/go/src go1.18 image/Point#Y. |
| 342 |
// Looks complicated but we're just calculating the size of the |
| 343 |
// image in cells, and rounding up since we will always take |
| 344 |
// over any cell we bleed into. |
| 345 |
columns := wPix / cellPixW |
| 346 |
if wPix%cellPixW != 0 { |
| 347 |
columns += 1 |
| 348 |
} |
| 349 |
lines := hPix / cellPixH |
| 350 |
if hPix%cellPixH != 0 { |
| 351 |
lines += 1 |
| 352 |
} |
| 353 |
logscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/.Debugscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/Debug().("resizing image from (%d x %d) to (%d x %d)", columns, lines, w, h) |
| 354 |
if columns <= w && lines <= h { |
| 355 |
return img |
| 356 |
} |
| 357 |
// calculate scale factors |
| 358 |
sfX := float64(w) / float64(columns) |
| 359 |
sfY := float64(h) / float64(lines) |
| 360 |
newPixelWidth := wPix |
| 361 |
newPixelHeight := hPix |
| 362 |
switch { |
| 363 |
case sfX == sfY: |
| 364 |
// no-op |
| 365 |
case sfX < sfY: |
| 366 |
// Width is farther off, so set our new width to w and scale h |
| 367 |
// appropriately |
| 368 |
newPixelWidth = int(sfX * float64(wPix)) |
| 369 |
newPixelHeight = int(sfX * float64(hPix)) |
| 370 |
case sfX > sfY: |
| 371 |
newPixelWidth = int(sfY * float64(wPix)) |
| 372 |
newPixelHeight = int(sfY * float64(hPix)) |
| 373 |
} |
| 374 |
dst := imagescip-go gomod github.com/golang/go/src go1.18 image/.NewRGBAscip-go gomod github.com/golang/go/src go1.18 image/NewRGBA().(imagescip-go gomod github.com/golang/go/src go1.18 image/.Rectscip-go gomod github.com/golang/go/src go1.18 image/Rect().(0, 0, newPixelWidth, newPixelHeight)) |
| 375 |
drawscip-go gomod golang.org/x/image v0.9.0 `golang.org/x/image/draw`/.NearestNeighborscip-go gomod golang.org/x/image v0.9.0 `golang.org/x/image/draw`/NearestNeighbor..Scalescip-go gomod golang.org/x/image v0.9.0 `golang.org/x/image/draw`/Scaler#Scale().(dst, dst.Rectscip-go gomod github.com/golang/go/src go1.18 image/RGBA#Rect., img, img.Boundsscip-go gomod github.com/golang/go/src go1.18 image/Image#Bounds().(), drawscip-go gomod golang.org/x/image v0.9.0 `golang.org/x/image/draw`/.Overscip-go gomod golang.org/x/image v0.9.0 `golang.org/x/image/draw`/Over., nil) |
| 376 |
return dst |
| 377 |
} |
| 378 |
|
| 379 |
// FullBlockImage is an image composed of 0x20 characters. This is the most |
| 380 |
// primitive graphics protocol |
| 381 |
type FullBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage# struct { |
| 382 |
vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#vx. *Vaxisscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis# |
| 383 |
imgscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#img. imagescip-go gomod github.com/golang/go/src go1.18 image/.Imagescip-go gomod github.com/golang/go/src go1.18 image/Image# |
| 384 |
cellsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#cells. []Colorscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Color# |
| 385 |
widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#width. int |
| 386 |
heightscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#height. int |
| 387 |
} |
| 388 |
|
| 389 |
func (vx *Vaxisscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#) NewFullBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#NewFullBlockImage().(img imagescip-go gomod github.com/golang/go/src go1.18 image/.Imagescip-go gomod github.com/golang/go/src go1.18 image/Image#) *FullBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage# { |
| 390 |
logscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/.Tracescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/Trace().("new full block image") |
| 391 |
fb := &FullBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#{ |
| 392 |
vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#vx.: vx, |
| 393 |
imgscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#img.: img, |
| 394 |
} |
| 395 |
return fb |
| 396 |
} |
| 397 |
|
| 398 |
func (fb *FullBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#) Drawscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#Draw().(win Windowscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Window#) { |
| 399 |
col, row := win.Originscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Window#Origin().() |
| 400 |
logscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/.Tracescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/Trace().("placing full block image at cell %d,%d", col, row) |
| 401 |
for i, cell := range fb.cellsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#cells. { |
| 402 |
y := i / fb.widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#width. |
| 403 |
x := i - (y * fb.widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#width.) |
| 404 |
win.SetCellscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Window#SetCell().(x, y, Cellscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#{ |
| 405 |
Characterscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#Character.: Characterscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Character#{ |
| 406 |
Graphemescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Character#Grapheme.: " ", |
| 407 |
Widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Character#Width.: 1, |
| 408 |
}, |
| 409 |
Stylescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#Style.: Stylescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Style#{ |
| 410 |
Backgroundscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Style#Background.: cell, |
| 411 |
}, |
| 412 |
}) |
| 413 |
} |
| 414 |
} |
| 415 |
|
| 416 |
// Resize resizes and re-encodes an image |
| 417 |
func (fb *FullBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#) Resizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#Resize().(w int, h int) { |
| 418 |
// FullBlockImage gets resized with a cell geometry of 1x2 pixels. We |
| 419 |
// will then average the vertical two pixels to make a single color ' ' |
| 420 |
// character |
| 421 |
img := resizeImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/resizeImage().(fb.imgscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#img., w, h, 1, 2) |
| 422 |
|
| 423 |
// Store the actual width and height of the resized image |
| 424 |
fb.widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#width. = img.Boundsscip-go gomod github.com/golang/go/src go1.18 image/Image#Bounds().().Maxscip-go gomod github.com/golang/go/src go1.18 image/Rectangle#Max..Xscip-go gomod github.com/golang/go/src go1.18 image/Point#X. |
| 425 |
h = img.Boundsscip-go gomod github.com/golang/go/src go1.18 image/Image#Bounds().().Maxscip-go gomod github.com/golang/go/src go1.18 image/Rectangle#Max..Yscip-go gomod github.com/golang/go/src go1.18 image/Point#Y. |
| 426 |
if h%2 != 0 { |
| 427 |
h += 1 |
| 428 |
} |
| 429 |
fb.heightscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#height. = h / 2 |
| 430 |
// The image will be made into an array of cells, each cell will capture |
| 431 |
// 1x2 pixels |
| 432 |
fb.cellsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#cells. = make([]Colorscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Color#, (fb.heightscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#height. * fb.widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#width.)) |
| 433 |
for i := range fb.cellsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#cells. { |
| 434 |
y := i / fb.widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#width. |
| 435 |
x := i - (y * fb.widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#width.) |
| 436 |
y *= 2 |
| 437 |
|
| 438 |
top := img.Atscip-go gomod github.com/golang/go/src go1.18 image/Image#At().(x, y) |
| 439 |
bot := img.Atscip-go gomod github.com/golang/go/src go1.18 image/Image#At().(x, y+1) |
| 440 |
r, g, b, a := averageColorscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/averageColor().(top, bot) |
| 441 |
switch { |
| 442 |
// TODO: What is the right value for alpha that we should set |
| 443 |
// the background color = 0?? |
| 444 |
case a < 50: |
| 445 |
fb.cellsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#cells.[i] = 0 |
| 446 |
default: |
| 447 |
fb.cellsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#cells.[i] = RGBColorscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/RGBColor().(r, g, b) |
| 448 |
} |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
func (fb *FullBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#) Destroyscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#Destroy().() { |
| 453 |
fb.cellsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#cells. = []Colorscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Color#{} |
| 454 |
} |
| 455 |
|
| 456 |
func (fb *FullBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#) CellSizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#CellSize().() (int, int) { |
| 457 |
return fb.widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#width., fb.heightscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/FullBlockImage#height. |
| 458 |
} |
| 459 |
|
| 460 |
func toRGBscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/toRGB().(c colorscip-go gomod github.com/golang/go/src go1.18 `image/color`/.Colorscip-go gomod github.com/golang/go/src go1.18 `image/color`/Color#) (uint8, uint8, uint8, uint8) { |
| 461 |
pr, pg, pb, pa := c.RGBAscip-go gomod github.com/golang/go/src go1.18 `image/color`/Color#RGBA().() |
| 462 |
var r, g, b, a uint8 |
| 463 |
switch pa { |
| 464 |
case 0: |
| 465 |
r = uint8(pr) |
| 466 |
g = uint8(pg) |
| 467 |
b = uint8(pb) |
| 468 |
default: |
| 469 |
r = uint8((pr * 255) / pa) |
| 470 |
g = uint8((pg * 255) / pa) |
| 471 |
b = uint8((pb * 255) / pa) |
| 472 |
a = uint8(pa >> 8) |
| 473 |
} |
| 474 |
return r, g, b, a |
| 475 |
} |
| 476 |
|
| 477 |
// averageColor computes the average color from all inputs and returns it's rgb |
| 478 |
// value |
| 479 |
func averageColorscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/averageColor().(c colorscip-go gomod github.com/golang/go/src go1.18 `image/color`/.Colorscip-go gomod github.com/golang/go/src go1.18 `image/color`/Color#, colors ...colorscip-go gomod github.com/golang/go/src go1.18 `image/color`/.Colorscip-go gomod github.com/golang/go/src go1.18 `image/color`/Color#) (uint8, uint8, uint8, uint8) { |
| 480 |
var r, g, b, a int |
| 481 |
colors = append(colors, c) |
| 482 |
for _, col := range colors { |
| 483 |
rA, gA, bA, aA := toRGBscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/toRGB().(col) |
| 484 |
r += int(rA) |
| 485 |
g += int(gA) |
| 486 |
b += int(bA) |
| 487 |
a += int(aA) |
| 488 |
} |
| 489 |
n := len(colors) |
| 490 |
return uint8(r / n), uint8(g / n), uint8(b / n), uint8(a / n) |
| 491 |
} |
| 492 |
|
| 493 |
// HalfBlockImage is an image composed of half block characters. |
| 494 |
type HalfBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage# struct { |
| 495 |
vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#vx. *Vaxisscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis# |
| 496 |
imgscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#img. imagescip-go gomod github.com/golang/go/src go1.18 image/.Imagescip-go gomod github.com/golang/go/src go1.18 image/Image# |
| 497 |
cellsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#cells. []Cellscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell# |
| 498 |
widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#width. int |
| 499 |
heightscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#height. int |
| 500 |
} |
| 501 |
|
| 502 |
func (vx *Vaxisscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#) NewHalfBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Vaxis#NewHalfBlockImage().(img imagescip-go gomod github.com/golang/go/src go1.18 image/.Imagescip-go gomod github.com/golang/go/src go1.18 image/Image#) *HalfBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage# { |
| 503 |
logscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/.Tracescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/Trace().("new half block image") |
| 504 |
hb := &HalfBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#{ |
| 505 |
vxscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#vx.: vx, |
| 506 |
imgscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#img.: img, |
| 507 |
} |
| 508 |
return hb |
| 509 |
} |
| 510 |
|
| 511 |
func (hb *HalfBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#) Drawscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#Draw().(win Windowscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Window#) { |
| 512 |
col, row := win.Originscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Window#Origin().() |
| 513 |
logscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/.Tracescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis/log`/Trace().("placing half block image at cell %d,%d", col, row) |
| 514 |
for i, cell := range hb.cellsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#cells. { |
| 515 |
y := i / hb.widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#width. |
| 516 |
x := i - (y * hb.widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#width.) |
| 517 |
win.SetCellscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Window#SetCell().(x, y, cell) |
| 518 |
} |
| 519 |
} |
| 520 |
|
| 521 |
// Resize resizes and re-encodes an image |
| 522 |
func (hb *HalfBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#) Resizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#Resize().(w int, h int) { |
| 523 |
// HalfBlockImage gets resized with a cell geometry of 1x2 pixels. |
| 524 |
img := resizeImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/resizeImage().(hb.imgscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#img., w, h, 1, 2) |
| 525 |
|
| 526 |
// Store the actual width and height of the resized image |
| 527 |
hb.widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#width. = img.Boundsscip-go gomod github.com/golang/go/src go1.18 image/Image#Bounds().().Maxscip-go gomod github.com/golang/go/src go1.18 image/Rectangle#Max..Xscip-go gomod github.com/golang/go/src go1.18 image/Point#X. |
| 528 |
h = img.Boundsscip-go gomod github.com/golang/go/src go1.18 image/Image#Bounds().().Maxscip-go gomod github.com/golang/go/src go1.18 image/Rectangle#Max..Yscip-go gomod github.com/golang/go/src go1.18 image/Point#Y. |
| 529 |
if h%2 != 0 { |
| 530 |
h += 1 |
| 531 |
} |
| 532 |
hb.heightscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#height. = h / 2 |
| 533 |
// The image will be made into an array of cells, each cell will capture |
| 534 |
// 1x2 pixels |
| 535 |
hb.cellsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#cells. = make([]Cellscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#, (hb.heightscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#height. * hb.widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#width.)) |
| 536 |
for i := range hb.cellsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#cells. { |
| 537 |
y := i / hb.widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#width. |
| 538 |
x := i - (y * hb.widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#width.) |
| 539 |
y *= 2 |
| 540 |
|
| 541 |
tr, tg, tb, ta := toRGBscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/toRGB().(img.Atscip-go gomod github.com/golang/go/src go1.18 image/Image#At().(x, y)) |
| 542 |
br, bg, bb, ba := toRGBscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/toRGB().(img.Atscip-go gomod github.com/golang/go/src go1.18 image/Image#At().(x, y+1)) |
| 543 |
// Figure out if one of the alpha channels is transparent |
| 544 |
// "enough" |
| 545 |
switch { |
| 546 |
case ta < transparentEnoughscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/transparentEnough. && ba < transparentEnoughscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/transparentEnough.: |
| 547 |
// Use a transparent space |
| 548 |
hb.cellsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#cells.[i] = Cellscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#{ |
| 549 |
Characterscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#Character.: Characterscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Character#{ |
| 550 |
Graphemescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Character#Grapheme.: " ", |
| 551 |
Widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Character#Width.: 1, |
| 552 |
}, |
| 553 |
} |
| 554 |
case ta < transparentEnoughscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/transparentEnough.: |
| 555 |
// Top is transparent. Use a lower block |
| 556 |
hb.cellsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#cells.[i] = Cellscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#{ |
| 557 |
Characterscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#Character.: Characterscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Character#{ |
| 558 |
Graphemescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Character#Grapheme.: "▄", |
| 559 |
Widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Character#Width.: 1, |
| 560 |
}, |
| 561 |
Stylescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#Style.: Stylescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Style#{ |
| 562 |
Foregroundscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Style#Foreground.: RGBColorscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/RGBColor().(br, bg, bb), |
| 563 |
}, |
| 564 |
} |
| 565 |
case ba < transparentEnoughscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/transparentEnough.: |
| 566 |
// Bottom is transparent. Use an upper block |
| 567 |
hb.cellsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#cells.[i] = Cellscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#{ |
| 568 |
Characterscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#Character.: Characterscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Character#{ |
| 569 |
Graphemescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Character#Grapheme.: "▀", |
| 570 |
Widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Character#Width.: 1, |
| 571 |
}, |
| 572 |
Stylescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#Style.: Stylescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Style#{ |
| 573 |
Foregroundscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Style#Foreground.: RGBColorscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/RGBColor().(tr, tg, tb), |
| 574 |
}, |
| 575 |
} |
| 576 |
default: |
| 577 |
// Neither is transparent. Use an upper block |
| 578 |
hb.cellsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#cells.[i] = Cellscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#{ |
| 579 |
Characterscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#Character.: Characterscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Character#{ |
| 580 |
Graphemescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Character#Grapheme.: "▀", |
| 581 |
Widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Character#Width.: 1, |
| 582 |
}, |
| 583 |
Stylescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#Style.: Stylescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Style#{ |
| 584 |
Foregroundscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Style#Foreground.: RGBColorscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/RGBColor().(tr, tg, tb), |
| 585 |
Backgroundscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Style#Background.: RGBColorscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/RGBColor().(br, bg, bb), |
| 586 |
}, |
| 587 |
} |
| 588 |
} |
| 589 |
} |
| 590 |
} |
| 591 |
|
| 592 |
func (hb *HalfBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#) Destroyscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#Destroy().() { |
| 593 |
hb.cellsscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#cells. = []Cellscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/Cell#{} |
| 594 |
} |
| 595 |
|
| 596 |
func (hb *HalfBlockImagescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#) CellSizescip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#CellSize().() (int, int) { |
| 597 |
return hb.widthscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#width., hb.heightscip-go gomod git.sr.ht/~rockorager/vaxis . `git.sr.ht/~rockorager/vaxis`/HalfBlockImage#height. |
| 598 |
} |