forked from RobCherry/govips
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_test.go
96 lines (90 loc) · 2.92 KB
/
image_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
package govips
import (
"image/color"
"testing"
)
func TestVipsImage_HasProfile(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, &DecodeJpegOptions{DecodeOptions: DecodeOptions{Access: VIPS_ACCESS_SEQUENTIAL}})
defer vi.Free()
if !vi.HasProfile() {
t.Fatal("Color profile is missing")
}
vi2 := test_DecodeJpegVips(t, "benchmark_images/1_bw.jpg", BENCHMARK_IMAGE_1_BOUNDS, &DecodeJpegOptions{DecodeOptions: DecodeOptions{Access: VIPS_ACCESS_SEQUENTIAL}})
defer vi2.Free()
if vi2.HasProfile() {
t.Fatal("Color profile is present")
}
}
func TestVipsImage_RemoveProfile(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, &DecodeJpegOptions{DecodeOptions: DecodeOptions{Access: VIPS_ACCESS_SEQUENTIAL}})
defer vi.Free()
if !vi.HasProfile() {
t.Fatal("Color profile is missing")
}
vi.RemoveProfile()
if vi.HasProfile() {
t.Fatal("Color profile is present")
}
}
func Test_NRGBAVipsImage(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, &DecodeJpegOptions{DecodeOptions: DecodeOptions{Access: VIPS_ACCESS_SEQUENTIAL}})
checkError(t, err)
defer vi.Free()
nrgba, err := NewNRGBAVipsImage(vi)
checkError(t, err)
defer nrgba.Free()
if nrgba.ColorModel() != color.NRGBAModel {
t.Fatal("Invalid color model")
}
if *nrgba.At(0, 0).(*color.NRGBA) != (color.NRGBA{249, 249, 249, 255}) {
t.Fatalf("Invalid color: %v", nrgba.At(0, 0))
}
}
func Test_CMYKVipsImage(t *testing.T) {
err := Initialize()
defer ThreadShutdown()
defer checkErrorBuffer(t)
checkError(t, err)
vi := test_DecodeJpegVips(t, "benchmark_images/1_cmyk.jpg", BENCHMARK_IMAGE_1_BOUNDS, &DecodeJpegOptions{DecodeOptions: DecodeOptions{Access: VIPS_ACCESS_SEQUENTIAL}})
checkError(t, err)
defer vi.Free()
cmyk, err := NewCMYKVipsImage(vi)
checkError(t, err)
defer cmyk.Free()
if cmyk.ColorModel() != color.CMYKModel {
t.Fatal("Invalid color model")
}
if *cmyk.At(0, 0).(*color.CMYK) != (color.CMYK{0, 0, 0, 6}) {
t.Fatalf("Invalid color: %v", cmyk.At(0, 0))
}
}
func Test_GrayVipsImage(t *testing.T) {
err := Initialize()
defer ThreadShutdown()
defer checkErrorBuffer(t)
checkError(t, err)
vi := test_DecodeJpegVips(t, "benchmark_images/1_bw.jpg", BENCHMARK_IMAGE_1_BOUNDS, &DecodeJpegOptions{DecodeOptions: DecodeOptions{Access: VIPS_ACCESS_SEQUENTIAL}})
checkError(t, err)
defer vi.Free()
gray, err := NewGrayVipsImage(vi)
checkError(t, err)
defer gray.Free()
if gray.ColorModel() != color.GrayModel {
t.Fatal("Invalid color model")
}
if *gray.At(0, 0).(*color.Gray) != (color.Gray{249}) {
t.Fatalf("Invalid color: %v", gray.At(0, 0))
}
}