mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 03:08:29 +02:00
implemented decode_data in img (tpl -> png) and added img-decode operation (useful if a texture modification need the original game image as a base)
This commit is contained in:
parent
5ddae33393
commit
ebb74a61df
2 changed files with 35 additions and 7 deletions
|
@ -261,16 +261,28 @@ class PatchOperation:
|
|||
"""
|
||||
# remove the last extension of the filename
|
||||
patched_file_name = file_name.rsplit(".", 1)[0]
|
||||
patch_content = BytesIO()
|
||||
patch_content = BytesIO(img.encode_data(file_content.read(), self.encoding))
|
||||
|
||||
# write the encoded image into the file
|
||||
patch_content.write(
|
||||
img.encode_data(file_content.read(), self.encoding)
|
||||
)
|
||||
|
||||
patch_content.seek(0)
|
||||
return patched_file_name, patch_content
|
||||
|
||||
class ImageDecoder(Operation):
|
||||
"""
|
||||
decode a game image to a image file
|
||||
"""
|
||||
|
||||
type = "img-decode"
|
||||
|
||||
def patch(self, patch: "Patch", file_name: str, file_content: IO) -> (str, IO):
|
||||
"""
|
||||
Patch a file to encode it in a game image file
|
||||
:param patch: the patch that is applied
|
||||
:param file_name: the file_name of the file
|
||||
:param file_content: the content of the file
|
||||
:return: the new name and new content of the file
|
||||
"""
|
||||
patch_content = BytesIO(img.decode_data(file_content.read()))
|
||||
return f"{file_name}.png", patch_content
|
||||
|
||||
class BmgEditor(Operation):
|
||||
"""
|
||||
edit a bmg
|
||||
|
|
|
@ -24,6 +24,22 @@ def encode_data(image_data: bytes, transform: str = "CMPR") -> bytes:
|
|||
return stdout
|
||||
|
||||
|
||||
@better_wt_error(tools_path)
|
||||
def decode_data(image_data: bytes) -> bytes:
|
||||
"""
|
||||
Convert the game image data and return the decoded image data
|
||||
:param image_data: the original game image data
|
||||
:return: the decoded image data
|
||||
"""
|
||||
process = _tools_run_popen("DECODE", "-", "--DEST", "-")
|
||||
stdout, _ = process.communicate(input=image_data)
|
||||
|
||||
if process.returncode != 0:
|
||||
raise WTError(tools_path, process.returncode)
|
||||
|
||||
return stdout
|
||||
|
||||
|
||||
class IMGPath:
|
||||
"""
|
||||
Represent a path to a normal image, that can be converted into game image data
|
||||
|
|
Loading…
Reference in a new issue