From 918b3735c39de887802aff309898349245b64115 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Wed, 29 Apr 2015 10:46:24 +1000 Subject: [PATCH] draw: disable the image.Rectangle DstMask fast path until Go 1.5 is released. Change-Id: Ie5d6766d53952d3a81dfbd19a9f4022aaad6af5a Reviewed-on: https://go-review.googlesource.com/9463 Reviewed-by: Rob Pike --- draw/scale.go | 8 +++++--- draw/scale_test.go | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/draw/scale.go b/draw/scale.go index 07cd20b..4d77764 100644 --- a/draw/scale.go +++ b/draw/scale.go @@ -410,9 +410,11 @@ func clipAffectedDestRect(adr image.Rectangle, dstMask image.Image, dstMaskP ima if dstMask == nil { return adr, nil } - if r, ok := dstMask.(image.Rectangle); ok { - return adr.Intersect(r.Sub(dstMaskP)), nil - } + // TODO: enable this fast path once Go 1.5 is released, where an + // image.Rectangle implements image.Image. + // if r, ok := dstMask.(image.Rectangle); ok { + // return adr.Intersect(r.Sub(dstMaskP)), nil + // } // TODO: clip to dstMask.Bounds() if the color model implies that out-of-bounds means 0 alpha? return adr, dstMask } diff --git a/draw/scale_test.go b/draw/scale_test.go index d9265a1..cfa38a7 100644 --- a/draw/scale_test.go +++ b/draw/scale_test.go @@ -433,7 +433,9 @@ func TestRectDstMask(t *testing.T) { for _, dstMaskP := range dstMaskPs { dstInside := mk(q, nil, image.Point{}) for _, wrap := range []bool{false, true} { - dstMask := image.Image(rect) + // TODO: replace "rectImage(rect)" with "rect" once Go 1.5 is + // released, where an image.Rectangle implements image.Image. + dstMask := image.Image(rectImage(rect)) if wrap { dstMask = srcWrapper{dstMask} } @@ -463,6 +465,19 @@ func TestRectDstMask(t *testing.T) { } } +// TODO: delete this wrapper type once Go 1.5 is released, where an +// image.Rectangle implements image.Image. +type rectImage image.Rectangle + +func (r rectImage) ColorModel() color.Model { return color.Alpha16Model } +func (r rectImage) Bounds() image.Rectangle { return image.Rectangle(r) } +func (r rectImage) At(x, y int) color.Color { + if (image.Point{x, y}).In(image.Rectangle(r)) { + return color.Opaque + } + return color.Transparent +} + // The fooWrapper types wrap the dst or src image to avoid triggering the // type-specific fast path implementations. type (