def convert_to_nametable(image_file): colors = [] original = Image.open(image_file) original = original.convert('RGB') template = Image.new('P', original.size) template.putpalette(create_pil_palette()) converted = original.quantize(palette=template, colors=4) pixels = converted.load() assert converted.size[0] == 256 assert converted.size[1] == 256 cnt = Counter() for i in range(converted.size[0]): for j in range(converted.size[1]): if pixels[i, j] not in colors: colors.append(pixels[i, j]) cnt[pixels[i, j]] += 1 break #cnt.most_common(4) sprs, indexes = convert_chr(converted, optimize_repeated=True) nametable = convert_nametable(converted, indexes) write_bin_code(sprs, 'sprite.chr') write_bin_code(nametable, 'nametable.bin') return nametable, sprs
def convert_to_nametable(image_file): colors = [] original = Image.open(image_file) original = original.convert("RGB") template = Image.new("P", original.size) template.putpalette(create_pil_palette()) converted = original.quantize(palette=template, colors=4) pixels = converted.load() assert converted.size[0] == 256 assert converted.size[1] == 256 cnt = Counter() for i in range(converted.size[0]): for j in range(converted.size[1]): if pixels[i, j] not in colors: colors.append(pixels[i, j]) cnt[pixels[i, j]] += 1 break # cnt.most_common(4) sprs, indexes = convert_chr(converted, optimize_repeated=True) nametable = convert_nametable(converted, indexes) write_bin_code(sprs, "sprite.chr") write_bin_code(nametable, "nametable.bin") return nametable, sprs
def convert_to_nametable(image_file): colors = [] original = Image.open(image_file) original = original.convert('RGB') template = Image.new('P', original.size) template.putpalette(create_pil_palette()) converted = original.quantize(palette=template, colors=4) pixels = converted.load() cnt = Counter() for i in range(converted.size[0]): for j in range(converted.size[1]): if pixels[i,j] not in colors: colors.append(pixels[i,j]) cnt[pixels[i,j]] += 1 break #cnt.most_common(4) sprs = convert_chr(converted) nametable = convert_nametable(converted, sprs) write_bin_code(sprs, 'sprite.chr') return (nametable, sprs)
def test_acquire_pythonbrasil8(self): (nt, sprs) = image.acquire_nametable('fixtures/pythonbrasil8.png') # debug image.export_chr(sprs, '/tmp/pythonbrasil8_sprite.png') # debug image.export_nametable(nt, sprs, '/tmp/pythonbrasil8_nametable.png') from pynes import write_bin_code write_bin_code(nt, '/tmp/pythonbrasil8.bin') write_bin_code(sprs[0], '/tmp/pythonbrasil8.chr')
def test_acquire_pythonbrasil8(self): (nt, sprs) = image.acquire_nametable('fixtures/pythonbrasil8.png') #debug image.export_chr(sprs, '/tmp/pythonbrasil8_sprite.png') #debug image.export_nametable(nt, sprs, '/tmp/pythonbrasil8_nametable.png') from pynes import write_bin_code write_bin_code(nt, '/tmp/pythonbrasil8.bin') write_bin_code(sprs[0], '/tmp/pythonbrasil8.chr')
def compile(code, output, path): cart = Cartridge() cart.path = path tokens = lexical(code) ast = syntax(tokens) opcodes = semantic(ast, True, cart) pynes.write_bin_code(opcodes, "output.nes")
def compile_file(asmfile, output=None, path=None): from os.path import dirname, realpath if path is None: path = dirname(realpath(asmfile)) + '/' if output is None: output = 'output.nes' with io.open(asmfile, "r", encoding="utf-8") as f: opcodes = compile(f, path) pynes.write_bin_code(opcodes, output)
def compile_file(asmfile, output=None, path=None): from os.path import dirname, realpath f = open(asmfile) code = f.read() f.close() if path == None: path = dirname(realpath(asmfile)) + '/' if output == None: output = 'output.nes' opcodes = compile(code, path) pynes.write_bin_code(opcodes, output)
def import_nametable(png_file, chr_file, nametable_file, palette=palette): image = Image.open(png_file) sprs = sprite.load_sprites(chr_file) nametable = read_nametable(image, sprs, palette) write_bin_code(nametable, nametable_file)
def import_chr(img_file, chr_file): img = Image.open(img_file) sprs, indexes = acquire_chr(img) write_bin_code(sprs, chr_file)
def import_chr(img_file, chr_file): img = Image.open(img_file) sprs = convert_chr(img) write_bin_code(sprs, chr_file)