Checkpoint

This commit is contained in:
maze authored and maze committed 2026-10-29 17:29:54 +01:00
1 parent c5d6137fab
commit 4ae7655cd8
223 files changed
+14770 -18352

No files matched your search

+50
View File
@@ -1,11 +1,18 @@
package app
import (
"bytes"
"image"
"image/color"
"image/draw"
"github.com/sirupsen/logrus"
"github.com/BeatGlow/display/pixel"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
)
// BufferFor creates a new image buffer for the provided display matching its color model.
@@ -32,11 +39,13 @@ type clearer interface {
// ImageCopy copies an image over dst.
func ImageCopy(dst draw.Image, src image.Image) {
logrus.Tracef("image copy %s -> %s", src.Bounds(), dst.Bounds())
draw.Draw(dst, dst.Bounds(), src, image.Point{}, draw.Src)
}
// ImageCopyBounds copies an image over dst bounded by r.
func ImageCopyBounds(dst draw.Image, src image.Image, r image.Rectangle) {
logrus.Tracef("image copy %s -> %s (of %s)", src.Bounds(), r, dst.Bounds())
draw.Draw(dst, r, src, image.Point{}, draw.Src)
}
@@ -74,3 +83,44 @@ func ImageFill(dst draw.Image, c color.Color) {
draw.Draw(dst, dst.Bounds(), src, image.Point{}, draw.Src)
}
// MustDecodeImage can decode JPEG, GIF and PNG images.
func MustDecodeImage(b []byte) image.Image {
i, _, err := image.Decode(bytes.NewBuffer(b))
if err != nil {
panic(err)
}
return i
}
type HorizontalWrappingImage struct {
image.Image
Gap int
}
func (i HorizontalWrappingImage) At(x, y int) color.Color {
var (
bounds = i.Image.Bounds()
dx = (bounds.Max.X - bounds.Min.X)
ox = x
oy = y
)
for ox < bounds.Min.X {
ox += dx
}
for ox >= bounds.Max.X {
ox -= dx
}
return i.Image.At(ox, oy)
}
func (i HorizontalWrappingImage) Bounds() image.Rectangle {
var (
bounds = i.Image.Bounds()
delta = image.Point{X: (bounds.Max.X - bounds.Min.X) + i.Gap}
)
return image.Rectangle{
Min: bounds.Min.Sub(delta),
Max: bounds.Max.Add(delta),
}
}