-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrgba.go
52 lines (46 loc) · 891 Bytes
/
rgba.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
package altv
// #include "capi.h"
import "C"
import (
"github.com/goccy/go-json"
"github.com/timo972/altv-go/mvalue"
)
type RGBA struct {
json.Marshaler
R uint8 `json:"r"`
G uint8 `json:"g"`
B uint8 `json:"b"`
A uint8 `json:"a"`
}
type rgbaData struct {
mvalue.SpecialType
R uint8 `json:"r"`
G uint8 `json:"g"`
B uint8 `json:"b"`
A uint8 `json:"a"`
}
func (c RGBA) MarshalJSON() ([]byte, error) {
return json.Marshal(rgbaData{
SpecialType: mvalue.SpecialType{Type: mvalue.TypeRGBA},
R: c.R,
G: c.G,
B: c.B,
A: c.A,
})
}
func newRGBA(cRGBA C.struct_rgba) RGBA {
return RGBA{
R: uint8(cRGBA.r),
G: uint8(cRGBA.g),
B: uint8(cRGBA.b),
A: uint8(cRGBA.a),
}
}
func newCRGBA(rgba RGBA) C.struct_rgba {
return C.struct_rgba{
r: C.uchar(rgba.R),
g: C.uchar(rgba.G),
b: C.uchar(rgba.B),
a: C.uchar(rgba.A),
}
}