Mercurial > repos > ghero
comparison img2tiles.py @ 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 |
comparison
equal
deleted
inserted
replaced
9:997690aa0507 | 10:eddc4ba6b0c3 |
---|---|
78 (width, height) = im.size | 78 (width, height) = im.size |
79 colors = get_color_info(pixels, xrange(0, height * width), trans_thresh) | 79 colors = get_color_info(pixels, xrange(0, height * width), trans_thresh) |
80 print len(colors), 'distinct 9-bit colors in image' | 80 print len(colors), 'distinct 9-bit colors in image' |
81 glob_pal = {} | 81 glob_pal = {} |
82 print 'Static Palette:' | 82 print 'Static Palette:' |
83 for idx in xrange(0, min(max_global, len(colors))): | 83 while len(glob_pal) < max_global: |
84 (score, color) = colors[0] | |
85 idx = len(glob_pal) | |
84 (count, color) = colors[idx] | 86 (count, color) = colors[idx] |
85 print str(idx) + ':', color, '(used', count, 'times)' | 87 print str(idx) + ':', color |
86 glob_pal[color] = idx | 88 glob_pal[color] = idx |
89 colors = get_color_info_both(pixels, xrange(0, height * width), trans_thresh, glob_pal) | |
87 line_pals = [] | 90 line_pals = [] |
88 if max_global < len(colors): | 91 if max_global < len(colors): |
89 for line in xrange(0, height): | 92 for line in xrange(0, height): |
90 linestart = line * width | 93 linestart = line * width |
91 #linecolors = get_color_info(pixels, xrange(linestart, linestart+width), trans_thresh, glob_pal) | 94 if len(glob_pal): |
92 #linecolors = get_color_info_error(pixels, xrange(linestart, linestart+width), trans_thresh, glob_pal) | 95 linecolors = get_color_info_both(pixels, xrange(linestart, linestart+width), trans_thresh, glob_pal) |
93 linecolors = get_color_info_both(pixels, xrange(linestart, linestart+width), trans_thresh, glob_pal) | 96 else: |
97 linecolors = get_color_info(pixels, xrange(linestart, linestart+width), trans_thresh) | |
94 line_pal = {} | 98 line_pal = {} |
95 while len(line_pal) < max_line and len(linecolors): | 99 while len(line_pal) < max_line and len(linecolors): |
96 (score, color) = linecolors[0] | 100 (score, color) = linecolors[0] |
97 line_pal[color] = len(line_pal) + max_global | 101 line_pal[color] = len(line_pal) + max_global |
98 if len(line_pal) < max_line: | 102 if len(line_pal) < max_line: |