mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.0 KiB
52 lines
1.0 KiB
import sys
|
|
from PIL import Image
|
|
|
|
def main():
|
|
f = open(sys.argv[1], 'rb')
|
|
data = f.read()
|
|
f.close()
|
|
|
|
use_bits = True
|
|
|
|
BYTESPERLINE = 128
|
|
BITSPERLINE = BYTESPERLINE * 8
|
|
|
|
if use_bits:
|
|
width = BITSPERLINE
|
|
height = (len(data) * 8 + BITSPERLINE - 1) / BITSPERLINE
|
|
else:
|
|
width = BYTESPERLINE
|
|
height = (len(data) + BYTESPERLINE - 1) / BYTESPERLINE
|
|
|
|
img = Image.new('RGBA', (width, height))
|
|
for y in xrange(height):
|
|
if use_bits:
|
|
for x in xrange(width):
|
|
idx = y * BYTESPERLINE + (x / 8)
|
|
bitidx = x % 8 # 0 = topmost
|
|
|
|
if idx >= len(data):
|
|
img.putpixel((x,y), (255, 255, 255, 255))
|
|
else:
|
|
v = ord(data[idx])
|
|
v = (v >> (7 - bitidx)) & 0x01
|
|
if v > 0:
|
|
v = 0
|
|
else:
|
|
v = 255
|
|
img.putpixel((x,y), (v, v, v, 255))
|
|
else:
|
|
for x in xrange(width):
|
|
idx = y * BYTESPERLINE + x
|
|
|
|
if idx >= len(data):
|
|
img.putpixel((x,y), (255, 255, 255, 255))
|
|
else:
|
|
v = ord(data[idx])
|
|
img.putpixel((x,y), (v, v, v, 255))
|
|
|
|
img.save(sys.argv[2])
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
|
|
|