# HG changeset patch # User Paul Boddie # Date 1540773822 -3600 # Node ID 812e66b7ad470985ebfe64a014c36f3bcb3ecbde # Parent 3981a018d7e040a755b19b0be99541f35c0ac4a3 Added options to strip/avoid padding the output image, and to use byte-aligned instead of word-aligned/padded data. Embed the options in the generated output for subsequent reference. diff -r 3981a018d7e0 -r 812e66b7ad47 tools/makeimage.py --- a/tools/makeimage.py Sun Oct 28 18:08:21 2018 +0100 +++ b/tools/makeimage.py Mon Oct 29 01:43:42 2018 +0100 @@ -24,16 +24,20 @@ import PIL.Image import sys -def convert_image(im, output_filename, width, height, label="screendata"): +def convert_image(im, output_filename, width, height, strip, bytealign, options, label="screendata"): "Convert 'im' and write pixel values to 'output_filename'." w, h = im.size - hpad = (width - w) / 2 - leftpad = hpad; rightpad = width - w - hpad - vpad = (height - h) / 2 - toppad = vpad; bottompad = height - h - vpad + if strip: + leftpad = rightpad = toppad = bottompad = 0 + width = w; height = h + else: + hpad = (width - w) / 2 + leftpad = hpad; rightpad = width - w - hpad + vpad = (height - h) / 2 + toppad = vpad; bottompad = height - h - vpad data = iter(im.getdata()) @@ -42,6 +46,10 @@ print >>f, """\ .section .rodata, "a" +/* Options: +%s +*/ + .globl %s .globl %s_width .globl %s_height @@ -52,7 +60,7 @@ .word %d %s: -""" % (label, label, label, label, width, label, height, label) +""" % (options, label, label, label, label, width, label, height, label) word = [] y = 0 @@ -66,10 +74,10 @@ while x < width: word.append(0) - flush_word(f, word) + flush_word(f, word, bytealign) x += 1 - flush_last_word(f, word) + flush_last_word(f, word, bytealign) # Lines with data. @@ -99,10 +107,10 @@ # B<7:6> -> D<1:0> (bm >> 6)) - flush_word(f, word) + flush_word(f, word, bytealign) x += 1 - flush_last_word(f, word) + flush_last_word(f, word, bytealign) y += 1 @@ -134,21 +142,31 @@ imp.putdata(data) return imp -def flush_last_word(f, word): +def flush_last_word(f, word, bytealign): if word: - pad_word(word) - write_word(f, word) + if bytealign: + write_bytes(f, word) + else: + pad_word(word) + write_word(f, word) del word[:] -def flush_word(f, word): +def flush_word(f, word, bytealign): if len(word) == 4: - write_word(f, word) + if bytealign: + write_bytes(f, word) + else: + write_word(f, word) del word[:] def pad_word(word): while len(word) < 4: word.insert(0, 0) +def write_bytes(f, word): + while word: + print >>f, ".byte 0x%02x" % word.pop() + def write_word(f, word): print >>f, ".word 0x%02x%02x%02x%02x" % tuple(word) @@ -228,16 +246,27 @@ %s