Magpie/tools/HookTextureResolver/resolve.py
2021-06-18 19:21:52 +08:00

19 lines
553 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# TEXTURE.txt 格式第一行为纹理的长和高用空格隔开第二行为16进制纹理数据
import struct
import numpy as np
def resolve(in_file: str) -> np.ndarray:
with open(in_file) as f:
header = f.readline()
raw_data = f.read()
(width, _, height) = header[:-1].partition(' ')
width = int(width)
height = int(height)
weights = struct.unpack("<%df" % (width * height * 4), bytes.fromhex(raw_data))
weights = np.array(weights, dtype=np.float)
return weights.reshape((height, width, 4))