''' Purpose: support image palette reduction transformation ''' def size( original ) : ''' Purpose: return the size of the new image when performing a palette reduction ''' nw, nh = original.size return (nw, nh) def distance( p1, p2 ) : ''' Returns the distance between p1 and p2; that is the sum of the red differences, green differences, and blue differences, where difference is an absolute value. ''' pass def color( opixel ) : ''' Returns the pixel in PALETTE8 to which opixel is closest ''' PALETTE8 = [ ( 0, 0, 0), (255,255,255), ( 0,255, 0), ( 0, 0,255), (255, 0, 0), (255,255, 0), (255, 0,255), ( 0,255,255) ] pass def where( nspot, original = None ) : ''' Purpose: return the correspondent of nspot in the original when doing a palette reduction ''' ospot = nspot return ospot if ( __name__ == '__main__' ) : import url from manip import manip # get web image of interest link = "http://www.cs.virginia.edu/~cs1112/images/mandrill/full.png" original = url.get_image( link ) new_image = manip( original, size, color, where ) new_image.show()