Commit Graph

26 Commits

Author SHA1 Message Date
Alexander Weinhold
c2f707aba7 change paths 2018-12-06 17:03:52 +01:00
Dmitri Shuralyov
249dc8530c draw: re-enable the image.Rectangle DstMask fast path
This change reverts the remaining part of CL 9463,
the image.Rectangle DstMask fast path, since Go 1.5
has been released.

	$ go test -bench=. -count=5 -timeout=1h > before.txt
	$ # apply change
	$ go test -bench=. -count=5 -timeout=1h > after.txt
	$ benchstat before.txt after.txt
	name                    old time/op    new time/op    delta
	SimpleScaleCopy-8         23.4µs ± 3%    21.8µs ± 4%   -7.14%  (p=0.016 n=5+5)
	SimpleTransformCopy-8     22.6µs ± 6%    21.4µs ± 1%   -5.07%  (p=0.008 n=5+5)
	SimpleTransformScale-8     904µs ± 0%     900µs ± 0%     ~     (p=0.056 n=5+5)
	ScaleNNLargeDown-8         641µs ± 1%     643µs ± 1%     ~     (p=0.548 n=5+5)
	ScaleABLargeDown-8        1.50ms ± 1%    1.50ms ± 1%     ~     (p=0.413 n=5+4)
	ScaleBLLargeDown-8         192ms ± 5%     196ms ± 4%     ~     (p=0.095 n=5+5)
	ScaleCRLargeDown-8         355ms ± 4%     350ms ± 2%     ~     (p=0.690 n=5+5)
	ScaleNNDown-8              134µs ± 2%     126µs ± 1%   -5.68%  (p=0.008 n=5+5)
	ScaleABDown-8              261µs ± 3%     256µs ± 1%   -1.92%  (p=0.016 n=5+5)
	ScaleBLDown-8             2.42ms ± 3%    2.44ms ± 8%     ~     (p=0.841 n=5+5)
	ScaleCRDown-8             4.36ms ± 1%    4.85ms ± 4%  +11.22%  (p=0.008 n=5+5)
	ScaleNNUp-8               6.27ms ± 2%    6.72ms ± 3%   +7.20%  (p=0.008 n=5+5)
	ScaleABUp-8               12.8ms ± 1%    13.8ms ± 2%   +7.26%  (p=0.008 n=5+5)
	ScaleBLUp-8               17.5ms ± 7%    17.4ms ± 2%     ~     (p=1.000 n=5+5)
	ScaleCRUp-8               23.2ms ± 2%    23.1ms ± 4%     ~     (p=0.690 n=5+5)
	ScaleNNSrcRGBA-8           419µs ± 1%     421µs ± 3%     ~     (p=0.690 n=5+5)
	ScaleNNSrcUnif-8          3.35µs ± 3%    3.35µs ± 2%     ~     (p=1.000 n=5+5)
	ScaleNNOverRGBA-8          470µs ± 1%     479µs ± 5%     ~     (p=0.548 n=5+5)
	ScaleNNOverUnif-8          102µs ± 2%     102µs ± 1%     ~     (p=0.222 n=5+5)
	TformNNSrcRGBA-8           215µs ± 1%     213µs ± 1%     ~     (p=0.222 n=5+5)
	TformNNSrcUnif-8          84.2µs ± 1%    86.6µs ± 2%   +2.82%  (p=0.016 n=5+5)
	TformNNOverRGBA-8          351µs ± 5%     359µs ± 0%     ~     (p=0.151 n=5+5)
	TformNNOverUnif-8          101µs ± 1%     104µs ± 1%   +3.47%  (p=0.008 n=5+5)
	ScaleABSrcGray-8           399µs ± 2%     400µs ± 2%     ~     (p=0.690 n=5+5)
	ScaleABSrcNRGBA-8          795µs ± 1%     809µs ± 4%     ~     (p=0.095 n=5+5)
	ScaleABSrcRGBA-8           807µs ± 1%     807µs ± 2%     ~     (p=1.000 n=5+5)
	ScaleABSrcYCbCr-8         1.50ms ± 1%    1.48ms ± 0%   -0.76%  (p=0.032 n=5+5)
	ScaleABOverGray-8          396µs ± 0%     395µs ± 1%     ~     (p=0.421 n=5+5)
	ScaleABOverNRGBA-8         886µs ± 1%     885µs ± 1%     ~     (p=0.556 n=4+5)
	ScaleABOverRGBA-8          893µs ± 1%     895µs ± 1%     ~     (p=0.310 n=5+5)
	ScaleABOverYCbCr-8        1.49ms ± 1%    1.49ms ± 1%     ~     (p=0.548 n=5+5)
	TformABSrcGray-8           359µs ± 1%     364µs ± 3%     ~     (p=0.421 n=5+5)
	TformABSrcNRGBA-8          618µs ± 1%     660µs ± 3%   +6.81%  (p=0.008 n=5+5)
	TformABSrcRGBA-8           614µs ± 1%     638µs ± 5%   +3.94%  (p=0.008 n=5+5)
	TformABSrcYCbCr-8          903µs ± 1%     913µs ± 2%     ~     (p=0.056 n=5+5)
	TformABOverGray-8          362µs ± 3%     358µs ± 1%     ~     (p=0.421 n=5+5)
	TformABOverNRGBA-8         691µs ± 1%     690µs ± 1%     ~     (p=0.841 n=5+5)
	TformABOverRGBA-8          671µs ± 1%     673µs ± 1%     ~     (p=0.690 n=5+5)
	TformABOverYCbCr-8         904µs ± 1%     906µs ± 0%     ~     (p=0.190 n=5+4)
	ScaleCRSrcGray-8          9.24ms ± 1%    9.16ms ± 1%     ~     (p=0.222 n=5+5)
	ScaleCRSrcNRGBA-8         21.9ms ± 2%    21.7ms ± 1%     ~     (p=0.222 n=5+5)
	ScaleCRSrcRGBA-8          22.5ms ± 8%    21.8ms ± 1%     ~     (p=1.000 n=5+5)
	ScaleCRSrcYCbCr-8         43.6ms ± 1%    43.9ms ± 1%     ~     (p=0.222 n=5+5)
	ScaleCROverGray-8         9.24ms ± 0%    9.35ms ± 6%     ~     (p=0.690 n=5+5)
	ScaleCROverNRGBA-8        21.9ms ± 1%    21.8ms ± 1%     ~     (p=0.548 n=5+5)
	ScaleCROverRGBA-8         21.8ms ± 0%    22.0ms ± 1%   +0.94%  (p=0.008 n=5+5)
	ScaleCROverYCbCr-8        43.5ms ± 1%    44.1ms ± 1%   +1.53%  (p=0.008 n=5+5)
	TformCRSrcGray-8          3.16ms ± 4%    3.06ms ± 1%     ~     (p=0.056 n=5+5)
	TformCRSrcNRGBA-8         4.21ms ± 1%    4.20ms ± 1%     ~     (p=0.841 n=5+5)
	TformCRSrcRGBA-8          4.29ms ± 1%    4.29ms ± 1%     ~     (p=0.841 n=5+5)
	TformCRSrcYCbCr-8         5.55ms ± 1%    5.58ms ± 0%   +0.67%  (p=0.032 n=5+4)
	TformCROverGray-8         3.08ms ± 1%    3.07ms ± 2%     ~     (p=0.421 n=5+5)
	TformCROverNRGBA-8        4.40ms ± 1%    4.39ms ± 0%     ~     (p=0.841 n=5+5)
	TformCROverRGBA-8         4.50ms ± 5%    4.44ms ± 0%     ~     (p=0.730 n=5+4)
	TformCROverYCbCr-8        5.57ms ± 0%    5.61ms ± 1%     ~     (p=0.095 n=5+5)

