Guest User

Untitled

a guest
Apr 17th, 2014
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. from pylab import *
  2. import sys
  3.  
  4.  
  5. fd = open('screen_data.bin', 'rb')
  6. data = fd.read()
  7. fd.close()
  8.  
  9. frames = data.split('\x1E\x00')
  10. print len(frames), 'frames'
  11.  
  12.  
  13. colors = {0: '#000000', 1: '#555555', 2: '#CCCCCC', 3: '#FFFFFF'}
  14.  
  15. # Reversed color scheme just in case
  16. #colors = {3: '#000000', 2: '#555555', 1: '#CCCCCC', 0: '#FFFFFF'}
  17.  
  18. # How many frames to skip from the beginning of the transmission
  19. skip = 30
  20.  
  21.  
  22. for frame in frames:
  23.     pixels = []
  24.  
  25.     # First and last frames can be smaller than that (because there's small chance we start capture right at the beginning of the frame)
  26.     if len(frame)!=5760:
  27.         continue
  28.  
  29.  
  30.     # Skipe frames if needed
  31.     if skip!=0:
  32.         skip-=1
  33.         continue
  34.  
  35.  
  36.     # Restore pixels from byte array
  37.     for y in range(144):
  38.         for x in range(160):
  39.  
  40.            
  41.             bit_offset = y*320+x*2
  42.             array_offset = bit_offset/8
  43.             byte_offset = bit_offset%8
  44.  
  45.             byte = ord(frame[array_offset])
  46.             pixel = (byte>>byte_offset)&0b11
  47.             c = colors[pixel]
  48.            
  49.             scatter(x, y, color = c, s=1)
  50.     show()
  51.  
  52.     break
Advertisement
Add Comment
Please, Sign In to add comment