ToolKit: transform function

pull/3/head
Máximo Cuadros 8 years ago
parent 53fa87a5d3
commit 8b18dc26f8

@ -5,6 +5,7 @@ import (
"os"
"time"
"github.com/disintegration/imaging"
"github.com/mcuadros/go-rpi-rgb-led-matrix"
)
@ -13,6 +14,7 @@ var (
chain = flag.Int("led-chain", 2, "number of displays daisy-chained")
brightness = flag.Int("brightness", 100, "brightness (0-100)")
image = flag.String("image", "", "image path")
rotate = flag.Int("rotate", 0, "rotate angle, 90, 180, 270")
)
func main() {
@ -30,6 +32,15 @@ func main() {
tk := rgbmatrix.NewToolKit(m)
defer tk.Close()
switch *rotate {
case 90:
tk.Transform = imaging.Rotate90
case 180:
tk.Transform = imaging.Rotate180
case 270:
tk.Transform = imaging.Rotate270
}
close, err := tk.PlayGIF(f)
fatal(err)

@ -9,13 +9,24 @@ import (
)
type ToolKit struct {
Canvas *Canvas
Canvas *Canvas
Transform func(img image.Image) *image.NRGBA
}
func NewToolKit(m Matrix) *ToolKit {
return &ToolKit{
Canvas: NewCanvas(m),
}
}
func (tk *ToolKit) PlayImage(i image.Image, delay time.Duration) error {
start := time.Now()
defer func() { time.Sleep(delay - time.Since(start)) }()
if tk.Transform != nil {
i = tk.Transform(i)
}
draw.Draw(tk.Canvas, tk.Canvas.Bounds(), i, image.ZP, draw.Over)
return tk.Canvas.Render()
}
@ -64,3 +75,7 @@ func (tk *ToolKit) PlayGIF(r io.Reader) (chan bool, error) {
return tk.PlayImages(images, delay, gif.LoopCount), nil
}
func (tk *ToolKit) Close() error {
return tk.Canvas.Close()
}

Loading…
Cancel
Save