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>
diff --git a/draw/example_test.go b/draw/example_test.go
index 5a1ee69..bcb4662 100644
--- a/draw/example_test.go
+++ b/draw/example_test.go
@@ -37,7 +37,7 @@
draw.CatmullRom,
}
const cos60, sin60 = 0.5, 0.866025404
- t := &f64.Aff3{
+ t := f64.Aff3{
+2 * cos60, -2 * sin60, 100,
+2 * sin60, +2 * cos60, 100,
}
@@ -67,7 +67,7 @@
for i, op := range ops {
dr := image.Rect(120+10*i, 150+60*i, 170+10*i, 200+60*i)
draw.NearestNeighbor.Scale(dst, dr, red, red.Bounds(), op, nil)
- t := &f64.Aff3{
+ t := f64.Aff3{
+cos60, -sin60, float64(190 + 10*i),
+sin60, +cos60, float64(140 + 50*i),
}
diff --git a/draw/gen.go b/draw/gen.go
index 4ce213a..f1e80af 100644
--- a/draw/gen.go
+++ b/draw/gen.go
@@ -913,13 +913,13 @@
}
}
- func (z $receiver) Transform(dst Image, s2d *f64.Aff3, src image.Image, sr image.Rectangle, op Op, opts *Options) {
+ func (z $receiver) Transform(dst Image, s2d f64.Aff3, src image.Image, sr image.Rectangle, op Op, opts *Options) {
var o Options
if opts != nil {
o = *opts
}
- dr := transformRect(s2d, &sr)
+ dr := transformRect(&s2d, &sr)
// adr is the affected destination pixels.
adr := dst.Bounds().Intersect(dr)
adr, o.DstMask = clipAffectedDestRect(adr, o.DstMask, o.DstMaskP)
@@ -930,7 +930,7 @@
op = Src
}
- d2s := invert(s2d)
+ d2s := invert(&s2d)
// bias is a translation of the mapping from dst coordinates to src
// coordinates such that the latter temporarily have non-negative X
// and Y coordinates. This allows us to write int(f) instead of
@@ -1179,13 +1179,13 @@
}
}
- func (q *Kernel) Transform(dst Image, s2d *f64.Aff3, src image.Image, sr image.Rectangle, op Op, opts *Options) {
+ func (q *Kernel) Transform(dst Image, s2d f64.Aff3, src image.Image, sr image.Rectangle, op Op, opts *Options) {
var o Options
if opts != nil {
o = *opts
}
- dr := transformRect(s2d, &sr)
+ dr := transformRect(&s2d, &sr)
// adr is the affected destination pixels.
adr := dst.Bounds().Intersect(dr)
adr, o.DstMask = clipAffectedDestRect(adr, o.DstMask, o.DstMaskP)
@@ -1195,7 +1195,7 @@
if op == Over && o.SrcMask == nil && opaque(src) {
op = Src
}
- d2s := invert(s2d)
+ d2s := invert(&s2d)
// bias is a translation of the mapping from dst coordinates to src
// coordinates such that the latter temporarily have non-negative X
// and Y coordinates. This allows us to write int(f) instead of
diff --git a/draw/impl.go b/draw/impl.go
index fa93d64..967e4e6 100644
--- a/draw/impl.go
+++ b/draw/impl.go
@@ -97,13 +97,13 @@
}
}
-func (z nnInterpolator) Transform(dst Image, s2d *f64.Aff3, src image.Image, sr image.Rectangle, op Op, opts *Options) {
+func (z nnInterpolator) Transform(dst Image, s2d f64.Aff3, src image.Image, sr image.Rectangle, op Op, opts *Options) {
var o Options
if opts != nil {
o = *opts
}
- dr := transformRect(s2d, &sr)
+ dr := transformRect(&s2d, &sr)
// adr is the affected destination pixels.
adr := dst.Bounds().Intersect(dr)
adr, o.DstMask = clipAffectedDestRect(adr, o.DstMask, o.DstMaskP)
@@ -114,7 +114,7 @@
op = Src
}
- d2s := invert(s2d)
+ d2s := invert(&s2d)
// bias is a translation of the mapping from dst coordinates to src
// coordinates such that the latter temporarily have non-negative X
// and Y coordinates. This allows us to write int(f) instead of
@@ -1118,13 +1118,13 @@
}
}
-func (z ablInterpolator) Transform(dst Image, s2d *f64.Aff3, src image.Image, sr image.Rectangle, op Op, opts *Options) {
+func (z ablInterpolator) Transform(dst Image, s2d f64.Aff3, src image.Image, sr image.Rectangle, op Op, opts *Options) {
var o Options
if opts != nil {
o = *opts
}
- dr := transformRect(s2d, &sr)
+ dr := transformRect(&s2d, &sr)
// adr is the affected destination pixels.
adr := dst.Bounds().Intersect(dr)
adr, o.DstMask = clipAffectedDestRect(adr, o.DstMask, o.DstMaskP)
@@ -1135,7 +1135,7 @@
op = Src
}
- d2s := invert(s2d)
+ d2s := invert(&s2d)
// bias is a translation of the mapping from dst coordinates to src
// coordinates such that the latter temporarily have non-negative X
// and Y coordinates. This allows us to write int(f) instead of
@@ -4498,13 +4498,13 @@
}
}
-func (q *Kernel) Transform(dst Image, s2d *f64.Aff3, src image.Image, sr image.Rectangle, op Op, opts *Options) {
+func (q *Kernel) Transform(dst Image, s2d f64.Aff3, src image.Image, sr image.Rectangle, op Op, opts *Options) {
var o Options
if opts != nil {
o = *opts
}
- dr := transformRect(s2d, &sr)
+ dr := transformRect(&s2d, &sr)
// adr is the affected destination pixels.
adr := dst.Bounds().Intersect(dr)
adr, o.DstMask = clipAffectedDestRect(adr, o.DstMask, o.DstMaskP)
@@ -4514,7 +4514,7 @@
if op == Over && o.SrcMask == nil && opaque(src) {
op = Src
}
- d2s := invert(s2d)
+ d2s := invert(&s2d)
// bias is a translation of the mapping from dst coordinates to src
// coordinates such that the latter temporarily have non-negative X
// and Y coordinates. This allows us to write int(f) instead of
diff --git a/draw/scale.go b/draw/scale.go
index 6c9e93a..98ab404 100644
--- a/draw/scale.go
+++ b/draw/scale.go
@@ -54,7 +54,7 @@
//
// A Transformer is safe to use concurrently.
type Transformer interface {
- Transform(dst Image, m *f64.Aff3, src image.Image, sr image.Rectangle, op Op, opts *Options)
+ Transform(dst Image, m f64.Aff3, src image.Image, sr image.Rectangle, op Op, opts *Options)
}
// Options are optional parameters to Copy, Scale and Transform.
diff --git a/draw/scale_test.go b/draw/scale_test.go
index b1f3db9..ca04a39 100644
--- a/draw/scale_test.go
+++ b/draw/scale_test.go
@@ -23,9 +23,9 @@
var genGoldenFiles = flag.Bool("gen_golden_files", false, "whether to generate the TestXxx golden files.")
-var transformMatrix = func(scale, tx, ty float64) *f64.Aff3 {
+var transformMatrix = func(scale, tx, ty float64) f64.Aff3 {
const cos30, sin30 = 0.866025404, 0.5
- return &f64.Aff3{
+ return f64.Aff3{
+scale * cos30, -scale * sin30, tx,
+scale * sin30, +scale * cos30, ty,
}
@@ -297,11 +297,11 @@
tsrc := &translatedImage{src, delta}
got := image.NewRGBA(image.Rect(0, 0, 20, 20))
if transform {
- m := matMul(m00, &f64.Aff3{
+ m := matMul(&m00, &f64.Aff3{
1, 0, -float64(delta.X),
0, 1, -float64(delta.Y),
})
- q.Transform(got, &m, tsrc, sr.Add(delta), Over, nil)
+ q.Transform(got, m, tsrc, sr.Add(delta), Over, nil)
} else {
q.Scale(got, got.Bounds(), tsrc, sr.Add(delta), Over, nil)
}