forked from RobCherry/govips
-
Notifications
You must be signed in to change notification settings - Fork 0
/
colour_test.go
62 lines (59 loc) · 2.09 KB
/
colour_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
package govips
import (
_ "image/jpeg"
"testing"
)
func Test_Colourspace(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 BENCHMARK_IMAGE_1_BOUNDS != vi.Bounds() {
t.Fatalf("Invalid bounds: %v", vi.Bounds())
}
if vi.Interpretation() != VIPS_INTERPRETATION_sRGB {
t.Fatalf("Invalid interpretation: %v", vi.Interpretation())
}
if vi.Bands() != 3 {
t.Fatalf("Invalid bands: %v", vi.Bands())
}
vi2, err := Colourspace(vi, VIPS_INTERPRETATION_LAB, nil)
checkError(t, err)
defer vi2.Free()
if BENCHMARK_IMAGE_1_BOUNDS != vi2.Bounds() {
t.Fatalf("Invalid bounds: %v", vi2.Bounds())
}
if vi2.Interpretation() != VIPS_INTERPRETATION_LAB {
t.Fatalf("Invalid interpretation: %v", vi2.Interpretation())
}
if vi2.Bands() != 3 {
t.Fatalf("Invalid bands: %v", vi2.Bands())
}
}
func Test_ColourspaceIsSupported(t *testing.T) {
err := Initialize()
defer ThreadShutdown()
defer checkErrorBuffer(t)
checkError(t, err)
runTest := func(path string, expectedInterpretation VipsInterpretation, expectedBands int, expectedSupport bool) {
vi := test_DecodeJpegVips(t, path, BENCHMARK_IMAGE_1_BOUNDS, &DecodeJpegOptions{DecodeOptions: DecodeOptions{Access: VIPS_ACCESS_SEQUENTIAL}})
defer vi.Free()
if BENCHMARK_IMAGE_1_BOUNDS != vi.Bounds() {
t.Fatalf("Invalid bounds for %s: %v", path, vi.Bounds())
}
if vi.Interpretation() != expectedInterpretation {
t.Fatalf("Invalid interpretation for %s: %v", path, vi.Interpretation())
}
if vi.Bands() != expectedBands {
t.Fatalf("Invalid bands for %s: %v", path, vi.Bands())
}
if expectedSupport != ColourspaceIsSupported(vi) {
t.Fatal("Colourspace support was incorrectly reported.")
}
}
runTest("benchmark_images/1.jpg", VIPS_INTERPRETATION_sRGB, 3, true)
runTest("benchmark_images/1_bw.jpg", VIPS_INTERPRETATION_B_W, 1, true)
runTest("benchmark_images/1_cmyk.jpg", VIPS_INTERPRETATION_CMYK, 4, false)
}