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

56 lines
1.5 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 image 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-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
}