2017-10-03 18:38:09 +00:00
|
|
|
package allegro5
|
|
|
|
|
|
|
|
// #include <allegro5/allegro.h>
|
|
|
|
import "C"
|
2018-08-07 04:59:52 +00:00
|
|
|
import "image/color"
|
|
|
|
|
|
|
|
var _ color.Color = &Color{}
|
2017-10-03 18:38:09 +00:00
|
|
|
|
|
|
|
type Color struct {
|
2018-08-07 04:59:52 +00:00
|
|
|
color C.ALLEGRO_COLOR
|
2017-10-03 18:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewColor(r, g, b byte) Color {
|
2018-08-07 04:59:52 +00:00
|
|
|
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))}
|
2017-10-03 18:38:09 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 04:59:52 +00:00
|
|
|
// 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
|
|
|
|
}
|