示例#1
0
文件: image.py 项目: acs022/pyNES
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
示例#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
示例#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)
示例#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')
示例#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')
示例#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")
示例#7
0
文件: compiler.py 项目: yxda/pyNES
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)
示例#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)
示例#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)
示例#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)
示例#11
0
文件: image.py 项目: BmanisKing/Mine
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)
示例#12
0
文件: image.py 项目: BmanisKing/Mine
def import_chr(img_file, chr_file):
    img = Image.open(img_file)
    sprs, indexes = acquire_chr(img)
    write_bin_code(sprs, chr_file)
示例#13
0
文件: image.py 项目: yxda/pyNES
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)
示例#14
0
文件: image.py 项目: yxda/pyNES
def import_chr(img_file, chr_file):
    img = Image.open(img_file)
    sprs, indexes = acquire_chr(img)
    write_bin_code(sprs, chr_file)
示例#15
0
def import_chr(img_file, chr_file):
    img = Image.open(img_file)
    sprs = convert_chr(img)
    write_bin_code(sprs, chr_file)