-
Notifications
You must be signed in to change notification settings - Fork 0
/
preset2png.py
42 lines (30 loc) · 958 Bytes
/
preset2png.py
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
# seigneurfuo
# 30 May 2017
# v0.02
import sys
def preset2png(inputFilename):
"""Extracting PNG data from a CM3D2 preset file"""
# Input file
inputFile = open(inputFilename, "rb")
# Ouput file
outputFilename = "%s.png" %inputFilename
outputFile = open(outputFilename, "wb")
# Start reading all the input file from the 25th position
inputFile.seek(25, 0)
content = inputFile.read()
# Split where the PNG ends
contentSplit = content.split(b"\x49\x45\x4e\x44\xae\x42")
# And get the first part
pngData = contentSplit[0]
# Writing ouput file
outputFile.write(pngData)
outputFile.write(b"\x49\x45\x4e\x44\xae\x42")
# Closing files
inputFile.close()
outputFile.close()
if __name__ == "__main__":
if len(sys.argv) > 1:
filename = sys.argv[1]
preset2png(filename)
else:
print("Usage: preset2png.py <preset file>")