Commit Graph

61 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
Dmitri Shuralyov
a3f9a0009f draw: remove Go 1.8 support
This change removes support for Go 1.8 and older, as they're no longer
supported per release policy¹.

This brings back a simpler file layout that was here prior to CL 36730,
but keeps using type aliases for the exported names from the standard
library's image/draw package.

Don't keep the comment motivating type alias use, since that feature is
no longer new, and commonly understood by now.

¹ https://tip.golang.org/doc/devel/release.html#policy

Change-Id: I5fab71162cf6daa5985a048ed06011efacddf886
Reviewed-on: https://go-review.googlesource.com/c/148567
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-11-08 21:44:26 +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
Jiulong Wang
12117c17ca draw: fix crash caused by Scale by Copy shortcut
When DstMask is not nil, this shortcut causes stack overflow because
Copy function in turn will call Scale with same dr and sr.

Fixes golang/go#23107

Change-Id: I8ccadbd9b7f16363ac17b6114308527d6fa9456e
Reviewed-on: https://go-review.googlesource.com/83537
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Run-TryBot: Nigel Tao <nigeltao@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-12-14 22:51:56 +00:00
Russ Cox
e6cbe778da draw: use type aliases for go1.8.typealias builds too
go1.8.typealias is the build tag defined by the unreleased
"Go 1.8 + type aliases" variant in the Go repo's dev.typealias branch.

Change-Id: Iff2566249ecc9a6788b78199743d2005708f1cd7
Reviewed-on: https://go-review.googlesource.com/37511
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-02-27 16:05:05 +00:00
Nigel Tao
306b829431 draw: alias the standard library's image/draw's exported types.
This relies on type aliases, a language feature new in Go 1.9.

The package documentation, in draw.go, explicitly gives the intent of
this package:

    This package is a superset of and a drop-in replacement for the
    image/draw package in the standard library.

Drop-in replacement means that I can replace all of my "image/draw"
imports with "golang.org/x/image/draw", to access additional features in
this package, and no further changes are required. That's mostly true,
but not completely true unless we use type aliases.

