Commit Graph

17 Commits

Author SHA1 Message Date
Nigel Tao
3940ddb240 draw: implement dstMask.
Change-Id: Id63695c3cef67fbe79fa1fbe916b85108f401093
Reviewed-on: https://go-review.googlesource.com/9191
Reviewed-by: Rob Pike <r@golang.org>
2015-04-22 04:18:19 +00:00
Nigel Tao
8ed4ff0a33 draw: implement the Over operator.
Change-Id: Id207b8f2fa5233175285800477e60f111ef4af63
Reviewed-on: https://go-review.googlesource.com/8744
Reviewed-by: Rob Pike <r@golang.org>
2015-04-13 23:42:02 +00:00
Nigel Tao
697863cec6 draw: clamp kernel output so red, green and blue <= alpha.
The raw computation can produce red > alpha when some weights are
negative.

Change-Id: Ic6701354770f012d3ef21a390a8400e14e9d1e25
Reviewed-on: https://go-review.googlesource.com/8740
Reviewed-by: Rob Pike <r@golang.org>
2015-04-10 05:40:26 +00:00
Nigel Tao
b293696c81 draw: switch on the Op compositing operator.
This change only *prepares* the codegen to handle multiple Ops. The
actual generated code still only supports one Op (Src) and not the other
(Over). A follow-up change will add Over.

This Op switch (an eventual x2 multiplier in the amount of code
generated) should be the last of the codegen LoC multipliers. The dst
and src mask options will be implemented in the slow path fallback.

Change-Id: Iecbcc6fad063e2aac36d78d5380c0a0947c709df
Reviewed-on: https://go-review.googlesource.com/8488
Reviewed-by: Rob Pike <r@golang.org>
2015-04-07 06:16:14 +00:00
Nigel Tao
c53fa16781 draw: use a sync.Pool for kernel scaling's temporary buffers.
benchmark                      old ns/op     new ns/op     delta
BenchmarkScaleBLLargeDown      257715146     260286012     +1.00%
BenchmarkScaleCRLargeDown      426797448     430078734     +0.77%
BenchmarkScaleBLDown           4449939       4222542       -5.11%
BenchmarkScaleCRDown           8160446       8010056       -1.84%
BenchmarkScaleBLUp             22290312      21044122      -5.59%
BenchmarkScaleCRUp             33010722      32021468      -3.00%
BenchmarkScaleCRSrcGray        13307961      13020192      -2.16%
BenchmarkScaleCRSrcNRGBA       40567431      40801939      +0.58%
BenchmarkScaleCRSrcRGBA        39892971      40240558      +0.87%
BenchmarkScaleCRSrcYCbCr       59020222      59686699      +1.13%

benchmark                      old allocs     new allocs     delta
BenchmarkScaleBLLargeDown      1              1              +0.00%
BenchmarkScaleCRLargeDown      1              2              +100.00%
BenchmarkScaleBLDown           1              0              -100.00%
BenchmarkScaleCRDown           1              0              -100.00%
BenchmarkScaleBLUp             1              0              -100.00%
BenchmarkScaleCRUp             1              0              -100.00%
BenchmarkScaleCRSrcGray        1              0              -100.00%
BenchmarkScaleCRSrcNRGBA       1              0              -100.00%
BenchmarkScaleCRSrcRGBA        1              0              -100.00%
BenchmarkScaleCRSrcYCbCr       1              0              -100.00%

benchmark                      old bytes     new bytes     delta
BenchmarkScaleBLLargeDown      14745600      2949200       -80.00%
BenchmarkScaleCRLargeDown      14745600      4915333       -66.67%
BenchmarkScaleBLDown           1523712       5079          -99.67%
BenchmarkScaleCRDown           1523712       7619          -99.50%
BenchmarkScaleBLUp             10117120      101175        -99.00%
BenchmarkScaleCRUp             10117120      202350        -98.00%
BenchmarkScaleCRSrcGray        4915200       49156         -99.00%
BenchmarkScaleCRSrcNRGBA       4915200       163853        -96.67%
BenchmarkScaleCRSrcRGBA        4915200       163853        -96.67%
BenchmarkScaleCRSrcYCbCr       4915200       245780        -95.00%

