Repository navigation
Expand file tree
/
Copy path_DIMG.py
More file actions
71 lines (60 loc) · 2.42 KB
/
Copy path_DIMG.py
File metadata and controls
71 lines (60 loc) · 2.42 KB
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
import struct
import argparse
import os
def process_dig(file_path):
"""
Обработка файла *.DAT
Args:
file_path: Путь к файлу *.DAT
"""
try:
file_name_without_extension = file_path.split(".")[0]
output_file_path = f"{file_name_without_extension}.png"
with open(file_path, 'rb') as f, open(output_file_path, "wb") as w:
# Проверка заголовка
header = f.read(4)
if header != b'DIMG':
print("Файл не распознан.")
return
w.write(b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0D\x49\x48\x44\x52')
#collor = struct.unpack('<I', f.read(4))[0]
collor, W_img, H_img, unk1, size_img, unk2 = struct.unpack('<IIIIII', f.read(24))
#print(size_img)
img = f.read(size_img)
w.write(struct.pack('>II', W_img, H_img))
w.write(b'\x08')
match collor:
case 0:
w.write(b'\x06')
case 1:
w.write(b'\x02')
case 5:
w.write(b'\x02')
case 4:
w.write(b'\x04')
case 3:
w.write(b'\x00')
case _:
w.write(b'\x00')
w.write(b''.join([
b'\x00\x00\x00\x42\xC2\xBC\xBE\x00\x00\x00\x09\x70\x48\x59\x73\x00',
b'\x00\x01\xB1\x00\x00\x01\xB1\x01\x61\x98\x28\x0E']))
w.write(struct.pack('>I', size_img))
w.write(b'\x49\x44\x41\x54')
w.write(img)
w.write(b'\x65\x0C\x6F\xAD\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82')
except FileNotFoundError:
print("Файл не найден.")
if __name__ == "__main__":
#parser = argparse.ArgumentParser(description='Конвертирование DIG в PNG')
#parser.add_argument('dig_file', help='Путь к *.DIG')
#args = parser.parse_args()
files = os.listdir()
# Пройти по всем файлам
for file in files:
# Проверить, есть ли у файла расширение .dig
if file.endswith(".dig"):
# Обработать файл
print(f"Обработка файла: {file}")
process_dig(file)
#process_dig(args.dig_file)