Got image flipping working. I realized it could be done very easily… but it’s using strings so probably would be faster if it was done in an extension, or image.load() had a flip flag.
local function flip_image(image)
local width = image.width
local height = image.height
local temp_buffer = ""
local width_chunk = width * 3
for i=1, height do
local start = (i - 1) * width_chunk + 1
local stop = start + width_chunk - 1
temp_buffer = string.sub(image.buffer, start, stop) .. temp_buffer
end
return temp_buffer
end
Here I was off by 1 at the end until I did -1. And a few abominations from editing width_chunk to custom values…
Now it’s time for the real cleanup and putting everything into a neat package.