Advertisement
ds84182

video

Jul 14th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.98 KB | None | 0 0
  1. gpu = peripheral.wrap("top")
  2. gpu.setBPP(1)
  3.  
  4. local function yield()
  5.     os.queueEvent('whataboutno') os.pullEvent('whataboutno')
  6. end
  7. yield()
  8.  
  9. local function massToNumber(...)
  10.     local r = {}
  11.     for i, v in pairs({...}) do
  12.         table.insert(r,tonumber(v))
  13.     end
  14.     return unpack(r)
  15. end
  16.  
  17. local nl = ("\n"):byte()
  18. local exists = fs.exists
  19. local open = fs.open
  20. local match = string.match
  21. local createTexture = gpu.createTexture
  22. local getBindedTexture = gpu.getBindedTexture
  23. local bindTexture = gpu.bindTexture
  24. local setPixels = gpu.setPixels
  25. local char = string.char
  26.  
  27. local function readLineB(read)
  28.     local s = ""
  29.     local r = read()
  30.     while r ~= nl do
  31.         s = s..char(r)
  32.         r = read()
  33.     end
  34.     return s
  35. end
  36.  
  37. function loadCCIMG(file)
  38.     local fh
  39.     local palette = {}
  40.     if not exists(file) then
  41.         print("FIle not exists")
  42.         return 0
  43.     end
  44.     fh = open(file,"rb")
  45.     local read = fh.read
  46.     --local sizeReadStart = os.clock()
  47.     local w,h = tonumber(readLineB(read)),tonumber(readLineB(read))
  48.     --local sizeReadEnd = os.clock()
  49.     --print("Size reading: "..(sizeReadEnd-sizeReadStart))
  50.     --local paletteReadStart = os.clock()
  51.     local line = readLineB(read)
  52.     --print(line)
  53.     while match(line,"(%d+):(%d+),(%d+),(%d+)") do
  54.         local i,r,g,b = massToNumber(match(line,"(%d+):(%d+),(%d+),(%d+)"))
  55.         palette[i] = {r,g,b}
  56.         --print(line)
  57.         if i ~= 0 then
  58.             line = readLineB(read)
  59.         else
  60.             break
  61.         end
  62.     end
  63.     --local paletteReadEnd = os.clock()
  64.     --print("Palette reading: "..(paletteReadEnd-paletteReadStart))
  65.     --local textureCreationStart = os.clock()
  66.     local tex = createTexture(w,h)
  67.     local oldtex = getBindedTexture()
  68.     --gpu.setTransparent(tex,true)
  69.     --gpu.setTransparencyColor(tex,255,0,255)
  70.     bindTexture(tex)
  71.     --local textureCreationEnd = os.clock()
  72.     --print("Texture creation: "..(textureCreationEnd-textureCreationStart))
  73.     --local pixelReadStart = os.clock()
  74.     local pat = 1
  75.     local pixels = {}
  76.     --local plot = gpu.plot
  77.     --local close = fh.close
  78.     local i = read()
  79.     while i ~= nil do
  80.         if pat%(96*8) == 0 then yield() end
  81.         local r,g,b = palette[i][1],palette[i][2],palette[i][3]
  82.         pixels[pat] = r
  83.         pixels[pat+1] = g
  84.         pixels[pat+2] = b
  85.         pat = pat+3
  86.         --plot(r,g,b,x-1,y-1)
  87.         i = read()
  88.     end
  89.     --local pixelReadEnd = os.clock()
  90.     --print("Pixel reading: "..(pixelReadEnd-pixelReadStart))
  91.     --local pixelSettingStart = os.clock()
  92.     setPixels(w,h,0,0,unpack(pixels))
  93.     --local pixelSettingEnd = os.clock()
  94.     --print("Pixel setting: "..(pixelSettingEnd-pixelSettingStart))
  95.     fh.close()
  96.     bindTexture(oldtex)
  97.     return tex
  98. end
  99.  
  100. local startTime = os.clock()
  101. local tex = {}
  102. --loadCCIMG("vid/image-1.ccimg")
  103. for i=1, 1024 do
  104.     print("Loading "..i)
  105.     tex[i] = loadCCIMG("vid/image-"..i..".ccimg")
  106.     --gpu.freeTexture(loadCCIMG("vid/image-"..i..".ccimg"))
  107.     --sleep(0)
  108.     if i%32 == 0 then yield() end
  109. end
  110. local endTime = os.clock()
  111. print("CCIMG: "..(endTime-startTime))
  112. local draw = gpu.drawTexture
  113. local free = gpu.freeTexture
  114. bindTexture(0)
  115. for i=1, 1024 do
  116.     draw(tex[i],0,0)
  117.     free(tex[i])
  118.     sleep(0)
  119. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement