diff --git a/init.lua b/init.lua index 6639407..47158cd 100644 --- a/init.lua +++ b/init.lua @@ -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