]> Cypherpunks repositories - gostls13.git/commitdiff
image: add a test for filling sub-images.
authorNigel Tao <nigeltao@golang.org>
Tue, 5 Jul 2011 04:42:31 +0000 (14:42 +1000)
committerNigel Tao <nigeltao@golang.org>
Tue, 5 Jul 2011 04:42:31 +0000 (14:42 +1000)
R=r
CC=golang-dev
https://golang.org/cl/4626091

src/pkg/image/draw/draw_test.go

index 6db567231e4f6a1e27bafe8ce64cfdef2cc70c26..edbf7b27abd3dd29c84a62ce79facfbc6591b282 100644 (file)
@@ -276,3 +276,63 @@ func TestNonZeroSrcPt(t *testing.T) {
                t.Errorf("non-zero src pt: want %v got %v", image.RGBAColor{5, 0, 0, 5}, a.At(0, 0))
        }
 }
+
+func TestFill(t *testing.T) {
+       rr := []image.Rectangle{
+               image.Rect(0, 0, 0, 0),
+               image.Rect(0, 0, 40, 30),
+               image.Rect(10, 0, 40, 30),
+               image.Rect(0, 20, 40, 30),
+               image.Rect(10, 20, 40, 30),
+               image.Rect(10, 20, 15, 25),
+               image.Rect(10, 0, 35, 30),
+               image.Rect(0, 15, 40, 16),
+               image.Rect(24, 24, 25, 25),
+               image.Rect(23, 23, 26, 26),
+               image.Rect(22, 22, 27, 27),
+               image.Rect(21, 21, 28, 28),
+               image.Rect(20, 20, 29, 29),
+       }
+       for _, r := range rr {
+               m := image.NewRGBA(40, 30).SubImage(r).(*image.RGBA)
+               b := m.Bounds()
+               c := image.RGBAColor{11, 0, 0, 255}
+               src := &image.ColorImage{c}
+               check := func(desc string) {
+                       for y := b.Min.Y; y < b.Max.Y; y++ {
+                               for x := b.Min.X; x < b.Max.X; x++ {
+                                       if !eq(c, m.At(x, y)) {
+                                               t.Errorf("%s fill: at (%d, %d), sub-image bounds=%v: want %v got %v", desc, x, y, r, c, m.At(x, y))
+                                               return
+                                       }
+                               }
+                       }
+               }
+               // Draw 1 pixel at a time.
+               for y := b.Min.Y; y < b.Max.Y; y++ {
+                       for x := b.Min.X; x < b.Max.X; x++ {
+                               DrawMask(m, image.Rect(x, y, x+1, y+1), src, image.ZP, nil, image.ZP, Src)
+                       }
+               }
+               check("pixel")
+               // Draw 1 row at a time.
+               c = image.RGBAColor{0, 22, 0, 255}
+               src = &image.ColorImage{c}
+               for y := b.Min.Y; y < b.Max.Y; y++ {
+                       DrawMask(m, image.Rect(b.Min.X, y, b.Max.X, y+1), src, image.ZP, nil, image.ZP, Src)
+               }
+               check("row")
+               // Draw 1 column at a time.
+               c = image.RGBAColor{0, 0, 33, 255}
+               src = &image.ColorImage{c}
+               for x := b.Min.X; x < b.Max.X; x++ {
+                       DrawMask(m, image.Rect(x, b.Min.Y, x+1, b.Max.Y), src, image.ZP, nil, image.ZP, Src)
+               }
+               check("column")
+               // Draw the whole image at once.
+               c = image.RGBAColor{44, 55, 66, 77}
+               src = &image.ColorImage{c}
+               DrawMask(m, b, src, image.ZP, nil, image.ZP, Src)
+               check("whole")
+       }
+}