You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
858 B

package main
import (
"os"
"image"
_ "image/jpeg"
_ "image/gif"
_ "image/png"
log "github.com/sirupsen/logrus"
)
func getImage(path string) [][][4]uint32 {
reader, err := os.Open(path)
if err != nil {
log.Fatalf("Could not load image: %s",err)
}
defer reader.Close()
m, _, err := image.Decode(reader)
if err != nil {
log.Fatal("could not find image in file", err)
}
bounds := m.Bounds()
var pixelmatrix [][][4]uint32
for x := bounds.Min.X; x < bounds.Max.X; x++ {
var xRow [][4]uint32
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
var pixel [4]uint32
pixel[0], pixel[1], pixel[2], pixel[3] = m.At(x, y).RGBA()
pixel[0] = pixel[0] >>8
pixel[1] = pixel[1] >>8
pixel[2] = pixel[2] >>8
pixel[3] = pixel[3] >>8
xRow = append(xRow, pixel)
}
pixelmatrix = append(pixelmatrix, xRow)
}
return pixelmatrix
}