#!/usr/bin/env python
from PIL import Image
from sys import argv
from os import system, unlink

def get_pixel(pixel):
  if type(pixel)==int:
    return ""
  elif (pixel[0]>pixel[1]) and (pixel[0]>pixel[2]):
    return ' '
  elif (pixel[1]>pixel[0]) and (pixel[1]>pixel[2]):
    return '\t'
  elif (pixel[2]>pixel[0]) and (pixel[2]>pixel[1]):
    return '\n'
  else:
    return ""

print
print "    Colorspace"
print
print "(C) GNU GPLv2+ 2010 Sebastian Krzyszkowiak and Agata Kurczewska"
print "---------------------------------------------------------------"

if len(argv)<2:
  print "Image not specified."
  exit(0)

im = Image.open(argv[1]).getdata()
prog = ""
for pixel in im:
  prog+=get_pixel(pixel)

f = open("/tmp/colorspace.ws", "w")
f.write(prog)
f.close()

system("wspace /tmp/colorspace.ws")
unlink("/tmp/colorspace.ws")
