forked from RobCherry/govips
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resample_test.go
167 lines (157 loc) · 4.86 KB
/
resample_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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package govips
import (
"image"
_ "image/jpeg"
"testing"
)
func Test_Affine(t *testing.T) {
err := Initialize()
defer ThreadShutdown()
defer checkErrorBuffer(t)
checkError(t, err)
vi := test_DecodeJpegVips(t, "benchmark_images/1.jpg", BENCHMARK_IMAGE_1_BOUNDS, nil)
defer vi.Free()
tests := map[float64]image.Point{
0.25: BENCHMARK_IMAGE_1_BOUNDS.Size().Div(4),
0.5: BENCHMARK_IMAGE_1_BOUNDS.Size().Div(2),
1: BENCHMARK_IMAGE_1_BOUNDS.Size(),
2: BENCHMARK_IMAGE_1_BOUNDS.Size().Mul(2),
}
for scale, expected := range tests {
vi2, err := Affine(vi, scale, 0, 0, scale, nil)
checkError(t, err)
defer vi2.Free()
if expected != vi2.Bounds().Size() {
t.Fatalf("Invalid bounds for scale with factor of %0.2f: %v", scale, vi2.Bounds())
}
}
}
func Test_Similarity(t *testing.T) {
err := Initialize()
defer ThreadShutdown()
defer checkErrorBuffer(t)
checkError(t, err)
vi := test_DecodeJpegVips(t, "benchmark_images/1.jpg", BENCHMARK_IMAGE_1_BOUNDS, nil)
defer vi.Free()
tests := map[float64]image.Point{
0.25: BENCHMARK_IMAGE_1_BOUNDS.Size().Div(4),
0.5: BENCHMARK_IMAGE_1_BOUNDS.Size().Div(2),
1: BENCHMARK_IMAGE_1_BOUNDS.Size(),
2: BENCHMARK_IMAGE_1_BOUNDS.Size().Mul(2),
}
for scale, expected := range tests {
vi2, err := Similarity(vi, &SimilarityOptions{Scale: scale})
checkError(t, err)
defer vi2.Free()
if expected != vi2.Bounds().Size() {
t.Fatalf("Invalid bounds for scale with factor of %0.2f: %v", scale, vi2.Bounds())
}
}
}
func Test_SimilarityRotate(t *testing.T) {
err := Initialize()
defer ThreadShutdown()
defer checkErrorBuffer(t)
checkError(t, err)
vi := test_DecodeJpegVips(t, "benchmark_images/1.jpg", BENCHMARK_IMAGE_1_BOUNDS, nil)
defer vi.Free()
tests := map[float64]image.Rectangle{
0: BENCHMARK_IMAGE_1_BOUNDS,
90: image.Rect(0, 0, BENCHMARK_IMAGE_1_BOUNDS.Dy(), BENCHMARK_IMAGE_1_BOUNDS.Dx()),
180: BENCHMARK_IMAGE_1_BOUNDS,
270: image.Rect(0, 0, BENCHMARK_IMAGE_1_BOUNDS.Dy(), BENCHMARK_IMAGE_1_BOUNDS.Dx()),
360: BENCHMARK_IMAGE_1_BOUNDS,
}
for angle, expected := range tests {
vi2, err := Similarity(vi, &SimilarityOptions{Angle: angle})
checkError(t, err)
defer vi2.Free()
if expected != vi2.Bounds() {
t.Fatalf("Invalid bounds for %0.0f degree rotation: %v", angle, vi2.Bounds())
}
}
}
func Test_ReduceVips(t *testing.T) {
err := Initialize()
defer ThreadShutdown()
defer checkErrorBuffer(t)
checkError(t, err)
vi := test_DecodeJpegVips(t, "benchmark_images/1.jpg", BENCHMARK_IMAGE_1_BOUNDS, nil)
defer vi.Free()
vi2, err := Reduce(vi, 2, 2, VIPS_KERNEL_LANCZOS3)
checkError(t, err)
defer vi2.Free()
if image.Rect(0, 0, vi.Bounds().Dx()/2, vi.Bounds().Dy()/2) != vi2.Bounds() {
t.Fatalf("Invalid bounds: %v", vi2.Bounds())
}
}
func Test_ReduceHVips(t *testing.T) {
err := Initialize()
defer ThreadShutdown()
defer checkErrorBuffer(t)
checkError(t, err)
vi := test_DecodeJpegVips(t, "benchmark_images/1.jpg", BENCHMARK_IMAGE_1_BOUNDS, nil)
defer vi.Free()
vi2, err := ReduceH(vi, 2, VIPS_KERNEL_LANCZOS3)
checkError(t, err)
defer vi2.Free()
if image.Rect(0, 0, vi.Bounds().Dx()/2, vi.Bounds().Dy()) != vi2.Bounds() {
t.Fatalf("Invalid bounds: %v", vi2.Bounds())
}
}
func Test_ReduceVVips(t *testing.T) {
err := Initialize()
defer ThreadShutdown()
defer checkErrorBuffer(t)
checkError(t, err)
vi := test_DecodeJpegVips(t, "benchmark_images/1.jpg", BENCHMARK_IMAGE_1_BOUNDS, nil)
defer vi.Free()
vi2, err := ReduceV(vi, 2, VIPS_KERNEL_LANCZOS3)
checkError(t, err)
defer vi2.Free()
if image.Rect(0, 0, vi.Bounds().Dx(), vi.Bounds().Dy()/2) != vi2.Bounds() {
t.Fatalf("Invalid bounds: %v", vi2.Bounds())
}
}
func Test_ShrinkVips(t *testing.T) {
err := Initialize()
defer ThreadShutdown()
defer checkErrorBuffer(t)
checkError(t, err)
vi := test_DecodeJpegVips(t, "benchmark_images/1.jpg", BENCHMARK_IMAGE_1_BOUNDS, nil)
defer vi.Free()
vi2, err := Shrink(vi, 2, 2)
checkError(t, err)
defer vi2.Free()
if image.Rect(0, 0, vi.Bounds().Dx()/2, vi.Bounds().Dy()/2) != vi2.Bounds() {
t.Fatalf("Invalid bounds: %v", vi2.Bounds())
}
}
func Test_ShrinkHVips(t *testing.T) {
err := Initialize()
defer ThreadShutdown()
defer checkErrorBuffer(t)
checkError(t, err)
vi := test_DecodeJpegVips(t, "benchmark_images/1.jpg", BENCHMARK_IMAGE_1_BOUNDS, nil)
defer vi.Free()
vi2, err := ShrinkH(vi, 2)
checkError(t, err)
defer vi2.Free()
if image.Rect(0, 0, vi.Bounds().Dx()/2, vi.Bounds().Dy()) != vi2.Bounds() {
t.Fatalf("Invalid bounds: %v", vi2.Bounds())
}
}
func Test_ShrinkVVips(t *testing.T) {
err := Initialize()
defer ThreadShutdown()
defer checkErrorBuffer(t)
checkError(t, err)
vi := test_DecodeJpegVips(t, "benchmark_images/1.jpg", BENCHMARK_IMAGE_1_BOUNDS, nil)
defer vi.Free()
vi2, err := ShrinkV(vi, 2)
checkError(t, err)
defer vi2.Free()
if image.Rect(0, 0, vi.Bounds().Dx(), vi.Bounds().Dy()/2) != vi2.Bounds() {
t.Fatalf("Invalid bounds: %v", vi2.Bounds())
}
}