always read images as NRGBA

This commit is contained in:
Norwin Roosen 2020-12-31 17:42:53 +01:00
parent 997fbe0d2a
commit 5f55530e3e
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
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)

View File

@ -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++ {

View File

@ -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
}
}