summaryrefslogtreecommitdiff
path: root/src/pkg/image/names.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/image/names.go')
-rw-r--r--src/pkg/image/names.go71
1 files changed, 41 insertions, 30 deletions
diff --git a/src/pkg/image/names.go b/src/pkg/image/names.go
index 0b621cff5..c309684ce 100644
--- a/src/pkg/image/names.go
+++ b/src/pkg/image/names.go
@@ -4,53 +4,64 @@
package image
-// Colors from the HTML 4.01 specification: http://www.w3.org/TR/REC-html40/types.html#h-6.5
-// These names do not necessarily match those from other lists, such as the X11 color names.
var (
- Aqua = ColorImage{RGBAColor{0x00, 0xff, 0xff, 0xff}}
- Black = ColorImage{RGBAColor{0x00, 0x00, 0x00, 0xff}}
- Blue = ColorImage{RGBAColor{0x00, 0x00, 0xff, 0xff}}
- Fuchsia = ColorImage{RGBAColor{0xff, 0x00, 0xff, 0xff}}
- Gray = ColorImage{RGBAColor{0x80, 0x80, 0x80, 0xff}}
- Green = ColorImage{RGBAColor{0x00, 0x80, 0x00, 0xff}}
- Lime = ColorImage{RGBAColor{0x00, 0xff, 0x00, 0xff}}
- Maroon = ColorImage{RGBAColor{0x80, 0x00, 0x00, 0xff}}
- Navy = ColorImage{RGBAColor{0x00, 0x00, 0x80, 0xff}}
- Olive = ColorImage{RGBAColor{0x80, 0x80, 0x00, 0xff}}
- Red = ColorImage{RGBAColor{0xff, 0x00, 0x00, 0xff}}
- Purple = ColorImage{RGBAColor{0x80, 0x00, 0x80, 0xff}}
- Silver = ColorImage{RGBAColor{0xc0, 0xc0, 0xc0, 0xff}}
- Teal = ColorImage{RGBAColor{0x00, 0x80, 0x80, 0xff}}
- White = ColorImage{RGBAColor{0xff, 0xff, 0xff, 0xff}}
- Yellow = ColorImage{RGBAColor{0xff, 0xff, 0x00, 0xff}}
-
- // These synonyms are not in HTML 4.01.
- Cyan = Aqua
- Magenta = Fuchsia
+ // Black is an opaque black ColorImage.
+ Black = NewColorImage(Gray16Color{0})
+ // White is an opaque white ColorImage.
+ White = NewColorImage(Gray16Color{0xffff})
+ // Transparent is a fully transparent ColorImage.
+ Transparent = NewColorImage(Alpha16Color{0})
+ // Opaque is a fully opaque ColorImage.
+ Opaque = NewColorImage(Alpha16Color{0xffff})
)
-// A ColorImage is a practically infinite-sized Image of uniform Color.
+// A ColorImage is an infinite-sized Image of uniform Color.
// It implements both the Color and Image interfaces.
type ColorImage struct {
C Color
}
-func (c ColorImage) RGBA() (r, g, b, a uint32) {
+func (c *ColorImage) RGBA() (r, g, b, a uint32) {
return c.C.RGBA()
}
-func (c ColorImage) ColorModel() ColorModel {
+func (c *ColorImage) ColorModel() ColorModel {
return ColorModelFunc(func(Color) Color { return c.C })
}
-func (c ColorImage) Width() int { return 1e9 }
+func (c *ColorImage) Bounds() Rectangle { return Rectangle{Point{-1e9, -1e9}, Point{1e9, 1e9}} }
-func (c ColorImage) Height() int { return 1e9 }
-
-func (c ColorImage) At(x, y int) Color { return c.C }
+func (c *ColorImage) At(x, y int) Color { return c.C }
// Opaque scans the entire image and returns whether or not it is fully opaque.
-func (c ColorImage) Opaque() bool {
+func (c *ColorImage) Opaque() bool {
_, _, _, a := c.C.RGBA()
return a == 0xffff
}
+
+func NewColorImage(c Color) *ColorImage {
+ return &ColorImage{c}
+}
+
+// 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
+}
+
+func (t *Tiled) ColorModel() ColorModel {
+ return t.I.ColorModel()
+}
+
+func (t *Tiled) Bounds() Rectangle { return Rectangle{Point{-1e9, -1e9}, Point{1e9, 1e9}} }
+
+func (t *Tiled) At(x, y int) Color {
+ 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}
+}