# -*- Mode: Python -*-

# Author: Sam Rushing (http://www.nightmare.com/rushing)
# convert a 'Kolor Raw' format file into a 'Photoshop Raw' file
#   in a form that can be uploaded via the Gigapan Uploader.

import struct

def read_kro_header (fi):
    block = fi.read (20)
    magic, width, height, bits, colors = struct.unpack ('>4sllll', block)
    assert (magic == 'KRO\x01')
    return magic, width, height, bits, colors 

def copy (fi):
    magic, width, height, bits, colors = read_kro_header (fi)
    pixels = width * height
    fo = open ('gigapan_%dx%d.raw' % (width, height), 'wb')
    while pixels:
        fo.write (fi.read (4)[:3])
        pixels -= 1

if __name__ == '__main__':
    import sys
    fi = open (sys.argv[1], 'rb')
    copy (fi)
