diff options
author | Nigel Tao <nigeltao@golang.org> | 2021-10-27 14:24:37 +1100 |
---|---|---|
committer | Nigel Tao <nigeltao@golang.org> | 2021-10-31 08:29:02 +0000 |
commit | 8e3d5f0bb324eebb92cc93264a63afa7ded9ab9a (patch) | |
tree | 3a7c961d8817154ef9af60be59e55c9c02a465e9 /src/image | |
parent | 0bef30d28ac0b9654e5daef0fef731d7a9495214 (diff) | |
download | go-8e3d5f0bb324eebb92cc93264a63afa7ded9ab9a.tar.gz go-8e3d5f0bb324eebb92cc93264a63afa7ded9ab9a.zip |
image/draw: rename and reorder some benchmarks
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>
Diffstat (limited to 'src/image')
-rw-r--r-- | src/image/draw/bench_test.go | 27 | ||||
-rw-r--r-- | src/image/draw/draw.go | 2 | ||||
-rw-r--r-- | src/image/draw/draw_test.go | 13 |
3 files changed, 24 insertions, 18 deletions
diff --git a/src/image/draw/bench_test.go b/src/image/draw/bench_test.go index 2b7c6d6ac4..55d25b8596 100644 --- a/src/image/draw/bench_test.go +++ b/src/image/draw/bench_test.go @@ -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) -} diff --git a/src/image/draw/draw.go b/src/image/draw/draw.go index d3c5b29097..7dd18dfdb5 100644 --- a/src/image/draw/draw.go +++ b/src/image/draw/draw.go @@ -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 diff --git a/src/image/draw/draw_test.go b/src/image/draw/draw_test.go index 75a2896631..77f1c5c2c2 100644 --- a/src/image/draw/draw_test.go +++ b/src/image/draw/draw_test.go @@ -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}}, } |