2023-01-08 23:03:19 -07:00
|
|
|
package artist
|
|
|
|
|
|
|
|
import "image"
|
|
|
|
import "image/color"
|
|
|
|
|
2023-01-13 23:54:57 -07:00
|
|
|
// Uniform is an infinite-sized pattern of uniform color. It implements the
|
2023-01-14 10:41:51 -07:00
|
|
|
// Pattern, color.Color, color.Model, and image.Image interfaces.
|
|
|
|
type Uniform color.RGBA
|
2023-01-08 23:03:19 -07:00
|
|
|
|
2023-02-19 23:52:50 -07:00
|
|
|
// NewUniform returns a new Uniform pattern of the given color.
|
2023-01-14 10:41:51 -07:00
|
|
|
func NewUniform (c color.Color) (uniform Uniform) {
|
2023-01-08 23:03:19 -07:00
|
|
|
r, g, b, a := c.RGBA()
|
2023-01-14 10:41:51 -07:00
|
|
|
uniform.R = uint8(r >> 8)
|
|
|
|
uniform.G = uint8(g >> 8)
|
|
|
|
uniform.B = uint8(b >> 8)
|
|
|
|
uniform.A = uint8(a >> 8)
|
2023-01-08 23:03:19 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-19 23:52:50 -07:00
|
|
|
func hex (color uint32) (c color.RGBA) {
|
|
|
|
c.A = uint8(color)
|
|
|
|
c.B = uint8(color >> 8)
|
|
|
|
c.G = uint8(color >> 16)
|
|
|
|
c.R = uint8(color >> 24)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Uhex creates a new Uniform pattern from an RGBA integer value.
|
|
|
|
func Uhex (color uint32) (uniform Uniform) {
|
|
|
|
return NewUniform(hex(color))
|
|
|
|
}
|
|
|
|
|
2023-01-14 10:41:51 -07:00
|
|
|
// ColorModel satisfies the image.Image interface.
|
|
|
|
func (uniform Uniform) ColorModel () (model color.Model) {
|
2023-01-13 23:54:57 -07:00
|
|
|
return uniform
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
|
|
|
|
2023-01-14 10:41:51 -07:00
|
|
|
// Convert satisfies the color.Model interface.
|
|
|
|
func (uniform Uniform) Convert (in color.Color) (c color.Color) {
|
|
|
|
return color.RGBA(uniform)
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
|
|
|
|
2023-01-14 10:41:51 -07:00
|
|
|
// Bounds satisfies the image.Image interface.
|
|
|
|
func (uniform Uniform) Bounds () (rectangle image.Rectangle) {
|
2023-01-08 23:03:19 -07:00
|
|
|
rectangle.Min = image.Point { -1e9, -1e9 }
|
|
|
|
rectangle.Max = image.Point { 1e9, 1e9 }
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-01-14 10:41:51 -07:00
|
|
|
// At satisfies the image.Image interface.
|
|
|
|
func (uniform Uniform) At (x, y int) (c color.Color) {
|
|
|
|
return color.RGBA(uniform)
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
|
|
|
|
2023-01-14 10:41:51 -07:00
|
|
|
// AtWhen satisfies the Pattern interface.
|
|
|
|
func (uniform Uniform) AtWhen (x, y, width, height int) (c color.RGBA) {
|
|
|
|
return color.RGBA(uniform)
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
|
|
|
|
2023-01-14 10:41:51 -07:00
|
|
|
// RGBA satisfies the color.Color interface.
|
|
|
|
func (uniform Uniform) RGBA () (r, g, b, a uint32) {
|
|
|
|
return color.RGBA(uniform).RGBA()
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Opaque scans the entire image and reports whether it is fully opaque.
|
2023-01-14 10:41:51 -07:00
|
|
|
func (uniform Uniform) Opaque () (opaque bool) {
|
|
|
|
return uniform.A == 0xFF
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|