import PIL.Image # # Utilities # # save a bytearray to a file def bin_save(filename,b): print("%20s %6d bytes" % (filename,len(b))) open(filename,"wb").write(b) # bad binary block to alignment def pad_align(b,align,fill=0): while (len(b) % align) != 0: b.append(fill) return b # load an image as indexed def index_img_load(filename): img = PIL.Image.open(filename) assert (img.mode == "P") # image must must be indexed palette colour format return img # set image palette from RGB tuples def index_setpal(img,palette): linpal = [p for tup in palette for p in tup[0:3]] img.putpalette(linpal) # get RGB tuples from image palette def index_getpal(img): linpal = img.getpalette() pal = [] for i in range(0,len(linpal)-2,3): pal.append(tuple(linpal[i:i+3])) return pal # convert palette to SNES 555 format def snes_pal(palette): d = bytearray() for p in palette: r = p[0] >> 3 g = p[1] >> 3 b = p[2] >> 3 d.append(r | ((g & 7) << 5)) d.append((g >> 3) | (b << 2)) return d # convert rectangles to CHR data, planes = 1 (2bpp) or 2 (4bpp) or 4 (8bpp) def chr(img,x=0,y=0,w=-1,h=-1,planes=2): b = bytearray() if w < 0: w = img.size[0] - x if h < 0: h = img.size[1] - y for ty in range(y,y+h,8): for tx in range(x,x+w,8): for tp in range(planes): for py in range(8): b0 = 0 b1 = 0 for px in range(8): p = (img.getpixel((tx+px,ty+py)) >> (tp * 2)) & 3 b0 = (b0 << 1) | (p & 1) b1 = (b1 << 1) | ((p >> 1) & 1) b.append(b0) b.append(b1) return b # # build # # make a bank def make_palcycle(filename,cycle_list): SCALE = 256 / 15000 print("make_palcycle(\"%s\")" % (filename)) img = index_img_load(filename) x0 = (img.width - 256) // 2 y0 = (img.height - 224) // 2 img = img.crop((x0,y0,x0+256,y0+224)) b = chr(img,planes=4) b += snes_pal(index_getpal(img)) for (c0,c1,speed,reverse) in cycle_list: assert(c1 > c0 or (c1 == 0 and c0 == 0)) # cycle range can't be backwards or 1 colour b.append(c0) b.append(c1) b.append(int(speed*SCALE)) b.append(reverse) return b # make a set of banks def make_set(art_list,binfile): art = bytearray() for (filename,cycle_list) in art_list: art += make_palcycle(filename,cycle_list) pad_align(art,64*1024,0) bin_save(binfile,art) # the list is made of an image, plus a list of colour ranges to rotate # each range is: start color, end color (inclusive), speed, mode # speed must be in the range of 59 to 14940 # 15000 would rotate the colours every frame, 7500 every 2 frames, etc. # mode can be: # 0 = forward # 1/2 = reverse # 16 = forward but in increments of 16 (a special case for the maelstrom 16x16 2D palette) # 17 = "split" mode: x,y are 2 start indices in the list which will alternate every tick demo_list = [ ("acid1.png",[(0,223,3100,1),(224,255,2000,1)]), ("maze1.png",[(2,128,3000,0),(129,255,3000,0)]), ("maelstrom1.png",[(x*16,x*16+15,3700,1) for x in range(16)]+[(0,255,5100,16)]), ("maze2.png",[(2,128,3000,0),(129,255,3000,0)]), ("acid2.png",[(0x10,0x8F,2700,1),(0x90,0xEF,4000,0),(0xF0,0xFF,2000,1)]), ("maelstrom2.png",[(1,3,59,17),(0,255,9000,16),(0,0,0,0)]+[(x*16,x*16+15,9000,0) for x in range(16)]), ("maze3.png",[(2,128,3000,0),(129,255,3000,0)]), ] # if your list is more than 3 images, increase the PRG size in palcycle.cfg, # and increase the mbit size in the palcycle.s HEADER # I can't redistribute these images, but for info on this data source, see: # https://github.com/jtsiomb/colcycle ferrari_list = [ ("ferrari/coral.js.tga",[(16,31,3456,0),(32,47,3456,0),(48,55,3456,2),(56,63,2457,0),(73,80,2148,0),(87,94,3456,0),(95,102,1536,0),(103,110,1689,0),(113,117,2304,2),(128,135,2457,0),(137,144,1536,0),(146,153,1536,0),(155,162,1536,0),(163,170,1689,0),(171,176,1842,0),]), ("ferrari/v01.js.tga",[(48,63,1995,0),(64,79,1995,0),(80,95,1995,0),(96,103,1536,0),(104,111,1536,0),(112,119,2688,0),(120,127,2304,0),(144,151,1536,0),(152,159,1536,0),(160,167,1995,0),(168,175,1995,0),(176,183,1995,0),(184,191,1995,0),(192,199,1995,0),(128,143,1995,0),(200,214,2688,0),]), ("ferrari/v02.js.tga",[(128,135,2304,0),(136,143,2304,0),(152,159,2304,0),(144,151,2304,0),(160,167,2304,0),(168,175,2304,0),(176,183,2304,0),(184,191,2148,0),(192,199,2304,0),(200,207,2304,0),(208,215,2304,0),(216,223,2304,0),(224,231,2304,0),(232,239,2304,0),(247,253,1995,0),(240,246,1689,0),]), ("ferrari/v03.js.tga",[(232,239,1689,2),(224,231,1689,2),(216,223,1689,0),(208,215,1689,2),(200,207,1689,0),(192,199,1689,0),(184,191,1689,0),(176,183,1689,0),(168,175,1689,2),(160,167,1689,2),]), ("ferrari/v04.js.tga",[(112,116,4914,0),(117,121,4914,0),(122,126,4914,0),(127,131,4914,0),(132,136,4914,0),(137,141,4914,0),(142,146,4914,0),(147,151,4914,0),(152,156,4914,0),(157,161,4914,0),(162,166,4914,0),(167,171,4914,0),(172,176,4914,0),(177,181,4914,0),(182,186,4914,0),(187,191,4914,0),]), ("ferrari/v05haunt.js.tga",[(160,164,1227,0),(165,169,3300,0),(170,174,2994,0),(176,199,1074,2),(200,223,1074,2),(150,159,1380,2),(232,235,1074,0),]), ("ferrari/v05rain.js.tga",[(215,219,4914,0),(210,214,4914,0),(205,209,4914,0),(200,204,4914,0),(195,199,4914,0),(190,194,4914,0),(171,175,4914,0),(166,170,4914,0),(161,165,4914,0),(156,160,4914,0),(151,155,4914,0),(146,150,4914,0),(141,145,4914,0),]), ("ferrari/v07.js.tga",[(112,127,1227,0),(128,143,1227,0),(144,159,1227,0),(160,175,1227,0),(176,191,1227,0),(240,247,1995,0),(192,207,1227,0),(208,223,1227,0),(224,239,1227,0),]), ("ferrari/v08.js.tga",[(175,181,2841,0),(182,188,2841,0),(189,195,2841,0),(196,202,2841,0),(203,209,2841,0),(210,216,2841,0),(217,223,1536,0),(119,126,2304,0),(127,134,1380,0),(135,143,1536,0),]), ("ferrari/v08am.js.tga",[(175,181,2841,0),(182,188,2841,0),(189,195,2841,0),(196,202,2841,0),(203,209,2841,0),(210,216,2841,0),(217,223,1536,0),(119,126,2304,0),(127,134,1380,0),(135,143,1536,0),]), ("ferrari/v08pm.js.tga",[(156,159,1227,0),(170,174,2994,0),(165,169,3300,0),(160,164,1227,0),(175,181,2841,0),(182,188,2841,0),(189,195,2841,0),(196,202,2841,0),(203,209,2841,0),(210,216,2841,0),(217,223,1536,0),(119,126,2304,0),(127,134,1380,0),(135,143,1536,0),(150,155,1227,0),]), ("ferrari/v08rain.js.tga",[(145,149,4914,0),(150,154,4914,0),(155,159,4641,0),(160,164,4641,0),(175,181,2730,0),(182,188,2730,0),(189,195,2730,0),(196,202,2730,0),(203,209,2730,0),(210,216,2730,0),(217,223,1365,0),(119,126,2184,0),(127,134,1365,0),(135,143,1365,0),(165,169,4914,0),(170,174,4914,0),]), ("ferrari/v09.js.tga",[(216,223,3147,0),(208,215,3147,0),(196,201,4914,0),(202,207,4224,0),(224,231,3147,0),(232,239,3609,2),(160,167,1995,0),(168,175,1995,0),(176,183,1995,0),(184,191,2688,0),]), ("ferrari/v10.js.tga",[(98,104,1536,0),(105,111,1536,0),(112,118,1536,0),(119,125,1536,0),(126,132,1536,0),(133,139,1536,0),(140,146,1536,0),(147,153,1536,0),(154,160,1536,0),(161,167,1536,0),(168,181,1227,2),(182,195,1227,2),(196,209,1227,2),]), ("ferrari/v11am.js.tga",[(209,216,1689,2),(203,208,2688,0),(192,202,1380,2),(217,223,2304,0),]), ("ferrari/v13.js.tga",[(144,148,1092,0),(149,155,1092,0),(156,166,1365,0),(167,177,1365,0),(178,187,1365,0),(188,198,1365,0),(199,226,1365,0),(227,254,1365,0),]), ("ferrari/v14.js.tga",[(208,223,1689,2),(192,207,1689,2),(176,191,1380,2),(160,175,1380,2),(144,159,1380,2),(128,143,1380,2),(224,239,1995,0),(112,127,1995,0),(96,111,1995,0),(80,95,1995,0),]), ("ferrari/v15.js.tga",[(112,116,2841,0),(117,121,1842,0),(122,126,1689,0),(232,239,3148,0),(224,231,3148,0),(216,223,3148,0),(208,215,3148,0),(200,207,3148,0),(192,199,3148,0),(184,191,3148,0),(176,183,4914,0),(168,175,4914,0),(160,167,4914,0),(152,159,4914,0),(144,151,4914,0),(136,143,4914,2),]), ("ferrari/v16.js.tga",[(216,223,1842,0),(208,215,1842,0),(200,207,1842,0),(192,199,1842,0),(152,159,1842,0),(144,151,1842,0),(136,143,1842,0),(128,135,1842,0),(120,127,1842,0),(112,119,1842,0),(98,103,1380,0),(92,97,1380,0),(104,111,1842,0),]), ("ferrari/v16pm.js.tga",[(216,223,1842,0),(208,215,1842,0),(200,207,1842,0),(192,199,1842,0),(152,159,1842,0),(144,151,1842,0),(136,143,1842,0),(128,135,1842,0),(120,127,1842,0),(112,119,1842,0),(98,103,1380,0),(92,97,1380,0),(104,111,1842,0),]), ("ferrari/v16rain.js.tga",[(186,190,4914,0),(208,215,1842,0),(200,207,1842,0),(192,199,1842,0),(181,185,4914,0),(176,180,4914,0),(170,174,4914,0),(128,135,1380,0),(120,127,1842,0),(112,119,1842,0),(165,169,4914,0),(92,97,1380,0),(104,111,1842,0),(160,164,4914,0),(98,102,4914,0),(87,91,4914,0),]), ("ferrari/v17.js.tga",[(224,239,1074,0),(216,223,2688,0),(205,215,1074,0),(195,204,1380,0),(185,194,2304,0),(175,184,2304,0),(165,174,2304,0),(155,164,2304,0),(147,154,2688,0),(139,146,2688,0),(131,138,2688,0),(123,130,2688,0),(240,246,1536,0),(247,254,2304,0),]), ("ferrari/v19.js.tga",[(113,118,1689,0),(119,122,1074,0),(123,128,1995,0),(129,134,1842,0),(135,140,1842,2),(141,145,1842,2),(146,151,1995,0),(152,159,3147,0),(192,199,4914,2),(200,205,4914,0),(206,211,4914,0),(212,217,4914,0),(218,223,3762,0),]), ("ferrari/v19aura.js.tga",[(25,35,1842,0),(36,46,1842,0),(123,128,1995,0),(129,134,1842,0),(135,140,1842,2),(141,145,1842,2),(146,151,1995,0),(152,159,3147,0),(170,174,2994,0),(192,199,4914,2),(200,205,4914,0),(206,211,4914,0),(212,217,4914,0),(176,186,1842,0),(165,169,3300,0),(160,164,1227,2),]), ("ferrari/v19pm.js.tga",[(113,118,1689,0),(119,122,1074,0),(123,128,1995,0),(129,134,1842,0),(135,140,1842,2),(141,145,1842,2),(146,151,1995,0),(152,159,3147,0),(192,199,4914,2),(200,205,4914,0),(206,211,4914,0),(212,217,4914,0),(218,223,3762,0),]), ("ferrari/v20.js.tga",[(176,185,4914,0),(216,223,3456,0),(80,87,2304,0),(88,95,3456,0),(96,103,4914,0),(104,111,4836,0),(112,143,3456,0),(144,175,2688,0),(208,215,2688,0),(192,199,1920,0),]), ("ferrari/v25heat.js.tga",[(219,223,3276,2),(214,218,4914,2),(209,213,2730,2),(204,208,4368,2),(199,203,2457,2),(194,198,3276,2),(161,165,2457,2),(166,170,3549,2),(171,175,4914,2),(146,150,4914,2),(151,155,3003,2),(156,160,3003,2),(141,145,4914,2),(136,140,2184,2),(131,135,3003,2),(126,130,2457,2),]), ("ferrari/v26snow.js.tga",[(160,169,4914,0),(170,179,4914,0),(180,189,4914,0),(190,199,4914,0),(200,209,4914,0),(210,219,4914,0),]), ("ferrari/v27.js.tga",[(232,239,4914,0),(224,231,3762,0),(216,223,4914,0),(208,215,4914,0),(200,207,4914,0),(192,199,4914,0),(184,191,3915,0),(176,183,3915,0),(168,175,3915,0),(160,167,3915,0),(152,159,3915,0),(144,151,2304,0),(136,143,2304,0),(128,135,2304,0),(112,119,3915,0),(120,127,1843,0),]), ("ferrari/v28.js.tga",[(240,247,1227,2),(232,239,1227,2),(224,231,1227,2),(216,223,1227,2),(208,215,1227,2),(200,207,1380,2),(192,199,1380,2),(184,191,1380,2),(176,183,1380,2),(160,174,1842,2),(145,159,1842,2),(130,144,1842,2),(115,129,1842,2),(100,114,1842,2),(85,99,1842,2),(70,84,1842,2),]), ("ferrari/v29.js.tga",[(22,31,1536,0),(128,143,1689,0),(96,103,921,0),(80,95,1227,0),(64,79,1689,0),(48,63,1689,0),(32,47,1227,0),]), ("ferrari/v29fog.js.tga",[(176,191,1536,0),(160,175,1536,0),(22,31,1536,0),(128,143,1689,0),(96,103,921,0),(80,95,1227,0),(64,79,1689,0),(48,63,1689,0),(32,47,1227,0),]), ("ferrari/v29pm.js.tga",[(158,159,768,0),(22,31,1536,0),(128,143,1689,0),(96,103,921,0),(80,95,1227,0),(64,79,1689,0),(48,63,1689,0),(32,47,1227,0),(170,174,2457,0),(165,169,3300,0),(160,164,1227,0),]), ("ferrari/v30.js.tga",[(216,223,2457,0),(208,215,2457,0),(196,201,4224,0),(202,207,3456,0),]), ("ferrari/v30rain.js.tga",[(216,223,2457,0),(208,215,2457,0),(196,201,4224,0),(202,207,3456,0),(164,168,4914,0),(159,163,4914,0),(154,158,4914,0),(149,153,4914,0),(144,148,4914,0),(169,173,4914,0),]), ] make_set(demo_list,"demo.bin") #make_set(ferrari_list,"ferrari.bin")