-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathframe.go
66 lines (56 loc) · 1.4 KB
/
frame.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
61
62
63
64
65
66
package pixoo64
import (
"encoding/base64"
"image"
"image/color"
"strconv"
)
type Frame struct {
client *Client
id int
rgba *image.RGBA
speed int
}
func (f *Frame) Id() int {
return f.id
}
func (f *Frame) Rgba() *image.RGBA {
return f.rgba
}
func (f *Frame) Speed() int {
return f.speed
}
func (f *Frame) SetSpeed(speed int) {
f.speed = speed
}
func (f *Frame) Fill(color color.Color) {
for y := 0; y < f.rgba.Rect.Size().Y; y++ {
for x := 0; x < f.rgba.Rect.Size().X; x++ {
f.rgba.Set(x, y, color)
}
}
}
func (f *Frame) Update(pictureId int, frameCount int) error {
count := 0
raw := make([]byte, f.rgba.Rect.Size().X*f.rgba.Rect.Size().Y*3)
for y := 0; y < f.rgba.Rect.Size().Y; y++ {
for x := 0; x < f.rgba.Rect.Size().X; x++ {
raw[count*3] = f.rgba.RGBAAt(x, y).R
raw[count*3+1] = f.rgba.RGBAAt(x, y).G
raw[count*3+2] = f.rgba.RGBAAt(x, y).B
count++
}
}
base64 := base64.StdEncoding.EncodeToString(raw)
var jsonData = []byte(`{
"Command": "Draw/SendHttpGif",
"PicNum": ` + strconv.FormatInt(int64(frameCount), 10) + `,
"PicWidth": ` + strconv.FormatInt(int64(Width), 10) + `,
"PicOffset": ` + strconv.FormatInt(int64(f.id), 10) + `,
"PicID": ` + strconv.FormatInt(int64(pictureId), 10) + `,
"PicSpeed": ` + strconv.FormatInt(int64(f.speed), 10) + `,
"PicData": "` + base64 + `"
}`)
_, err := f.client.Post(jsonData)
return err
}