initial commit

This commit is contained in:
Nihilazo 2019-08-22 18:53:51 +01:00
commit 5d3c3146d3
5 changed files with 81 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
__pycache__
photo.txt

8
LICENCE Normal file
View File

@ -0,0 +1,8 @@
Copyright 2019 Nihilazo
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

49
main.py Normal file
View File

@ -0,0 +1,49 @@
'''
Converter of gameboy camera images to PNGs. Probably awful.
Gameboy camera images are saved in the format of the mofosyne printer emulator.
'''
#!/usr/bin/env/python
import json
import twobpp
from PIL import Image
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]
TILES_PER_LINE = 20
HEIGHT = 144
WIDTH = 160
colors = [(0xff, 0xff, 0xff), (0xaa, 0xaa, 0xaa), (0x55,0x55,0x55), (0x00,0x00,0x00)]
l = f.readlines()
d = []
for line in l:
if line.startswith("#"):
pass
elif line.startswith("!"):
pass
else:
d.append(line)
b = [bytes.fromhex(h.strip()) for h in d]
tiles = [twobpp.decode_tile(l) for l in b]
tile_image = []
for t in chunks(tiles, TILES_PER_LINE):
chunk = []
for l in range(8):
line = []
for tile in range(TILES_PER_LINE):
line += t[tile][l]
chunk += line
tile_image += chunk
image_data = [colors[x] for x in tile_image]
image = Image.new(mode='RGB',size=(WIDTH,HEIGHT))
image.putdata(image_data)

7
readme.md Normal file
View File

@ -0,0 +1,7 @@
# GB Printer
These are my python tools for use with the mofodyne printer emulator.
The emulator is available from here: https://github.com/mofosyne/arduino-gameboy-printer-emulator
I built one but I wasn't happy with the existing software, so I built my own.
Mainly designed for my own personal use. Very incomplete.

15
twobpp.py Normal file
View File

@ -0,0 +1,15 @@
# 2bpp.py - functions for the gameboy 2bpp graphics format.
def decode_tile(tile):
d = []
for i in range(0,16,2):
d.append(decode_line(tile[i], tile[i+1]))
return d
def decode_line(b1, b2):
line = []
for i in range(8):
hi_bit = (b2 >> (7-i)) & 1;
lo_bit = (b1 >> (7-i)) & 1;
line.append((hi_bit << 1) | lo_bit)
return line