33
44local ffi = require " ffi"
55
6- local bitops = require " vips.bitops"
76local verror = require " vips.verror"
87local version = require " vips.version"
98local log = require " vips.log"
109local gvalue = require " vips.gvalue"
1110local vobject = require " vips.vobject"
1211local Image = require " vips.Image"
1312
14- local band = bitops .band
1513local type = type
1614local error = error
1715local pairs = pairs
@@ -30,6 +28,10 @@ local OUTPUT = 32
3028local DEPRECATED = 64
3129local MODIFY = 128
3230
31+ local function isbitset (a , b )
32+ return ( (a - (a % b )) / b ) % 2 == 1
33+ end
34+
3335-- find the first image, and recurse
3436local function find_first_image (array , length )
3537 length = length or # array
@@ -90,7 +92,7 @@ voperation.set = function(self, name, flags, match_image, value)
9092 end
9193
9294 -- MODIFY args need to be copied before they are set
93- if band (flags , MODIFY ) ~= 0 then
95+ if isbitset (flags , MODIFY ) then
9496 log .msg (" copying MODIFY arg" , name )
9597 -- make sure we have a unique copy
9698 value = value :copy ():copy_memory ()
@@ -167,9 +169,9 @@ voperation.call = function(name, string_options, ...)
167169 local flag = flags [i ]
168170 flags_from_name [names [i ]] = flag
169171
170- if band (flag , INPUT ) ~= 0 and
171- band (flag , REQUIRED ) ~= 0 and
172- band (flag , DEPRECATED ) == 0 then
172+ if isbitset (flag , INPUT ) and
173+ isbitset (flag , REQUIRED ) and
174+ not isbitset (flag , DEPRECATED ) then
173175 n_required = n_required + 1
174176 end
175177 end
@@ -207,9 +209,9 @@ voperation.call = function(name, string_options, ...)
207209 for i = 1 , arguments_length do
208210 local flag = flags [i ]
209211
210- if band (flag , INPUT ) ~= 0 and
211- band (flag , REQUIRED ) ~= 0 and
212- band (flag , DEPRECATED ) == 0 then
212+ if isbitset (flag , INPUT ) and
213+ isbitset (flag , REQUIRED ) and
214+ not isbitset (flag , DEPRECATED ) then
213215 n = n + 1
214216
215217 if not vop :set (names [i ], flag ,
@@ -247,17 +249,17 @@ voperation.call = function(name, string_options, ...)
247249 for i = 1 , arguments_length do
248250 local flag = flags [i ]
249251
250- if band (flag , OUTPUT ) ~= 0 and
251- band (flag , REQUIRED ) ~= 0 and
252- band (flag , DEPRECATED ) == 0 then
252+ if isbitset (flag , OUTPUT ) and
253+ isbitset (flag , REQUIRED ) and
254+ not isbitset (flag , DEPRECATED ) then
253255 result [n ] = vob :get (names [i ])
254256 n = n + 1
255257 end
256258
257259 -- MODIFY input args are returned .. this will get the copy we
258260 -- made above
259- if band (flag , INPUT ) ~= 0 and
260- band (flag , MODIFY ) ~= 0 then
261+ if isbitset (flag , INPUT ) and
262+ isbitset (flag , MODIFY ) then
261263 result [n ] = vob :get (names [i ])
262264 n = n + 1
263265 end
@@ -267,9 +269,9 @@ voperation.call = function(name, string_options, ...)
267269 for i = 1 , arguments_length do
268270 local flag = flags [i ]
269271
270- if band (flag , OUTPUT ) ~= 0 and
271- band (flag , REQUIRED ) == 0 and
272- band (flag , DEPRECATED ) == 0 then
272+ if isbitset (flag , OUTPUT ) and
273+ not isbitset (flag , REQUIRED ) and
274+ not isbitset (flag , DEPRECATED ) then
273275 result [n ] = vob :get (names [i ])
274276 n = n + 1
275277 end
0 commit comments