Skip to content

Commit bff54e4

Browse files
v0.3.8
1 parent 1f4c39a commit bff54e4

File tree

5 files changed

+81
-17
lines changed

5 files changed

+81
-17
lines changed

src/GUI/gui_main.py

+46-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from src.GUI.gui_params import GuiParams
2222
from src.Image.constants import (
2323
DEFAULT_PIXEL_FORMAT_NAME,
24+
ENDIANESS_TYPES_NAMES,
2425
PIXEL_FORMATS_NAMES,
2526
SWIZZLING_TYPES_NAMES,
2627
)
@@ -67,7 +68,7 @@ def __init__(self, master: tk.Tk, in_version_num: str, in_main_directory: str):
6768
# IMAGE PARAMETERS BOX #
6869
########################
6970
self.parameters_labelframe = tk.LabelFrame(self.main_frame, text="Image Parameters", font=self.gui_font)
70-
self.parameters_labelframe.place(x=5, y=5, width=160, height=210)
71+
self.parameters_labelframe.place(x=5, y=5, width=160, height=260)
7172

7273
###################################
7374
# IMAGE PARAMETERS - IMAGE WIDTH #
@@ -199,18 +200,52 @@ def _get_next_pixel_format_by_key(event):
199200
self.master.bind("<z>", _get_previous_pixel_format_by_key)
200201
self.master.bind("<x>", _get_next_pixel_format_by_key)
201202

203+
####################################
204+
# IMAGE PARAMETERS - ENDIANESS #
205+
####################################
206+
207+
self.endianess_label = tk.Label(self.parameters_labelframe, text="Endianess Type", anchor="w", font=self.gui_font)
208+
self.endianess_label.place(x=5, y=140, width=100, height=20)
209+
210+
self.current_endianess = tk.StringVar()
211+
self.endianess_combobox = ttk.Combobox(self.parameters_labelframe, values=ENDIANESS_TYPES_NAMES, textvariable=self.current_endianess,
212+
font=self.gui_font, state='readonly')
213+
self.endianess_combobox.bind("<<ComboboxSelected>>", reload_image_callback)
214+
self.endianess_combobox.place(x=5, y=160, width=135, height=20)
215+
self.endianess_combobox.set(ENDIANESS_TYPES_NAMES[0])
216+
217+
def _get_previous_endianess_type_by_key(event):
218+
selection = self.endianess_combobox.current()
219+
last = len(self.endianess_combobox['values']) - 1
220+
try:
221+
self.endianess_combobox.current(selection - 1)
222+
except tk.TclError:
223+
self.endianess_combobox.current(last)
224+
reload_image_callback(event)
225+
226+
def _get_next_endianess_type_by_key(event):
227+
selection = self.endianess_combobox.current()
228+
try:
229+
self.endianess_combobox.current(selection + 1)
230+
except tk.TclError:
231+
self.endianess_combobox.current(0)
232+
reload_image_callback(event)
233+
234+
self.master.bind("<q>", _get_previous_endianess_type_by_key)
235+
self.master.bind("<w>", _get_next_endianess_type_by_key)
236+
237+
202238
####################################
203239
# IMAGE PARAMETERS - SWIZZLING #
204240
####################################
205241
self.swizzling_label = tk.Label(self.parameters_labelframe, text="Swizzling Type", anchor="w", font=self.gui_font)
206-
self.swizzling_label.place(x=5, y=140, width=100, height=20)
207-
242+
self.swizzling_label.place(x=5, y=185, width=100, height=20)
208243

209244
self.current_swizzling = tk.StringVar()
210245
self.swizzling_combobox = ttk.Combobox(self.parameters_labelframe,
211246
values=SWIZZLING_TYPES_NAMES, textvariable=self.current_swizzling, font=self.gui_font, state='readonly')
212247
self.swizzling_combobox.bind("<<ComboboxSelected>>", reload_image_callback)
213-
self.swizzling_combobox.place(x=5, y=160, width=135, height=20)
248+
self.swizzling_combobox.place(x=5, y=205, width=135, height=20)
214249
self.swizzling_combobox.set(SWIZZLING_TYPES_NAMES[0])
215250

216251
def _get_previous_swizzling_type_by_key(event):
@@ -266,7 +301,7 @@ def _force_reload_image_by_pressing_enter(event):
266301
##########################
267302

268303
self.controls_labelframe = tk.LabelFrame(self.main_frame, text="Controls", font=self.gui_font)
269-
self.controls_labelframe.place(x=-200, y=115, width=195, height=170, relx=1)
304+
self.controls_labelframe.place(x=-200, y=115, width=195, height=190, relx=1)
270305

271306
self.controls_img_width_label = HTMLLabel(self.controls_labelframe, html=self._get_html_for_infobox_label("Img width - ", "Left/Right"), wrap=None)
272307
self.controls_img_width_label.place(x=5, y=5, width=175, height=18)
@@ -283,11 +318,14 @@ def _force_reload_image_by_pressing_enter(event):
283318
self.controls_pixel_format_label = HTMLLabel(self.controls_labelframe, html=self._get_html_for_infobox_label("Pixel Format - ", "Z/X"), wrap=None)
284319
self.controls_pixel_format_label.place(x=5, y=85, width=175, height=18)
285320

321+
self.controls_endianess_label = HTMLLabel(self.controls_labelframe, html=self._get_html_for_infobox_label("Endianess - ", "Q/W"), wrap=None)
322+
self.controls_endianess_label.place(x=5, y=105, width=175, height=18)
323+
286324
self.controls_swizzling_label = HTMLLabel(self.controls_labelframe, html=self._get_html_for_infobox_label("Swizzling - ", "A/S"), wrap=None)
287-
self.controls_swizzling_label.place(x=5, y=105, width=175, height=18)
325+
self.controls_swizzling_label.place(x=5, y=125, width=175, height=18)
288326

289327
self.controls_swizzling_label = HTMLLabel(self.controls_labelframe, html=self._get_html_for_infobox_label("Reload img - ", "Enter"), wrap=None)
290-
self.controls_swizzling_label.place(x=5, y=125, width=175, height=18)
328+
self.controls_swizzling_label.place(x=5, y=145, width=175, height=18)
291329

292330

293331
########################
@@ -368,6 +406,7 @@ def get_gui_params_from_gui_elements(self) -> bool:
368406
self.gui_params.img_height = self.get_spinbox_value(self.height_spinbox)
369407
self.gui_params.img_width = self.get_spinbox_value(self.width_spinbox)
370408
self.gui_params.pixel_format = self.pixel_format_combobox.get()
409+
self.gui_params.endianess_type = self.endianess_combobox.get()
371410
self.gui_params.swizzling_type = self.swizzling_combobox.get()
372411
self.gui_params.img_start_offset = self.get_spinbox_value(self.img_start_offset_spinbox)
373412
self.gui_params.img_end_offset = self.get_spinbox_value(self.img_end_offset_spinbox)

src/GUI/gui_params.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class GuiParams:
1010
def __init__(self):
1111
self.pixel_format: Optional[str] = None
12+
self.endianess_type: Optional[str] = None
1213
self.swizzling_type: Optional[str] = None
1314
self.img_start_offset: int = 0
1415
self.img_end_offset: int = 0

src/Image/constants.py

+28-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ class SwizzlingType:
2020
unique_id: str
2121

2222

23+
@dataclass
24+
class EndianessType:
25+
display_name: str
26+
unique_id: str
27+
28+
2329
SUPPORTED_PIXEL_FORMATS: list[PixelFormat] = [
2430
PixelFormat(format_name=image_format.name, format_type=image_format) for image_format in ImageFormats
2531
]
@@ -36,16 +42,29 @@ class SwizzlingType:
3642
SwizzlingType(display_name="BC", unique_id="bc"),
3743
]
3844

45+
SUPPORTED_ENDIANESS_TYPES: list[EndianessType] = [
46+
EndianessType(display_name="Little Endian", unique_id="little"),
47+
EndianessType(display_name="Big Endian", unique_id="big"),
48+
]
3949

40-
def check_swizzling_codes() -> bool:
41-
swizzling_codes = []
42-
for swizzling_type in SUPPORTED_SWIZZLING_TYPES:
43-
if swizzling_type.unique_id in swizzling_codes:
44-
raise Exception(f"ID={swizzling_type.unique_id} is not unique!")
45-
swizzling_codes.append(swizzling_type.unique_id)
50+
51+
def check_unique_ids(list_to_check: list) -> bool:
52+
id_list: list = []
53+
for entry in list_to_check:
54+
if entry.unique_id in id_list:
55+
raise Exception(f"ID={entry.unique_id} is not unique!")
56+
id_list.append(entry.unique_id)
4657
return True
4758

4859

60+
def get_endianess_id(endianess_name: str) -> str:
61+
for endianess_type in SUPPORTED_ENDIANESS_TYPES:
62+
if endianess_name == endianess_type.display_name:
63+
return endianess_type.unique_id
64+
65+
raise Exception(f"Couldn't find code for endianess name: {endianess_name}")
66+
67+
4968
def get_swizzling_id(swizzling_name: str) -> str:
5069
for swizzling_type in SUPPORTED_SWIZZLING_TYPES:
5170
if swizzling_name == swizzling_type.display_name:
@@ -54,8 +73,10 @@ def get_swizzling_id(swizzling_name: str) -> str:
5473
raise Exception(f"Couldn't find code for swizzling name: {swizzling_name}")
5574

5675

57-
check_swizzling_codes()
76+
check_unique_ids(SUPPORTED_SWIZZLING_TYPES)
77+
check_unique_ids(SUPPORTED_ENDIANESS_TYPES)
5878

5979
PIXEL_FORMATS_NAMES: list = [pixel_format.format_name for pixel_format in SUPPORTED_PIXEL_FORMATS]
6080
DEFAULT_PIXEL_FORMAT_NAME = "RGB565"
6181
SWIZZLING_TYPES_NAMES: list = [swizzling_type.display_name for swizzling_type in SUPPORTED_SWIZZLING_TYPES]
82+
ENDIANESS_TYPES_NAMES: list = [endianess_type.display_name for endianess_type in SUPPORTED_ENDIANESS_TYPES]

src/Image/heatimage.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from reversebox.image.swizzling.swizzle_x360 import unswizzle_x360
2222

2323
from src.GUI.gui_params import GuiParams
24-
from src.Image.constants import PIXEL_FORMATS_NAMES, get_swizzling_id
24+
from src.Image.constants import PIXEL_FORMATS_NAMES, get_endianess_id, get_swizzling_id
2525

2626
logger = get_logger(__name__)
2727

@@ -61,6 +61,9 @@ def _image_decode(self) -> bool:
6161
image_decoder = ImageDecoder()
6262
image_format: ImageFormats = self._get_image_format_from_str(self.gui_params.pixel_format)
6363

64+
# endianess logic
65+
endianess_id: str = get_endianess_id(self.gui_params.endianess_type)
66+
6467
# unswizzling logic
6568
swizzling_id = get_swizzling_id(self.gui_params.swizzling_type)
6669

@@ -139,7 +142,7 @@ def _image_decode(self) -> bool:
139142
ImageFormats.N64_IA8
140143
):
141144
self.decoded_image_data = image_decoder.decode_image(
142-
self.encoded_image_data, self.gui_params.img_width, self.gui_params.img_height, image_format
145+
self.encoded_image_data, self.gui_params.img_width, self.gui_params.img_height, image_format, endianess_id
143146
)
144147
elif image_format in (ImageFormats.N64_RGBA32, ImageFormats.N64_CMPR):
145148
self.decoded_image_data = image_decoder.decode_n64_image(

src/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from src.GUI.gui_main import ImageHeatGUI
1515

16-
VERSION_NUM = "v0.3.7"
16+
VERSION_NUM = "v0.3.8"
1717

1818
logger = get_logger("main")
1919

0 commit comments

Comments
 (0)