Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gpu = peripheral.wrap("top")
- gpu.setBPP(1)
- local function yield()
- os.queueEvent('whataboutno') os.pullEvent('whataboutno')
- end
- yield()
- local function massToNumber(...)
- local r = {}
- for i, v in pairs({...}) do
- table.insert(r,tonumber(v))
- end
- return unpack(r)
- end
- local nl = ("\n"):byte()
- local exists = fs.exists
- local open = fs.open
- local match = string.match
- local createTexture = gpu.createTexture
- local getBindedTexture = gpu.getBindedTexture
- local bindTexture = gpu.bindTexture
- local setPixels = gpu.setPixels
- local char = string.char
- local function readLineB(read)
- local s = ""
- local r = read()
- while r ~= nl do
- s = s..char(r)
- r = read()
- end
- return s
- end
- function loadCCIMG(file)
- local fh
- local palette = {}
- if not exists(file) then
- print("FIle not exists")
- return 0
- end
- fh = open(file,"rb")
- local read = fh.read
- --local sizeReadStart = os.clock()
- local w,h = tonumber(readLineB(read)),tonumber(readLineB(read))
- --local sizeReadEnd = os.clock()
- --print("Size reading: "..(sizeReadEnd-sizeReadStart))
- --local paletteReadStart = os.clock()
- local line = readLineB(read)
- --print(line)
- while match(line,"(%d+):(%d+),(%d+),(%d+)") do
- local i,r,g,b = massToNumber(match(line,"(%d+):(%d+),(%d+),(%d+)"))
- palette[i] = {r,g,b}
- --print(line)
- if i ~= 0 then
- line = readLineB(read)
- else
- break
- end
- end
- --local paletteReadEnd = os.clock()
- --print("Palette reading: "..(paletteReadEnd-paletteReadStart))
- --local textureCreationStart = os.clock()
- local tex = createTexture(w,h)
- local oldtex = getBindedTexture()
- --gpu.setTransparent(tex,true)
- --gpu.setTransparencyColor(tex,255,0,255)
- bindTexture(tex)
- --local textureCreationEnd = os.clock()
- --print("Texture creation: "..(textureCreationEnd-textureCreationStart))
- --local pixelReadStart = os.clock()
- local pat = 1
- local pixels = {}
- --local plot = gpu.plot
- --local close = fh.close
- local i = read()
- while i ~= nil do
- if pat%(96*8) == 0 then yield() end
- local r,g,b = palette[i][1],palette[i][2],palette[i][3]
- pixels[pat] = r
- pixels[pat+1] = g
- pixels[pat+2] = b
- pat = pat+3
- --plot(r,g,b,x-1,y-1)
- i = read()
- end
- --local pixelReadEnd = os.clock()
- --print("Pixel reading: "..(pixelReadEnd-pixelReadStart))
- --local pixelSettingStart = os.clock()
- setPixels(w,h,0,0,unpack(pixels))
- --local pixelSettingEnd = os.clock()
- --print("Pixel setting: "..(pixelSettingEnd-pixelSettingStart))
- fh.close()
- bindTexture(oldtex)
- return tex
- end
- local startTime = os.clock()
- local tex = {}
- --loadCCIMG("vid/image-1.ccimg")
- for i=1, 1024 do
- print("Loading "..i)
- tex[i] = loadCCIMG("vid/image-"..i..".ccimg")
- --gpu.freeTexture(loadCCIMG("vid/image-"..i..".ccimg"))
- --sleep(0)
- if i%32 == 0 then yield() end
- end
- local endTime = os.clock()
- print("CCIMG: "..(endTime-startTime))
- local draw = gpu.drawTexture
- local free = gpu.freeTexture
- bindTexture(0)
- for i=1, 1024 do
- draw(tex[i],0,0)
- free(tex[i])
- sleep(0)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement