File size: 3,936 Bytes
2c3f34a
 
 
 
 
 
 
 
 
ccfa6b3
 
73a9705
 
 
2c3f34a
 
 
 
 
73a9705
 
 
2c3f34a
ccfa6b3
2c3f34a
 
 
 
 
ac4ade7
 
 
 
 
 
 
 
 
 
 
 
 
2c3f34a
 
 
 
 
73a9705
 
 
2c3f34a
73a9705
 
2c3f34a
 
 
 
 
 
ac4ade7
2c3f34a
 
ac4ade7
2c3f34a
 
 
ac4ade7
2c3f34a
 
 
73a9705
2c3f34a
 
 
 
73a9705
 
 
 
 
 
 
 
 
 
 
 
 
 
2c3f34a
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import os
import sys
import subprocess
from PIL import Image

# Import skin conversion logic
from convert_skin import convert_skin_64x32_to_64x64

def main():
    skins_dir = "skins"
    control_imgs_dir = "control_imgs"
    tmp_dir = os.path.join(control_imgs_dir, "tmp")
    front_dir = os.path.join(control_imgs_dir, "front")
    back_dir = os.path.join(control_imgs_dir, "back")

    if not os.path.exists(skins_dir):
        print(f"Error: Skins directory '{skins_dir}' does not exist.")
        sys.exit(1)

    os.makedirs(tmp_dir, exist_ok=True)
    os.makedirs(front_dir, exist_ok=True)
    os.makedirs(back_dir, exist_ok=True)

    # List all PNG files in skins
    skin_files = [f for f in os.listdir(skins_dir) if f.lower().endswith(".png")]
    skin_files.sort()

    print(f"[*] Found {len(skin_files)} skin files in {skins_dir}.")

    # 1. Pre-repair pass: check and convert all legacy 64x32 skins in the candidate directory
    print("[*] Running pre-repair check on all skin files...")
    for skin_file in skin_files:
        skin_path = os.path.join(skins_dir, skin_file)
        try:
            with Image.open(skin_path) as img:
                width, height = img.size
                if (width, height) == (64, 32):
                    print(f"[*] Pre-repair: Detected legacy 64x32 skin format for {skin_file}. Auto-converting to 64x64...")
                    convert_skin_64x32_to_64x64(skin_path, skin_path)
        except Exception as e:
            print(f"[!] Pre-repair: Error checking skin size for {skin_file}: {e}")

    skipped = 0
    processed = 0

    for skin_file in skin_files:
        skin_path = os.path.join(skins_dir, skin_file)
        front_path = os.path.join(front_dir, skin_file)
        back_path = os.path.join(back_dir, skin_file)
        tmp_output_path = os.path.join(tmp_dir, skin_file)

        # Check if the output control images (front and back) already exist
        if os.path.exists(front_path) and os.path.exists(back_path):
            skipped += 1
            continue

        print("="*60)
        print(f"[*] Processing: {skin_file}")

        # Verify skin size (should be 64x64 after pre-repair)
        try:
            with Image.open(skin_path) as img:
                if img.size != (64, 64):
                    print(f"[!] Warning: Skin '{skin_file}' has unexpected dimensions {img.size}. Skipping.")
                    continue
        except Exception as e:
            print(f"[!] Error verifying skin size: {e}")
            continue

        # Invoke gpt_skin2real.py using subprocess
        cmd = [sys.executable, "gpt_skin2real.py", skin_path, "-o", tmp_output_path]
        print(f"[*] Running command: {' '.join(cmd)}")
        try:
            # We run the command and check for success. If it fails, we output the error but continue to other skins.
            subprocess.run(cmd, check=True)
            
            # Split the generated image into front and back
            with Image.open(tmp_output_path) as img:
                width, height = img.size
                left_half = img.crop((0, 0, width // 2, height))
                right_half = img.crop((width // 2, 0, width, height))
                left_half.save(front_path)
                right_half.save(back_path)
            
            # Clean up the temporary file in control_imgs/tmp
            if os.path.exists(tmp_output_path):
                os.remove(tmp_output_path)
                
            print(f"[+] Completed: {skin_file} -> {front_path} and {back_path}")
            processed += 1
        except subprocess.CalledProcessError as e:
            print(f"[!] Command failed for {skin_file}: {e}")
        except Exception as e:
            print(f"[!] Error running pipeline for {skin_file}: {e}")

    print("="*60)
    print(f"[*] Batch run completed. Processed: {processed}, Skipped (Already existed): {skipped}.")

if __name__ == "__main__":
    main()