Change-Id: I981861c28e103b68275a82e051d2999a8e714502
Reviewed-on: https://go-review.googlesource.com/c/148575
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-09 23:22:46 +00:00
Dmitri Shuralyov
22fd5b5408 draw: fix Transformer documentation formatting
Each span of unindented non-blank lines is converted into a
single paragraph. This isn't desired here. Indent the matrix,
so that it's converted into a <pre> block. That also prevents
the previous line from being interpreted as a heading.

Reference: https://godoc.org/go/doc#ToHTML

Fixes golang/go#28683

Change-Id: Ibc5488d5cc66fe3a5f2bbe2fe23628dd08276037
Reviewed-on: https://go-review.googlesource.com/c/148573
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-08 22:41:23 +00:00
Igor Zhilianin
69cc3646b9 all: fix typos
Change-Id: I2140a1a74d1319d9b8746efad539bfaae6038a2d
GitHub-Last-Rev: b00b49e87ed3adb72d11c81e4cff98671d411b52
GitHub-Pull-Request: golang/image#1
Reviewed-on: https://go-review.googlesource.com/c/145740
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-10-30 00:21:51 +00:00
Nigel Tao
5c9906b535 image/draw: have Transform take a f64.Aff3 instead of a *f64.Aff3.
It's more args (in terms of bytes), but fewer allocations (Transformer
is an interface). Either way, it's not really that big of a deal, but
the value instead of the pointer seems conceptually more correct.

