This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
tomo-old/artist/uniform.go

69 lines
1.8 KiB
Go
Raw Normal View History

2023-01-08 23:03:19 -07:00
package artist
import "image"
import "image/color"
// 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
// 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
}
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) {
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
}