-
Notifications
You must be signed in to change notification settings - Fork 2
/
epeg_test.go
193 lines (179 loc) · 8.62 KB
/
epeg_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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package goepeg
import (
"io/ioutil"
"os"
"reflect"
"testing"
)
var sourceInput []byte = []byte{
255, 216, 255, 219, 0, 67, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 255, 219, 0, 67, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 255, 194, 0, 17, 8, 0, 16, 0, 16, 3, 1, 17, 0,
2, 17, 1, 3, 17, 1, 255, 196, 0, 22, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 9, 7, 8, 255, 196, 0, 23, 1, 0, 3, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 9, 10, 7, 255, 218, 0, 12, 3, 1, 0,
2, 16, 3, 16, 0, 0, 1, 197, 226, 155, 252, 74, 5, 184, 87, 6, 237,
49, 172, 66, 208, 30, 169, 255, 196, 0, 20, 16, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 255, 218, 0, 8, 1, 1, 0, 1, 5, 2, 31,
255, 196, 0, 20, 17, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
32, 255, 218, 0, 8, 1, 3, 1, 1, 63, 1, 31, 255, 196, 0, 20, 17, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 255, 218, 0, 8, 1,
2, 1, 1, 63, 1, 31, 255, 196, 0, 20, 16, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 32, 255, 218, 0, 8, 1, 1, 0, 6, 63, 2, 31, 255,
196, 0, 20, 16, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32,
255, 218, 0, 8, 1, 1, 0, 1, 63, 33, 31, 255, 218, 0, 12, 3, 1, 0, 2,
0, 3, 0, 0, 0, 16, 0, 15, 255, 196, 0, 20, 17, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 255, 218, 0, 8, 1, 3, 1, 1, 63, 16,
31, 255, 196, 0, 20, 17, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 32, 255, 218, 0, 8, 1, 2, 1, 1, 63, 16, 31, 255, 196, 0, 20,
16, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 255, 218, 0,
8, 1, 1, 0, 1, 63, 16, 31, 255, 217,
}
var thumbnailOutput []byte = []byte{
255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0,
0, 255, 219, 0, 67, 0, 8, 6, 6, 7, 6, 5, 8, 7, 7, 7, 9, 9, 8, 10, 12,
20, 13, 12, 11, 11, 12, 25, 18, 19, 15, 20, 29, 26, 31, 30, 29, 26,
28, 28, 32, 36, 46, 39, 32, 34, 44, 35, 28, 28, 40, 55, 41, 44, 48,
49, 52, 52, 52, 31, 39, 57, 61, 56, 50, 60, 46, 51, 52, 50, 255, 219,
0, 67, 1, 9, 9, 9, 12, 11, 12, 24, 13, 13, 24, 50, 33, 28, 33, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 255, 192, 0,
17, 8, 0, 4, 0, 4, 3, 1, 34, 0, 2, 17, 1, 3, 17, 1, 255, 196, 0, 31,
0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 255, 196, 0, 181, 16, 0, 2, 1, 3, 3, 2, 4, 3, 5,
5, 4, 4, 0, 0, 1, 125, 1, 2, 3, 0, 4, 17, 5, 18, 33, 49, 65, 6, 19,
81, 97, 7, 34, 113, 20, 50, 129, 145, 161, 8, 35, 66, 177, 193, 21,
82, 209, 240, 36, 51, 98, 114, 130, 9, 10, 22, 23, 24, 25, 26, 37, 38,
39, 40, 41, 42, 52, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72,
73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, 103, 104,
105, 106, 115, 116, 117, 118, 119, 120, 121, 122, 131, 132, 133, 134,
135, 136, 137, 138, 146, 147, 148, 149, 150, 151, 152, 153, 154, 162,
163, 164, 165, 166, 167, 168, 169, 170, 178, 179, 180, 181, 182, 183,
184, 185, 186, 194, 195, 196, 197, 198, 199, 200, 201, 202, 210, 211,
212, 213, 214, 215, 216, 217, 218, 225, 226, 227, 228, 229, 230, 231,
232, 233, 234, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 255,
196, 0, 31, 1, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255, 196, 0, 181, 17, 0, 2, 1, 2, 4,
4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119, 0, 1, 2, 3, 17, 4, 5, 33, 49, 6,
18, 65, 81, 7, 97, 113, 19, 34, 50, 129, 8, 20, 66, 145, 161, 177,
193, 9, 35, 51, 82, 240, 21, 98, 114, 209, 10, 22, 36, 52, 225, 37,
241, 23, 24, 25, 26, 38, 39, 40, 41, 42, 53, 54, 55, 56, 57, 58, 67,
68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100,
101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122,
130, 131, 132, 133, 134, 135, 136, 137, 138, 146, 147, 148, 149, 150,
151, 152, 153, 154, 162, 163, 164, 165, 166, 167, 168, 169, 170, 178,
179, 180, 181, 182, 183, 184, 185, 186, 194, 195, 196, 197, 198, 199,
200, 201, 202, 210, 211, 212, 213, 214, 215, 216, 217, 218, 226, 227,
228, 229, 230, 231, 232, 233, 234, 242, 243, 244, 245, 246, 247, 248,
249, 250, 255, 218, 0, 12, 3, 1, 0, 2, 17, 3, 17, 0, 63, 0, 242, 83,
227, 95, 16, 216, 159, 179, 91, 106, 27, 33, 79, 186, 190, 76, 103,
25, 231, 169, 95, 83, 69, 20, 86, 153, 150, 3, 11, 28, 109, 104, 198,
148, 82, 82, 151, 69, 221, 249, 28, 146, 193, 225, 235, 55, 82, 165,
56, 202, 82, 213, 182, 147, 109, 189, 219, 125, 91, 234, 207, 255, 217,
}
var transformOutput []byte = []byte{
255, 216, 255, 219, 0, 67, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 255, 219, 0, 67, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 255, 192, 0, 17, 8, 0, 16, 0, 16, 3, 1, 17, 0, 2,
17, 1, 3, 17, 1, 255, 196, 0, 31, 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255, 196, 0, 181,
16, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125, 1, 2, 3, 0, 4,
17, 5, 18, 33, 49, 65, 6, 19, 81, 97, 7, 34, 113, 20, 50, 129, 145,
161, 8, 35, 66, 177, 193, 21, 82, 209, 240, 36, 51, 98, 114, 130, 9,
10, 22, 23, 24, 25, 26, 37, 38, 39, 40, 41, 42, 52, 53, 54, 55, 56,
57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89,
90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119,
120, 121, 122, 131, 132, 133, 134, 135, 136, 137, 138, 146, 147, 148,
149, 150, 151, 152, 153, 154, 162, 163, 164, 165, 166, 167, 168, 169,
170, 178, 179, 180, 181, 182, 183, 184, 185, 186, 194, 195, 196, 197,
198, 199, 200, 201, 202, 210, 211, 212, 213, 214, 215, 216, 217, 218,
225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 241, 242, 243, 244,
245, 246, 247, 248, 249, 250, 255, 196, 0, 31, 1, 0, 3, 1, 1, 1, 1, 1,
1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255,
196, 0, 181, 17, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119, 0,
1, 2, 3, 17, 4, 5, 33, 49, 6, 18, 65, 81, 7, 97, 113, 19, 34, 50, 129,
8, 20, 66, 145, 161, 177, 193, 9, 35, 51, 82, 240, 21, 98, 114, 209,
10, 22, 36, 52, 225, 37, 241, 23, 24, 25, 26, 38, 39, 40, 41, 42, 53,
54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86,
87, 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117,
118, 119, 120, 121, 122, 130, 131, 132, 133, 134, 135, 136, 137, 138,
146, 147, 148, 149, 150, 151, 152, 153, 154, 162, 163, 164, 165, 166,
167, 168, 169, 170, 178, 179, 180, 181, 182, 183, 184, 185, 186, 194,
195, 196, 197, 198, 199, 200, 201, 202, 210, 211, 212, 213, 214, 215,
216, 217, 218, 226, 227, 228, 229, 230, 231, 232, 233, 234, 242, 243,
244, 245, 246, 247, 248, 249, 250, 255, 218, 0, 12, 3, 1, 0, 2, 17, 3,
17, 0, 63, 0, 255, 0, 63, 250, 0, 255, 0, 75, 10, 255, 0, 149, 243,
254, 41, 207, 224, 222, 191, 246, 152, 63, 234, 192, 253, 120, 175,
252, 171, 207, 253, 40, 15, 255, 217,
}
func TestThumbnail(t *testing.T) {
input, err := ioutil.TempFile("", "")
if err != nil {
t.Fatal(err)
}
defer os.Remove(input.Name())
if _, err := input.Write(sourceInput); err != nil {
t.Fatal(err)
}
if err := input.Close(); err != nil {
t.Fatal(err)
}
output, err := ioutil.TempFile("", "")
if err != nil {
t.Fatal(err)
}
defer os.Remove(output.Name())
if err := output.Close(); err != nil {
t.Fatal(err)
}
if err := Thumbnail(input.Name(), output.Name(), 4, 75, ScaleTypeFitMin); err != nil {
t.Fatal(err)
}
bytes, err := ioutil.ReadFile(output.Name())
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(bytes, thumbnailOutput) {
t.Errorf("Thumbnail failed")
}
}
func TestTransform(t *testing.T) {
input, err := ioutil.TempFile("", "")
if err != nil {
t.Fatal(err)
}
defer os.Remove(input.Name())
if _, err := input.Write(sourceInput); err != nil {
t.Fatal(err)
}
if err := input.Close(); err != nil {
t.Fatal(err)
}
output, err := ioutil.TempFile("", "")
if err != nil {
t.Fatal(err)
}
defer os.Remove(output.Name())
if err := output.Close(); err != nil {
t.Fatal(err)
}
if err := Transform(input.Name(), output.Name(), TransformTransverse); err != nil {
t.Fatal(err)
}
bytes, err := ioutil.ReadFile(output.Name())
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(bytes, transformOutput) {
t.Errorf("TestTransform failed")
}
}