Skip to content

Commit

Permalink
Replace bitops module with custom isbitset function
Browse files Browse the repository at this point in the history
  • Loading branch information
RiskoZoSlovenska authored and rolandlo committed Mar 28, 2024
1 parent 1364a52 commit 24e7485
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 51 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ jobs:
run: |
make dev
if [[ ${{ matrix.luaVersion }} == 5.* ]]; then make ffi; fi
if [[ ${{ matrix.luaVersion }} == 5.1 ]] || [[ ${{ matrix.luaVersion }} == 5.2 ]]; then
make bit
fi
- name: Lint with luacheck
run: |
Expand Down Expand Up @@ -79,11 +76,6 @@ jobs:
mingw-w64-x86_64-lua-luarocks
mingw-w64-x86_64-${{ matrix.lua.name }}

- if: matrix.lua.name == 'lua51'
name: Install bitop
run: |
pacman --noconfirm -S mingw-w64-x86_64-lua51-bitop
- name: Lua dependencies
run: |
if [[ ${{ matrix.lua.exe }} == lua5.3 ]]; then
Expand Down
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DEV_ROCKS = "busted 2.2.0" "luacheck 1.1.2"

.PHONY: dev ffi bit
.PHONY: dev ffi

dev:
@for rock in $(DEV_ROCKS) ; do \
Expand All @@ -14,6 +14,3 @@ dev:

ffi:
@luarocks install luaffi-tkl

bit:
@luarocks install luabitop
1 change: 0 additions & 1 deletion lua-vips-1.1-10.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ build = {
type = "builtin",
modules = {
vips = "src/vips.lua",
["vips.bitops"] = "src/vips/bitops.lua",
["vips.cdefs"] = "src/vips/cdefs.lua",
["vips.verror"] = "src/vips/verror.lua",
["vips.version"] = "src/vips/version.lua",
Expand Down
21 changes: 0 additions & 21 deletions src/vips/bitops.lua

This file was deleted.

36 changes: 19 additions & 17 deletions src/vips/voperation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@

local ffi = require "ffi"

local bitops = require "vips.bitops"
local verror = require "vips.verror"
local version = require "vips.version"
local log = require "vips.log"
local gvalue = require "vips.gvalue"
local vobject = require "vips.vobject"
local Image = require "vips.Image"

local band = bitops.band
local type = type
local error = error
local pairs = pairs
Expand All @@ -30,6 +28,10 @@ local OUTPUT = 32
local DEPRECATED = 64
local MODIFY = 128

local function isbitset(a, b)
return ( (a - (a % b)) / b ) % 2 == 1
end

-- find the first image, and recurse
local function find_first_image(array, length)
length = length or #array
Expand Down Expand Up @@ -90,7 +92,7 @@ voperation.set = function(self, name, flags, match_image, value)
end

-- MODIFY args need to be copied before they are set
if band(flags, MODIFY) ~= 0 then
if isbitset(flags, MODIFY) then
log.msg("copying MODIFY arg", name)
-- make sure we have a unique copy
value = value:copy():copy_memory()
Expand Down Expand Up @@ -167,9 +169,9 @@ voperation.call = function(name, string_options, ...)
local flag = flags[i]
flags_from_name[names[i]] = flag

if band(flag, INPUT) ~= 0 and
band(flag, REQUIRED) ~= 0 and
band(flag, DEPRECATED) == 0 then
if isbitset(flag, INPUT) and
isbitset(flag, REQUIRED) and
not isbitset(flag, DEPRECATED) then
n_required = n_required + 1
end
end
Expand Down Expand Up @@ -207,9 +209,9 @@ voperation.call = function(name, string_options, ...)
for i = 1, arguments_length do
local flag = flags[i]

if band(flag, INPUT) ~= 0 and
band(flag, REQUIRED) ~= 0 and
band(flag, DEPRECATED) == 0 then
if isbitset(flag, INPUT) and
isbitset(flag, REQUIRED) and
not isbitset(flag, DEPRECATED) then
n = n + 1

if not vop:set(names[i], flag,
Expand Down Expand Up @@ -247,17 +249,17 @@ voperation.call = function(name, string_options, ...)
for i = 1, arguments_length do
local flag = flags[i]

if band(flag, OUTPUT) ~= 0 and
band(flag, REQUIRED) ~= 0 and
band(flag, DEPRECATED) == 0 then
if isbitset(flag, OUTPUT) and
isbitset(flag, REQUIRED) and
not isbitset(flag, DEPRECATED) then
result[n] = vob:get(names[i])
n = n + 1
end

-- MODIFY input args are returned .. this will get the copy we
-- made above
if band(flag, INPUT) ~= 0 and
band(flag, MODIFY) ~= 0 then
if isbitset(flag, INPUT) and
isbitset(flag, MODIFY) then
result[n] = vob:get(names[i])
n = n + 1
end
Expand All @@ -267,9 +269,9 @@ voperation.call = function(name, string_options, ...)
for i = 1, arguments_length do
local flag = flags[i]

if band(flag, OUTPUT) ~= 0 and
band(flag, REQUIRED) == 0 and
band(flag, DEPRECATED) == 0 then
if isbitset(flag, OUTPUT) and
not isbitset(flag, REQUIRED) and
not isbitset(flag, DEPRECATED) then
result[n] = vob:get(names[i])
n = n + 1
end
Expand Down

0 comments on commit 24e7485

Please sign in to comment.