Mercurial > repos > ghero
changeset 10:eddc4ba6b0c3
Use error*count method for choosing static palette entries, not just dynamic ones
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 06 Sep 2013 19:08:56 -0700 |
parents | 997690aa0507 |
children | 19226d79f839 |
files | img2tiles.py |
diffstat | 1 files changed, 9 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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]