Almost there

This commit is contained in:
KikooDX 2020-04-24 14:38:12 +02:00
parent 8254ff84cc
commit caadb6165e
14 changed files with 33 additions and 28 deletions

View File

@ -1,3 +1,4 @@
local cairo = require'cairo' --used to open the file
local bitmap = require'bitmap' --used to read its content
function int_hex(nb)
@ -9,34 +10,38 @@ end
io.write([[from draw import *
]])
do --open image
local cairo = require'cairo' --used to open the file
local image = cairo.load_png(arg[1])
image_infos = {width = image:width(), height = image:height()}
image_bitmap = image:bitmap()
end
local getpixel, setpixel = bitmap.pixel_interface(image_bitmap)
pallet = {} --will store colors
pallet_last = 0
io.write("width=", image_infos.width, "\n", [[data=b"]])
for j = 1, image_infos.height, 1 do
for i = 1, image_infos.width, 1 do
r, g, b = getpixel(i, j)
if not pallet[r..","..g..","..b] then
pallet[r..","..g..","..b] = pallet_last
pallet_last = pallet_last + 1
end
io.write(int_hex(pallet[r..","..g..","..b]))
for i = 1, 12, 1 do
do --open image
path = "spongebob/out-"
if i < 10 then path = path.."0" end
path = path..i.."0.png"
local image = cairo.load_png(path)
image_infos = {width = image:width(), height = image:height()}
image_bitmap = image:bitmap()
end
end
local getpixel, setpixel = bitmap.pixel_interface(image_bitmap)
--let's write the pallet
io.write("\"\npallet={")
for i, v in pairs(pallet) do
io.write(v, ":(", i, "),")
end
pallet = {} --will store colors
pallet_last = 0
io.write("}\ndraw(data,pallet,", image_infos.width, ")")
io.write("width=", image_infos.width, "\n", [[data=b"]])
for j = 1, image_infos.height, 1 do
for i = 1, image_infos.width, 1 do
r, g, b = getpixel(i, j)
if not pallet[r..","..g..","..b] then
pallet[r..","..g..","..b] = pallet_last
pallet_last = pallet_last + 1
end
io.write(int_hex(pallet[r..","..g..","..b]))
end
end
--let's write the pallet
io.write("\"\npallet={")
for i, v in pairs(pallet) do
io.write(v, ":(", i, "),")
end
io.write("}\ndraw(data,pallet,", image_infos.width, ")")
end

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB