Created
November 14, 2025 19:56
-
-
Save cheapie/6f6e4377f8437a4b01f46c2161a71a63 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 imlib2 = require("imlib2") | |
| local img,err = imlib2.image.load(arg[1]) | |
| if not img then | |
| print(err) | |
| return | |
| end | |
| local xsize = img:get_width() | |
| local ysize = img:get_height() | |
| local function explodebits(input,count) | |
| local output = {} | |
| if not count then count = 8 end | |
| for i=0,count-1,1 do | |
| output[i] = input%(2^(i+1)) >= 2^i | |
| end | |
| return output | |
| end | |
| local function implodebits(input,count) | |
| local output = 0 | |
| if not count then count = 8 end | |
| for i=0,count-1,1 do | |
| output = output + (input[i] and 2^i or 0) | |
| end | |
| return output | |
| end | |
| local packtable = {} | |
| local unpacktable = {} | |
| for i=0,25,1 do | |
| packtable[i] = string.char(i+65) | |
| packtable[i+26] = string.char(i+97) | |
| unpacktable[string.char(i+65)] = i | |
| unpacktable[string.char(i+97)] = i+26 | |
| end | |
| for i=0,9,1 do | |
| packtable[i+52] = tostring(i) | |
| unpacktable[tostring(i)] = i+52 | |
| end | |
| packtable[62] = "+" | |
| packtable[63] = "/" | |
| unpacktable["+"] = 62 | |
| unpacktable["/"] = 63 | |
| local function packpixel(pixel) | |
| pixel = tonumber(pixel,16) | |
| if not pixel then return "AAAA" end | |
| local bits = explodebits(pixel,24) | |
| local block1 = {} | |
| local block2 = {} | |
| local block3 = {} | |
| local block4 = {} | |
| for i=0,5,1 do | |
| block1[i] = bits[i] | |
| block2[i] = bits[i+6] | |
| block3[i] = bits[i+12] | |
| block4[i] = bits[i+18] | |
| end | |
| local char1 = packtable[implodebits(block1,6)] or "A" | |
| local char2 = packtable[implodebits(block2,6)] or "A" | |
| local char3 = packtable[implodebits(block3,6)] or "A" | |
| local char4 = packtable[implodebits(block4,6)] or "A" | |
| return char1..char2..char3..char4 | |
| end | |
| local function unpackpixel(pack) | |
| local block1 = unpacktable[pack:sub(1,1)] or 0 | |
| local block2 = unpacktable[pack:sub(2,2)] or 0 | |
| local block3 = unpacktable[pack:sub(3,3)] or 0 | |
| local block4 = unpacktable[pack:sub(4,4)] or 0 | |
| local out = block1+(2^6*block2)+(2^12*block3)+(2^18*block4) | |
| return string.format("%06X",out) | |
| end | |
| local maxysub = math.ceil(ysize/64) | |
| local maxxsub = math.ceil(xsize/64) | |
| for xsub=1,maxxsub,1 do | |
| for ysub=1,maxysub,1 do | |
| local b64 = "" | |
| local function processcolor(x,y,xsub,ysub) | |
| x = math.min(x+((xsub-1)*64),xsize) | |
| y = math.min(y+((ysub-1)*64),ysize) | |
| local color = img:get_pixel(x,y) | |
| if color.alpha == 0 then | |
| b64 = b64..packpixel("000000") | |
| else | |
| b64 = b64..packpixel(string.format("%02X%02X%02X",color.red,color.green,color.blue)) | |
| end | |
| end | |
| for y=0,63,1 do | |
| for x=0,63,1 do | |
| processcolor(x,y,xsub,ysub) | |
| end | |
| end | |
| local b641 = string.sub(b64,1,8192) | |
| local b642 = string.sub(b64,8193,-1) | |
| print("local data = \""..b641.."\"..\n\""..b642.."\"") | |
| print("if event.type ~= \"program\" then return end\n".. | |
| "digiline_send(\"gpu\",{\n".. | |
| " {command=\"createbuffer\",buffer=0,xsize=64,ysize=64},\n".. | |
| " {command=\"loadpacked\",buffer=0,x=1,y=1,xsize=64,ysize=64,data=data},\n".. | |
| " {command=\"send\",buffer=0,channel=\""..xsub.."."..ysub.."\"},\n".. | |
| "})") | |
| print() | |
| print() | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment