#!/usr/local/bin/python

"otb Nokia OTA Bitmap "

"""
   +00 number of animated icons
   +01 width in pixels
   +02 height in pixels
   +03 bits per pixel
"""

def tobits(x):
   s = []
   for b in range(8):
      s += [ [ 0, 1 ][x&1] ]
      x >>= 1
   s.reverse()
   return s

import sys, struct

fp = open(sys.argv[1])

icons, width, height, bpp = struct.unpack('BBBB', fp.read(4))

bits = []

while 1:
   c = fp.read(1)
   if not c:
      break
   bits += tobits(ord(c))

size = ( width, height )
step = 0

print len(bits), len(bits) / size[1], size[0] * size[1]

def render(bits):
   global size, step
   print "Using", size, "and", step
   for y in range(size[1]):
      for x in range(size[0]):
         try:
            sys.stdout.write([ ' ', 'X' ][bits[step + y*size[0] + x]])
         except:
            sys.stdout.write('!')
      sys.stdout.write('.\n')

render(bits)
while 1:
   cmd = raw_input('cmd:')
   if cmd == 'd':
      size = input('size:')
   elif cmd == 's':
      step = int(raw_input('step:'))
   render(bits)