summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2005-09-27 22:23:32 +0000
committerSimon Howard2005-09-27 22:23:32 +0000
commite2896ba221018d26c27201716a82945e2b005973 (patch)
tree209a2918b794e80dced1074141ce851a8adde9cb
parent8ade4fd18056dd2ea5559d002a9d240c3a9e8461 (diff)
downloadchocolate-doom-e2896ba221018d26c27201716a82945e2b005973.tar.gz
chocolate-doom-e2896ba221018d26c27201716a82945e2b005973.tar.bz2
chocolate-doom-e2896ba221018d26c27201716a82945e2b005973.zip
Don't write converted output file unless everything went through
okay. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 137
-rw-r--r--src/Makefile.am2
-rwxr-xr-xsrc/convert-icon33
2 files changed, 20 insertions, 15 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 163eb5be..f2b0277f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -41,5 +41,5 @@ EXTRA_DIST = convert-icon chocolate_doom_icon.c
windres $^ -o $@
chocolate_doom_icon.c : ../data/chocolate-doom.png
- ./convert-icon $^ > $@
+ ./convert-icon $^ $@
diff --git a/src/convert-icon b/src/convert-icon
index a55d8138..9c093b89 100755
--- a/src/convert-icon
+++ b/src/convert-icon
@@ -1,6 +1,6 @@
#!/usr/bin/python
#
-# $Id: convert-icon 126 2005-09-24 22:04:03Z fraggle $
+# $Id: convert-icon 137 2005-09-27 22:23:32Z fraggle $
#
# Copyright(C) 2005 Simon Howard
#
@@ -22,6 +22,10 @@
# Converts images into C structures to be inserted in programs
#
# $Log$
+# Revision 1.2 2005/09/27 22:23:32 fraggle
+# Don't write converted output file unless everything went through
+# okay.
+#
# Revision 1.1 2005/09/24 22:04:03 fraggle
# Add application icon to running program
#
@@ -31,41 +35,42 @@ import sys
import os
import re
-def convert_image(filename):
+def convert_image(filename, output_filename):
im = Image.open(filename).convert("RGB")
+ outfile = open(output_filename, "w")
+
size = im.size
struct_name = os.path.basename(filename)
struct_name = re.sub(re.compile("\\..*$"), "", struct_name)
struct_name = re.sub(re.compile("\W"), "_", struct_name)
- print "static int %s_w = %i;" % (struct_name, size[0])
- print "static int %s_h = %i;" % (struct_name, size[1])
+ outfile.write("static int %s_w = %i;\n" % (struct_name, size[0]))
+ outfile.write("static int %s_h = %i;\n" % (struct_name, size[1]))
- print
- print "static unsigned char %s_data[] = {" % (struct_name)
+ outfile.write("\n")
+ outfile.write("static unsigned char %s_data[] = {\n" % (struct_name))
elements_on_line = 0
- print " ",
+ outfile.write(" ")
for y in range(size[1]):
for x in range(size[0]):
val = im.getpixel((x, y))
- print "%i,%i,%i, " % val,
+ outfile.write("%i,%i,%i, " % val)
elements_on_line += 1
if elements_on_line > 4:
elements_on_line = 0
- print
- print " ",
+ outfile.write("\n")
+ outfile.write(" ")
- print
- print "};\n"
+ outfile.write("\n")
+ outfile.write("};\n")
-for filename in sys.argv[1:len(sys.argv)]:
- convert_image(filename)
+convert_image(sys.argv[1], sys.argv[2])