Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
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)
Beispiel #4
0
 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')
Beispiel #5
0
 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')
Beispiel #6
0
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")
Beispiel #7
0
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)
Beispiel #8
0
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)
Beispiel #9
0
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)
Beispiel #10
0
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)
Beispiel #11
0
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)
Beispiel #12
0
def import_chr(img_file, chr_file):
    img = Image.open(img_file)
    sprs, indexes = acquire_chr(img)
    write_bin_code(sprs, chr_file)
Beispiel #13
0
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)
Beispiel #14
0
def import_chr(img_file, chr_file):
    img = Image.open(img_file)
    sprs, indexes = acquire_chr(img)
    write_bin_code(sprs, chr_file)
Beispiel #15
0
def import_chr(img_file, chr_file):
    img = Image.open(img_file)
    sprs = convert_chr(img)
    write_bin_code(sprs, chr_file)