1
2
3
4
5 package image
6
7 var (
8
9 Black = NewColorImage(Gray16Color{0})
10
11 White = NewColorImage(Gray16Color{0xffff})
12
13 Transparent = NewColorImage(Alpha16Color{0})
14
15 Opaque = NewColorImage(Alpha16Color{0xffff})
16 )
17
18
19
20 type ColorImage struct {
21 C Color
22 }
23
24 func (c *ColorImage) RGBA() (r, g, b, a uint32) {
25 return c.C.RGBA()
26 }
27
28 func (c *ColorImage) ColorModel() ColorModel {
29 return ColorModelFunc(func(Color) Color { return c.C })
30 }
31
32 func (c *ColorImage) Bounds() Rectangle { return Rectangle{Point{-1e9, -1e9}, Point{1e9, 1e9}} }
33
34 func (c *ColorImage) At(x, y int) Color { return c.C }
35
36
37 func (c *ColorImage) Opaque() bool {
38 _, _, _, a := c.C.RGBA()
39 return a == 0xffff
40 }
41
42 func NewColorImage(c Color) *ColorImage {
43 return &ColorImage{c}
44 }
45
46
47
48
49 type Tiled struct {
50 I Image
51 Offset Point
52 }
53
54 func (t *Tiled) ColorModel() ColorModel {
55 return t.I.ColorModel()
56 }
57
58 func (t *Tiled) Bounds() Rectangle { return Rectangle{Point{-1e9, -1e9}, Point{1e9, 1e9}} }
59
60 func (t *Tiled) At(x, y int) Color {
61 p := Point{x, y}.Add(t.Offset).Mod(t.I.Bounds())
62 return t.I.At(p.X, p.Y)
63 }
64
65 func NewTiled(i Image, offset Point) *Tiled {
66 return &Tiled{i, offset}
67 }