The increase in BenchmarkScale??LargeDown number of allocs I think is an
accounting error due to the low number of iterations: a low denominator.
I suspect that there are one or two extra allocs up front for using the
sync.Pool, but one fewer alloc per iteration. The number of iterations
is only 5 for BL and 3 for CR, for the default timeout. If I increase
the -test.benchtime value to 5s, then the reported average (allocs/op)
drop from 2 to 0, so the delta should actually be -100% instead of +0 or
+100%.

Change-Id: I21d9bb0086bdb25517b6a430e8a21bdf3db026f6
Reviewed-on: https://go-review.googlesource.com/8150
Reviewed-by: Rob Pike <r@golang.org>
2015-04-02 05:39:46 +00:00
Nigel Tao
575b100276 draw: eliminate some math.Floor calls in Transform methods.
benchmark                      old ns/op     new ns/op     delta
BenchmarkTformNNSrcRGBA        524533        293230        -44.10%
BenchmarkTformNNSrcUniform     362974        149389        -58.84%
BenchmarkTformABSrcGray        827461        427720        -48.31%
BenchmarkTformABSrcNRGBA       1286930       919391        -28.56%
BenchmarkTformABSrcRGBA        1115444       794334        -28.79%
BenchmarkTformABSrcYCbCr       1732420       1379846       -20.35%
BenchmarkTformCRSrcGray        3629048       3467404       -4.45%
BenchmarkTformCRSrcNRGBA       7569407       7418874       -1.99%
BenchmarkTformCRSrcRGBA        7552459       7432745       -1.59%
BenchmarkTformCRSrcYCbCr       8072351       7854715       -2.70%

Change-Id: I6c01e631d9f88c36ae99d0cd181104ad5ac48db0
Reviewed-on: https://go-review.googlesource.com/7926
Reviewed-by: Rob Pike <r@golang.org>
2015-03-23 22:47:47 +00:00
Nigel Tao
ff75b2d824 draw: have TestSrcTranslationInvariance work on smaller images.
Before/after:
$ go test
PASS
ok      golang.org/x/image/draw 1.173s
$ go test
PASS
ok      golang.org/x/image/draw 0.225s

Change-Id: I5b4742f045870db9353da1d85b0677be992cb347
Reviewed-on: https://go-review.googlesource.com/7712
Reviewed-by: Rob Pike <r@golang.org>
2015-03-18 06:02:26 +00:00
Nigel Tao
a71fdfe7d1 draw: implement Kernel.Transform.
Also fix the NN and ABL fast paths to only apply if we can access the
Pix elements without src-bounds checking.

Change-Id: Ie9fc96b28e0665df49d00c4c53cb81385faee4db
Reviewed-on: https://go-review.googlesource.com/7675
Reviewed-by: Rob Pike <r@golang.org>
2015-03-17 23:09:51 +00:00
Nigel Tao
87013da148 draw: implement NearestNeighbor and ApproxBiLinear Transform.
Change-Id: I70a5e3703dea436354e9591fce7b704ec749c2d1
Reviewed-on: https://go-review.googlesource.com/7541
Reviewed-by: Rob Pike <r@golang.org>
2015-03-16 23:32:22 +00:00
Nigel Tao
4bf24024c9 draw: add a test for src translation invariance.
Change-Id: Iedd4cc4e2b88c5fa9e4fcd547756588e4d87bfff
Reviewed-on: https://go-review.googlesource.com/7471
Reviewed-by: Rob Pike <r@golang.org>
2015-03-12 23:26:12 +00:00
Nigel Tao
08593990c4 draw: add Transformer and Option types.
Just stub implementations for now. Actual implementations will be
follow-up changes.

