1. 28 color gimp palette generator

    this python script generates a gimp palette which you can use to convert rgb images to an indexed image which can be converted for use on the avr.

    # copy-it-right
    
    def main():
        colors = set()
    
        print 'GIMP Palette'
        print 'Name: avr-vga'
        print 'Columns: 0'
        print '#'
    
        for n in range(0, 256):
            b = bin(n)[2:].rjust(8, '0')[:-2] + '00'
            colors.add(b)
    
        colors = list(colors)
        colors.sort()
        colors.reverse()
        color_map = {}
    
        for c in colors:
    
            r = 0
            g = 0
            b = 0
    
            if int(c[0]):
                b += 127.5
            if int(c[1]):
                g += 127.5
            if int(c[2]):
                r += 127.5
            if int(c[3]):
                b += 127.5
            if int(c[4]):
                g += 127.5
            if int(c[5]):
                r += 127.5
    
            color_map[(r, g, b)] = c
    
        colors = color_map.items()
        colors.sort(key=lambda i: i[0])
    
        for (r, g, b), c in colors:
            print ' %3i %3i %3i\t%s' % (r, g, b, c)
    
    
    if __name__ == '__main__':
        main()
    

Powered by Tumblr; designed by Adam Lloyd.