Skip to content

Commit

Permalink
Update - DWIN_ICO.py
Browse files Browse the repository at this point in the history
  • Loading branch information
classicrocker883 committed Dec 29, 2023
1 parent c4b4866 commit b1aa56b
Show file tree
Hide file tree
Showing 2 changed files with 230 additions and 236 deletions.
231 changes: 114 additions & 117 deletions buildroot/share/dwin/bin/DWIN_ICO.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,15 @@ def splitFile(self, filename, outDir):
def _parseHeader(self, infile):
maxEntries = 256
count = 0
validEntries = 0
icon_nums = _iconNames.keys()
while count < maxEntries:
rawBytes = infile.read(16)
entry = Entry()
entry.parseRawData(rawBytes)
# check that it is valid: is offset nonzero?
# Special case: treat 39 as valid
#if (entry.offset > 0) or (count == 39):
validEntries += 1
self.entries.append(entry)
# Special case: treat missing numbers as valid
if (entry.offset > 0) or count not in icon_nums:
self.entries.append(entry)
count += 1
return

Expand All @@ -110,15 +109,14 @@ def _splitEntryData(self, infile, outDir):
if entry.length == 0:
count += 1
continue
# Seek file position, read length bytes, and write to new output file.
print('%02d: offset: 0x%06x len: 0x%04x width: %d height: %d' %
(count, entry.offset, entry.length, entry.width, entry.height))
outfilename = os.path.join(outDir, '%03d-ICON_%s.jpg' % (count, _iconNames.get(count, "UNKNOWN")))
with open(outfilename, 'wb') as outfile:
infile.seek(entry.offset)
blob = infile.read(entry.length)
outfile.write(blob)
print('Wrote %d bytes to %s' % (entry.length, outfilename))
# Seek file position, read length bytes, and write to new output file.
print('(%3d: width=%3d height=%3d offset=%6d len=%4d) ... %s' %
(count, entry.width, entry.height, entry.offset, entry.length, os.path.basename(outfilename)))

count += 1
return
Expand All @@ -143,7 +141,7 @@ def createFile(self, iconDir, filename):
# process each file:
try:
index = int(dirEntry.name[0:3])
if (index < 0) or (index > 255):
if not (0 <= index <= 255):
print('...Ignoring invalid index on', dirEntry.path)
continue
#dirEntry.path is iconDir/name
Expand Down Expand Up @@ -246,111 +244,110 @@ def serialize(self):
return rawdata

