always read images as NRGBA

This commit is contained in:
Norwin Roosen 2020-12-31 17:42:53 +01:00
parent 93473eba8f
commit f191386a75
No known key found for this signature in database
GPG Key ID: 24BC059DE24C43A3
3 changed files with 6 additions and 7 deletions

View File

@ -64,11 +64,10 @@ func taskFromFlags(stop chan bool, wg *sync.WaitGroup) {
var img *image.NRGBA var img *image.NRGBA
if *imgPath != "" { if *imgPath != "" {
imgTmp, err := render.ReadImage(*imgPath) var err error
if err != nil { if img, err = render.ReadImage(*imgPath); err != nil {
log.Fatal(err) log.Fatal(err)
} }
img = render.ImgToNRGBA(imgTmp)
} }
r.SetTask(img, image.Pt(*x, *y), *address, *connections) r.SetTask(img, image.Pt(*x, *y), *address, *connections)

View File

@ -11,7 +11,7 @@ import (
"golang.org/x/image/draw" "golang.org/x/image/draw"
) )
func ReadImage(path string) (image.Image, error) { func ReadImage(path string) (*image.NRGBA, error) {
reader, err := os.Open(path) reader, err := os.Open(path)
if err != nil { if err != nil {
return nil, err return nil, err
@ -20,7 +20,7 @@ func ReadImage(path string) (image.Image, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return img, nil return imgToNRGBA(img), nil
} }
func WriteImage(path string, img image.Image) error { func WriteImage(path string, img image.Image) error {
@ -35,7 +35,7 @@ func WriteImage(path string, img image.Image) error {
return nil return nil
} }
func ImgToNRGBA(img image.Image) *image.NRGBA { func imgToNRGBA(img image.Image) *image.NRGBA {
b := img.Bounds() b := img.Bounds()
r := image.NewNRGBA(b) r := image.NewNRGBA(b)
for x := b.Min.X; x < b.Max.X; x++ { for x := b.Min.X; x < b.Max.X; x++ {

View File

@ -123,7 +123,7 @@ func RunREPL(f Fluter) {
if img, err := render.ReadImage(path); err != nil { if img, err := render.ReadImage(path); err != nil {
fmt.Println(err) fmt.Println(err)
} else { } else {
t.Img = render.ImgToNRGBA(img) t.Img = img
} }
} }