Without type aliases, users might need to import both "image/draw" and
"golang.org/x/image/draw" in order to convert from two conceptually
equivalent but different (from the compiler's point of view) types, such
as from one draw.Op type to another draw.Op type, to satisfy some other
interface or function signature.

Change-Id: Ice6d000d49b019c2d8761739a904232e9cd01cae
Reviewed-on: https://go-review.googlesource.com/36730
Run-TryBot: Nigel Tao <nigeltao@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2017-02-15 00:37:23 +00:00
Nigel Tao
df2aa51d44 draw: tweak the YCbCr to RGBA conversion formula again.
This is the golang.org/x equivalent of the golang.org/cl/36732 change to
the standard library.

Change-Id: I71c09a72e24c8e1c013769a6fed8f9a031724d9d
Reviewed-on: https://go-review.googlesource.com/36733
Run-TryBot: Nigel Tao <nigeltao@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2017-02-10 23:08:06 +00:00
Nigel Tao
8e3389fa81 draw: have Scale and Transform recognize straight copies.
This is only for the NearestNeighbor and ApproxBiLinear Interpolators. A
Kernel interpolator will add blur even when the dst and src rectangles
are the same size.

We do not bother recognizing Transforms that are Scales. The performance
difference is minimal, as you still need to do a per-dst-pixel inverse
mapping either way.

benchmark                           old ns/op     new ns/op     delta
BenchmarkSimpleScaleCopy-8          4866297       29586         -99.39%
BenchmarkSimpleTransformCopy-8      4875991       29531         -99.39%
BenchmarkSimpleTransformScale-8     1208147       1223206       +1.25%

Change-Id: If649ad27a4e81bcbb24b18315745c02c9186a5b7
Reviewed-on: https://go-review.googlesource.com/13004
Reviewed-by: Rob Pike <r@golang.org>
2015-08-02 10:47:07 +00:00
Nigel Tao
5f5d3e0618 draw: skip TestFastPaths for Go 1.4.
Fixes golang/go#11921

Change-Id: Iafca8b21523d486ce9b2be494b8fb93216573968
Reviewed-on: https://go-review.googlesource.com/12861
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-07-30 05:48:34 +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
6b7a488d1e draw: tweak the YCbCr to RGBA conversion formula.
This is the golang.org/x equivalent of the golang.org/cl/12220 change to
the standard library.

Change-Id: I220d1398902dec374472ef5b08db8501607cc971
Reviewed-on: https://go-review.googlesource.com/12222
Reviewed-by: Rob Pike <r@golang.org>
2015-07-15 05:30:06 +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
b621bdc118 draw: delete some dead code.
Change-Id: I5830755b0be52df2be536a918f47684a1b7eda9d
Reviewed-on: https://go-review.googlesource.com/9232
Reviewed-by: Rob Pike <r@golang.org>
2015-04-22 05:24:54 +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
76b4869e5a draw: factor out some float64 to uint32 conversions.
This will make the upcoming "implement masks" change easier.

Change-Id: I2b316a0b25f98779d9cd076e64266c617464a08e
Reviewed-on: https://go-review.googlesource.com/8999
Reviewed-by: Rob Pike <r@golang.org>
2015-04-21 01:05:21 +00:00
Nigel Tao
26bd17363f draw: plumb the Options through to the type-specific code.
It'll only be used by the fallback code paths, but it's easiest if all
code paths take the extra argument.

Change-Id: I09c4067df6af7c4cd270e8ffcad96d1d8af29057
Reviewed-on: https://go-review.googlesource.com/8909
Reviewed-by: Rob Pike <r@golang.org>
2015-04-16 23:50:31 +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
e83a2376af draw: refactor codegen to use argf instead of fmt.Sprintf.
Change-Id: Iee4cb1b605c381b75a688a5e65e9afc4d34df193
Reviewed-on: https://go-review.googlesource.com/8900
Reviewed-by: Rob Pike <r@golang.org>
2015-04-14 01:31:41 +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
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
65a798f031 draw: generate code for op == Over.
This change just does the mechanical codegen for the op == Over cases.
The actual compositing operator is still effectively Src. Fixing that,
which is less mechanical, will be a follow-up change.

Change-Id: I87805114d49e7ce7087066187a2f4c722a883c01
Reviewed-on: https://go-review.googlesource.com/8524
Reviewed-by: Rob Pike <r@golang.org>
2015-04-07 22:35:06 +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
d5c5125b57 draw: update the inlined YCbCr.RGBA code to use 16 bit color.
This matches the standard library change at
https://go-review.googlesource.com/#/c/8073/

Change-Id: I216028e18678a70e449167cd9ab910c63d37adcc
Reviewed-on: https://go-review.googlesource.com/8075
Reviewed-by: Rob Pike <r@golang.org>
2015-03-26 22:31:54 +00:00
Nigel Tao
500a27f912 draw: optimize some multiply-by-zeroes in Kernel.Transform.
benchmark                      old ns/op     new ns/op     delta
BenchmarkTformCRSrcGray        5096041       4820642       -5.40%
BenchmarkTformCRSrcNRGBA       10476578      8414331       -19.68%
BenchmarkTformCRSrcRGBA        10361135      7954413       -23.23%
BenchmarkTformCRSrcYCbCr       11952218      9824899       -17.80%

Change-Id: I8b4cfe68ecae85e447ae65ceecf185261445a8a2
Reviewed-on: https://go-review.googlesource.com/7991
Reviewed-by: Rob Pike <r@golang.org>
2015-03-25 21:02:11 +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
41f747b91e draw: inline the generated YCbCrToRGB calls.
benchmark                      old ns/op     new ns/op     delta
BenchmarkScaleLargeDownNN      1302036       1168046       -10.29%
BenchmarkScaleLargeDownAB      3995006       3447621       -13.70%
BenchmarkScaleLargeDownBL      455470707     387598726     -14.90%
BenchmarkScaleLargeDownCR      818317661     679199442     -17.00%
BenchmarkScaleSrcYCbCr         3965076       3422325       -13.69%
BenchmarkTformABSrcYCbCr       2921253       2551934       -12.64%
BenchmarkTformCRSrcYCbCr       14839184      12263956      -17.35%

Change-Id: I60dcb5c00a30709fdc6616cbc8c2fc48ec3a8b14
Reviewed-on: https://go-review.googlesource.com/7921
Reviewed-by: Rob Pike <r@golang.org>
2015-03-23 00:17:39 +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
4180bcbc4a draw: inline the generated PixOffset calls.
Only the YCbCr benchmarks show significant changes. The other benchmark
changes look noisy. The PixOffset and YOffset calls were previously
already inlined by the gc compiler. COffset was different because it's
more complicated than YOffset, and the switch inside the COffset body is
redundant when you already know the src image sratio.
http://golang.org/src/image/ycbcr.go?s=2377:2414#L77

benchmark                      old ns/op     new ns/op     delta
BenchmarkScaleLargeDownNN      1037504       908236        -12.46%
BenchmarkScaleLargeDownAB      3196568       2735776       -14.42%
BenchmarkScaleLargeDownBL      357165552     311463393     -12.80%
BenchmarkScaleLargeDownCR      649403305     544985134     -16.08%
BenchmarkScaleSrcYCbCr         3204063       2699147       -15.76%
BenchmarkTformABSrcYCbCr       2155142       1968540       -8.66%
BenchmarkTformCRSrcYCbCr       11672625      9865358       -15.48%

Change-Id: Ifa109363a1282ab114b2fdb0b577dcafef927333
Reviewed-on: https://go-review.googlesource.com/7880
Reviewed-by: Rob Pike <r@golang.org>
2015-03-21 04:17:09 +00:00
Nigel Tao
415cb3b420 draw: add Scale and Transform fast paths for YCbCr src images.
benchmark                      old ns/op      new ns/op     delta
BenchmarkScaleLargeDownNN      3239565        1044458       -67.76%
BenchmarkScaleLargeDownAB      12162059       3205972       -73.64%
BenchmarkScaleLargeDownBL      1437923310     358229213     -75.09%
BenchmarkScaleLargeDownCR      2844139449     651228380     -77.10%
BenchmarkScaleSrcYCbCr         12413692       3176042       -74.42%
BenchmarkTformABSrcYCbCr       8363947        2163052       -74.14%
BenchmarkTformCRSrcYCbCr       49944171       11652821      -76.67%

Change-Id: I8cd5ab20aa1f516114599690cab037441a328aec
Reviewed-on: https://go-review.googlesource.com/7796
Reviewed-by: Rob Pike <r@golang.org>
2015-03-20 00:55:56 +00:00
Nigel Tao
c62001d39b draw: optimize Kernel.Transform.
benchmark                      old ns/op      new ns/op      delta
BenchmarkTformCRSrcGray        6111610        5344117        -12.56%
BenchmarkTformCRSrcNRGBA       62070281       59295178       -4.47%
BenchmarkTformCRSrcRGBA        13840290       10612547       -23.32%
BenchmarkTformCRSrcUniform     591637         587621         -0.68%
BenchmarkTformCRSrcYCbCr       72219184       69404747       -3.90%

As of current origin/master, Gray and RGBA have fast paths but the other src
image types do not. They have more fat, so the relative improvement is smaller.

Change-Id: Ibbae91cd3cb3c139efb1dcc8fda1cb6432505189
Reviewed-on: https://go-review.googlesource.com/7794
Reviewed-by: Rob Pike <r@golang.org>
2015-03-19 21:20:14 +00:00
Nigel Tao
ffd1dee1b5 draw: add a fast path for NRGBA src images.
benchmark                      old ns/op      new ns/op      delta
BenchmarkScaleSrcNRGBA         14142583       2043782        -85.55%
BenchmarkTformABSrcNRGBA       9846421        1993564        -79.75%
BenchmarkTformCRSrcNRGBA       62041569       13866457       -77.65%

Change-Id: I1edf699dfc6436c0da7e3ab221684406ab1e362f
Reviewed-on: https://go-review.googlesource.com/7793
Reviewed-by: Rob Pike <r@golang.org>
2015-03-19 21:00:06 +00:00
Nigel Tao
5fe9683216 draw: change tweaks to be at end-of-line, not start-of-line.
I think it reads better that way.

Change-Id: I770fdb6362d2a281f7c62cabade186725daced9b
Reviewed-on: https://go-review.googlesource.com/7714
Reviewed-by: Rob Pike <r@golang.org>
2015-03-19 06:15:25 +00:00
Nigel Tao
ad68cd9759 draw: distinguish YCbCr fast paths by their chroma subsample ratios.
These code paths aren't actually fast yet. That will be a follow-up
change.

Change-Id: I814992573cc6af422e49d0ddf336003e662897a5
Reviewed-on: https://go-review.googlesource.com/7791
Reviewed-by: Rob Pike <r@golang.org>
2015-03-19 00:59:56 +00:00
Nigel Tao
2f47ec36fb draw: add a fast path for Gray src images.
benchmark                      old ns/op      new ns/op      delta
BenchmarkScaleSrcGray          9296680        552705         -94.05%
BenchmarkTformABSrcGray        6323894        817986         -87.07%
BenchmarkTformCRSrcGray        39229583       4193194        -89.31%

Change-Id: Ie7d43dfe323d49b245b47c3206b5aad2b50cb7fb
Reviewed-on: https://go-review.googlesource.com/7711
Reviewed-by: Rob Pike <r@golang.org>
2015-03-18 06:04:53 +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
9b6f4595fb draw: actually use type-specific Transform code paths.
I simply forgot to do this in the previous change.

Change-Id: I0ea5d6bb0a09154cb995a665476ffceb155bd49e
Reviewed-on: https://go-review.googlesource.com/7651
Reviewed-by: Rob Pike <r@golang.org>
2015-03-17 01:16:05 +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
ab1ce1a88c draw: make example_test more example-like, by being outside "package
draw".

Change-Id: Ie65c96a81250866c5813d4e3a8843b1168ed5579
Reviewed-on: https://go-review.googlesource.com/7612
Reviewed-by: Rob Pike <r@golang.org>
2015-03-15 21:34:34 +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
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