golang-image/vector/vector.go

477 lines
14 KiB
Go
Raw Normal View History

// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:generate go run gen.go
//go:generate asmfmt -w acc_amd64.s
// asmfmt is https://github.com/klauspost/asmfmt
// Package vector provides a rasterizer for 2-D vector graphics.
package vector // import "golang.org/x/image/vector"
// The rasterizer's design follows
// https://medium.com/@raphlinus/inside-the-fastest-font-renderer-in-the-world-75ae5270c445
//
// Proof of concept code is in
// https://github.com/google/font-go
//
// See also:
// http://nothings.org/gamedev/rasterize/
// http://projects.tuxee.net/cl-vectors/section-the-cl-aa-algorithm
// https://people.gnome.org/~mathieu/libart/internals.html#INTERNALS-SCANLINE
import (
"image"
"image/color"
"image/draw"
"math"
"golang.org/x/image/math/f32"
)
vector: fix overflow when rasterizing a 30 degree line. There are some obvious TODOs, but they will be follow-up commits. This is about correctness, not performance, but for the record: name old time/op new time/op delta GlyphAlpha16Over-8 3.16µs ± 0% 3.38µs ± 0% +6.96% (p=0.000 n=9+10) GlyphAlpha16Src-8 3.06µs ± 0% 3.28µs ± 0% +7.21% (p=0.000 n=10+10) GlyphAlpha32Over-8 4.92µs ± 1% 5.23µs ± 1% +6.24% (p=0.000 n=10+10) GlyphAlpha32Src-8 4.53µs ± 1% 4.83µs ± 0% +6.69% (p=0.000 n=10+10) GlyphAlpha64Over-8 9.60µs ± 1% 10.21µs ± 0% +6.36% (p=0.000 n=10+10) GlyphAlpha64Src-8 8.04µs ± 0% 8.68µs ± 1% +7.99% (p=0.000 n=9+10) GlyphAlpha128Over-8 23.1µs ± 0% 24.2µs ± 1% +5.08% (p=0.000 n=9+10) GlyphAlpha128Src-8 16.8µs ± 0% 18.0µs ± 1% +6.76% (p=0.000 n=10+10) GlyphAlpha256Over-8 68.6µs ± 1% 70.3µs ± 0% +2.50% (p=0.000 n=10+10) GlyphAlpha256Src-8 43.6µs ± 0% 45.4µs ± 0% +4.08% (p=0.000 n=10+8) GlyphRGBA16Over-8 4.92µs ± 0% 5.14µs ± 0% +4.48% (p=0.000 n=9+9) GlyphRGBA16Src-8 4.39µs ± 0% 4.59µs ± 0% +4.60% (p=0.000 n=8+9) GlyphRGBA32Over-8 11.8µs ± 0% 12.2µs ± 1% +2.89% (p=0.000 n=9+10) GlyphRGBA32Src-8 9.79µs ± 1% 10.03µs ± 0% +2.49% (p=0.000 n=10+7) GlyphRGBA64Over-8 36.7µs ± 1% 37.5µs ± 1% +2.23% (p=0.000 n=10+10) GlyphRGBA64Src-8 28.5µs ± 0% 29.1µs ± 0% +2.09% (p=0.000 n=10+10) GlyphRGBA128Over-8 133µs ± 0% 135µs ± 0% +1.51% (p=0.000 n=10+9) GlyphRGBA128Src-8 99.1µs ± 0% 100.5µs ± 1% +1.47% (p=0.000 n=9+10) GlyphRGBA256Over-8 505µs ± 0% 511µs ± 0% +1.18% (p=0.000 n=9+10) GlyphRGBA256Src-8 372µs ± 0% 374µs ± 0% +0.69% (p=0.000 n=9+10) Change-Id: Ice1d77de5bc2649f8cd88366bcae3c00e78d65c2 Reviewed-on: https://go-review.googlesource.com/31113 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-14 08:12:05 +02:00
// floatingPointMathThreshold is the width or height above which the rasterizer
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
// chooses to used floating point math instead of fixed point math.
//
// Both implementations of line segmentation rasterization (see raster_fixed.go
// and raster_floating.go) implement the same algorithm (in ideal, infinite
// precision math) but they perform differently in practice. The fixed point
// math version is roughtly 1.25x faster (on GOARCH=amd64) on the benchmarks,
// but at sufficiently large scales, the computations will overflow and hence
// show rendering artifacts. The floating point math version has more
// consistent quality over larger scales, but it is significantly slower.
//
// This constant determines when to use the faster implementation and when to
// use the better quality implementation.
//
// The rationale for this particular value is that TestRasterizePolygon in
// vector_test.go checks the rendering quality of polygon edges at various
vector: change ϕ from 10 to 9. This slight loss in quality allows us to use int32 math exclusively throughout raster_fixed.go, instead of occasionally dropping into int64 math. The change in ϕ doesn't affect the benchmarks noticably, but staying in int32 does. The net effect: name old time/op new time/op delta GlyphAlpha16Over-8 3.36µs ± 0% 2.99µs ± 0% -10.89% (p=0.000 n=10+9) GlyphAlpha16Src-8 3.26µs ± 0% 2.89µs ± 1% -11.34% (p=0.000 n=9+10) GlyphAlpha32Over-8 5.20µs ± 0% 4.53µs ± 0% -12.76% (p=0.000 n=8+10) GlyphAlpha32Src-8 4.81µs ± 1% 4.14µs ± 0% -13.91% (p=0.000 n=9+9) GlyphAlpha64Over-8 10.2µs ± 0% 9.0µs ± 1% -11.99% (p=0.000 n=9+10) GlyphAlpha64Src-8 8.62µs ± 0% 7.42µs ± 1% -13.89% (p=0.000 n=9+10) GlyphAlpha128Over-8 24.1µs ± 0% 21.8µs ± 0% -9.32% (p=0.000 n=9+9) GlyphAlpha128Src-8 17.9µs ± 0% 15.6µs ± 0% -12.68% (p=0.000 n=9+10) GlyphAlpha256Over-8 70.1µs ± 0% 66.3µs ± 1% -5.44% (p=0.000 n=10+10) GlyphAlpha256Src-8 45.2µs ± 1% 41.2µs ± 1% -8.92% (p=0.000 n=10+10) GlyphRGBA16Over-8 5.12µs ± 0% 4.75µs ± 0% -7.15% (p=0.000 n=10+9) GlyphRGBA16Src-8 4.57µs ± 1% 4.20µs ± 0% -8.18% (p=0.000 n=9+8) GlyphRGBA32Over-8 12.1µs ± 0% 11.4µs ± 0% -5.50% (p=0.000 n=10+9) GlyphRGBA32Src-8 10.0µs ± 0% 9.3µs ± 1% -6.80% (p=0.000 n=10+9) GlyphRGBA64Over-8 37.2µs ± 0% 36.0µs ± 0% -3.17% (p=0.000 n=9+8) GlyphRGBA64Src-8 29.0µs ± 1% 27.9µs ± 1% -4.05% (p=0.000 n=9+10) GlyphRGBA128Over-8 134µs ± 1% 131µs ± 0% -1.85% (p=0.000 n=9+9) GlyphRGBA128Src-8 100µs ± 1% 98µs ± 0% -2.27% (p=0.000 n=10+9) GlyphRGBA256Over-8 506µs ± 0% 503µs ± 0% -0.56% (p=0.000 n=10+8) GlyphRGBA256Src-8 373µs ± 0% 370µs ± 0% -1.01% (p=0.000 n=10+9) Change-Id: Ie02afac6fd6fa95f090bf3fe0a5c744799ea9dc5 Reviewed-on: https://go-review.googlesource.com/31532 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-20 01:34:23 +02:00
// angles, inscribed in a circle of diameter 512. It may be that a higher value
// would still produce acceptable quality, but 512 seems to work.
const floatingPointMathThreshold = 512
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
func midPoint(p, q f32.Vec2) f32.Vec2 {
return f32.Vec2{
(p[0] + q[0]) * 0.5,
(p[1] + q[1]) * 0.5,
}
}
func lerp(t float32, p, q f32.Vec2) f32.Vec2 {
return f32.Vec2{
p[0] + t*(q[0]-p[0]),
p[1] + t*(q[1]-p[1]),
}
}
func clamp(i, width int32) uint {
if i < 0 {
return 0
}
if i < width {
return uint(i)
}
return uint(width)
}
// NewRasterizer returns a new Rasterizer whose rendered mask image is bounded
// by the given width and height.
func NewRasterizer(w, h int) *Rasterizer {
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
z := &Rasterizer{}
z.Reset(w, h)
return z
}
// Raster is a 2-D vector graphics rasterizer.
//
// The zero value is usable, in that it is a Rasterizer whose rendered mask
// image has zero width and zero height. Call Reset to change its bounds.
type Rasterizer struct {
// bufXxx are buffers of float32 or uint32 values, holding either the
// individual or cumulative area values.
//
// We don't actually need both values at any given time, and to conserve
// memory, the integration of the individual to the cumulative could modify
// the buffer in place. In other words, we could use a single buffer, say
// of type []uint32, and add some math.Float32bits and math.Float32frombits
// calls to satisfy the compiler's type checking. As of Go 1.7, though,
// there is a performance penalty between:
// bufF32[i] += x
// and
// bufU32[i] = math.Float32bits(x + math.Float32frombits(bufU32[i]))
//
// See golang.org/issue/17220 for some discussion.
bufF32 []float32
bufU32 []uint32
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
useFloatingPointMath bool
size image.Point
first f32.Vec2
pen f32.Vec2
// DrawOp is the operator used for the Draw method.
//
// The zero value is draw.Over.
DrawOp draw.Op
// TODO: an exported field equivalent to the mask point in the
// draw.DrawMask function in the stdlib image/draw package?
}
// Reset resets a Rasterizer as if it was just returned by NewRasterizer.
//
// This includes setting z.DrawOp to draw.Over.
func (z *Rasterizer) Reset(w, h int) {
z.size = image.Point{w, h}
z.first = f32.Vec2{}
z.pen = f32.Vec2{}
z.DrawOp = draw.Over
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
z.setUseFloatingPointMath(w > floatingPointMathThreshold || h > floatingPointMathThreshold)
}
func (z *Rasterizer) setUseFloatingPointMath(b bool) {
z.useFloatingPointMath = b
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
// Make z.bufF32 or z.bufU32 large enough to hold width * height samples.
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
if z.useFloatingPointMath {
if n := z.size.X * z.size.Y; n > cap(z.bufF32) {
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
z.bufF32 = make([]float32, n)
} else {
z.bufF32 = z.bufF32[:n]
for i := range z.bufF32 {
z.bufF32[i] = 0
}
}
} else {
if n := z.size.X * z.size.Y; n > cap(z.bufU32) {
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
z.bufU32 = make([]uint32, n)
} else {
z.bufU32 = z.bufU32[:n]
for i := range z.bufU32 {
z.bufU32[i] = 0
}
}
}
}
// Size returns the width and height passed to NewRasterizer or Reset.
func (z *Rasterizer) Size() image.Point {
return z.size
}
// Bounds returns the rectangle from (0, 0) to the width and height passed to
// NewRasterizer or Reset.
func (z *Rasterizer) Bounds() image.Rectangle {
return image.Rectangle{Max: z.size}
}
// Pen returns the location of the path-drawing pen: the last argument to the
// most recent XxxTo call.
func (z *Rasterizer) Pen() f32.Vec2 {
return z.pen
}
// ClosePath closes the current path.
func (z *Rasterizer) ClosePath() {
z.LineTo(z.first)
}
// MoveTo starts a new path and moves the pen to a.
//
// The coordinates are allowed to be out of the Rasterizer's bounds.
func (z *Rasterizer) MoveTo(a f32.Vec2) {
z.first = a
z.pen = a
}
// LineTo adds a line segment, from the pen to b, and moves the pen to b.
//
// The coordinates are allowed to be out of the Rasterizer's bounds.
func (z *Rasterizer) LineTo(b f32.Vec2) {
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
if z.useFloatingPointMath {
z.floatingLineTo(b)
} else {
z.fixedLineTo(b)
}
}
// QuadTo adds a quadratic Bézier segment, from the pen via b to c, and moves
// the pen to c.
//
// The coordinates are allowed to be out of the Rasterizer's bounds.
func (z *Rasterizer) QuadTo(b, c f32.Vec2) {
a := z.pen
devsq := devSquared(a, b, c)
if devsq >= 0.333 {
const tol = 3
n := 1 + int(math.Sqrt(math.Sqrt(tol*float64(devsq))))
t, nInv := float32(0), 1/float32(n)
for i := 0; i < n-1; i++ {
t += nInv
ab := lerp(t, a, b)
bc := lerp(t, b, c)
z.LineTo(lerp(t, ab, bc))
}
}
z.LineTo(c)
}
// CubeTo adds a cubic Bézier segment, from the pen via b and c to d, and moves
// the pen to d.
//
// The coordinates are allowed to be out of the Rasterizer's bounds.
func (z *Rasterizer) CubeTo(b, c, d f32.Vec2) {
a := z.pen
devsq := devSquared(a, b, d)
if devsqAlt := devSquared(a, c, d); devsq < devsqAlt {
devsq = devsqAlt
}
if devsq >= 0.333 {
const tol = 3
n := 1 + int(math.Sqrt(math.Sqrt(tol*float64(devsq))))
t, nInv := float32(0), 1/float32(n)
for i := 0; i < n-1; i++ {
t += nInv
ab := lerp(t, a, b)
bc := lerp(t, b, c)
cd := lerp(t, c, d)
abc := lerp(t, ab, bc)
bcd := lerp(t, bc, cd)
z.LineTo(lerp(t, abc, bcd))
}
}
z.LineTo(d)
}
// devSquared returns a measure of how curvy the sequnce a to b to c is. It
// determines how many line segments will approximate a Bézier curve segment.
//
// http://lists.nongnu.org/archive/html/freetype-devel/2016-08/msg00080.html
// gives the rationale for this evenly spaced heuristic instead of a recursive
// de Casteljau approach:
//
// The reason for the subdivision by n is that I expect the "flatness"
// computation to be semi-expensive (it's done once rather than on each
// potential subdivision) and also because you'll often get fewer subdivisions.
// Taking a circular arc as a simplifying assumption (ie a spherical cow),
// where I get n, a recursive approach would get 2^⌈lg n⌉, which, if I haven't
// made any horrible mistakes, is expected to be 33% more in the limit.
func devSquared(a, b, c f32.Vec2) float32 {
devx := a[0] - 2*b[0] + c[0]
devy := a[1] - 2*b[1] + c[1]
return devx*devx + devy*devy
}
// Draw implements the Drawer interface from the standard library's image/draw
// package.
//
// The vector paths previously added via the XxxTo calls become the mask for
// drawing src onto dst.
func (z *Rasterizer) Draw(dst draw.Image, r image.Rectangle, src image.Image, sp image.Point) {
// TODO: adjust r and sp (and mp?) if src.Bounds() doesn't contain
// r.Add(sp.Sub(r.Min)).
if src, ok := src.(*image.Uniform); ok {
srcR, srcG, srcB, srcA := src.RGBA()
switch dst := dst.(type) {
case *image.Alpha:
// Fast path for glyph rendering.
if srcA == 0xffff {
if z.DrawOp == draw.Over {
z.rasterizeDstAlphaSrcOpaqueOpOver(dst, r)
} else {
z.rasterizeDstAlphaSrcOpaqueOpSrc(dst, r)
}
return
}
case *image.RGBA:
if z.DrawOp == draw.Over {
z.rasterizeDstRGBASrcUniformOpOver(dst, r, srcR, srcG, srcB, srcA)
} else {
z.rasterizeDstRGBASrcUniformOpSrc(dst, r, srcR, srcG, srcB, srcA)
}
return
}
}
if z.DrawOp == draw.Over {
z.rasterizeOpOver(dst, r, src, sp)
} else {
z.rasterizeOpSrc(dst, r, src, sp)
}
}
func (z *Rasterizer) accumulateMask() {
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
if z.useFloatingPointMath {
if n := z.size.X * z.size.Y; n > cap(z.bufU32) {
z.bufU32 = make([]uint32, n)
} else {
z.bufU32 = z.bufU32[:n]
}
vector: add SIMD versions of xxxAccumulateMask. name old time/op new time/op delta GlyphAlphaLoose16Over-8 3.96µs ± 0% 3.64µs ± 1% -8.08% (p=0.000 n=8+10) GlyphAlphaLoose16Src-8 3.64µs ± 0% 3.35µs ± 0% -7.88% (p=0.000 n=8+9) GlyphAlphaLoose32Over-8 8.45µs ± 0% 6.74µs ± 0% -20.22% (p=0.000 n=8+9) GlyphAlphaLoose32Src-8 7.24µs ± 0% 5.54µs ± 1% -23.48% (p=0.000 n=8+10) GlyphAlphaLoose64Over-8 22.2µs ± 0% 17.4µs ± 0% -21.67% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 17.6µs ± 1% 12.2µs ± 1% -30.32% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 67.9µs ± 0% 53.3µs ± 1% -21.53% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 48.2µs ± 0% 32.6µs ± 2% -32.41% (p=0.000 n=9+10) GlyphAlphaLoose256Over-8 242µs ± 1% 187µs ± 1% -22.96% (p=0.000 n=9+9) GlyphAlphaLoose256Src-8 163µs ± 0% 105µs ± 1% -35.83% (p=0.000 n=9+9) GlyphRGBA16Over-8 5.25µs ± 1% 4.95µs ± 0% -5.78% (p=0.000 n=9+9) GlyphRGBA16Src-8 4.72µs ± 0% 4.43µs ± 1% -6.22% (p=0.000 n=9+10) GlyphRGBA32Over-8 13.5µs ± 0% 11.9µs ± 1% -12.19% (p=0.000 n=9+10) GlyphRGBA32Src-8 11.5µs ± 1% 9.8µs ± 0% -14.72% (p=0.000 n=9+9) GlyphRGBA64Over-8 42.0µs ± 2% 36.9µs ± 1% -12.19% (p=0.000 n=10+10) GlyphRGBA64Src-8 34.1µs ± 1% 28.5µs ± 0% -16.25% (p=0.000 n=9+7) GlyphRGBA128Over-8 149µs ± 2% 133µs ± 1% -10.24% (p=0.000 n=10+9) GlyphRGBA128Src-8 115µs ± 1% 99µs ± 1% -13.57% (p=0.000 n=9+10) GlyphRGBA256Over-8 566µs ± 0% 511µs ± 1% -9.85% (p=0.000 n=9+10) GlyphRGBA256Src-8 435µs ± 0% 372µs ± 0% -14.64% (p=0.000 n=9+8) GlyphNRGBA16Over-8 26.9µs ± 3% 26.0µs ± 3% -3.55% (p=0.000 n=10+9) GlyphNRGBA16Src-8 18.8µs ± 2% 18.4µs ± 2% -2.21% (p=0.000 n=9+10) GlyphNRGBA32Over-8 99.1µs ± 2% 95.9µs ± 3% -3.23% (p=0.000 n=10+10) GlyphNRGBA32Src-8 65.6µs ± 3% 62.8µs ± 2% -4.36% (p=0.000 n=10+10) GlyphNRGBA64Over-8 376µs ± 4% 370µs ± 2% ~ (p=0.063 n=10+10) GlyphNRGBA64Src-8 238µs ± 3% 233µs ± 1% -2.21% (p=0.000 n=9+10) GlyphNRGBA128Over-8 1.52ms ± 2% 1.48ms ± 0% -2.11% (p=0.000 n=10+8) GlyphNRGBA128Src-8 951µs ± 3% 935µs ± 1% -1.69% (p=0.013 n=10+9) GlyphNRGBA256Over-8 6.00ms ± 1% 5.87ms ± 3% -2.12% (p=0.002 n=10+10) GlyphNRGBA256Src-8 3.94ms ± 2% 3.80ms ± 2% -3.64% (p=0.000 n=10+10) A comparison of the non-SIMD and SIMD versions: name time/op FixedAccumulateMask16-8 237ns ± 0% FixedAccumulateMaskSIMD16-8 80.0ns ± 1% FloatingAccumulateMask16-8 413ns ± 2% FloatingAccumulateMaskSIMD16-8 166ns ± 0% FixedAccumulateMask64-8 3.42µs ± 0% FixedAccumulateMaskSIMD64-8 1.09µs ± 0% FloatingAccumulateMask64-8 6.92µs ± 0% FloatingAccumulateMaskSIMD64-8 2.47µs ± 1% Change-Id: Ib6980e5975ed2842ff2a372f76dd5f2e95c5526c Reviewed-on: https://go-review.googlesource.com/30898 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-13 05:50:52 +02:00
if haveFloatingAccumulateSIMD {
floatingAccumulateMaskSIMD(z.bufU32, z.bufF32)
} else {
floatingAccumulateMask(z.bufU32, z.bufF32)
}
} else {
vector: add SIMD versions of xxxAccumulateMask. name old time/op new time/op delta GlyphAlphaLoose16Over-8 3.96µs ± 0% 3.64µs ± 1% -8.08% (p=0.000 n=8+10) GlyphAlphaLoose16Src-8 3.64µs ± 0% 3.35µs ± 0% -7.88% (p=0.000 n=8+9) GlyphAlphaLoose32Over-8 8.45µs ± 0% 6.74µs ± 0% -20.22% (p=0.000 n=8+9) GlyphAlphaLoose32Src-8 7.24µs ± 0% 5.54µs ± 1% -23.48% (p=0.000 n=8+10) GlyphAlphaLoose64Over-8 22.2µs ± 0% 17.4µs ± 0% -21.67% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 17.6µs ± 1% 12.2µs ± 1% -30.32% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 67.9µs ± 0% 53.3µs ± 1% -21.53% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 48.2µs ± 0% 32.6µs ± 2% -32.41% (p=0.000 n=9+10) GlyphAlphaLoose256Over-8 242µs ± 1% 187µs ± 1% -22.96% (p=0.000 n=9+9) GlyphAlphaLoose256Src-8 163µs ± 0% 105µs ± 1% -35.83% (p=0.000 n=9+9) GlyphRGBA16Over-8 5.25µs ± 1% 4.95µs ± 0% -5.78% (p=0.000 n=9+9) GlyphRGBA16Src-8 4.72µs ± 0% 4.43µs ± 1% -6.22% (p=0.000 n=9+10) GlyphRGBA32Over-8 13.5µs ± 0% 11.9µs ± 1% -12.19% (p=0.000 n=9+10) GlyphRGBA32Src-8 11.5µs ± 1% 9.8µs ± 0% -14.72% (p=0.000 n=9+9) GlyphRGBA64Over-8 42.0µs ± 2% 36.9µs ± 1% -12.19% (p=0.000 n=10+10) GlyphRGBA64Src-8 34.1µs ± 1% 28.5µs ± 0% -16.25% (p=0.000 n=9+7) GlyphRGBA128Over-8 149µs ± 2% 133µs ± 1% -10.24% (p=0.000 n=10+9) GlyphRGBA128Src-8 115µs ± 1% 99µs ± 1% -13.57% (p=0.000 n=9+10) GlyphRGBA256Over-8 566µs ± 0% 511µs ± 1% -9.85% (p=0.000 n=9+10) GlyphRGBA256Src-8 435µs ± 0% 372µs ± 0% -14.64% (p=0.000 n=9+8) GlyphNRGBA16Over-8 26.9µs ± 3% 26.0µs ± 3% -3.55% (p=0.000 n=10+9) GlyphNRGBA16Src-8 18.8µs ± 2% 18.4µs ± 2% -2.21% (p=0.000 n=9+10) GlyphNRGBA32Over-8 99.1µs ± 2% 95.9µs ± 3% -3.23% (p=0.000 n=10+10) GlyphNRGBA32Src-8 65.6µs ± 3% 62.8µs ± 2% -4.36% (p=0.000 n=10+10) GlyphNRGBA64Over-8 376µs ± 4% 370µs ± 2% ~ (p=0.063 n=10+10) GlyphNRGBA64Src-8 238µs ± 3% 233µs ± 1% -2.21% (p=0.000 n=9+10) GlyphNRGBA128Over-8 1.52ms ± 2% 1.48ms ± 0% -2.11% (p=0.000 n=10+8) GlyphNRGBA128Src-8 951µs ± 3% 935µs ± 1% -1.69% (p=0.013 n=10+9) GlyphNRGBA256Over-8 6.00ms ± 1% 5.87ms ± 3% -2.12% (p=0.002 n=10+10) GlyphNRGBA256Src-8 3.94ms ± 2% 3.80ms ± 2% -3.64% (p=0.000 n=10+10) A comparison of the non-SIMD and SIMD versions: name time/op FixedAccumulateMask16-8 237ns ± 0% FixedAccumulateMaskSIMD16-8 80.0ns ± 1% FloatingAccumulateMask16-8 413ns ± 2% FloatingAccumulateMaskSIMD16-8 166ns ± 0% FixedAccumulateMask64-8 3.42µs ± 0% FixedAccumulateMaskSIMD64-8 1.09µs ± 0% FloatingAccumulateMask64-8 6.92µs ± 0% FloatingAccumulateMaskSIMD64-8 2.47µs ± 1% Change-Id: Ib6980e5975ed2842ff2a372f76dd5f2e95c5526c Reviewed-on: https://go-review.googlesource.com/30898 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-13 05:50:52 +02:00
if haveFixedAccumulateSIMD {
fixedAccumulateMaskSIMD(z.bufU32)
} else {
fixedAccumulateMask(z.bufU32)
}
}
}
func (z *Rasterizer) rasterizeDstAlphaSrcOpaqueOpOver(dst *image.Alpha, r image.Rectangle) {
// TODO: non-zero vs even-odd winding?
if r == dst.Bounds() && r == z.Bounds() {
// We bypass the z.accumulateMask step and convert straight from
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
// z.bufF32 or z.bufU32 to dst.Pix.
if z.useFloatingPointMath {
if haveFloatingAccumulateSIMD {
floatingAccumulateOpOverSIMD(dst.Pix, z.bufF32)
} else {
floatingAccumulateOpOver(dst.Pix, z.bufF32)
}
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
} else {
if haveFixedAccumulateSIMD {
fixedAccumulateOpOverSIMD(dst.Pix, z.bufU32)
} else {
fixedAccumulateOpOver(dst.Pix, z.bufU32)
}
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
}
return
}
z.accumulateMask()
pix := dst.Pix[dst.PixOffset(r.Min.X, r.Min.Y):]
for y, y1 := 0, r.Max.Y-r.Min.Y; y < y1; y++ {
for x, x1 := 0, r.Max.X-r.Min.X; x < x1; x++ {
ma := z.bufU32[y*z.size.X+x]
i := y*dst.Stride + x
// This formula is like rasterizeOpOver's, simplified for the
// concrete dst type and opaque src assumption.
a := 0xffff - ma
pix[i] = uint8((uint32(pix[i])*0x101*a/0xffff + ma) >> 8)
}
}
}
func (z *Rasterizer) rasterizeDstAlphaSrcOpaqueOpSrc(dst *image.Alpha, r image.Rectangle) {
// TODO: non-zero vs even-odd winding?
if r == dst.Bounds() && r == z.Bounds() {
// We bypass the z.accumulateMask step and convert straight from
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
// z.bufF32 or z.bufU32 to dst.Pix.
if z.useFloatingPointMath {
if haveFloatingAccumulateSIMD {
floatingAccumulateOpSrcSIMD(dst.Pix, z.bufF32)
} else {
floatingAccumulateOpSrc(dst.Pix, z.bufF32)
}
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
} else {
if haveFixedAccumulateSIMD {
fixedAccumulateOpSrcSIMD(dst.Pix, z.bufU32)
} else {
fixedAccumulateOpSrc(dst.Pix, z.bufU32)
}
vector: add a fixed point math implementation. name old time/op new time/op delta GlyphAlpha16Over-8 4.48µs ± 1% 3.56µs ± 0% -20.70% (p=0.000 n=9+10) GlyphAlpha16Src-8 4.17µs ± 0% 3.38µs ± 1% -19.09% (p=0.000 n=10+10) GlyphAlpha32Over-8 9.03µs ± 0% 6.74µs ± 0% -25.33% (p=0.000 n=9+10) GlyphAlpha32Src-8 7.46µs ± 1% 5.98µs ± 0% -19.80% (p=0.000 n=10+9) GlyphAlpha64Over-8 21.3µs ± 0% 16.4µs ± 0% -22.84% (p=0.000 n=10+10) GlyphAlpha64Src-8 16.2µs ± 1% 13.1µs ± 0% -19.33% (p=0.000 n=10+10) GlyphAlpha128Over-8 59.8µs ± 0% 47.2µs ± 0% -21.11% (p=0.000 n=9+9) GlyphAlpha128Src-8 41.3µs ± 1% 33.0µs ± 0% -20.26% (p=0.000 n=9+10) GlyphAlpha256Over-8 197µs ± 0% 158µs ± 0% -19.44% (p=0.000 n=9+10) GlyphAlpha256Src-8 124µs ± 0% 98µs ± 0% -21.17% (p=0.000 n=9+9) GlyphAlphaLoose16Over-8 4.73µs ± 0% 3.97µs ± 1% -16.06% (p=0.000 n=10+10) GlyphAlphaLoose16Src-8 4.41µs ± 0% 3.64µs ± 1% -17.50% (p=0.000 n=10+10) GlyphAlphaLoose32Over-8 9.62µs ± 0% 8.47µs ± 0% -11.95% (p=0.000 n=10+10) GlyphAlphaLoose32Src-8 8.25µs ± 0% 7.19µs ± 0% -12.88% (p=0.000 n=9+9) GlyphAlphaLoose64Over-8 25.6µs ± 0% 22.2µs ± 0% -13.01% (p=0.000 n=9+9) GlyphAlphaLoose64Src-8 20.2µs ± 0% 17.2µs ± 1% -14.98% (p=0.000 n=10+10) GlyphAlphaLoose128Over-8 83.4µs ± 1% 68.2µs ± 0% -18.27% (p=0.000 n=10+10) GlyphAlphaLoose128Src-8 59.8µs ± 0% 47.4µs ± 0% -20.77% (p=0.000 n=10+9) GlyphAlphaLoose256Over-8 273µs ± 1% 239µs ± 0% -12.52% (p=0.000 n=10+9) GlyphAlphaLoose256Src-8 187µs ± 0% 155µs ± 1% -16.91% (p=0.000 n=9+10) GlyphRGBA16Over-8 5.99µs ± 0% 5.24µs ± 1% -12.60% (p=0.000 n=9+10) GlyphRGBA16Src-8 5.48µs ± 0% 4.68µs ± 0% -14.68% (p=0.000 n=9+10) GlyphRGBA32Over-8 14.6µs ± 0% 13.5µs ± 0% -7.60% (p=0.000 n=9+9) GlyphRGBA32Src-8 12.6µs ± 0% 11.4µs ± 0% -9.62% (p=0.000 n=9+9) GlyphRGBA64Over-8 44.8µs ± 0% 42.2µs ± 0% -5.69% (p=0.000 n=9+9) GlyphRGBA64Src-8 36.6µs ± 1% 33.5µs ± 1% -8.55% (p=0.000 n=9+9) GlyphRGBA128Over-8 162µs ± 0% 148µs ± 1% -8.85% (p=0.000 n=10+9) GlyphRGBA128Src-8 129µs ± 1% 114µs ± 0% -11.61% (p=0.000 n=9+10) GlyphRGBA256Over-8 588µs ± 0% 573µs ± 0% -2.53% (p=0.000 n=9+10) GlyphRGBA256Src-8 455µs ± 0% 426µs ± 1% -6.51% (p=0.000 n=9+10) GlyphNRGBA16Over-8 27.0µs ± 4% 26.3µs ± 2% -2.65% (p=0.001 n=9+10) GlyphNRGBA16Src-8 19.4µs ± 3% 18.6µs ± 1% -4.35% (p=0.000 n=9+10) GlyphNRGBA32Over-8 97.4µs ± 3% 96.8µs ± 2% ~ (p=0.447 n=9+10) GlyphNRGBA32Src-8 66.6µs ± 3% 64.5µs ± 1% -3.21% (p=0.000 n=10+9) GlyphNRGBA64Over-8 372µs ± 3% 368µs ± 1% ~ (p=0.105 n=10+10) GlyphNRGBA64Src-8 235µs ± 1% 234µs ± 1% ~ (p=0.130 n=8+8) GlyphNRGBA128Over-8 1.45ms ± 2% 1.48ms ± 3% +2.06% (p=0.014 n=9+9) GlyphNRGBA128Src-8 926µs ± 3% 937µs ± 1% ~ (p=0.113 n=10+9) GlyphNRGBA256Over-8 5.76ms ± 2% 5.90ms ± 3% +2.29% (p=0.001 n=9+10) GlyphNRGBA256Src-8 3.59ms ± 1% 3.86ms ± 1% +7.46% (p=0.000 n=9+10) Change-Id: I72f25193b5be4e57af09e9eea4eee50545a34cbf Reviewed-on: https://go-review.googlesource.com/29972 Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-28 11:29:02 +02:00
}
return
}
z.accumulateMask()
pix := dst.Pix[dst.PixOffset(r.Min.X, r.Min.Y):]
for y, y1 := 0, r.Max.Y-r.Min.Y; y < y1; y++ {
for x, x1 := 0, r.Max.X-r.Min.X; x < x1; x++ {
ma := z.bufU32[y*z.size.X+x]
// This formula is like rasterizeOpSrc's, simplified for the
// concrete dst type and opaque src assumption.
pix[y*dst.Stride+x] = uint8(ma >> 8)
}
}
}
func (z *Rasterizer) rasterizeDstRGBASrcUniformOpOver(dst *image.RGBA, r image.Rectangle, sr, sg, sb, sa uint32) {
z.accumulateMask()
pix := dst.Pix[dst.PixOffset(r.Min.X, r.Min.Y):]
for y, y1 := 0, r.Max.Y-r.Min.Y; y < y1; y++ {
for x, x1 := 0, r.Max.X-r.Min.X; x < x1; x++ {
ma := z.bufU32[y*z.size.X+x]
// This formula is like rasterizeOpOver's, simplified for the
// concrete dst type and uniform src assumption.
a := 0xffff - (sa * ma / 0xffff)
i := y*dst.Stride + 4*x
pix[i+0] = uint8(((uint32(pix[i+0])*0x101*a + sr*ma) / 0xffff) >> 8)
pix[i+1] = uint8(((uint32(pix[i+1])*0x101*a + sg*ma) / 0xffff) >> 8)
pix[i+2] = uint8(((uint32(pix[i+2])*0x101*a + sb*ma) / 0xffff) >> 8)
pix[i+3] = uint8(((uint32(pix[i+3])*0x101*a + sa*ma) / 0xffff) >> 8)
}
}
}
func (z *Rasterizer) rasterizeDstRGBASrcUniformOpSrc(dst *image.RGBA, r image.Rectangle, sr, sg, sb, sa uint32) {
z.accumulateMask()
pix := dst.Pix[dst.PixOffset(r.Min.X, r.Min.Y):]
for y, y1 := 0, r.Max.Y-r.Min.Y; y < y1; y++ {
for x, x1 := 0, r.Max.X-r.Min.X; x < x1; x++ {
ma := z.bufU32[y*z.size.X+x]
// This formula is like rasterizeOpSrc's, simplified for the
// concrete dst type and uniform src assumption.
i := y*dst.Stride + 4*x
pix[i+0] = uint8((sr * ma / 0xffff) >> 8)
pix[i+1] = uint8((sg * ma / 0xffff) >> 8)
pix[i+2] = uint8((sb * ma / 0xffff) >> 8)
pix[i+3] = uint8((sa * ma / 0xffff) >> 8)
}
}
}
func (z *Rasterizer) rasterizeOpOver(dst draw.Image, r image.Rectangle, src image.Image, sp image.Point) {
z.accumulateMask()
out := color.RGBA64{}
outc := color.Color(&out)
for y, y1 := 0, r.Max.Y-r.Min.Y; y < y1; y++ {
for x, x1 := 0, r.Max.X-r.Min.X; x < x1; x++ {
sr, sg, sb, sa := src.At(sp.X+x, sp.Y+y).RGBA()
ma := z.bufU32[y*z.size.X+x]
// This algorithm comes from the standard library's image/draw
// package.
dr, dg, db, da := dst.At(r.Min.X+x, r.Min.Y+y).RGBA()
a := 0xffff - (sa * ma / 0xffff)
out.R = uint16((dr*a + sr*ma) / 0xffff)
out.G = uint16((dg*a + sg*ma) / 0xffff)
out.B = uint16((db*a + sb*ma) / 0xffff)
out.A = uint16((da*a + sa*ma) / 0xffff)
dst.Set(r.Min.X+x, r.Min.Y+y, outc)
}
}
}
func (z *Rasterizer) rasterizeOpSrc(dst draw.Image, r image.Rectangle, src image.Image, sp image.Point) {
z.accumulateMask()
out := color.RGBA64{}
outc := color.Color(&out)
for y, y1 := 0, r.Max.Y-r.Min.Y; y < y1; y++ {
for x, x1 := 0, r.Max.X-r.Min.X; x < x1; x++ {
sr, sg, sb, sa := src.At(sp.X+x, sp.Y+y).RGBA()
ma := z.bufU32[y*z.size.X+x]
// This algorithm comes from the standard library's image/draw
// package.
out.R = uint16(sr * ma / 0xffff)
out.G = uint16(sg * ma / 0xffff)
out.B = uint16(sb * ma / 0xffff)
out.A = uint16(sa * ma / 0xffff)
dst.Set(r.Min.X+x, r.Min.Y+y, outc)
}
}
}