Esempio n. 1
0
#!/usr/bin/env python3
'''
View a TEX file
Niema Moshiri 2019
'''
from PyFF7.tex import TEX
from sys import argv,stderr
USAGE = "USAGE: %s <input_tex_file>" % argv[0]

if __name__ == "__main__":
    if len(argv) != 2 or argv[1] == '-h' or argv[1] == '--help':
        print(USAGE); exit(1)
    TEX(argv[1]).show()
Esempio n. 2
0
#!/usr/bin/env python3
'''
Change the image inside of a TEX file
Niema Moshiri 2019
'''
from PyFF7.tex import TEX
from os.path import isdir, isfile
from sys import argv, stderr
USAGE = "USAGE: %s <input_tex_file> <input_image_file> <output_tex_file>" % argv[
    0]

if __name__ == "__main__":
    if len(argv) != 4:
        print(USAGE)
        exit(1)
    if isdir(argv[3]) or isfile(argv[3]):
        raise ValueError("ERROR: Specified output file exists: %s" % argv[3])
    tex = TEX(argv[1])
    tex.change_image(argv[2])
    data = tex.get_bytes()
    f = open(argv[3], 'wb')
    f.write(data)
    f.close()
Esempio n. 3
0
#!/usr/bin/env python3
'''
View a TEX file
Niema Moshiri 2019
'''
from PyFF7 import file_prompt
from PyFF7.tex import TEX
from sys import argv, stderr
USAGE = "USAGE: %s <input_tex_file>" % argv[0]

if __name__ == "__main__":
    if len(argv) == 1:
        TEX(file_prompt()).show()
        exit()
    if len(argv) != 2 or argv[1] == '-h' or argv[1] == '--help':
        print(USAGE)
        exit(1)
    TEX(argv[1]).show()
Esempio n. 4
0
#!/usr/bin/env python3
'''
Read the information of a TEX file
Niema Moshiri 2019
'''
from PyFF7 import file_prompt
from PyFF7.tex import TEX
from sys import argv, stderr

USAGE = "USAGE: %s <input_tex_file>" % argv[0]

if __name__ == "__main__":
    if len(argv) == 1:
        filename = file_prompt()
    elif len(argv) != 2 or argv[1] == '-h' or argv[1] == '--help':
        print(USAGE)
        exit(1)
    else:
        filename = argv[1]
    tex = TEX(filename)
    try:
        print("* File Name: %s" % filename)
        print("* Image Width: %d" % tex.get_width())
        print("* Image Height: %d" % tex.get_height())
        print("* Unique RGBA Colors: %d" % tex.num_colors())
        for c in tex.unique_colors():
            print("  * (%d,%d,%d,%d)" % c)
    except BrokenPipeError:
        stderr.close()
Esempio n. 5
0
#!/usr/bin/env python3
'''
Create a TEX file from an image file
Niema Moshiri 2019
'''
from PyFF7.tex import TEX
from PIL import Image
from os.path import isdir, isfile
from sys import argv, stderr
USAGE = "USAGE: %s <input_image_file> <output_tex_file> [-bmp]" % argv[0]

if __name__ == "__main__":
    if len(argv) != 3 and (len(argv) != 4 or argv[-1].lower() != '-bmp'):
        print(USAGE)
        exit(1)
    if isdir(argv[2]) or isfile(argv[2]):
        raise ValueError("ERROR: Specified output file exists: %s" % argv[2])
    img = Image.open(argv[1])
    tex = TEX(img)
    data = tex.get_bytes(
        bmp_mode=(len(argv) == 4 and argv[-1].lower() == '-bmp'))
    f = open(argv[2], 'wb')
    f.write(data)
    f.close()
Esempio n. 6
0
#!/usr/bin/env python3
'''
Convert a TEX file to a regular image file
Niema Moshiri 2019
'''
from PyFF7.tex import TEX
from os.path import isdir, isfile
from sys import argv, stderr

USAGE = "USAGE: %s <input_tex_file> <output_image_file>" % argv[0]

if __name__ == "__main__":
    if len(argv) != 3:
        print(USAGE)
        exit(1)
    if isdir(argv[2]) or isfile(argv[2]):
        raise ValueError("ERROR: Specified output file exists: %s" % argv[2])
    TEX(argv[1]).get_image().save(argv[2])
Esempio n. 7
0
#!/usr/bin/env python3
'''
Convert a TEX file to a regular image file
Niema Moshiri 2019
'''
from PyFF7.tex import TEX
from os.path import isdir, isfile
from sys import argv, stderr

USAGE = "USAGE: %s <input_tex_file> <output_image_file>" % argv[0]

if __name__ == "__main__":
    if len(argv) != 3:
        print(USAGE)
        exit(1)
    if isdir(argv[2]) or isfile(argv[2]):
        raise ValueError("ERROR: Specified output file exists: %s" % argv[2])
    images = TEX(argv[1]).get_images()
    if len(images) == 1:
        images[0].save(argv[2])
    else:  # multiple color palettes
        pre = '.'.join(argv[2].split('.')[:-1])
        suf = argv[2].split('.')[-1]
        numlen = len(str(len(images) - 1))
        for i, img in enumerate(images):
            img.save("%s.pal%s.%s" % (pre, str(i).zfill(numlen), suf))