# HG changeset patch # User Mike Pavone # Date 1378226230 25200 # Node ID 3148b6389042f0c064ddbb2a865b351b5b96bf4b # Parent a74776d80f95259567c24b58dadfe76e6aee5cf0 Set dynamic colors to 8 in tiles2img diff -r a74776d80f95 -r 3148b6389042 tiles2img.py --- a/tiles2img.py Tue Sep 03 09:36:29 2013 -0700 +++ b/tiles2img.py Tue Sep 03 09:37:10 2013 -0700 @@ -3,7 +3,7 @@ def gchannel(Val): return (Val >> 4) & 0xE - + threshold = 127 def get_color_info(pixels, rng, threshold, exclude={}): @@ -26,10 +26,10 @@ glist.sort() glist.reverse() return glist - + def totiles(im, palette): pass - + def make_palette(im, trans_thresh, max_global, max_line): pixels = im.getdata() (width, height) = im.size @@ -49,7 +49,7 @@ line_pal[color] = idx line_pals.append(line_pal) return (glob_pal, line_pals) - + def color_dist(a, b): (ra, ga, ba) = a (rb, gb, bb) = b @@ -106,9 +106,9 @@ for x in xrange(0, width): gpixels.append(0) height += 8-(height%8) - + return (width, height, gpixels) - + def appendword(b, word): b.append(word >> 8) b.append(word & 0xff) @@ -122,7 +122,7 @@ appendword(b, words) appendword(b, cwidth) appendword(b, cheight) - + for cy in xrange(0, cheight): ystart = cy*8*width for cx in xrange(0, cwidth): @@ -135,7 +135,7 @@ #print 'pixels[boff]:', pixels[boff] b.append(pixels[boff] << 4 | pixels[boff+1]) return b - + def add_pal_entries(tiles, pal): (global_pal, line_pals) = pal pal_list = [()] * len(global_pal) @@ -168,7 +168,7 @@ if palidx < len(fixedpal): return fixedpal[palidx] return linepals[y][palidx - len(fixedpal)] - + def to_pixels(tiles, im): (_, width, height), tiles, (fixedpal, linepals) = tiles for y in xrange(0, height): @@ -176,7 +176,7 @@ color = getcolor(tiles, fixedpal, linepals, width, x, y) im.putpixel((x,y), color) return im - + def expand_pal(pal): def expand_pal_int(pal): return ((pal << 4) & 0xE0, pal & 0xE0, (pal >> 4) & 0xE0) @@ -184,7 +184,7 @@ fixedpal = [expand_pal_int(color) for color in fixedpal] linepals = [[expand_pal_int(color) for color in linepal] for linepal in linepals] return (fixedpal, linepals) - + def open_tiles(name): from struct import unpack, unpack_from f = open(name, 'rb') @@ -194,8 +194,8 @@ height *= 8 meta = (words, width, height) pixels = bytearray(f.read(words * 2)) - numfixed = 12 - numdynamic = 4 + numfixed = 8 + numdynamic = 8 fixedpalb = f.read(numfixed*2) fixedpal = [] for offset in xrange(0, numfixed*2, 2): @@ -223,7 +223,7 @@ to_pixels(tiles, im) out = open(argv[2], 'wb') im.save(out) - + if __name__ == '__main__': import sys main(sys.argv)