From 5d3c3146d3634c5b4059b38ca07579c3105ddbf0 Mon Sep 17 00:00:00 2001 From: Nihilazo Date: Thu, 22 Aug 2019 18:53:51 +0100 Subject: [PATCH] initial commit --- .gitignore | 2 ++ LICENCE | 8 ++++++++ main.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 7 +++++++ twobpp.py | 15 +++++++++++++++ 5 files changed, 81 insertions(+) create mode 100644 .gitignore create mode 100644 LICENCE create mode 100644 main.py create mode 100644 readme.md create mode 100644 twobpp.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4eb77a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__ +photo.txt diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..5e42f9a --- /dev/null +++ b/LICENCE @@ -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. + diff --git a/main.py b/main.py new file mode 100644 index 0000000..053b32a --- /dev/null +++ b/main.py @@ -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) diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..e4d24f0 --- /dev/null +++ b/readme.md @@ -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. diff --git a/twobpp.py b/twobpp.py new file mode 100644 index 0000000..74ba106 --- /dev/null +++ b/twobpp.py @@ -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