import (
"image"
"image/color"
+ "reflect"
"testing"
)
srcw, srch = 400, 300
)
+var palette = color.Palette{
+ color.Black,
+ color.White,
+}
+
// bench benchmarks drawing src and mask images onto a dst image with the
// given op and the color models to create those images from.
// The created images' pixels are initialized to non-zero values.
}
dst = dst1
default:
- b.Fatal("unknown destination color model", dcm)
+ // The == operator isn't defined on a color.Palette (a slice), so we
+ // use reflection.
+ if reflect.DeepEqual(dcm, palette) {
+ dst1 := image.NewPaletted(image.Rect(0, 0, dstw, dsth), palette)
+ for y := 0; y < dsth; y++ {
+ for x := 0; x < dstw; x++ {
+ dst1.SetColorIndex(x, y, uint8(x^y)&1)
+ }
+ }
+ dst = dst1
+ } else {
+ b.Fatal("unknown destination color model", dcm)
+ }
}
var src image.Image
bench(b, color.RGBAModel, color.RGBA64Model, nil, Src)
}
+func BenchmarkPaletted(b *testing.B) {
+ bench(b, palette, color.RGBAModel, nil, Src)
+}
+
// The BenchmarkGenericFoo functions exercise the generic, slow-path code.
func BenchmarkGenericOver(b *testing.B) {
case *image.Paletted:
if op == Src && mask == nil && !processBackward(dst, r, src, sp) {
drawPaletted(dst0, r, src, sp, false)
+ return
}
}