_iconNames = {
0 : "LOGO_Creality",
1 : "Print_0",
2 : "Print_1",
3 : "Prepare_0",
4 : "Prepare_1",
5 : "Control_0",
6 : "Control_1",
7 : "Leveling_0",
8 : "Leveling_1",
9 : "HotendTemp",
10 : "BedTemp",
11 : "Speed",
12 : "Zoffset",
13 : "Back",
14 : "File",
15 : "PrintTime",
16 : "RemainTime",
17 : "Setup_0",
18 : "Setup_1",
19 : "Pause_0",
20 : "Pause_1",
21 : "Continue_0",
22 : "Continue_1",
23 : "Stop_0",
24 : "Stop_1",
25 : "Bar",
26 : "More",
27 : "Axis",
28 : "CloseMotor",
29 : "Homing",
30 : "SetHome",
31 : "PLAPreheat",
32 : "ABSPreheat",
33 : "Cool",
34 : "Language",
35 : "MoveX",
36 : "MoveY",
37 : "MoveZ",
38 : "Extruder",
# Skip 39
40 : "Temperature",
41 : "Motion",
42 : "WriteEEPROM",
43 : "ReadEEPROM",
44 : "ResetEEPROM",
45 : "Info",
46 : "SetEndTemp",
47 : "SetBedTemp",
48 : "FanSpeed",
49 : "SetPLAPreheat",
50 : "SetABSPreheat",
51 : "MaxSpeed",
52 : "MaxAccelerated",
53 : "MaxJerk",
54 : "Step",
55 : "PrintSize",
56 : "Version",
57 : "Contact",
58 : "StockConfiguraton",
59 : "MaxSpeedX",
60 : "MaxSpeedY",
61 : "MaxSpeedZ",
62 : "MaxSpeedE",
63 : "MaxAccX",
64 : "MaxAccY",
65 : "MaxAccZ",
66 : "MaxAccE",
67 : "MaxSpeedJerkX",
68 : "MaxSpeedJerkY",
69 : "MaxSpeedJerkZ",
70 : "MaxSpeedJerkE",
71 : "StepX",
72 : "StepY",
73 : "StepZ",
74 : "StepE",
75 : "Setspeed",
76 : "SetZOffset",
77 : "Rectangle",
78 : "BLTouch",
79 : "TempTooLow",
80 : "AutoLeveling",
81 : "TempTooHigh",
82 : "NoTips_C",
83 : "NoTips_E",
84 : "Continue_C",
85 : "Continue_E",
86 : "Cancel_C",
87 : "Cancel_E",
88 : "Confirm_C",
89 : "Confirm_E",
90 : "Info_0",
91 : 'Info_1',
93 : 'Printer_0',
#94 : 'Printer_1',
200 : 'Checkbox_F',
201 : 'Checkbox_T',
202 : 'Fade',
203 : 'Mesh',
204 : 'Tilt',
205 : 'Brightness',
206 : 'Probe',
249 : 'AxisD',
250 : 'AxisBR',
251 : 'AxisTR',
252 : 'AxisBL',
253 : 'AxisTL',
254 : 'AxisC'
0 : "LOGO_Creality",
1 : "Print_0",
2 : "Print_1",
3 : "Prepare_0",
4 : "Prepare_1",
5 : "Control_0",
6 : "Control_1",
7 : "Leveling_0",
8 : "Leveling_1",
9 : "HotendTemp",
10 : "BedTemp",
11 : "Speed",
12 : "Zoffset",
13 : "Back",
14 : "File",
15 : "PrintTime",
16 : "RemainTime",
17 : "Setup_0",
18 : "Setup_1",
19 : "Pause_0",
20 : "Pause_1",
21 : "Continue_0",
22 : "Continue_1",
23 : "Stop_0",
24 : "Stop_1",
25 : "Bar",
26 : "More",
27 : "Axis",
28 : "CloseMotor",
29 : "Homing",
30 : "SetHome",
31 : "PLAPreheat",
32 : "ABSPreheat",
33 : "Cool",
34 : "Language",
35 : "MoveX",
36 : "MoveY",
37 : "MoveZ",
38 : "Extruder",
# Skip 39
40 : "Temperature",
41 : "Motion",
42 : "WriteEEPROM",
43 : "ReadEEPROM",
44 : "ResetEEPROM",
45 : "Info",
46 : "SetEndTemp",
47 : "SetBedTemp",
48 : "FanSpeed",
49 : "SetPLAPreheat",
50 : "SetABSPreheat",
51 : "MaxSpeed",
52 : "MaxAccelerated",
53 : "MaxJerk",
54 : "Step",
55 : "PrintSize",
56 : "Version",
57 : "Contact",
58 : "StockConfiguraton",
59 : "MaxSpeedX",
60 : "MaxSpeedY",
61 : "MaxSpeedZ",
62 : "MaxSpeedE",
63 : "MaxAccX",
64 : "MaxAccY",
65 : "MaxAccZ",
66 : "MaxAccE",
67 : "MaxSpeedJerkX",
68 : "MaxSpeedJerkY",
69 : "MaxSpeedJerkZ",
70 : "MaxSpeedJerkE",
71 : "StepX",
72 : "StepY",
73 : "StepZ",
74 : "StepE",
75 : "Setspeed",
76 : "SetZOffset",
77 : "Rectangle",
78 : "BLTouch",
79 : "TempTooLow",
80 : "AutoLeveling",
81 : "TempTooHigh",
82 : "NoTips_C",
83 : "NoTips_E",
84 : "Continue_C",
85 : "Continue_E",
86 : "Cancel_C",
87 : "Cancel_E",
88 : "Confirm_C",
89 : "Confirm_E",
90 : "Info_0",
91 : "Info_1",
93 : "Printer_0",
200 : "Checkbox_F",
201 : "Checkbox_T",
202 : "Fade",
203 : "Mesh",
204 : "Tilt",
205 : "Brightness",
206 : "Probe",
249 : "AxisD",
250 : "AxisBR",
251 : "AxisTR",
252 : "AxisBL",
253 : "AxisTL",
254 : "AxisC"
}
Loading

0 comments on commit b1aa56b

Please sign in to comment.