]> Cypherpunks repositories - gostls13.git/commitdiff
image/draw: rename and reorder some benchmarks
authorNigel Tao <nigeltao@golang.org>
Wed, 27 Oct 2021 03:24:37 +0000 (14:24 +1100)
committerNigel Tao <nigeltao@golang.org>
Sun, 31 Oct 2021 08:29:02 +0000 (08:29 +0000)
The intention is for BenchmarkFooBar functions to map 1:1 to drawFooBar
functions. Recent draw.go changes have added more drawFooBar functions
and have further modified the mapping, as fallback drawFooBar functions
aren't invoked as often as they used to.

This commit restores the 1:1 mapping and reorganizes the BenchmarkFooBar
functions in the same order as the matching drawFooBar functions appear.

Also modify a TestDraw test case from vgradGreen(255) = {0, 136, 0, 255}
to vgradGreen(90) = {0, 48, 0, 90}. Doing so matches the existing "The
source pixel is {0, 48, 0, 90}" comment but also makes for a more
interesting test case, as the source pixel is no longer fully opaque.
Fully opaque is already covered by the vgradGray() test case on the next
line.

Also fix a "variable source" comment copy-pasto when the source image is
actually uniform, not variable.

Also add a func DrawMask type switch comment about interface types.

Change-Id: I828e71f2ee8ec617f523c8aafb118fb7ba166876
Reviewed-on: https://go-review.googlesource.com/c/go/+/358974
Trust: Nigel Tao <nigeltao@golang.org>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Nigel Tao <nigeltao@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/image/draw/bench_test.go
src/image/draw/draw.go
src/image/draw/draw_test.go

index 2b7c6d6ac45645cb77a8e8fca6c10b77e5326a2d..55d25b85963f422794923b6c10450372d4918aba 100644 (file)
@@ -190,8 +190,7 @@ func bench(b *testing.B, dcm, scm, mcm color.Model, op Op) {
        }
 }
 
-// The BenchmarkFoo and BenchmarkFooN functions exercise a drawFoo fast-path
-// function in draw.go.
+// The BenchmarkFoo functions exercise a drawFoo fast-path function in draw.go.
 
 func BenchmarkFillOver(b *testing.B) {
        bench(b, color.RGBAModel, nil, nil, Over)
@@ -233,12 +232,20 @@ func BenchmarkGlyphOver(b *testing.B) {
        bench(b, color.RGBAModel, nil, color.AlphaModel, Over)
 }
 
-func BenchmarkRGBA1(b *testing.B) {
-       bench(b, color.RGBAModel, color.RGBA64Model, nil, Src)
+func BenchmarkRGBAMaskOver(b *testing.B) {
+       bench(b, color.RGBAModel, color.RGBAModel, color.AlphaModel, Over)
 }
 
-func BenchmarkRGBA2(b *testing.B) {
-       bench(b, color.RGBAModel, color.RGBAModel, color.AlphaModel, Over)
+func BenchmarkGrayMaskOver(b *testing.B) {
+       bench(b, color.RGBAModel, color.GrayModel, color.AlphaModel, Over)
+}
+
+func BenchmarkRGBA64ImageMaskOver(b *testing.B) {
+       bench(b, color.RGBAModel, color.RGBA64Model, color.AlphaModel, Over)
+}
+
+func BenchmarkRGBA(b *testing.B) {
+       bench(b, color.RGBAModel, color.RGBA64Model, nil, Src)
 }
 
 func BenchmarkPalettedFill(b *testing.B) {
@@ -266,11 +273,3 @@ func BenchmarkGenericSrc(b *testing.B) {
 func BenchmarkGenericMaskSrc(b *testing.B) {
        bench(b, color.RGBA64Model, color.RGBA64Model, color.AlphaModel, Src)
 }
-
-func BenchmarkRGBA64Over(b *testing.B) {
-       bench(b, color.RGBAModel, color.RGBA64Model, color.AlphaModel, Over)
-}
-
-func BenchmarkGrayOver(b *testing.B) {
-       bench(b, color.RGBAModel, color.GrayModel, color.AlphaModel, Over)
-}
index d3c5b29097cede0a906ec1ad986a11290fe083ff..7dd18dfdb59a1b11ece550a1d2f3da58c4078022 100644 (file)
@@ -166,6 +166,8 @@ func DrawMask(dst Image, r image.Rectangle, src image.Image, sp image.Point, mas
                                case *image.Gray:
                                        drawGrayMaskOver(dst0, r, src0, sp, mask0, mp)
                                        return
+                               // Case order matters. The next case (image.RGBA64Image) is an
+                               // interface type that the concrete types above also implement.
                                case image.RGBA64Image:
                                        drawRGBA64ImageMaskOver(dst0, r, src0, sp, mask0, mp)
                                        return
index 75a2896631b7fd220dfe24263949a4673453064b..77f1c5c2c2cfbc0f2730fa32b468390c7b79e017 100644 (file)
@@ -380,7 +380,7 @@ var drawTests = []drawTest{
        {"cmykAlphaSrc", vgradMagenta(), fillAlpha(192), Src, color.RGBA{145, 67, 145, 192}},
        {"cmykNil", vgradMagenta(), nil, Over, color.RGBA{192, 89, 192, 255}},
        {"cmykNilSrc", vgradMagenta(), nil, Src, color.RGBA{192, 89, 192, 255}},
-       // Variable mask and variable source.
+       // Variable mask and uniform source.
        // At (x, y) == (8, 8):
        // The destination pixel is {136, 0, 0, 255}.
        // The source pixel is {0, 0, 255, 255}.
@@ -397,9 +397,14 @@ var drawTests = []drawTest{
                Over, color.RGBA{81, 0, 102, 255}},
        {"genericSrcSlowest", fillBlue(255), convertToSlowestRGBA(vgradAlpha(192)),
                Src, color.RGBA{0, 0, 102, 102}},
-       // The source pixel is {0, 48, 0, 90}.
-       {"rgbaVariableMaskOver", vgradGreen(255), vgradAlpha(192), Over, color.RGBA{81, 54, 0, 255}},
-       // The source pixel is {136} in Gray-space, which is {136, 136, 136, 255} in RGBA-space.
+       // Variable mask and variable source.
+       // At (x, y) == (8, 8):
+       // The destination pixel is {136, 0, 0, 255}.
+       // The source pixel is:
+       //   - {0, 48, 0, 90}.
+       //   - {136} in Gray-space, which is {136, 136, 136, 255} in RGBA-space.
+       // The mask pixel's alpha is 102, or 40%.
+       {"rgbaVariableMaskOver", vgradGreen(90), vgradAlpha(192), Over, color.RGBA{117, 19, 0, 255}},
        {"grayVariableMaskOver", vgradGray(), vgradAlpha(192), Over, color.RGBA{136, 54, 54, 255}},
 }