Upload files to "/"
Added support for files with more than 1 texture
This commit is contained in:
parent
bf86ede0d2
commit
9b437b610b
61
decode.py
61
decode.py
|
@ -4,42 +4,53 @@ import UnityPy
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
#made by Katboi01
|
#made by Katboi01
|
||||||
def convert(in_path, out_path):
|
def convert(in_path, out_path, file_name):
|
||||||
env = UnityPy.load(in_path)
|
env = UnityPy.load(os.path.join(in_path, file_name))
|
||||||
|
|
||||||
|
textures = []
|
||||||
for obj in env.objects:
|
for obj in env.objects:
|
||||||
if obj.type.name == "Texture2D":
|
if obj.type.name == "Texture2D":
|
||||||
data = obj.read()
|
textures.append(obj)
|
||||||
im : Image = data.image
|
|
||||||
width, height = im.size
|
|
||||||
|
|
||||||
left = int((width - 2) * 0.8)
|
if len(textures) > 1:
|
||||||
|
out_path = os.path.join(out_path, file_name)
|
||||||
|
os.makedirs(out_path, exist_ok=True)
|
||||||
|
|
||||||
im1 = im.crop((0, 0, left, height))
|
for idx, obj in enumerate(textures):
|
||||||
im1_array = np.asarray(im1, dtype=np.float32) / 255
|
try:
|
||||||
|
data = obj.read()
|
||||||
y_channel = im1_array[:, :, 0]
|
im : Image = data.image
|
||||||
alpha_channel = im1_array[:, :, 2]
|
width, height = im.size
|
||||||
|
|
||||||
im2 = im.crop((left+2, 0, width, height)).resize((left, height), Image.NEAREST)
|
left = int((width - 2) * 0.8)
|
||||||
im2_array = np.asarray(im2, dtype=np.float32) / 255
|
|
||||||
|
|
||||||
cr_channel = im2_array[:, :, 0]
|
im1 = im.crop((0, 0, left, height))
|
||||||
cb_channel = im2_array[:, :, 2]
|
im1_array = np.asarray(im1, dtype=np.float32) / 255
|
||||||
|
|
||||||
|
y_channel = im1_array[:, :, 0]
|
||||||
|
alpha_channel = im1_array[:, :, 2]
|
||||||
|
|
||||||
cr_channel -= 0.5
|
im2 = im.crop((left+2, 0, width, height)).resize((left, height), Image.NEAREST)
|
||||||
cb_channel -= 0.5
|
im2_array = np.asarray(im2, dtype=np.float32) / 255
|
||||||
|
|
||||||
r_channel = np.clip(y_channel + (1.402 * cr_channel), 0, 1)
|
cr_channel = im2_array[:, :, 0]
|
||||||
g_channel = np.clip(y_channel + (-0.344136 * cb_channel) + (-0.714136 * cr_channel), 0, 1)
|
cb_channel = im2_array[:, :, 2]
|
||||||
b_channel = np.clip(y_channel + (1.772 * cb_channel), 0, 1)
|
|
||||||
|
|
||||||
new_image = np.stack([r_channel, g_channel, b_channel, alpha_channel], axis=-1)
|
cr_channel -= 0.5
|
||||||
new_image = (new_image * 255).astype(np.uint8)
|
cb_channel -= 0.5
|
||||||
|
|
||||||
result = Image.fromarray(new_image)
|
r_channel = np.clip(y_channel + (1.402 * cr_channel), 0, 1)
|
||||||
|
g_channel = np.clip(y_channel + (-0.344136 * cb_channel) + (-0.714136 * cr_channel), 0, 1)
|
||||||
|
b_channel = np.clip(y_channel + (1.772 * cb_channel), 0, 1)
|
||||||
|
|
||||||
result.save(out_path, format="PNG")
|
new_image = np.stack([r_channel, g_channel, b_channel, alpha_channel], axis=-1)
|
||||||
|
new_image = (new_image * 255).astype(np.uint8)
|
||||||
|
|
||||||
|
result = Image.fromarray(new_image)
|
||||||
|
|
||||||
|
result.save(os.path.join(out_path, data.m_Name + ".png"), format="PNG")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to extract ({idx}/{len(textures)}) from {file_name}", e)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
in_path = "decoder_in"
|
in_path = "decoder_in"
|
||||||
|
@ -54,6 +65,6 @@ def main():
|
||||||
for _, _, files in os.walk(in_path):
|
for _, _, files in os.walk(in_path):
|
||||||
for name in files:
|
for name in files:
|
||||||
print(name)
|
print(name)
|
||||||
convert(os.path.join(in_path, name), os.path.join(out_path, name))
|
convert(in_path, out_path, name)
|
||||||
|
|
||||||
main()
|
main()
|
Loading…
Reference in New Issue