Change-Id: Id21d9042a2073c2dc0f78c9977c4940f000a41df
Reviewed-on: https://go-review.googlesource.com/6805
Reviewed-by: Rob Pike <r@golang.org>
2015-03-10 00:41:02 +00:00
Nigel Tao
2c27a34d37 draw: make Scale an Interpolator method instead of a function.
This means that only Kernel values have a NewScaler method, which
re-uses computation when scaling multiple images of the same dst and src
dimensions. The NearestNeighbor and ApproxBiLinear scalers don't get any
pre-computation to re-use, so don't need a NewScaler method just to
satisfy the previous Interpolator interface. As a small bonus, NN.Scale
and ABL.Scale should no longer allocate on the fast paths.

This change is consistent the upcoming Transformer method, so that the
Interpolator interface will be

type Interpolator interface {
	Scale(etc)
	Transform(etc)
}

instead of

type Interpolator interface {
	NewScaler(etc) Scaler
	Transform(etc)
}

I don't have a good theory for why the "func (ablInterpolator)
scale_RGBA_RGBA" benchmark is such a dramatic improvement, but at least
it's in the right direction. I'm calling the other benchmark changes as
noise.

benchmark                     old ns/op      new ns/op      delta
BenchmarkScaleLargeDownNN     3233406        3169060        -1.99%
BenchmarkScaleLargeDownAB     12018178       12011348       -0.06%
BenchmarkScaleLargeDownBL     1420827834     1409335695     -0.81%
BenchmarkScaleLargeDownCR     2820669690     2795534035     -0.89%
BenchmarkScaleDownNN          866628         869241         +0.30%
BenchmarkScaleDownAB          3175963        3216041        +1.26%
BenchmarkScaleDownBL          26639767       26677003       +0.14%
BenchmarkScaleDownCR          51720996       51621628       -0.19%
BenchmarkScaleUpNN            42758485       43258611       +1.17%
BenchmarkScaleUpAB            156693813      156943367      +0.16%
BenchmarkScaleUpBL            69511444       69621698       +0.16%
BenchmarkScaleUpCR            124530191      124885601      +0.29%
BenchmarkScaleSrcGray         8992205        9129321        +1.52%
BenchmarkScaleSrcNRGBA        9807837        9894466        +0.88%
BenchmarkScaleSrcRGBA         1333188        1104282        -17.17%
BenchmarkScaleSrcUniform      1147788        1162488        +1.28%
BenchmarkScaleSrcYCbCr        12164542       12305373       +1.16%

Change-Id: I2aee6c392eb7437e843260775aed97ce145b4d47
Reviewed-on: https://go-review.googlesource.com/6556
Reviewed-by: Rob Pike <r@golang.org>
2015-03-04 22:50:18 +00:00
Nigel Tao
f510ad81a1 draw: generate code paths for image.Gray sources.
Optimizing this code path will be follow-up changes.

Change-Id: Ifece6c7d3685bb8f2d20cf8828a121c9ff346434
Reviewed-on: https://go-review.googlesource.com/6238
Reviewed-by: Rob Pike <r@golang.org>
2015-02-28 21:42:51 +00:00
Nigel Tao
db892dd957 draw: clip scaling to the dst bounds.
This is necessary for the upcoming RGBA dst fast path. The RGBA.Set slow
path will clip automatically. Accessing RGBA.Pix directly will not.

Benchmarks look like noise to me:
benchmark                     old ns/op      new ns/op      delta
BenchmarkScaleLargeDownNN     6212108        6131166        -1.30%
BenchmarkScaleLargeDownAB     15586042       15656681       +0.45%
BenchmarkScaleLargeDownBL     1518783517     1508124217     -0.70%
BenchmarkScaleLargeDownCR     2998969089     2978114154     -0.70%
BenchmarkScaleDownNN          1821187        1809314        -0.65%
BenchmarkScaleDownAB          4286983        4248974        -0.89%
BenchmarkScaleDownBL          29396818       30181926       +2.67%
BenchmarkScaleDownCR          56441945       57952417       +2.68%
BenchmarkScaleUpNN            90325384       89734496       -0.65%
BenchmarkScaleUpAB            211613922      211625435      +0.01%
BenchmarkScaleUpBL            119730880      120817135      +0.91%
BenchmarkScaleUpCR            178592665      182305702      +2.08%
BenchmarkScaleSrcNRGBA        13271034       13210760       -0.45%
BenchmarkScaleSrcRGBA         13082234       12997551       -0.65%
BenchmarkScaleSrcUniform      4003966        3934184        -1.74%
BenchmarkScaleSrcYCbCr        15939182       15900123       -0.25%

