-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolimage.go
61 lines (40 loc) · 1.07 KB
/
colimage.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
59
60
package main
import "os"
import "image"
import "image/color"
import "image/png"
type colImage struct {
rect *image.Rectangle
img *image.NRGBA
f *os.File
}
func NewColImage(r image.Rectangle, fname string) *colImage {
if thef, err := os.Create(fname) ; err != nil {
return nil
} else {
theimg := image.NewNRGBA(r)
return &colImage{rect: &r, f: thef, img: theimg}
}
}
func (gimg colImage) Close() error {
return gimg.f.Close()
}
func (gimg colImage) Sync() error {
gimg.f.Seek(0,0)
png.Encode(gimg.f, gimg.img)
return gimg.f.Sync()
}
func (gimg colImage) Max() image.Point { return gimg.rect.Max }
func (gimg colImage) Min() image.Point { return gimg.rect.Min }
func (gimg colImage) Set(x,y, col int) {
r, g, b := uint8(0), uint8(0), uint8(0)
if col != 0 {
// this here defines the coloring of the picture
// currently quite daftly made. We probably should
// define a curve through rgb space.
r = uint8((7*col + 25) % 256 )
b = uint8((11*col + 50) % 256)
g = uint8((17*col + 75) % 256)
}
gimg.img.Set(x,y, color.NRGBA{r,g,b,255})
}