-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmount.go
More file actions
61 lines (50 loc) · 1.38 KB
/
mount.go
File metadata and controls
61 lines (50 loc) · 1.38 KB
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
59
60
61
package packer
import (
"sort"
"image"
)
//MountPoints[0xFFFFFF]
type MountFrames struct {
Frames map[string]MountData
}
type MountData struct {
Filename string
MountPoints map[uint32]image.Point
}
func CalculateMountPoints(images []ImageData) MountFrames {
// Sort images by their filename, so that there is some sort of determinism on input of files
// TODO - this might be automatic, but I haven't tested it cross platform. Maybe check docs
sort.Slice(images, func(i, j int) bool {
return images[i].filename < images[j].filename
})
frames := MountFrames{
Frames: make(map[string]MountData),
}
//'#00ff00'
for _, img := range images {
data := MountData{
Filename: img.filename,
MountPoints: make(map[uint32]image.Point),
}
bounds := img.img.Bounds()
for x := bounds.Min.X; x < bounds.Max.X; x++ {
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
color := img.img.At(x, y)
r, g, b, a := color.RGBA()
if a == 0 {continue } // Skip if the pixel is transparent
// fmt.Println("Found one:")
// fmt.Printf("#%x%x%x\n", r, g, b)
// fmt.Println(r, g, b, a)
// fmt.Println(color)
colorKey := ((r>>8) << 16) | ((g>>8) << 8) | ((b>>8) << 4)
// fmt.Printf("%x\n", colKey)
data.MountPoints[colorKey] = image.Point{
(bounds.Dx()/2) - x,
(bounds.Dy()/2) - y,
}
}
frames.Frames[data.Filename] = data
}
}
return frames
}