Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """Bitmapper
- Usage:
- bitmapper.py <input> <output> [<width>]
- Options:
- -h --help Show this screen.
- <input> The input binary file.
- <output> The output bitmap.
- <width> The width of the bitmap in pixels. Optional.
- """
- import docopt
- import struct
- DEFAULT_WIDTH = 1000
- HEADER = ("42 4D 36 E0 2E 00 00 00 00 00 36 00 00 00 28 00"
- "00 00 E8 03 00 00 00 04 00 00 01 00 20 00 00 00"
- "00 00 00 E0 2E 00 00 00 00 00 00 00 00 00 00 00"
- "00 00 00 00 00 00").decode("hex-bytes")
- def make_bitmap(data, width=1000):
- size = len(data)
- height = len(data) / 4 / width
- header = (HEADER[:2] +
- struct.pack("<I", size) +
- HEADER[6:0x12] +
- struct.pack("<I", width) +
- struct.pack("<I", height) +
- HEADER[0x1A:0x22] +
- struct.pack("<I", size - 54) +
- HEADER[0x26:])
- return header + data
- if __name__ == '__main__':
- arguments = docopt.docopt(__doc__)
- input_path = arguments["<input>"]
- output_path = arguments["<output>"]
- try:
- width = int(arguments["<width>"])
- except (ValueError, TypeError):
- width = DEFAULT_WIDTH
- with open(input_path, "rb") as f:
- data = f.read()
- bitmap = make_bitmap(data, width)
- with open(output_path, "wb") as f:
- f.write(bitmap)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement