From 5f55530e3eb909e15d90d7ce920c92dfc5baf917 Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Thu, 31 Dec 2020 17:42:53 +0100 Subject: [PATCH] always read images as NRGBA --- main.go | 5 ++--- render/image.go | 6 +++--- rpc/repl.go | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 81b5785..2b2e103 100644 --- a/main.go +++ b/main.go @@ -64,11 +64,10 @@ func taskFromFlags(stop chan bool, wg *sync.WaitGroup) { var img *image.NRGBA if *imgPath != "" { - imgTmp, err := render.ReadImage(*imgPath) - if err != nil { + var err error + if img, err = render.ReadImage(*imgPath); err != nil { log.Fatal(err) } - img = render.ImgToNRGBA(imgTmp) } r.SetTask(img, image.Pt(*x, *y), *address, *connections) diff --git a/render/image.go b/render/image.go index b3782f7..1e9605a 100644 --- a/render/image.go +++ b/render/image.go @@ -11,7 +11,7 @@ import ( "golang.org/x/image/draw" ) -func ReadImage(path string) (image.Image, error) { +func ReadImage(path string) (*image.NRGBA, error) { reader, err := os.Open(path) if err != nil { return nil, err @@ -20,7 +20,7 @@ func ReadImage(path string) (image.Image, error) { if err != nil { return nil, err } - return img, nil + return imgToNRGBA(img), nil } func WriteImage(path string, img image.Image) error { @@ -35,7 +35,7 @@ func WriteImage(path string, img image.Image) error { return nil } -func ImgToNRGBA(img image.Image) *image.NRGBA { +func imgToNRGBA(img image.Image) *image.NRGBA { b := img.Bounds() r := image.NewNRGBA(b) for x := b.Min.X; x < b.Max.X; x++ { diff --git a/rpc/repl.go b/rpc/repl.go index 656cfd0..4377d08 100644 --- a/rpc/repl.go +++ b/rpc/repl.go @@ -123,7 +123,7 @@ func RunREPL(f Fluter) { if img, err := render.ReadImage(path); err != nil { fmt.Println(err) } else { - t.Img = render.ImgToNRGBA(img) + t.Img = img } }