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.
|
2011-12-14 16:41:54 +01:00
|
|
|
// It implements the color.Color, color.ColorModel, 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
|
|
|
}
|
|
|
|
|
|
|
|
// A Tiled is an infinite-sized Image that repeats another Image in both
|
|
|
|
// directions. Tiled{i, p}.At(x, y) will equal i.At(x+p.X, y+p.Y) for all
|
|
|
|
// points {x+p.X, y+p.Y} within i's Bounds.
|
|
|
|
type Tiled struct {
|
|
|
|
I Image
|
|
|
|
Offset Point
|
|
|
|
}
|
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
func (t *Tiled) ColorModel() color.Model {
|
2010-12-03 05:34:57 +01:00
|
|
|
return t.I.ColorModel()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Tiled) Bounds() Rectangle { return Rectangle{Point{-1e9, -1e9}, Point{1e9, 1e9}} }
|
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
func (t *Tiled) At(x, y int) color.Color {
|
2010-12-03 05:34:57 +01:00
|
|
|
p := Point{x, y}.Add(t.Offset).Mod(t.I.Bounds())
|
|
|
|
return t.I.At(p.X, p.Y)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTiled(i Image, offset Point) *Tiled {
|
|
|
|
return &Tiled{i, offset}
|
|
|
|
}
|