Skip to content

Instantly share code, notes, and snippets.

@flamendless
Created October 16, 2018 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flamendless/0c1ed3a401f314acce4c8a27ca53ec91 to your computer and use it in GitHub Desktop.
Save flamendless/0c1ed3a401f314acce4c8a27ca53ec91 to your computer and use it in GitHub Desktop.
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