Last active
June 29, 2018 05:00
-
-
Save flamendless/ade6c6b5a04299a45574dfa926dee59d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local Pswap = {} | |
local orig_pal | |
local new_pal | |
local image | |
local image2 | |
local lookup = {} | |
function Pswap:load() | |
local orig_pal_data = love.image.newImageData("orig.png") | |
orig_pal = love.graphics.newImage(orig_pal_data) | |
local new_pal_data = love.image.newImageData("new2.png") | |
new_pal = love.graphics.newImage(new_pal_data) | |
for x = 0, orig_pal_data:getWidth() - 1 do --4 | |
lookup[x] = {} | |
for y = 0, orig_pal_data:getHeight() - 1 do --1 | |
local r,g,b,a = orig_pal_data:getPixel(x,y) | |
local nr,ng,nb,na = new_pal_data:getPixel(x,y) | |
lookup[x][1] = {r=r,g=g,b=b,a=a} | |
lookup[x][2] = {r=nr,g=ng,b=nb,a=na} | |
end | |
end | |
--for _,t in pairs(lookup) do | |
--for k,v in pairs(t) do | |
--print(k,v) | |
--end | |
--end | |
local data = love.image.newImageData("sample.png") | |
image = love.graphics.newImage(data) | |
for x = 0, data:getWidth() - 1 do | |
for y = 0, data:getHeight() - 1 do | |
local r,g,b,a = data:getPixel(x,y) | |
for _,t in pairs(lookup) do | |
for k,v in pairs(t) do | |
if v.r == r and v.g == g and v.b == b and v.a == a then | |
data:setPixel(x,y, t[2].r, t[2].g, t[2].b, t[2].a) | |
end | |
end | |
end | |
end | |
end | |
image2 = love.graphics.newImage(data) | |
orig_pal:setFilter("nearest", "nearest") | |
new_pal:setFilter("nearest", "nearest") | |
image:setFilter("nearest", "nearest") | |
image2:setFilter("nearest", "nearest") | |
end | |
function Pswap:update(dt) | |
end | |
function Pswap:draw() | |
love.graphics.setBackgroundColor(1/2,1/2,1/2) | |
love.graphics.setColor(1,1,1,1) | |
love.graphics.draw(image,32,32, 0, 8,8) | |
love.graphics.draw(image2,512,32, 0, 8,8) | |
love.graphics.draw(orig_pal, 32, 512, 0, 16,16) | |
love.graphics.draw(new_pal, 512, 512, 0, 16,16) | |
end | |
return Pswap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment