-
-
Notifications
You must be signed in to change notification settings - Fork 382
/
processor_test.go
100 lines (78 loc) · 2.48 KB
/
processor_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package caire
import (
"image"
"testing"
"github.com/stretchr/testify/assert"
)
func TestResize_ShrinkImageWidth(t *testing.T) {
assert := assert.New(t)
img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight))
var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy())
newWidth := imgWidth / 2
p.NewWidth = newWidth
p.NewHeight = imgHeight
for x := 0; x < newWidth; x++ {
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
c = NewCarver(width, height)
c.ComputeSeams(p, img)
seams := c.FindLowestEnergySeams(p)
img = c.RemoveSeam(img, seams, p.Debug)
}
imgWidth := img.Bounds().Max.X
assert.Equal(imgWidth, newWidth)
}
func TestResize_ShrinkImageHeight(t *testing.T) {
assert := assert.New(t)
img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight))
var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy())
newHeight := imgHeight / 2
p.NewWidth = imgWidth
p.NewHeight = newHeight
img = c.RotateImage90(img)
for x := 0; x < newHeight; x++ {
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
c = NewCarver(width, height)
c.ComputeSeams(p, img)
seams := c.FindLowestEnergySeams(p)
img = c.RemoveSeam(img, seams, p.Debug)
}
img = c.RotateImage270(img)
imgHeight := img.Bounds().Max.Y
assert.Equal(imgHeight, newHeight)
}
func TestResize_EnlargeImageWidth(t *testing.T) {
assert := assert.New(t)
img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight))
var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy())
newWidth := imgWidth * 2
p.NewWidth = newWidth
p.NewHeight = imgHeight
for x := 0; x < newWidth; x++ {
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
c = NewCarver(width, height)
c.ComputeSeams(p, img)
seams := c.FindLowestEnergySeams(p)
img = c.AddSeam(img, seams, p.Debug)
}
imgWidth := img.Bounds().Max.X - img.Bounds().Dx()
assert.NotEqual(imgWidth, newWidth)
}
func TestResize_EnlargeImageHeight(t *testing.T) {
assert := assert.New(t)
img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight))
var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy())
newHeight := imgHeight * 2
p.NewWidth = imgWidth
p.NewHeight = newHeight
img = c.RotateImage90(img)
for x := 0; x < newHeight; x++ {
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
c = NewCarver(width, height)
c.ComputeSeams(p, img)
seams := c.FindLowestEnergySeams(p)
img = c.AddSeam(img, seams, p.Debug)
}
img = c.RotateImage270(img)
imgHeight := img.Bounds().Max.Y - img.Bounds().Dy()
assert.NotEqual(imgHeight, newHeight)
}