zntg/allg5/color.go

32 lines
642 B
Go

package allg5
// #include <allegro5/allegro.h>
import "C"
import "image/color"
var _ color.Color = &Color{}
type Color struct {
color C.ALLEGRO_COLOR
}
func NewColor(r, g, b byte) Color {
return Color{C.al_map_rgb(C.uchar(r), C.uchar(g), C.uchar(b))}
}
func NewColorAlpha(r, g, b, a byte) Color {
return Color{C.al_map_rgba(C.uchar(r), C.uchar(g), C.uchar(b), C.uchar(a))}
}
// RGBA implements the color.Color interface.
func (c Color) RGBA() (r, g, b, a uint32) {
var cr, cg, cb, ca C.uchar
C.al_unmap_rgba(c.color, &cr, &cg, &cb, &ca)
a = uint32(ca)
r = uint32(cr) * a
g = uint32(cg) * a
b = uint32(cb) * a
a *= a
return
}