Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function readInteger(hndl)
- local buffer = hndl:read(4)
- if buffer == nil or #buffer < 4 then
- return nil
- end
- local bytes = {}
- bytes[1] = string.byte(buffer, 1)
- bytes[2] = string.byte(buffer, 2)
- bytes[3] = string.byte(buffer, 3)
- bytes[4] = string.byte(buffer, 4)
- local num = bytes[1] + bit32.lshift(bytes[2], 8) + bit32.lshift(bytes[3], 16) + bit32.lshift(bytes[4], 24)
- return num
- end
- function mkBrairle(x1y1,x1y2,x1y3,x1y4,x2y1,x2y2,x3y2,x4y2)
- local base = 0x2800
- if x1y1 then
- base = base + 0x01
- end
- if x1y2 then
- base = base + 0x02
- end
- if x1y3 then
- base = base + 0x04
- end
- if x1y4 then
- base = base + 0x40
- end
- if x2y1 then
- base = base + 0x08
- end
- if x2y2 then
- base = base + 0x10
- end
- if x2y3 then
- base = base + 0x20
- end
- if x2y4 then
- base = base + 0x80
- end
- return require("unicode").char(base)
- end
- function reverseTable(input)
- local new = {}
- for i=1,#input do
- new[#input+1-i] = input[i]
- end
- return new
- end
- function addColors(r,g,b)
- local c = b
- local t = math.pow(2,8)
- c = t * g + c
- t = math.pow(2,16)
- c = t * r + c
- return c
- end
- local gpu = require('component').gpu
- function splitByte(byte)
- local data = {}
- local remaining = byte
- for i=7,0,-1 do
- local toRm = math.pow(2, i)
- if remaining - toRm > -1 then
- remaining = remaining - toRm
- data[i + 1] = true
- else
- data[i + 1] = false
- end
- end
- return data
- end
- function zdraw(path)
- local handle = io.open(path, 'rb')
- readInteger(handle)
- local readstart = readInteger(handle)
- local w = readInteger(handle)
- local h = readInteger(handle)
- local rawSegments = {}
- for j=1,h do
- for i=1,w do
- if rawSegments[i] == nil then
- rawSegments[i] = {}
- end
- seg = handle:read(7)
- rawSegments[i][j] = {}
- for k=1,7 do
- rawSegments[i][j][k] = seg:sub(k,k)
- end
- end
- end
- for i=1,#rawSegments do
- for j=1,#rawSegments[i] do
- gpu.setBackground(addColors(
- string.byte(rawSegments[i][j][1]),
- string.byte(rawSegments[i][j][2]),
- string.byte(rawSegments[i][j][3])))
- gpu.setForeground(addColors(
- string.byte(rawSegments[i][j][4]),
- string.byte(rawSegments[i][j][5]),
- string.byte(rawSegments[i][j][6])))
- local pix = splitByte(string.byte(rawSegments[i][j][7]))
- -- pix = reverseTable(pix)
- local char = mkBrairle(pix[1], pix[2], pix[3], pix[4], pix[5], pix[6], pix[7], pix[8])
- gpu.set(i, j, char)
- end
- end
- end
- local argv= {...}
- zdraw(argv[1])
- print(mkBrairle(true,false,false,true,true))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement