Mercurial > rinkhals
comparison regenerate-pngs.py @ 160:8a11bbafa07f
Add support for creting xbm cursors
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Thu, 03 Sep 2009 22:15:35 +0000 |
parents | 3381af605912 |
children | ab7063d7c5e5 |
comparison
equal
deleted
inserted
replaced
159:7bb8d9d6858a | 160:8a11bbafa07f |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 import cairo | 3 import cairo |
4 import rsvg | 4 import rsvg |
5 import os | 5 import os |
6 from Image import open | |
6 | 7 |
7 def svg_to_png(svg_name, png_name, w, h): | 8 def svg_to_png(svg_name, png_name, w, h): |
8 """Convert an SVG file to a PNG file.""" | 9 """Convert an SVG file to a PNG file.""" |
9 print "Generating %s at %dx%d..." % (png_name, w, h) | 10 print "Generating %s at %dx%d..." % (png_name, w, h) |
10 r = rsvg.Handle(svg_name) | 11 r = rsvg.Handle(svg_name) |
33 def process_sprite(name, width, height, sprite_path): | 34 def process_sprite(name, width, height, sprite_path): |
34 svg_name = os.path.join(sprite_path, name) + ".svg" | 35 svg_name = os.path.join(sprite_path, name) + ".svg" |
35 png_name = os.path.join(sprite_path, name) + ".png" | 36 png_name = os.path.join(sprite_path, name) + ".png" |
36 svg_to_png(svg_name, png_name, width, height) | 37 svg_to_png(svg_name, png_name, width, height) |
37 | 38 |
39 def process_cursor(name, width, height, sprite_path, cursor_path): | |
40 # We bounce through png to get something PIL understands | |
41 svg_name = os.path.join(sprite_path, name) + '.svg' | |
42 png_name = os.path.join(cursor_path, name) + '.png' | |
43 xbm_name = os.path.join(cursor_path, name) + '.xbm' | |
44 svg_to_png(svg_name, png_name, width, height) | |
45 # We need to bounce through 'L' first to handle transparency OK | |
46 pixeldata = open(png_name).convert('L') | |
47 # Everything > 0 goes to white | |
48 lut = [0] + [1]*255 | |
49 pixeldata.point(lut, mode='1').save(xbm_name) | |
50 os.remove(png_name) | |
51 | |
38 if __name__ == "__main__": | 52 if __name__ == "__main__": |
39 tile_path = "data/tiles" | 53 tile_path = "data/tiles" |
40 sprite_path = "data/sprites" | 54 sprite_path = "data/sprites" |
41 image_path = "data/images" | 55 image_path = "data/images" |
56 cursor_path = "data/cursors" | |
42 sprites = [ | 57 sprites = [ |
43 ("chkn", 20, 20), | 58 ("chkn", 20, 20), |
44 ("select_chkn", 20, 20), | 59 ("select_chkn", 20, 20), |
45 ("chkn_death", 20, 20), | 60 ("chkn_death", 20, 20), |
46 ("egg", 20, 20), | 61 ("egg", 20, 20), |
60 ("select_watchtower", 40, 40), | 75 ("select_watchtower", 40, 40), |
61 ("chknnest", 20, 20), | 76 ("chknnest", 20, 20), |
62 ("emptynest", 20, 20), | 77 ("emptynest", 20, 20), |
63 ] | 78 ] |
64 | 79 |
80 cursors = [ | |
81 ("chkn", 16, 16), | |
82 ("equip_knife", 16, 16), | |
83 ("equip_rifle", 16, 16), | |
84 ("egg", 16, 16), | |
85 ] | |
86 | |
65 process_svg_folder("data/tiles", 20, 20) | 87 process_svg_folder("data/tiles", 20, 20) |
66 process_svg_folder("data/icons", 40, 40) | 88 process_svg_folder("data/icons", 40, 40) |
67 for name, width, height in sprites: | 89 for name, width, height in sprites: |
68 process_sprite(name, width, height, sprite_path) | 90 process_sprite(name, width, height, sprite_path) |
69 process_sprite("splash", 800, 600, image_path) | 91 process_sprite("splash", 800, 600, image_path) |
70 process_sprite("gameover_win", 800, 600, image_path) | 92 process_sprite("gameover_win", 800, 600, image_path) |
71 process_sprite("gameover_lose", 800, 600, image_path) | 93 process_sprite("gameover_lose", 800, 600, image_path) |
94 for name, width, height in cursors: | |
95 process_cursor(name, width, height, sprite_path, cursor_path) |