refactoring. Incomplete panorama mode.
This commit is contained in:
parent
5cfebaf706
commit
85d9a7cbc8
|
@ -10,6 +10,10 @@ import sys
|
||||||
import docopt
|
import docopt
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
TILES_PER_LINE = 20
|
||||||
|
HEIGHT = 144
|
||||||
|
WIDTH = 160
|
||||||
|
|
||||||
arguments = docopt(__doc__)
|
arguments = docopt(__doc__)
|
||||||
|
|
||||||
colors = [(0xff, 0xff, 0xff), (0xaa, 0xaa, 0xaa), (0x55,0x55,0x55), (0x00,0x00,0x00)]
|
colors = [(0xff, 0xff, 0xff), (0xaa, 0xaa, 0xaa), (0x55,0x55,0x55), (0x00,0x00,0x00)]
|
||||||
|
@ -27,5 +31,5 @@ for line in l:
|
||||||
d.append(line)
|
d.append(line)
|
||||||
|
|
||||||
b = [bytes.fromhex(h.strip()) for h in d]
|
b = [bytes.fromhex(h.strip()) for h in d]
|
||||||
image = twobpp.convert_photo(b, colors)
|
image = twobpp.convert_photo(b, colors, TILES_PER_LINE, WIDTH, HEIGHT)
|
||||||
image.save(arguments["<output>"])
|
image.save(arguments["<output>"])
|
||||||
|
|
|
@ -9,6 +9,7 @@ Usage:
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-b amount Batch Mode, Downloads the specified amount of images at once.
|
-b amount Batch Mode, Downloads the specified amount of images at once.
|
||||||
|
-p Panorama mode. Works with print panoramas on the camera.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import twobpp
|
import twobpp
|
||||||
|
@ -17,6 +18,10 @@ import serial
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
TILES_PER_LINE = 20
|
||||||
|
HEIGHT = 144
|
||||||
|
WIDTH = 160
|
||||||
|
|
||||||
arguments = docopt(__doc__)
|
arguments = docopt(__doc__)
|
||||||
|
|
||||||
colors = [(0xff, 0xff, 0xff), (0xaa, 0xaa, 0xaa), (0x55,0x55,0x55), (0x00,0x00,0x00)]
|
colors = [(0xff, 0xff, 0xff), (0xaa, 0xaa, 0xaa), (0x55,0x55,0x55), (0x00,0x00,0x00)]
|
||||||
|
@ -40,7 +45,7 @@ for photo_number in range(int(runs)):
|
||||||
d.append(line)
|
d.append(line)
|
||||||
|
|
||||||
b = [bytes.fromhex(h.strip().decode()) for h in d]
|
b = [bytes.fromhex(h.strip().decode()) for h in d]
|
||||||
image = twobpp.convert_photo(b, colors)
|
image = twobpp.convert_photo(b, colors, TILES_PER_LINE, WIDTH, HEIGHT)
|
||||||
if runs != 1:
|
if runs != 1:
|
||||||
p = arguments["<path>"].split(".")
|
p = arguments["<path>"].split(".")
|
||||||
image.save(f"{p[0]}-{photo_number}.{p[1]}")
|
image.save(f"{p[0]}-{photo_number}.{p[1]}")
|
||||||
|
|
12
twobpp.py
12
twobpp.py
|
@ -1,10 +1,6 @@
|
||||||
# twobpp.py - functions for the gameboy 2bpp graphics format and gameboy camera
|
# twobpp.py - functions for the gameboy 2bpp graphics format and gameboy camera
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
TILES_PER_LINE = 20
|
|
||||||
HEIGHT = 144
|
|
||||||
WIDTH = 160
|
|
||||||
|
|
||||||
def chunks(l, n):
|
def chunks(l, n):
|
||||||
"""Yield successive n-sized chunks from l."""
|
"""Yield successive n-sized chunks from l."""
|
||||||
for i in range(0, len(l), n):
|
for i in range(0, len(l), n):
|
||||||
|
@ -26,22 +22,22 @@ def decode_line(b1, b2):
|
||||||
line.append((hi_bit << 1) | lo_bit)
|
line.append((hi_bit << 1) | lo_bit)
|
||||||
return line
|
return line
|
||||||
|
|
||||||
def convert_photo(byte_seq, colors):
|
def convert_photo(byte_seq, colors, tiles_per_line, width, height):
|
||||||
"""converts the sequence of bytes from a gameboy camera image into a pillow image."""
|
"""converts the sequence of bytes from a gameboy camera image into a pillow image."""
|
||||||
|
|
||||||
tiles = [decode_tile(l) for l in byte_seq]
|
tiles = [decode_tile(l) for l in byte_seq]
|
||||||
tile_image = []
|
tile_image = []
|
||||||
|
|
||||||
for t in chunks(tiles, TILES_PER_LINE):
|
for t in chunks(tiles, tiles_per_line):
|
||||||
chunk = []
|
chunk = []
|
||||||
for l in range(8):
|
for l in range(8):
|
||||||
line = []
|
line = []
|
||||||
for tile in range(TILES_PER_LINE):
|
for tile in range(tiles_per_line):
|
||||||
line += t[tile][l]
|
line += t[tile][l]
|
||||||
chunk += line
|
chunk += line
|
||||||
tile_image += chunk
|
tile_image += chunk
|
||||||
|
|
||||||
image_data = [colors[x] for x in tile_image]
|
image_data = [colors[x] for x in tile_image]
|
||||||
image = Image.new(mode='RGB',size=(WIDTH,HEIGHT))
|
image = Image.new(mode='RGB',size=(width,height))
|
||||||
image.putdata(image_data)
|
image.putdata(image_data)
|
||||||
return image
|
return image
|
||||||
|
|
Loading…
Reference in New Issue