-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.go
58 lines (48 loc) · 984 Bytes
/
files.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"image"
"log"
"os"
)
func readImageFromFilePath(path string) image.Image {
// Load GB ROM
infile, err := os.Open(path)
if err != nil {
// replace this with real error handling
log.Fatal(err)
}
defer func(infile *os.File) {
err := infile.Close()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}(infile)
// Decode the image
imData, imType, err := image.Decode(infile)
if err != nil {
fmt.Println(err)
}
// Make sure it's a PNG
if imType != "png" {
fmt.Println("Not a PNG")
}
return imData
}
func saveUniqueTiles(tiles []image.Image, tilesPerRow int, numRows int, filename string) ([]image.Image, error) {
uniqueTiles := []image.Image{}
for _, tile := range tiles {
isUnique := true
for j := 0; j < len(uniqueTiles); j++ {
if areImagesEquivalent(tile, uniqueTiles[j]) {
isUnique = false
break
}
}
if isUnique {
uniqueTiles = append(uniqueTiles, tile)
}
}
return uniqueTiles, nil
}