Change-Id: Ibea76da17cbda0d9633110fd56044b4e2c690e81
Reviewed-on: https://go-review.googlesource.com/12669
Reviewed-by: Rob Pike <r@golang.org>
2015-07-29 01:18:37 +00:00
Nigel Tao
70cb8023e6 draw: make op a mandatory argument, not optional.
Change-Id: Ic08ce587cf458444b098b752f0fa7ab16d43c914
Reviewed-on: https://go-review.googlesource.com/9468
Reviewed-by: Rob Pike <r@golang.org>
2015-05-04 06:41:52 +00:00
Nigel Tao
918b3735c3 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 <r@golang.org>
2015-04-29 03:28:00 +00:00
Nigel Tao
8642173156 draw: implement srcMask.
Change-Id: Ibf710521f466847afaf2d005dc8a2bb817169298
Reviewed-on: https://go-review.googlesource.com/9276
Reviewed-by: Rob Pike <r@golang.org>
2015-04-26 09:25:24 +00:00
Nigel Tao
24b0de15f1 draw: add a fast path for an image.Rectangle DstMask.
Change-Id: Id5227b9d217b56a342bc1ffc735dababa8a9e3e9
Reviewed-on: https://go-review.googlesource.com/9233
Reviewed-by: Rob Pike <r@golang.org>
2015-04-24 00:51:48 +00:00
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
69a0d8f9aa draw: add mask fields to Options.
This change only adds the fields, more or less. Follow-up changes will
actually honor the masks.

Change-Id: I81411dc1aac4b3c846dcdf13e2cb0b5cd60fb2b4
Reviewed-on: https://go-review.googlesource.com/8902
Reviewed-by: Rob Pike <r@golang.org>
2015-04-16 00:20:49 +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
67c770d218 draw: substitute Src for Over when the source image is completely opaque.
The two Ops are equivalent, but Src is faster.

Change-Id: I2c73a13755047c224c71fb5af786875f02681de9
Reviewed-on: https://go-review.googlesource.com/8640
Reviewed-by: Rob Pike <r@golang.org>
2015-04-08 22:38:33 +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
7eedc6044d draw: add Scale and Transform fast paths for Uniform src images.
benchmark                      old ns/op     new ns/op     delta
BenchmarkScaleSrcUniform       1744610       6305          -99.64%
BenchmarkTformABSrcUniform     586201        520028        -11.29%
BenchmarkTformCRSrcUniform     586952        519151        -11.55%

Change-Id: Ide9148f9e91bb6ec607fa7e9d78b35772ca189fe
Reviewed-on: https://go-review.googlesource.com/7881
Reviewed-by: Rob Pike <r@golang.org>
2015-03-21 04:28:23 +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
efa0c0977f draw: implement Copy; add an example_test.
Change-Id: Ia9cceac17c0326702530eac3a205308b02b85986
Reviewed-on: https://go-review.googlesource.com/7262
Reviewed-by: Rob Pike <r@golang.org>
2015-03-11 22:37:25 +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
93a98e7805 draw: fix a comment typo.
Change-Id: I6d34d091514915333e488cee9e2ddb5a9d78b6a5
Reviewed-on: https://go-review.googlesource.com/6801
Reviewed-by: David Symonds <dsymonds@golang.org>
2015-03-05 00:26:58 +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
999c3975a8 draw: autogenerate impl.go.
Adding fast paths for concrete dst and src image types will be follow-up
changes.

Change-Id: Ib23e3cc46d9c7a52ebd5eddfbad09177b0b421af
Reviewed-on: https://go-review.googlesource.com/5417
Reviewed-by: Rob Pike <r@golang.org>
2015-02-24 00:55:15 +00:00
Nigel Tao
2a1231edb8 draw: factor out the Scale implementations.
This is just a copy/paste/rename in anticipation of automatically
generating fast-path code for specific dst-image types and src-image
types, a la the standard library's image/draw package.

Change-Id: If6385b347cb5e1d134b0ce841ef38ed4450a6fef
Reviewed-on: https://go-review.googlesource.com/5252
Reviewed-by: David Symonds <dsymonds@golang.org>
2015-02-20 07:27:42 +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