initial commit
This commit is contained in:
7
brickIconFixer/conf.lua
Normal file
7
brickIconFixer/conf.lua
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
function love.conf(t)
|
||||
t.window.width = 512
|
||||
t.window.height = 512
|
||||
t.window.title = "Brick Icon Generator"
|
||||
t.console = true
|
||||
end
|
78
brickIconFixer/fixicons.lua
Normal file
78
brickIconFixer/fixicons.lua
Normal file
@ -0,0 +1,78 @@
|
||||
--love 1
|
||||
|
||||
local le = love.event
|
||||
local lg = love.graphics
|
||||
local li = love.image
|
||||
local lf = love.filesystem
|
||||
|
||||
--------------------------------------------------------------
|
||||
|
||||
local drawable
|
||||
local function yieldImage(imagedata)
|
||||
drawable = lg.newImage(imagedata)
|
||||
coroutine.yield()
|
||||
end
|
||||
|
||||
--------------------------------------------------------------
|
||||
|
||||
local function imageLoad(filename)
|
||||
local imagedata = li.newImageData(filename..".png")
|
||||
return imagedata
|
||||
end
|
||||
|
||||
local function imageStore(imagedata, filename)
|
||||
local filedata = imagedata:encode("png")
|
||||
|
||||
local outfile = io.open(filename..".png", "wb")
|
||||
outfile:write(filedata:getString())
|
||||
outfile:close()
|
||||
end
|
||||
|
||||
--------------------------------------------------------------
|
||||
|
||||
local imageFixIcon = require "imagefixicon"
|
||||
|
||||
--------------------------------------------------------------
|
||||
|
||||
local function fixAllIcons()
|
||||
local files = lf.getDirectoryItems("icons-unfixed")
|
||||
for fileidx, filename in ipairs(files) do
|
||||
local fileext = filename:match("%.[a-zA-Z0-9]+$")
|
||||
if fileext==".png" then
|
||||
local filepart = filename:gsub("%.[a-zA-Z0-9]+$", "")
|
||||
|
||||
local imagedata = imageLoad("icons-unfixed/"..filepart)
|
||||
print(filepart)
|
||||
|
||||
local newimagedata = imageFixIcon(imagedata, fileidx, true)
|
||||
|
||||
imageStore(newimagedata, "icons-fixed/"..filepart)
|
||||
|
||||
yieldImage(newimagedata)
|
||||
end
|
||||
end
|
||||
print("Done")
|
||||
love.event.quit()
|
||||
end
|
||||
|
||||
--------------------------------------------------------------
|
||||
|
||||
local cor
|
||||
function love.load()
|
||||
cor = coroutine.create(fixAllIcons)
|
||||
--fixAllIcons()
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
if drawable then
|
||||
lg.draw(drawable)
|
||||
end
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
coroutine.resume(cor)
|
||||
end
|
||||
|
||||
function love.keypressed(k)
|
||||
if k=="escape" then le.quit() end
|
||||
end
|
BIN
brickIconFixer/icons-fixed/16x16.png
Normal file
BIN
brickIconFixer/icons-fixed/16x16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
BIN
brickIconFixer/icons-unfixed/16x16.png
Normal file
BIN
brickIconFixer/icons-unfixed/16x16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 98 KiB |
112
brickIconFixer/imagefixicon.lua
Normal file
112
brickIconFixer/imagefixicon.lua
Normal file
@ -0,0 +1,112 @@
|
||||
--love 1
|
||||
|
||||
local lg = love.graphics
|
||||
local li = love.image
|
||||
|
||||
local function round(x)
|
||||
return math.floor(x+0.5)
|
||||
end
|
||||
|
||||
local function clamp(x, a, b)
|
||||
return math.min(math.max(x, a), b)
|
||||
end
|
||||
|
||||
local function imageFixIcon(imagedata, identifier, brickmode)
|
||||
local xs, ys = imagedata:getDimensions()
|
||||
|
||||
--remove upper skybox bullshit
|
||||
if brickmode then
|
||||
for x = 1, xs do
|
||||
for y = 1, ys/5 do
|
||||
imagedata:setPixel(x-1, y-1, 1, 0, 1, 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local xmin = xs
|
||||
local xmax = 1
|
||||
local ymin = ys
|
||||
local ymax = 1
|
||||
|
||||
for x = 1, xs do
|
||||
for y = 1, ys do
|
||||
local r, g, b, a = imagedata:getPixel(x-1, y-1)
|
||||
|
||||
if r==1 and g==0 and b==1 then
|
||||
imagedata:setPixel(x-1, y-1, 1, 1, 1, 0)
|
||||
else
|
||||
if x<xmin then xmin = x end
|
||||
if x>xmax then xmax = x end
|
||||
if y<ymin then ymin = y end
|
||||
if y>ymax then ymax = y end
|
||||
|
||||
local l = (r+g+b)/3
|
||||
|
||||
imagedata:setPixel(x-1, y-1, l, l, l, a)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local xc = round((xmax-xmin)/2+xmin)
|
||||
local yc = round((ymax-ymin)/2+ymin)
|
||||
|
||||
local xextent = math.max(xmax-xmin, 96)
|
||||
local yextent = math.max(ymax-ymin, 96)
|
||||
|
||||
local scale = 1
|
||||
if xextent>96 or yextent>96 then
|
||||
scale = 96/math.max(xextent, yextent)
|
||||
end
|
||||
|
||||
--[[
|
||||
local newimagedata = li.newImageData(96, 96)
|
||||
for x = 1, 96 do
|
||||
for y = 1, 96 do
|
||||
local xp = math.round(xc+x/scale-48/scale), 0, xs-1
|
||||
local yp = math.round(yc+y/scale-48/scale), 0, ys-1
|
||||
|
||||
local r, g, b, a
|
||||
if xp>=0 and xp<=xs-1 and yp>=0 and yp<=ys-1 then
|
||||
r, g, b, a = imagedata:getPixel(xp, yp)
|
||||
else
|
||||
r, g, b, a = 1, 1, 1, 0
|
||||
end
|
||||
|
||||
local l = (r+g+b)/3
|
||||
|
||||
newimagedata:setPixel(x-1, y-1, l, l, l, a)
|
||||
end
|
||||
end]]
|
||||
|
||||
--scale = 1
|
||||
if not brickmode then
|
||||
scale = scale*0.95
|
||||
end
|
||||
|
||||
local drawable = lg.newImage(imagedata)
|
||||
|
||||
local canvas = lg.newCanvas(96, 96)
|
||||
|
||||
lg.setCanvas(canvas) lg.push()
|
||||
lg.clear()
|
||||
lg.setColor(0,0,0,0)
|
||||
lg.rectangle("fill", 0, 0, 96, 96)
|
||||
local v = 1
|
||||
--if brickmode then v = 1 end
|
||||
lg.setColor(v,v,v,1)
|
||||
local filter = "linear"
|
||||
--local filter = "nearest"
|
||||
lg.setDefaultFilter(filter, filter, 2)
|
||||
lg.draw(drawable, 48, 48, 0, scale, scale, xc, yc)
|
||||
lg.pop() lg.setCanvas()
|
||||
|
||||
local newimagedata = canvas:newImageData()
|
||||
|
||||
if not brickmode then
|
||||
--newimagedata:setPixel(identifier%96, math.floor(identifier/96), 1, 1, 1, 1)
|
||||
end
|
||||
|
||||
return newimagedata
|
||||
end
|
||||
|
||||
return imageFixIcon
|
2
brickIconFixer/main.lua
Normal file
2
brickIconFixer/main.lua
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
require "fixicons"
|
2
brickIconFixer/run.bat
Normal file
2
brickIconFixer/run.bat
Normal file
@ -0,0 +1,2 @@
|
||||
cd /d %~dp0
|
||||
love .
|
Reference in New Issue
Block a user