if dst0, ok := dst.(*image.RGBA); ok {
if op == Over {
if mask == nil {
- if src0, ok := src.(image.ColorImage); ok {
+ if src0, ok := src.(*image.ColorImage); ok {
drawFillOver(dst0, r, src0)
return
}
return
}
} else if mask0, ok := mask.(*image.Alpha); ok {
- if src0, ok := src.(image.ColorImage); ok {
+ if src0, ok := src.(*image.ColorImage); ok {
drawGlyphOver(dst0, r, src0, mask0, mp)
return
}
}
} else {
if mask == nil {
- if src0, ok := src.(image.ColorImage); ok {
+ if src0, ok := src.(*image.ColorImage); ok {
drawFillSrc(dst0, r, src0)
return
}
}
}
-func drawFillOver(dst *image.RGBA, r image.Rectangle, src image.ColorImage) {
+func drawFillOver(dst *image.RGBA, r image.Rectangle, src *image.ColorImage) {
cr, cg, cb, ca := src.RGBA()
// The 0x101 is here for the same reason as in drawRGBA.
a := (m - ca) * 0x101
}
}
-func drawGlyphOver(dst *image.RGBA, r image.Rectangle, src image.ColorImage, mask *image.Alpha, mp image.Point) {
+func drawGlyphOver(dst *image.RGBA, r image.Rectangle, src *image.ColorImage, mask *image.Alpha, mp image.Point) {
x0, x1 := r.Min.X, r.Max.X
y0, y1 := r.Min.Y, r.Max.Y
cr, cg, cb, ca := src.RGBA()
}
}
-func drawFillSrc(dst *image.RGBA, r image.Rectangle, src image.ColorImage) {
+func drawFillSrc(dst *image.RGBA, r image.Rectangle, src *image.ColorImage) {
if r.Dy() < 1 {
return
}
return Point{p.X / k, p.Y / k}
}
+// Mod returns the point q in r such that p.X-q.X is a multiple of r's width
+// and p.Y-q.Y is a multiple of r's height.
+func (p Point) Mod(r Rectangle) Point {
+ w, h := r.Dx(), r.Dy()
+ p = p.Sub(r.Min)
+ if p.X >= 0 {
+ p.X = p.X % w
+ } else {
+ p.X = w - 1 - (-1-p.X)%w
+ }
+ if p.Y >= 0 {
+ p.Y = p.Y % h
+ } else {
+ p.Y = h - 1 - (-1-p.Y)%h
+ }
+ return p.Add(r.Min)
+}
+
// Eq returns whether p and q are equal.
func (p Point) Eq(q Point) bool {
return p.X == q.X && p.Y == q.Y
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) Bounds() Rectangle { return Rectangle{Point{-1e9, -1e9}, Point{1e9, 1e9}} }
+func (c *ColorImage) Bounds() Rectangle { return Rectangle{Point{-1e9, -1e9}, Point{1e9, 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 a practically infinite-sized Image that repeats another Image in
+// both directions. Tiled{i}.At(x, y) will equal i.At(x, y) for all points
+// within i's Bounds.
+type Tiled struct {
+ I Image
+}
+
+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}.Mod(t.I.Bounds())
+ return t.I.At(p.X, p.Y)
+}
+
+func NewTiled(i Image) *Tiled {
+ return &Tiled{i}
+}