1
0

Fixed bad behaviour in init

This commit is contained in:
Jon Michael Aanes 2023-02-16 21:59:30 +01:00
parent 0e8a501049
commit 0a64b6e966

View File

@ -117,15 +117,21 @@ function palette_swap.color_map.invert (r,g,b)
return 1 - r, 1 - g, 1 - b
end
function palette_swap.color_map.switch_channel (mode)
local channels = {'r', 'g', 'b'}
local channel_order = {}
for i = 1, #channels do
local index = (mode % #channels) + 1
mode = mode / #channels
channel_order[#channel_order+1] = table.remove(channels,index)
end
local CHANNEL_ORDERS = {
[0] = {'r', 'g', 'b'},
[1] = {'g', 'b', 'r'},
[2] = {'b', 'r', 'g'},
[3] = {'r', 'b', 'g'},
[4] = {'b', 'g', 'r'},
[5] = {'g', 'r', 'b'},
[6] = {'b', 'g', 'r'},
[7] = {'b', 'g', 'r'}, -- TODO
[8] = {'b', 'g', 'r'}, -- TODO
[9] = {'r', 'g', 'b'}, -- TODO
}
function palette_swap.color_map.switch_channel (mode)
local channel_order = CHANNEL_ORDERS[mode]
local func_s = ("return function (r, g, b) return %s, %s, %s end"):format(unpack(channel_order))
return loadstring (func_s)()
end