names.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2010 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package image
  5. import (
  6. "image/color"
  7. )
  8. var (
  9. // Black is an opaque black uniform image.
  10. Black = NewUniform(color.Black)
  11. // White is an opaque white uniform image.
  12. White = NewUniform(color.White)
  13. // Transparent is a fully transparent uniform image.
  14. Transparent = NewUniform(color.Transparent)
  15. // Opaque is a fully opaque uniform image.
  16. Opaque = NewUniform(color.Opaque)
  17. )
  18. // Uniform is an infinite-sized Image of uniform color.
  19. // It implements the color.Color, color.Model, and Image interfaces.
  20. type Uniform struct {
  21. C color.Color
  22. }
  23. func (c *Uniform) RGBA() (r, g, b, a uint32) {
  24. return c.C.RGBA()
  25. }
  26. func (c *Uniform) ColorModel() color.Model {
  27. return c
  28. }
  29. func (c *Uniform) Convert(color.Color) color.Color {
  30. return c.C
  31. }
  32. func (c *Uniform) Bounds() Rectangle { return Rectangle{Point{-1e9, -1e9}, Point{1e9, 1e9}} }
  33. func (c *Uniform) At(x, y int) color.Color { return c.C }
  34. // Opaque scans the entire image and reports whether it is fully opaque.
  35. func (c *Uniform) Opaque() bool {
  36. _, _, _, a := c.C.RGBA()
  37. return a == 0xffff
  38. }
  39. func NewUniform(c color.Color) *Uniform {
  40. return &Uniform{c}
  41. }