mirror of
https://git.planet-casio.com/Lephenixnoir/fxsdk.git
synced 2024-12-29 13:03:37 +01:00
fxconv: return data in standard conversions
Instead of generating the ELF file right away. This makes these functions brilliantly reusable.
This commit is contained in:
parent
0acea3baf6
commit
c53a3fcdec
1 changed files with 21 additions and 20 deletions
|
@ -310,15 +310,14 @@ class Grid:
|
||||||
# Binary conversion
|
# Binary conversion
|
||||||
#
|
#
|
||||||
|
|
||||||
def convert_binary(input, output, params, target):
|
def convert_binary(input, params):
|
||||||
data = open(input, "rb").read()
|
return open(input, "rb").read()
|
||||||
elf(data, output, "_" + params["name"], **target)
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Image conversion for fx-9860G
|
# Image conversion for fx-9860G
|
||||||
#
|
#
|
||||||
|
|
||||||
def convert_bopti_fx(input, output, params, target):
|
def convert_bopti_fx(input, params):
|
||||||
if isinstance(input, Image.Image):
|
if isinstance(input, Image.Image):
|
||||||
img = input.copy()
|
img = input.copy()
|
||||||
else:
|
else:
|
||||||
|
@ -373,8 +372,7 @@ def convert_bopti_fx(input, output, params, target):
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
# Generate the object file
|
# Generate the object file
|
||||||
|
return header + data
|
||||||
elf(header + data, output, "_" + params["name"], **target)
|
|
||||||
|
|
||||||
def _image_project(img, f):
|
def _image_project(img, f):
|
||||||
# New width and height
|
# New width and height
|
||||||
|
@ -396,7 +394,7 @@ def _image_project(img, f):
|
||||||
# Image conversion for fx-CG 50
|
# Image conversion for fx-CG 50
|
||||||
#
|
#
|
||||||
|
|
||||||
def convert_bopti_cg(input, output, params, target):
|
def convert_bopti_cg(input, params):
|
||||||
if isinstance(input, Image.Image):
|
if isinstance(input, Image.Image):
|
||||||
img = input.copy()
|
img = input.copy()
|
||||||
else:
|
else:
|
||||||
|
@ -442,7 +440,7 @@ def convert_bopti_cg(input, output, params, target):
|
||||||
h >> 8, h & 0xff, # Height
|
h >> 8, h & 0xff, # Height
|
||||||
])
|
])
|
||||||
|
|
||||||
elf(header + encoded, output, "_" + params["name"], **target)
|
return header + encoded
|
||||||
|
|
||||||
#
|
#
|
||||||
# Font conversion
|
# Font conversion
|
||||||
|
@ -473,7 +471,7 @@ def _blockstart(name):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def convert_topti(input, output, params, target):
|
def convert_topti(input, params):
|
||||||
|
|
||||||
#--
|
#--
|
||||||
# Character set
|
# Character set
|
||||||
|
@ -650,13 +648,13 @@ def convert_topti(input, output, params, target):
|
||||||
o += u16(grid.w)
|
o += u16(grid.w)
|
||||||
o += u16((grid.w * grid.h + 31) >> 5)
|
o += u16((grid.w * grid.h + 31) >> 5)
|
||||||
|
|
||||||
elf(o, output, "_" + params["name"], **target)
|
return o
|
||||||
|
|
||||||
#
|
#
|
||||||
# libimg conversion for fx-9860G
|
# libimg conversion for fx-9860G
|
||||||
#
|
#
|
||||||
|
|
||||||
def convert_libimg_fx(input, output, params, target):
|
def convert_libimg_fx(input, params):
|
||||||
if isinstance(input, Image.Image):
|
if isinstance(input, Image.Image):
|
||||||
img = input.copy()
|
img = input.copy()
|
||||||
else:
|
else:
|
||||||
|
@ -688,14 +686,14 @@ def convert_libimg_fx(input, output, params, target):
|
||||||
o += u16(img.width) + u8(LIBIMG_FLAG_RO) + bytes(1)
|
o += u16(img.width) + u8(LIBIMG_FLAG_RO) + bytes(1)
|
||||||
o += ref(data)
|
o += ref(data)
|
||||||
|
|
||||||
elf(o, output, "_" + params["name"], **target)
|
return o
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# libimg conversion for fx-CG 50
|
# libimg conversion for fx-CG 50
|
||||||
#
|
#
|
||||||
|
|
||||||
def convert_libimg_cg(input, output, params, target):
|
def convert_libimg_cg(input, params):
|
||||||
if isinstance(input, Image.Image):
|
if isinstance(input, Image.Image):
|
||||||
img = input.copy()
|
img = input.copy()
|
||||||
else:
|
else:
|
||||||
|
@ -715,7 +713,7 @@ def convert_libimg_cg(input, output, params, target):
|
||||||
o += u16(img.width) + u8(LIBIMG_FLAG_RO) + bytes(1)
|
o += u16(img.width) + u8(LIBIMG_FLAG_RO) + bytes(1)
|
||||||
o += ref(encoded)
|
o += ref(encoded)
|
||||||
|
|
||||||
elf(o, output, "_" + params["name"], **target)
|
return o
|
||||||
|
|
||||||
#
|
#
|
||||||
# Exceptions
|
# Exceptions
|
||||||
|
@ -986,17 +984,17 @@ def convert(input, params, target, output=None, model=None, custom=None):
|
||||||
raise FxconvError(f"missing type in conversion '{input}'")
|
raise FxconvError(f"missing type in conversion '{input}'")
|
||||||
|
|
||||||
if t == "binary":
|
if t == "binary":
|
||||||
convert_binary(input, output, params, target)
|
o = convert_binary(input, params)
|
||||||
elif t == "bopti-image" and model in [ "fx", None ]:
|
elif t == "bopti-image" and model in [ "fx", None ]:
|
||||||
convert_bopti_fx(input, output, params, target)
|
o = convert_bopti_fx(input, params)
|
||||||
elif t == "bopti-image" and model == "cg":
|
elif t == "bopti-image" and model == "cg":
|
||||||
convert_bopti_cg(input, output, params, target)
|
o = convert_bopti_cg(input, params)
|
||||||
elif t == "font":
|
elif t == "font":
|
||||||
convert_topti(input, output, params, target)
|
o = convert_topti(input, params)
|
||||||
elif t == "libimg-image" and model in [ "fx", None ]:
|
elif t == "libimg-image" and model in [ "fx", None ]:
|
||||||
convert_libimg_fx(input, output, params, target)
|
o = convert_libimg_fx(input, params)
|
||||||
elif t == "libimg-image" and model == "cg":
|
elif t == "libimg-image" and model == "cg":
|
||||||
convert_libimg_cg(input, output, params, target)
|
o = convert_libimg_cg(input, params)
|
||||||
elif custom is not None:
|
elif custom is not None:
|
||||||
for converter in custom:
|
for converter in custom:
|
||||||
if converter(input, output, params, target) == 0:
|
if converter(input, output, params, target) == 0:
|
||||||
|
@ -1005,6 +1003,9 @@ def convert(input, params, target, output=None, model=None, custom=None):
|
||||||
else:
|
else:
|
||||||
raise FxconvError(f'unknown resource type \'{t}\'')
|
raise FxconvError(f'unknown resource type \'{t}\'')
|
||||||
|
|
||||||
|
# Standard conversions: save to ELF in the natural way
|
||||||
|
elf(o, output, "_" + params["name"], **target)
|
||||||
|
|
||||||
def elf(data, output, symbol, toolchain=None, arch=None, section=None,
|
def elf(data, output, symbol, toolchain=None, arch=None, section=None,
|
||||||
assembly=None):
|
assembly=None):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue