1.1 --- a/tools/makeimage.py Sun Oct 28 18:08:21 2018 +0100
1.2 +++ b/tools/makeimage.py Mon Oct 29 01:43:42 2018 +0100
1.3 @@ -24,16 +24,20 @@
1.4 import PIL.Image
1.5 import sys
1.6
1.7 -def convert_image(im, output_filename, width, height, label="screendata"):
1.8 +def convert_image(im, output_filename, width, height, strip, bytealign, options, label="screendata"):
1.9
1.10 "Convert 'im' and write pixel values to 'output_filename'."
1.11
1.12 w, h = im.size
1.13
1.14 - hpad = (width - w) / 2
1.15 - leftpad = hpad; rightpad = width - w - hpad
1.16 - vpad = (height - h) / 2
1.17 - toppad = vpad; bottompad = height - h - vpad
1.18 + if strip:
1.19 + leftpad = rightpad = toppad = bottompad = 0
1.20 + width = w; height = h
1.21 + else:
1.22 + hpad = (width - w) / 2
1.23 + leftpad = hpad; rightpad = width - w - hpad
1.24 + vpad = (height - h) / 2
1.25 + toppad = vpad; bottompad = height - h - vpad
1.26
1.27 data = iter(im.getdata())
1.28
1.29 @@ -42,6 +46,10 @@
1.30 print >>f, """\
1.31 .section .rodata, "a"
1.32
1.33 +/* Options:
1.34 +%s
1.35 +*/
1.36 +
1.37 .globl %s
1.38 .globl %s_width
1.39 .globl %s_height
1.40 @@ -52,7 +60,7 @@
1.41 .word %d
1.42
1.43 %s:
1.44 -""" % (label, label, label, label, width, label, height, label)
1.45 +""" % (options, label, label, label, label, width, label, height, label)
1.46
1.47 word = []
1.48 y = 0
1.49 @@ -66,10 +74,10 @@
1.50
1.51 while x < width:
1.52 word.append(0)
1.53 - flush_word(f, word)
1.54 + flush_word(f, word, bytealign)
1.55 x += 1
1.56
1.57 - flush_last_word(f, word)
1.58 + flush_last_word(f, word, bytealign)
1.59
1.60 # Lines with data.
1.61
1.62 @@ -99,10 +107,10 @@
1.63 # B<7:6> -> D<1:0>
1.64 (bm >> 6))
1.65
1.66 - flush_word(f, word)
1.67 + flush_word(f, word, bytealign)
1.68 x += 1
1.69
1.70 - flush_last_word(f, word)
1.71 + flush_last_word(f, word, bytealign)
1.72
1.73 y += 1
1.74
1.75 @@ -134,21 +142,31 @@
1.76 imp.putdata(data)
1.77 return imp
1.78
1.79 -def flush_last_word(f, word):
1.80 +def flush_last_word(f, word, bytealign):
1.81 if word:
1.82 - pad_word(word)
1.83 - write_word(f, word)
1.84 + if bytealign:
1.85 + write_bytes(f, word)
1.86 + else:
1.87 + pad_word(word)
1.88 + write_word(f, word)
1.89 del word[:]
1.90
1.91 -def flush_word(f, word):
1.92 +def flush_word(f, word, bytealign):
1.93 if len(word) == 4:
1.94 - write_word(f, word)
1.95 + if bytealign:
1.96 + write_bytes(f, word)
1.97 + else:
1.98 + write_word(f, word)
1.99 del word[:]
1.100
1.101 def pad_word(word):
1.102 while len(word) < 4:
1.103 word.insert(0, 0)
1.104
1.105 +def write_bytes(f, word):
1.106 + while word:
1.107 + print >>f, ".byte 0x%02x" % word.pop()
1.108 +
1.109 def write_word(f, word):
1.110 print >>f, ".word 0x%02x%02x%02x%02x" % tuple(word)
1.111
1.112 @@ -228,16 +246,27 @@
1.113
1.114 %s <input filename> <output filename> <label> [ <options> ]
1.115
1.116 -Options are...
1.117 +Preview options:
1.118 +
1.119 +-p - Generate a preview with a filename based on the output filename
1.120 +
1.121 +Size options:
1.122
1.123 -W - Indicate the output width (default is 160)
1.124
1.125 -H - Indicate the output height (default is 256)
1.126
1.127 --p - Generate a preview with a filename based on the output filename
1.128 +-S - Employ the width and height to define the appropriate output ratio but
1.129 + refine the final width and height and strip away padding
1.130 +
1.131 +Transformation options:
1.132
1.133 -r - Rotate the input image clockwise explicitly
1.134 (EXIF information is used otherwise)
1.135 +
1.136 +Output options:
1.137 +
1.138 +-b - Use bytes instead of padded words for each line of the output
1.139 """ % basename
1.140 sys.exit(1)
1.141
1.142 @@ -251,8 +280,10 @@
1.143
1.144 width = get_parameter(options, "-W", int, width, width)
1.145 height = get_parameter(options, "-H", int, height, height)
1.146 + bytealign = "-b" in options
1.147 rotate = "-r" in options
1.148 preview = "-p" in options
1.149 + strip = "-S" in options
1.150
1.151 # Load the input image.
1.152
1.153 @@ -263,7 +294,7 @@
1.154
1.155 # Generate an output image.
1.156
1.157 - convert_image(im, output_filename, width, height, label)
1.158 + convert_image(im, output_filename, width, height, strip, bytealign, options, label)
1.159
1.160 # Generate a preview image if requested.
1.161