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 (