Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert a palette .png (num of colours x 1 pixel) to appropriate grayscaled palette (for colour swap shader)
function love.load()
for k, file in pairs(love.filesystem.getDirectoryItems("source")) do
convert(file)
end
end
function convert(file)
local data = love.image.newImageData("source/" .. file)
local width = data:getWidth()
local div = 255/width
for i = 0, width - 1 do
local v = div * (i + 0.5)/255
data:setPixel(i, 0, v, v, v, 1)
end
local file = data:encode("png", file)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment