1
- -- test image writers
2
-
3
- require ' busted.runner' ()
4
-
5
- say = require (" say" )
6
-
7
- local function almost_equal (state , arguments )
8
- local has_key = false
9
- local threshold = arguments [3 ] or 0.001
10
-
11
- if type (arguments [1 ]) ~= " number" or type (arguments [2 ]) ~= " number" then
12
- return false
13
- end
14
-
15
- return math.abs (arguments [1 ] - arguments [2 ]) < threshold
16
- end
17
-
18
- say :set (" assertion.almost_equal.positive" ,
19
- " Expected %s to almost equal %s" )
20
- say :set (" assertion.almost_equal.negative" ,
21
- " Expected %s to not almost equal %s" )
22
- assert :register (" assertion" , " almost_equal" , almost_equal ,
23
- " assertion.almost_equal.positive" ,
24
- " assertion.almost_equal.negative" )
1
+ local vips = require " vips"
25
2
3
+ -- test convenience functions
26
4
describe (" test convenience functions" , function ()
27
- vips = require (" vips" )
28
- -- vips.log.enable(true)
5
+ local array , im
29
6
30
- local array = {1 , 2 , 3 , 4 }
31
- local im = vips .Image .new_from_array (array )
7
+ setup (function ()
8
+ array = { 1 , 2 , 3 , 4 }
9
+ im = vips .Image .new_from_array (array )
10
+ -- vips.log.enable(true)
11
+ end )
32
12
33
- it (" can join one image bandwise" , function ()
13
+ it (" can join one image bandwise" , function ()
34
14
local im2 = im :bandjoin (im )
35
15
36
16
assert .are .equal (im2 :width (), 4 )
37
17
assert .are .equal (im2 :height (), 1 )
38
18
assert .are .equal (im2 :bands (), 2 )
39
19
assert .are .equal (im2 :extract_band (0 ):avg (), 2.5 )
40
20
assert .are .equal (im2 :extract_band (1 ):avg (), 2.5 )
41
-
42
21
end )
43
22
44
- it (" can join images bandwise" , function ()
45
- local im2 = im :bandjoin { im + 1 , im + 2 }
23
+ it (" can join images bandwise" , function ()
24
+ local im2 = im :bandjoin { im + 1 , im + 2 }
46
25
47
26
assert .are .equal (im2 :width (), 4 )
48
27
assert .are .equal (im2 :height (), 1 )
49
28
assert .are .equal (im2 :bands (), 3 )
50
29
assert .are .equal (im2 :extract_band (0 ):avg (), 2.5 )
51
30
assert .are .equal (im2 :extract_band (1 ):avg (), 3.5 )
52
31
assert .are .equal (im2 :extract_band (2 ):avg (), 4.5 )
53
-
54
32
end )
55
33
56
- it (" can join constants to images bandwise" , function ()
34
+ it (" can join constants to images bandwise" , function ()
57
35
local im2 = im :bandjoin (255 )
58
36
59
37
assert .are .equal (im2 :width (), 4 )
60
38
assert .are .equal (im2 :height (), 1 )
61
39
assert .are .equal (im2 :bands (), 2 )
62
40
assert .are .equal (im2 :extract_band (0 ):avg (), 2.5 )
63
41
assert .are .equal (im2 :extract_band (1 ):avg (), 255 )
64
-
65
42
end )
66
43
67
- it (" can join images and constants bandwise" , function ()
68
- local im2 = im :bandjoin { im + 1 , 255 , im + 2 }
44
+ it (" can join images and constants bandwise" , function ()
45
+ local im2 = im :bandjoin { im + 1 , 255 , im + 2 }
69
46
70
47
assert .are .equal (im2 :width (), 4 )
71
48
assert .are .equal (im2 :height (), 1 )
@@ -74,11 +51,10 @@ describe("test convenience functions", function()
74
51
assert .are .equal (im2 :extract_band (1 ):avg (), 3.5 )
75
52
assert .are .equal (im2 :extract_band (2 ):avg (), 255 )
76
53
assert .are .equal (im2 :extract_band (3 ):avg (), 4.5 )
77
-
78
54
end )
79
55
80
- it (" can join images and array constants bandwise" , function ()
81
- local im2 = im :bandjoin { im + 1 , {255 , 128 } }
56
+ it (" can join images and array constants bandwise" , function ()
57
+ local im2 = im :bandjoin { im + 1 , { 255 , 128 } }
82
58
83
59
assert .are .equal (im2 :width (), 4 )
84
60
assert .are .equal (im2 :height (), 1 )
@@ -87,12 +63,11 @@ describe("test convenience functions", function()
87
63
assert .are .equal (im2 :extract_band (1 ):avg (), 3.5 )
88
64
assert .are .equal (im2 :extract_band (2 ):avg (), 255 )
89
65
assert .are .equal (im2 :extract_band (3 ):avg (), 128 )
90
-
91
66
end )
92
67
93
- if vips . version . at_least ( 8 , 6 ) then
94
- it ( " can call composite " , function ()
95
- local base = (im + {10 , 11 , 12 }):copy { interpretation = " srgb" }
68
+ it ( " can call composite " , function ()
69
+ if vips . version . at_least ( 8 , 6 ) then
70
+ local base = (im + { 10 , 11 , 12 }):copy { interpretation = " srgb" }
96
71
local overlay = (base + 10 ):bandjoin (128 )
97
72
local comp = base :composite (overlay , " over" )
98
73
local pixel = comp :getpoint (0 , 0 )
@@ -104,48 +79,43 @@ describe("test convenience functions", function()
104
79
assert .is_true (math.abs (pixel [2 ] - 17 ) < 0.1 )
105
80
assert .is_true (math.abs (pixel [3 ] - 18 ) < 0.1 )
106
81
assert .are .equal (pixel [4 ], 255 )
107
- end )
108
- end
82
+ end
83
+ end )
109
84
110
- it (" can call bandrank" , function ()
111
- local im2 = im :bandrank (im + 1 , {index = 0 })
85
+ it (" can call bandrank" , function ()
86
+ local im2 = im :bandrank (im + 1 , { index = 0 })
112
87
113
88
assert .are .equal (im2 :width (), 4 )
114
89
assert .are .equal (im2 :height (), 1 )
115
90
assert .are .equal (im2 :bands (), 1 )
116
91
assert .are .equal (im2 :extract_band (0 ):avg (), 2.5 )
117
-
118
92
end )
119
93
120
- it (" can call bandsplit" , function ()
121
- local bands = im :bandjoin { im + 1 , {255 , 128 } }:bandsplit ()
94
+ it (" can call bandsplit" , function ()
95
+ local bands = im :bandjoin { im + 1 , { 255 , 128 } }:bandsplit ()
122
96
123
97
assert .are .equal (# bands , 4 )
124
98
assert .are .equal (bands [1 ]:width (), 4 )
125
99
assert .are .equal (bands [1 ]:height (), 1 )
126
100
assert .are .equal (bands [1 ]:bands (), 1 )
127
-
128
101
end )
129
102
130
- it (" can call ifthenelse with an image and two constants" , function ()
103
+ it (" can call ifthenelse with an image and two constants" , function ()
131
104
local result = im :more (2 ):ifthenelse (1 , 2 )
132
105
133
106
assert .are .equal (result :width (), 4 )
134
107
assert .are .equal (result :height (), 1 )
135
108
assert .are .equal (result :bands (), 1 )
136
109
assert .are .equal (result :avg (), 6 / 4 )
137
-
138
110
end )
139
111
140
- it (" can call ifthenelse with two images and one constant" , function ()
112
+ it (" can call ifthenelse with two images and one constant" , function ()
141
113
local result = im :more (2 ):ifthenelse (im + 3 , 2 )
142
114
143
115
assert .are .equal (result :width (), 4 )
144
116
assert .are .equal (result :height (), 1 )
145
117
assert .are .equal (result :bands (), 1 )
146
118
assert .are .equal (result :avg (), 17 / 4 )
147
-
148
119
end )
149
-
150
120
end )
151
121
0 commit comments