summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/disintegration/imaging/transform_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/disintegration/imaging/transform_test.go')
-rw-r--r--vendor/github.com/disintegration/imaging/transform_test.go246
1 files changed, 201 insertions, 45 deletions
diff --git a/vendor/github.com/disintegration/imaging/transform_test.go b/vendor/github.com/disintegration/imaging/transform_test.go
index 6e64082f4..3772225a3 100644
--- a/vendor/github.com/disintegration/imaging/transform_test.go
+++ b/vendor/github.com/disintegration/imaging/transform_test.go
@@ -2,17 +2,18 @@ package imaging
import (
"image"
+ "image/color"
"testing"
)
-func TestRotate90(t *testing.T) {
+func TestFlipH(t *testing.T) {
td := []struct {
desc string
src image.Image
want *image.NRGBA
}{
{
- "Rotate90 2x3",
+ "FlipH 2x3",
&image.NRGBA{
Rect: image.Rect(-1, -1, 1, 2),
Stride: 2 * 4,
@@ -23,17 +24,18 @@ func TestRotate90(t *testing.T) {
},
},
&image.NRGBA{
- Rect: image.Rect(0, 0, 3, 2),
- Stride: 3 * 4,
+ Rect: image.Rect(0, 0, 2, 3),
+ Stride: 2 * 4,
Pix: []uint8{
- 0xcc, 0xdd, 0xee, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
- 0x00, 0x11, 0x22, 0x33, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00,
+ 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33,
+ 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00,
},
},
},
}
for _, d := range td {
- got := Rotate90(d.src)
+ got := FlipH(d.src)
want := d.want
if !compareNRGBA(got, want, 0) {
t.Errorf("test [%s] failed: %#v", d.desc, got)
@@ -41,14 +43,14 @@ func TestRotate90(t *testing.T) {
}
}
-func TestRotate180(t *testing.T) {
+func TestFlipV(t *testing.T) {
td := []struct {
desc string
src image.Image
want *image.NRGBA
}{
{
- "Rotate180 2x3",
+ "FlipV 2x3",
&image.NRGBA{
Rect: image.Rect(-1, -1, 1, 2),
Stride: 2 * 4,
@@ -62,15 +64,15 @@ func TestRotate180(t *testing.T) {
Rect: image.Rect(0, 0, 2, 3),
Stride: 2 * 4,
Pix: []uint8{
- 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00,
- 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
- 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33,
+ 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff,
+ 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00,
+ 0x00, 0x11, 0x22, 0x33, 0xcc, 0xdd, 0xee, 0xff,
},
},
},
}
for _, d := range td {
- got := Rotate180(d.src)
+ got := FlipV(d.src)
want := d.want
if !compareNRGBA(got, want, 0) {
t.Errorf("test [%s] failed: %#v", d.desc, got)
@@ -78,14 +80,14 @@ func TestRotate180(t *testing.T) {
}
}
-func TestRotate270(t *testing.T) {
+func TestTranspose(t *testing.T) {
td := []struct {
desc string
src image.Image
want *image.NRGBA
}{
{
- "Rotate270 2x3",
+ "Transpose 2x3",
&image.NRGBA{
Rect: image.Rect(-1, -1, 1, 2),
Stride: 2 * 4,
@@ -99,14 +101,14 @@ func TestRotate270(t *testing.T) {
Rect: image.Rect(0, 0, 3, 2),
Stride: 3 * 4,
Pix: []uint8{
- 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x11, 0x22, 0x33,
- 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xcc, 0xdd, 0xee, 0xff,
+ 0x00, 0x11, 0x22, 0x33, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00,
+ 0xcc, 0xdd, 0xee, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
},
},
},
}
for _, d := range td {
- got := Rotate270(d.src)
+ got := Transpose(d.src)
want := d.want
if !compareNRGBA(got, want, 0) {
t.Errorf("test [%s] failed: %#v", d.desc, got)
@@ -114,14 +116,14 @@ func TestRotate270(t *testing.T) {
}
}
-func TestFlipV(t *testing.T) {
+func TestTransverse(t *testing.T) {
td := []struct {
desc string
src image.Image
want *image.NRGBA
}{
{
- "FlipV 2x3",
+ "Transverse 2x3",
&image.NRGBA{
Rect: image.Rect(-1, -1, 1, 2),
Stride: 2 * 4,
@@ -132,18 +134,17 @@ func TestFlipV(t *testing.T) {
},
},
&image.NRGBA{
- Rect: image.Rect(0, 0, 2, 3),
- Stride: 2 * 4,
+ Rect: image.Rect(0, 0, 3, 2),
+ Stride: 3 * 4,
Pix: []uint8{
- 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff,
- 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00,
- 0x00, 0x11, 0x22, 0x33, 0xcc, 0xdd, 0xee, 0xff,
+ 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xcc, 0xdd, 0xee, 0xff,
+ 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x11, 0x22, 0x33,
},
},
},
}
for _, d := range td {
- got := FlipV(d.src)
+ got := Transverse(d.src)
want := d.want
if !compareNRGBA(got, want, 0) {
t.Errorf("test [%s] failed: %#v", d.desc, got)
@@ -151,14 +152,14 @@ func TestFlipV(t *testing.T) {
}
}
-func TestFlipH(t *testing.T) {
+func TestRotate90(t *testing.T) {
td := []struct {
desc string
src image.Image
want *image.NRGBA
}{
{
- "FlipH 2x3",
+ "Rotate90 2x3",
&image.NRGBA{
Rect: image.Rect(-1, -1, 1, 2),
Stride: 2 * 4,
@@ -169,18 +170,17 @@ func TestFlipH(t *testing.T) {
},
},
&image.NRGBA{
- Rect: image.Rect(0, 0, 2, 3),
- Stride: 2 * 4,
+ Rect: image.Rect(0, 0, 3, 2),
+ Stride: 3 * 4,
Pix: []uint8{
- 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33,
- 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00,
+ 0xcc, 0xdd, 0xee, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
+ 0x00, 0x11, 0x22, 0x33, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00,
},
},
},
}
for _, d := range td {
- got := FlipH(d.src)
+ got := Rotate90(d.src)
want := d.want
if !compareNRGBA(got, want, 0) {
t.Errorf("test [%s] failed: %#v", d.desc, got)
@@ -188,14 +188,14 @@ func TestFlipH(t *testing.T) {
}
}
-func TestTranspose(t *testing.T) {
+func TestRotate180(t *testing.T) {
td := []struct {
desc string
src image.Image
want *image.NRGBA
}{
{
- "Transpose 2x3",
+ "Rotate180 2x3",
&image.NRGBA{
Rect: image.Rect(-1, -1, 1, 2),
Stride: 2 * 4,
@@ -206,17 +206,18 @@ func TestTranspose(t *testing.T) {
},
},
&image.NRGBA{
- Rect: image.Rect(0, 0, 3, 2),
- Stride: 3 * 4,
+ Rect: image.Rect(0, 0, 2, 3),
+ Stride: 2 * 4,
Pix: []uint8{
- 0x00, 0x11, 0x22, 0x33, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00,
- 0xcc, 0xdd, 0xee, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
+ 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00,
+ 0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
+ 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33,
},
},
},
}
for _, d := range td {
- got := Transpose(d.src)
+ got := Rotate180(d.src)
want := d.want
if !compareNRGBA(got, want, 0) {
t.Errorf("test [%s] failed: %#v", d.desc, got)
@@ -224,14 +225,14 @@ func TestTranspose(t *testing.T) {
}
}
-func TestTransverse(t *testing.T) {
+func TestRotate270(t *testing.T) {
td := []struct {
desc string
src image.Image
want *image.NRGBA
}{
{
- "Transverse 2x3",
+ "Rotate270 2x3",
&image.NRGBA{
Rect: image.Rect(-1, -1, 1, 2),
Stride: 2 * 4,
@@ -245,17 +246,172 @@ func TestTransverse(t *testing.T) {
Rect: image.Rect(0, 0, 3, 2),
Stride: 3 * 4,
Pix: []uint8{
- 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xcc, 0xdd, 0xee, 0xff,
0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x11, 0x22, 0x33,
+ 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xcc, 0xdd, 0xee, 0xff,
},
},
},
}
for _, d := range td {
- got := Transverse(d.src)
+ got := Rotate270(d.src)
want := d.want
if !compareNRGBA(got, want, 0) {
t.Errorf("test [%s] failed: %#v", d.desc, got)
}
}
}
+
+func TestRotate(t *testing.T) {
+ testCases := []struct {
+ desc string
+ src image.Image
+ angle float64
+ bg color.Color
+ want *image.NRGBA
+ }{
+ {
+ "Rotate 0",
+ &image.NRGBA{
+ Rect: image.Rect(-1, -1, 3, 3),
+ Stride: 4 * 4,
+ Pix: []uint8{
+ 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
+ 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ },
+ },
+ 0,
+ color.Black,
+ &image.NRGBA{
+ Rect: image.Rect(0, 0, 4, 4),
+ Stride: 4 * 4,
+ Pix: []uint8{
+ 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
+ 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ },
+ },
+ },
+ {
+ "Rotate 90",
+ &image.NRGBA{
+ Rect: image.Rect(-1, -1, 3, 3),
+ Stride: 4 * 4,
+ Pix: []uint8{
+ 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
+ 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ },
+ },
+ 90,
+ color.Black,
+ &image.NRGBA{
+ Rect: image.Rect(0, 0, 4, 4),
+ Stride: 4 * 4,
+ Pix: []uint8{
+ 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ },
+ },
+ },
+ {
+ "Rotate 180",
+ &image.NRGBA{
+ Rect: image.Rect(-1, -1, 3, 3),
+ Stride: 4 * 4,
+ Pix: []uint8{
+ 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
+ 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ },
+ },
+ 180,
+ color.Black,
+ &image.NRGBA{
+ Rect: image.Rect(0, 0, 4, 4),
+ Stride: 4 * 4,
+ Pix: []uint8{
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff,
+ 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
+ 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
+ },
+ },
+ },
+ {
+ "Rotate 45",
+ &image.NRGBA{
+ Rect: image.Rect(-1, -1, 3, 3),
+ Stride: 4 * 4,
+ Pix: []uint8{
+ 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
+ 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ },
+ },
+ 45,
+ color.Black,
+ &image.NRGBA{
+ Rect: image.Rect(0, 0, 6, 6),
+ Stride: 6 * 4,
+ Pix: []uint8{
+ 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x61, 0x00, 0x00, 0xff, 0x58, 0x08, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff,
+ 0x00, 0x00, 0x00, 0xff, 0x61, 0x00, 0x00, 0xff, 0xe9, 0x16, 0x00, 0xff, 0x35, 0xca, 0x00, 0xff, 0x00, 0x30, 0x30, 0xff, 0x00, 0x00, 0x00, 0xff,
+ 0x61, 0x00, 0x00, 0xff, 0xe9, 0x16, 0x00, 0xff, 0x35, 0xca, 0x00, 0xff, 0x00, 0x80, 0x80, 0xff, 0x35, 0x35, 0xff, 0xff, 0x58, 0x58, 0x61, 0xff,
+ 0x58, 0x08, 0x00, 0xff, 0x35, 0xca, 0x00, 0xff, 0x00, 0x80, 0x80, 0xff, 0x35, 0x35, 0xff, 0xff, 0xe9, 0xe9, 0xff, 0xff, 0x61, 0x61, 0x61, 0xff,
+ 0x00, 0x00, 0x00, 0xff, 0x00, 0x30, 0x30, 0xff, 0x35, 0x35, 0xff, 0xff, 0xe9, 0xe9, 0xff, 0xff, 0x61, 0x61, 0x61, 0xff, 0x00, 0x00, 0x00, 0xff,
+ 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x58, 0x58, 0x61, 0xff, 0x61, 0x61, 0x61, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff,
+ },
+ },
+ },
+ {
+ "Rotate 0x0",
+ &image.NRGBA{
+ Rect: image.Rect(0, 0, 0, 0),
+ Stride: 0,
+ Pix: []uint8{},
+ },
+ 123,
+ color.Black,
+ &image.NRGBA{
+ Rect: image.Rect(0, 0, 0, 0),
+ Stride: 0,
+ Pix: []uint8{},
+ },
+ },
+ {
+ "Rotate -90",
+ &image.NRGBA{
+ Rect: image.Rect(-1, -1, 0, 1),
+ Stride: 1 * 4,
+ Pix: []uint8{
+ 0xff, 0x00, 0x00, 0xff,
+ 0x00, 0xff, 0x00, 0xff,
+ },
+ },
+ -90,
+ color.Black,
+ &image.NRGBA{
+ Rect: image.Rect(0, 0, 2, 1),
+ Stride: 2 * 4,
+ Pix: []uint8{
+ 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
+ },
+ },
+ },
+ }
+ for _, test := range testCases {
+ got := Rotate(test.src, test.angle, test.bg)
+ want := test.want
+ if !compareNRGBA(got, want, 0) {
+ t.Errorf("test [%s] failed: %#v", test.desc, got)
+ }
+ }
+}