37 lines
895 B
Lua
37 lines
895 B
Lua
local bitmap = require'bitmap' --used to read its content
|
|
|
|
function int_exa(nb)
|
|
if nb < 16 then add = "0"
|
|
else add = "" end
|
|
return [[\x]]..add..string.format("%x", nb)
|
|
end
|
|
|
|
io.write([[from casioplot import set_pixel, show_screen as S, R
|
|
data=b"]])
|
|
|
|
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
|
|
|
|
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_exa(pallet[r.." "..g.." "..b]))
|
|
end
|
|
end
|
|
|
|
io.write([["
|
|
R()
|
|
]])
|