#!/usr/bin/env python import sys def mkRGB (px): r = ord (px[1]) & 0xf8 g = (ord (px[1]) & 0x07) << 5 g += (ord (px[0]) & 0xe0) >> 3 b = (ord (px[0]) & 0x1f) << 3 r = r + (r >> 5) g = g + (g >> 6) b = b + (b >> 5) return chr(r) + chr(g) + chr(b) sys.argv.append ('-') sys.argv.append ('-') if sys.argv[1] != '-': input = file (sys.argv[1]) else: input = sys.stdin if sys.argv[2] != '-': output = file (sys.argv[2], "w") else: output = sys.stdout imagedata = input.read () [:800 * 480 * 2] conv = "".join ([mkRGB (z) for z in zip (imagedata[::2], imagedata[1::2])]) output.write ("P6 800 480 255\n") output.write (conv)