2010-12-03 05:34:57 +01:00
|
|
|
// Copyright 2010 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package image
|
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
import (
|
|
|
|
"image/color"
|
|
|
|
)
|
|
|
|
|
2010-12-03 05:34:57 +01:00
|
|
|
var (
|
2011-10-27 01:57:58 +02:00
|
|
|
// Black is an opaque black uniform image.
|
|
|
|
Black = NewUniform(color.Black)
|
|
|
|
// White is an opaque white uniform image.
|
|
|
|
White = NewUniform(color.White)
|
|
|
|
// Transparent is a fully transparent uniform image.
|
|
|
|
Transparent = NewUniform(color.Transparent)
|
|
|
|
// Opaque is a fully opaque uniform image.
|
|
|
|
Opaque = NewUniform(color.Opaque)
|
2010-12-03 05:34:57 +01:00
|
|
|
)
|
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
// Uniform is an infinite-sized Image of uniform color.
|
2012-10-03 07:27:36 +02:00
|
|
|
// It implements the color.Color, color.Model, and Image interfaces.
|
2011-10-27 01:57:58 +02:00
|
|
|
type Uniform struct {
|
|
|
|
C color.Color
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
func (c *Uniform) RGBA() (r, g, b, a uint32) {
|
2010-12-03 05:34:57 +01:00
|
|
|
return c.C.RGBA()
|
|
|
|
}
|
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
func (c *Uniform) ColorModel() color.Model {
|
2011-12-14 16:41:54 +01:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Uniform) Convert(color.Color) color.Color {
|
|
|
|
return c.C
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
func (c *Uniform) Bounds() Rectangle { return Rectangle{Point{-1e9, -1e9}, Point{1e9, 1e9}} }
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
func (c *Uniform) At(x, y int) color.Color { return c.C }
|
2010-12-03 05:34:57 +01:00
|
|
|
|
|
|
|
// Opaque scans the entire image and returns whether or not it is fully opaque.
|
2011-10-27 01:57:58 +02:00
|
|
|
func (c *Uniform) Opaque() bool {
|
2010-12-03 05:34:57 +01:00
|
|
|
_, _, _, a := c.C.RGBA()
|
|
|
|
return a == 0xffff
|
|
|
|
}
|
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
func NewUniform(c color.Color) *Uniform {
|
|
|
|
return &Uniform{c}
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|