# HG changeset patch # User Mike Pavone # Date 1378519736 25200 # Node ID eddc4ba6b0c330e4ba2f65817befa168c75259b1 # Parent 997690aa05076de5413e545ea59d76d685b80b79 Use error*count method for choosing static palette entries, not just dynamic ones diff -r 997690aa0507 -r eddc4ba6b0c3 img2tiles.py --- a/img2tiles.py Wed Sep 04 00:41:52 2013 -0700 +++ b/img2tiles.py Fri Sep 06 19:08:56 2013 -0700 @@ -80,17 +80,21 @@ print len(colors), 'distinct 9-bit colors in image' glob_pal = {} print 'Static Palette:' - for idx in xrange(0, min(max_global, len(colors))): + while len(glob_pal) < max_global: + (score, color) = colors[0] + idx = len(glob_pal) (count, color) = colors[idx] - print str(idx) + ':', color, '(used', count, 'times)' + print str(idx) + ':', color glob_pal[color] = idx + colors = get_color_info_both(pixels, xrange(0, height * width), trans_thresh, glob_pal) line_pals = [] if max_global < len(colors): for line in xrange(0, height): linestart = line * width - #linecolors = get_color_info(pixels, xrange(linestart, linestart+width), trans_thresh, glob_pal) - #linecolors = get_color_info_error(pixels, xrange(linestart, linestart+width), trans_thresh, glob_pal) - linecolors = get_color_info_both(pixels, xrange(linestart, linestart+width), trans_thresh, glob_pal) + if len(glob_pal): + linecolors = get_color_info_both(pixels, xrange(linestart, linestart+width), trans_thresh, glob_pal) + else: + linecolors = get_color_info(pixels, xrange(linestart, linestart+width), trans_thresh) line_pal = {} while len(line_pal) < max_line and len(linecolors): (score, color) = linecolors[0]