--- xs-rh.py	2005-04-01 18:20:22.221040508 +1000
+++ xs.py	2004-07-10 13:08:35.000000000 +1000
@@ -67,70 +67,6 @@
 
 ##################################################
 #
-# my GIMP palette object can find nearest colors!
-#
-##################################################
-
-class GIMPPalette:
-
-    def __init__(self, palette=None):
-        self.palette = {}
-
-    def setDefaultPalette(self, palette):
-        self.name = "Default Palette"
-        #print len(palette)
-        i = 0
-        while i < len(palette)/3:
-            self.palette[str(palette[i*3:i*3+3])] = palette[i*3:i*3+3]
-            i = i + 1
-        #print self.palette
-        
-    def loadPalette(self,filename):
-        try:
-            f=open(gimp_palette_file, 'r')
-        # the first three lines are assumed to be header info
-            f.readline()
-            self.name = f.readline()
-            f.readline()
-            f.readline()
-            filelines = f.readlines()
-            gimp_colors = {}
-            for dmc_color in filelines:
-                color_component_list = dmc_color.split()
-                color_name = ""
-                gimp_colors[color_name.join(color_component_list[3:])] = map(int,color_component_list[0:3])
-            self.palette = gimp_colors
-        except IOError, err:
-            AssertionError("Couldn't open %s for reading: %s" % (filename, err.strerror))
-
-    def getPalette(self):
-        return self.palette
-
-#################################################
-#
-# Find the closest color within a set (self.palette)
-# to the true pixel color value.
-#
-#################################################
-    def getBestMatch(self, rgb_array):
-        true_r, true_g, true_b = rgb_array
-        palette_difference = {}
-        for color in self.palette:
-            dmc_R, dmc_G, dmc_B = self.palette[color]
-          # sum of the squares of the difference between the true palette and thread palette
-            palette_difference[color] = (dmc_R - true_r)**2 + (dmc_G - true_g)**2 + (dmc_B - true_b)**2
-         
-        bestcolor = ""
-        matchvalue = 9999
-        while len(palette_difference):
-            testcolor, testvalue = palette_difference.popitem()
-            if testvalue < matchvalue:
-                matchvalue = testvalue
-                bestcolor = testcolor
-        return self.palette[bestcolor], bestcolor        
-
-##################################################
-#
 # function draws one symbol on location x,y
 #
 ##################################################
@@ -142,13 +78,10 @@
             c.fill(s.transformed(trafo.translate(x,y)))
         else:
             c.stroke(s.transformed(trafo.translate(x,y)))
-def quit_program():
-    print "Usage: prog file.png [-p palette.gpl]"
-    print "  where palette.gpl is a color palette file in GIMP format"
-    sys.exit(0)
 
-if len(sys.argv) < 2 or len(sys.argv) > 4:
-    quit_program()
+if len(sys.argv) != 2:
+    print "Usage: prog file.png"
+    assert(0)
 in_file = sys.argv[1]
 in_file_root,in_file_ext = os.path.splitext(in_file)
 im = Image.open(in_file)
@@ -166,37 +99,6 @@
 
 ##################################################
 #
-# if commanded, load the DMC palette, otherwise the true palette
-#
-##################################################
-gimp_palette_file = ''
-thread_palette = GIMPPalette()
-thread_palette.setDefaultPalette(pal_data)
-if len(sys.argv) > 2:
-    if sys.argv[2] == '-p':
-        gimp_palette_file = sys.argv[3]
-        thread_palette.loadPalette(gimp_palette_file)
-    else:
-        quit_program()
-dmc_colors = thread_palette.getPalette();
-
-##################################################
-#
-# go throught all the colors in the current palette and find the bast match
-#
-##################################################
-print "finding palette matches."
-x = 0
-replacements = {}
-while x < len(pal_data)/3:
-    pic_R, pic_G, pic_B = pal_data[x*3:x*3+3]
-    replacements[str(pal_data[x*3:x*3+3])] = thread_palette.getBestMatch(pal_data[x*3:x*3+3])
-    x = x + 1
-print 'matching complete.'
-print 'rendering postscript...'
-
-##################################################
-#
 # compose legend for symbols <-> colour
 #
 ##################################################
@@ -206,20 +108,14 @@
     r,g,b = map(lambda a:a/255.,tuple(pal_data[i*3:i*3+3]))
     y = i
     s = path.rect(x,y,1,1)
-    t = path.rect(x+2,y,1,1)
     c.stroke(s)
     if i != transparency:
         c.fill(s, [color.rgb(r,g,b)])
-        hash = str(pal_data[i*3:i*3+3])
-        dmc_color = replacements[hash]
-        dmc_r, dmc_g, dmc_b = map(lambda a:a/255.,tuple(dmc_color[0]))
-        c.fill(t, [color.rgb(dmc_r, dmc_g, dmc_b)])
-        c.text(x+3,y, str(dmc_color[1]))
     draw_symbol(c,(x+1,y),i)
 
-c.text(x,y+1, r"true")
-c.text(x+2, y+1, thread_palette.name)
 c.writetofile(in_file_root+"-colour.eps")
+
+
 c = canvas.canvas()
 
 ##################################################
@@ -250,4 +146,3 @@
         draw_symbol(c,(x,y), im.getpixel((x,height-y-1)))
 c.writetofile(in_file_root+".eps")
 
-
