2018-11-21 13:35:14 +00:00
|
|
|
package allg5
|
2017-10-03 18:38:09 +00:00
|
|
|
|
|
|
|
// #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
|
|
|
}
|
|
|
|
|
2019-03-13 18:49:00 +00:00
|
|
|
func NewColorGo(c color.Color) Color {
|
|
|
|
r, g, b, a := c.RGBA()
|
|
|
|
return Color{C.al_premul_rgba(C.uchar(r>>8), C.uchar(g>>8), C.uchar(b>>8), C.uchar(a>>8))}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|