Mercurial > repos > ghero
comparison img2tiles.py @ 9:997690aa0507
Improve method for choosing line palette entries. Read number of global and dynamic colors from image binary. Go back to doing a word, longword, word pattern of writes for turning off display, doing DMA and turning it back on again to make things work correctly on the real hardware.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 04 Sep 2013 00:41:52 -0700 |
parents | a049de420cc1 |
children | eddc4ba6b0c3 |
comparison
equal
deleted
inserted
replaced
8:a049de420cc1 | 9:997690aa0507 |
---|---|
90 linestart = line * width | 90 linestart = line * width |
91 #linecolors = get_color_info(pixels, xrange(linestart, linestart+width), trans_thresh, glob_pal) | 91 #linecolors = get_color_info(pixels, xrange(linestart, linestart+width), trans_thresh, glob_pal) |
92 #linecolors = get_color_info_error(pixels, xrange(linestart, linestart+width), trans_thresh, glob_pal) | 92 #linecolors = get_color_info_error(pixels, xrange(linestart, linestart+width), trans_thresh, glob_pal) |
93 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) |
94 line_pal = {} | 94 line_pal = {} |
95 for idx in xrange(0, min(max_line, len(linecolors))): | 95 while len(line_pal) < max_line and len(linecolors): |
96 (count, color) = linecolors[idx] | 96 (score, color) = linecolors[0] |
97 line_pal[color] = idx + max_global | 97 line_pal[color] = len(line_pal) + max_global |
98 if len(line_pal) < max_line: | |
99 combo = dict(glob_pal) | |
100 for color in line_pal: | |
101 combo[color] = line_pal[color] | |
102 linecolors = get_color_info_both(pixels, xrange(linestart, linestart+width), trans_thresh, combo) | |
103 #for idx in xrange(0, min(max_line, len(linecolors))): | |
104 # (count, color) = linecolors[idx] | |
105 # line_pal[color] = idx + max_global | |
98 line_pals.append(line_pal) | 106 line_pals.append(line_pal) |
99 return (glob_pal, line_pals, max_global, max_line) | 107 return (glob_pal, line_pals, max_global, max_line) |
100 | 108 |
101 def color_dist(a, b): | 109 def color_dist(a, b): |
102 (ra, ga, ba) = a | 110 (ra, ga, ba) = a |
187 b.append(pixels[boff] << 4 | pixels[boff+1]) | 195 b.append(pixels[boff] << 4 | pixels[boff+1]) |
188 return b | 196 return b |
189 | 197 |
190 def add_pal_entries(tiles, pal): | 198 def add_pal_entries(tiles, pal): |
191 (global_pal, line_pals, max_global, max_line) = pal | 199 (global_pal, line_pals, max_global, max_line) = pal |
200 tiles.append(max_global) | |
201 tiles.append(max_line) | |
192 pal_list = [(0, 0, 0)] * max_global | 202 pal_list = [(0, 0, 0)] * max_global |
193 for entry in global_pal: | 203 for entry in global_pal: |
194 pal_list[global_pal[entry]] = entry | 204 pal_list[global_pal[entry]] = entry |
195 for entry in pal_list: | 205 for entry in pal_list: |
196 (R, G, B) = entry | 206 (R, G, B) = entry |
214 fname = argv[1] | 224 fname = argv[1] |
215 static_colors = 8 | 225 static_colors = 8 |
216 dynamic_colors = 8 | 226 dynamic_colors = 8 |
217 if len(argv) > 3: | 227 if len(argv) > 3: |
218 static_colors = int(argv[3]) | 228 static_colors = int(argv[3]) |
219 dynamic_colors = min(dynamic_colors, 16-static_colors) | 229 dynamic_colors = 16-static_colors |
220 if len(argv) > 4: | 230 if len(argv) > 4: |
221 dynamic_colors = int(argv[4]) | 231 dynamic_colors = int(argv[4]) |
222 if dynamic_colors + static_colors > 16: | 232 if dynamic_colors + static_colors > 16: |
223 print "No more than 16 combined dynamic and static colors are allowed" | 233 print "No more than 16 combined dynamic and static colors are allowed" |
224 return | 234 return |