Change-Id: Ibf2843bb3c4eb695b58030e7314053c669533016
Reviewed-on: https://go-review.googlesource.com/6073
Reviewed-by: Rob Pike <r@golang.org>
2015-02-26 22:56:31 +00:00
Nigel Tao
284bc4b702 draw: test that the fast path implementations match the generic ones.
Change-Id: I34418bd8e5dec7b03e9c29efdab10f6116b4463f
Reviewed-on: https://go-review.googlesource.com/5730
Reviewed-by: Rob Pike <r@golang.org>
2015-02-26 00:12:42 +00:00
Nigel Tao
748adb17a1 draw: generate impl.go type switches.
This just the type switches to concrete-type-specific methods.
Generating RGBA- or YCbCr-specific code instead of calling the
general-purpose At and Set methods will be follow-up changes.

benchmark                     old ns/op      new ns/op      delta
BenchmarkScaleLargeDownNN     5771212        5766160        -0.09%
BenchmarkScaleLargeDownAB     14057354       14023083       -0.24%
BenchmarkScaleLargeDownBL     1349968635     1347746478     -0.16%
BenchmarkScaleLargeDownCR     2687753329     2678909022     -0.33%
BenchmarkScaleDownNN          1802408        1808723        +0.35%
BenchmarkScaleDownAB          4352978        4284878        -1.56%
BenchmarkScaleDownBL          29760913       29522171       -0.80%
BenchmarkScaleDownCR          57666917       56334005       -2.31%
BenchmarkScaleUpNN            88886450       89235790       +0.39%
BenchmarkScaleUpAB            214687758      213797857      -0.41%
BenchmarkScaleUpBL            119588096      119846371      +0.22%
BenchmarkScaleUpCR            179784111      180662030      +0.49%
BenchmarkScaleSrcUniform      4128528        3855385        -6.62%
BenchmarkScaleSrcNRGBA        13275457       13375039       +0.75%
BenchmarkScaleSrcRGBA         13333672       12812895       -3.91%
BenchmarkScaleSrcYCbCr        14321945       14139071       -1.28%

Change-Id: I28025c3b49186a12d20ee0182a4c8ff9b036d0ae
Reviewed-on: https://go-review.googlesource.com/5712
Reviewed-by: Rob Pike <r@golang.org>
2015-02-24 06:30:29 +00:00
Nigel Tao
96b77d5c7a draw: new package, a superset of the standard library's image/draw
package, including the ability to scale an image.

Design discussion:
https://groups.google.com/forum/#!topic/golang-dev/B7-OrWdheic

Previous code review (when Go used hg instead of git):
https://codereview.appspot.com/101670045

New benchmarks:
BenchmarkScaleLargeDownNN	     300	   5935174 ns/op
BenchmarkScaleLargeDownAB	     100	  14482372 ns/op
BenchmarkScaleLargeDownBL	       1	1383805986 ns/op
BenchmarkScaleLargeDownCR	       1	2724631789 ns/op
BenchmarkScaleDownNN     	    1000	   1850500 ns/op
BenchmarkScaleDownAB     	     300	   4413499 ns/op
BenchmarkScaleDownBL     	      50	  30498748 ns/op
BenchmarkScaleDownCR     	      20	  58349653 ns/op
BenchmarkScaleUpNN       	      20	  92306475 ns/op
BenchmarkScaleUpAB       	       5	 220103753 ns/op
BenchmarkScaleUpBL       	      10	 122635195 ns/op
BenchmarkScaleUpCR       	      10	 183275927 ns/op

Change-Id: I69d397e68897bae024c7b330a9375fa3e7688591
Reviewed-on: https://go-review.googlesource.com/4210
Reviewed-by: Rob Pike <r@golang.org>
2015-02-17 23:20:02 +00:00