import sys
import os
import re

def CsToBits(Cs):
	bits = re.findall(r'\d+', Cs)[0]
	if Cs.lower().find("x") >= 0 and int(bits) == 32:
		return "24";
	return bits

def IsRgb(Cs):
	return Cs.lower().find("rgb") >= 0 or Cs.lower().find("bgr") >= 0

def CsToPx(Cs):
	return "G" + Cs[2:]

def HasAlpha(Cs):
	return Cs.lower().find("a") >= 0

txt = open(os.path.join("..", "..", "..", "include", "common", "GColourSpace.h"), "r").read().split("\n")
in_cs_def = False
colourspaces = []
for t in txt:
	if t.find("enum GColourSpace") >= 0:
		in_cs_def = True
	elif in_cs_def:
		if t.find("}") >= 0:
			in_cs_def = False
		elif t.find("Cs") > 0 and t.find("CsNone") < 0:
			parts = t.split()
			cs = parts[0]
			colourspaces.append(parts[0])
			# print "// ", cs, CsToBits(cs)

print "// This file is generated by", sys.argv[0]
for dst_cs in colourspaces:
	for src_cs in colourspaces:
		if IsRgb(dst_cs) and IsRgb(src_cs):
			print "case JointCs("+dst_cs+", "+src_cs+"):"
			if HasAlpha(src_cs):
				print "\tif (Composite)"
				print "\t\tGComposite" + CsToBits(src_cs) + "To" + CsToBits(dst_cs) + "((" + CsToPx(dst_cs) + "*)d, (" + CsToPx(src_cs) + "*)s, x);"
				print "\telse";
				print "\t\tGRop" + CsToBits(src_cs) + "To" + CsToBits(dst_cs) + "((" + CsToPx(dst_cs) + "*)d, (" + CsToPx(src_cs) + "*)s, x);"
			else:
				print "\tGRop" + CsToBits(src_cs) + "To" + CsToBits(dst_cs) + "((" + CsToPx(dst_cs) + "*)d, (" + CsToPx(src_cs) + "*)s, x);"
			print "\tbreak;"