Skip to content

Commit

Permalink
v0.3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomiejduda committed Nov 18, 2024
1 parent 1f4c39a commit bff54e4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 17 deletions.
53 changes: 46 additions & 7 deletions src/GUI/gui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from src.GUI.gui_params import GuiParams
from src.Image.constants import (
DEFAULT_PIXEL_FORMAT_NAME,
ENDIANESS_TYPES_NAMES,
PIXEL_FORMATS_NAMES,
SWIZZLING_TYPES_NAMES,
)
Expand Down Expand Up @@ -67,7 +68,7 @@ def __init__(self, master: tk.Tk, in_version_num: str, in_main_directory: str):
# IMAGE PARAMETERS BOX #
########################
self.parameters_labelframe = tk.LabelFrame(self.main_frame, text="Image Parameters", font=self.gui_font)
self.parameters_labelframe.place(x=5, y=5, width=160, height=210)
self.parameters_labelframe.place(x=5, y=5, width=160, height=260)

###################################
# IMAGE PARAMETERS - IMAGE WIDTH #
Expand Down Expand Up @@ -199,18 +200,52 @@ def _get_next_pixel_format_by_key(event):
self.master.bind("<z>", _get_previous_pixel_format_by_key)
self.master.bind("<x>", _get_next_pixel_format_by_key)

####################################
# IMAGE PARAMETERS - ENDIANESS #
####################################

self.endianess_label = tk.Label(self.parameters_labelframe, text="Endianess Type", anchor="w", font=self.gui_font)
self.endianess_label.place(x=5, y=140, width=100, height=20)

self.current_endianess = tk.StringVar()
self.endianess_combobox = ttk.Combobox(self.parameters_labelframe, values=ENDIANESS_TYPES_NAMES, textvariable=self.current_endianess,
font=self.gui_font, state='readonly')
self.endianess_combobox.bind("<<ComboboxSelected>>", reload_image_callback)
self.endianess_combobox.place(x=5, y=160, width=135, height=20)
self.endianess_combobox.set(ENDIANESS_TYPES_NAMES[0])

def _get_previous_endianess_type_by_key(event):
selection = self.endianess_combobox.current()
last = len(self.endianess_combobox['values']) - 1
try:
self.endianess_combobox.current(selection - 1)
except tk.TclError:
self.endianess_combobox.current(last)
reload_image_callback(event)

def _get_next_endianess_type_by_key(event):
selection = self.endianess_combobox.current()
try:
self.endianess_combobox.current(selection + 1)
except tk.TclError:
self.endianess_combobox.current(0)
reload_image_callback(event)

self.master.bind("<q>", _get_previous_endianess_type_by_key)
self.master.bind("<w>", _get_next_endianess_type_by_key)


####################################
# IMAGE PARAMETERS - SWIZZLING #
####################################
self.swizzling_label = tk.Label(self.parameters_labelframe, text="Swizzling Type", anchor="w", font=self.gui_font)
self.swizzling_label.place(x=5, y=140, width=100, height=20)

self.swizzling_label.place(x=5, y=185, width=100, height=20)

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

def _get_previous_swizzling_type_by_key(event):
Expand Down Expand Up @@ -266,7 +301,7 @@ def _force_reload_image_by_pressing_enter(event):
##########################

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

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

self.controls_endianess_label = HTMLLabel(self.controls_labelframe, html=self._get_html_for_infobox_label("Endianess - ", "Q/W"), wrap=None)
self.controls_endianess_label.place(x=5, y=105, width=175, height=18)

self.controls_swizzling_label = HTMLLabel(self.controls_labelframe, html=self._get_html_for_infobox_label("Swizzling - ", "A/S"), wrap=None)
self.controls_swizzling_label.place(x=5, y=105, width=175, height=18)
self.controls_swizzling_label.place(x=5, y=125, width=175, height=18)

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


########################
Expand Down Expand Up @@ -368,6 +406,7 @@ def get_gui_params_from_gui_elements(self) -> bool:
self.gui_params.img_height = self.get_spinbox_value(self.height_spinbox)
self.gui_params.img_width = self.get_spinbox_value(self.width_spinbox)
self.gui_params.pixel_format = self.pixel_format_combobox.get()
self.gui_params.endianess_type = self.endianess_combobox.get()
self.gui_params.swizzling_type = self.swizzling_combobox.get()
self.gui_params.img_start_offset = self.get_spinbox_value(self.img_start_offset_spinbox)
self.gui_params.img_end_offset = self.get_spinbox_value(self.img_end_offset_spinbox)
Expand Down
1 change: 1 addition & 0 deletions src/GUI/gui_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class GuiParams:
def __init__(self):
self.pixel_format: Optional[str] = None
self.endianess_type: Optional[str] = None
self.swizzling_type: Optional[str] = None
self.img_start_offset: int = 0
self.img_end_offset: int = 0
Expand Down
35 changes: 28 additions & 7 deletions src/Image/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class SwizzlingType:
unique_id: str


@dataclass
class EndianessType:
display_name: str
unique_id: str


SUPPORTED_PIXEL_FORMATS: list[PixelFormat] = [
PixelFormat(format_name=image_format.name, format_type=image_format) for image_format in ImageFormats
]
Expand All @@ -36,16 +42,29 @@ class SwizzlingType:
SwizzlingType(display_name="BC", unique_id="bc"),
]

SUPPORTED_ENDIANESS_TYPES: list[EndianessType] = [
EndianessType(display_name="Little Endian", unique_id="little"),
EndianessType(display_name="Big Endian", unique_id="big"),
]

def check_swizzling_codes() -> bool:
swizzling_codes = []
for swizzling_type in SUPPORTED_SWIZZLING_TYPES:
if swizzling_type.unique_id in swizzling_codes:
raise Exception(f"ID={swizzling_type.unique_id} is not unique!")
swizzling_codes.append(swizzling_type.unique_id)

def check_unique_ids(list_to_check: list) -> bool:
id_list: list = []
for entry in list_to_check:
if entry.unique_id in id_list:
raise Exception(f"ID={entry.unique_id} is not unique!")
id_list.append(entry.unique_id)
return True


def get_endianess_id(endianess_name: str) -> str:
for endianess_type in SUPPORTED_ENDIANESS_TYPES:
if endianess_name == endianess_type.display_name:
return endianess_type.unique_id

raise Exception(f"Couldn't find code for endianess name: {endianess_name}")


def get_swizzling_id(swizzling_name: str) -> str:
for swizzling_type in SUPPORTED_SWIZZLING_TYPES:
if swizzling_name == swizzling_type.display_name:
Expand All @@ -54,8 +73,10 @@ def get_swizzling_id(swizzling_name: str) -> str:
raise Exception(f"Couldn't find code for swizzling name: {swizzling_name}")


check_swizzling_codes()
check_unique_ids(SUPPORTED_SWIZZLING_TYPES)
check_unique_ids(SUPPORTED_ENDIANESS_TYPES)

PIXEL_FORMATS_NAMES: list = [pixel_format.format_name for pixel_format in SUPPORTED_PIXEL_FORMATS]
DEFAULT_PIXEL_FORMAT_NAME = "RGB565"
SWIZZLING_TYPES_NAMES: list = [swizzling_type.display_name for swizzling_type in SUPPORTED_SWIZZLING_TYPES]
ENDIANESS_TYPES_NAMES: list = [endianess_type.display_name for endianess_type in SUPPORTED_ENDIANESS_TYPES]
7 changes: 5 additions & 2 deletions src/Image/heatimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from reversebox.image.swizzling.swizzle_x360 import unswizzle_x360

from src.GUI.gui_params import GuiParams
from src.Image.constants import PIXEL_FORMATS_NAMES, get_swizzling_id
from src.Image.constants import PIXEL_FORMATS_NAMES, get_endianess_id, get_swizzling_id

logger = get_logger(__name__)

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

# endianess logic
endianess_id: str = get_endianess_id(self.gui_params.endianess_type)

# unswizzling logic
swizzling_id = get_swizzling_id(self.gui_params.swizzling_type)

Expand Down Expand Up @@ -139,7 +142,7 @@ def _image_decode(self) -> bool:
ImageFormats.N64_IA8
):
self.decoded_image_data = image_decoder.decode_image(
self.encoded_image_data, self.gui_params.img_width, self.gui_params.img_height, image_format
self.encoded_image_data, self.gui_params.img_width, self.gui_params.img_height, image_format, endianess_id
)
elif image_format in (ImageFormats.N64_RGBA32, ImageFormats.N64_CMPR):
self.decoded_image_data = image_decoder.decode_n64_image(
Expand Down
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from src.GUI.gui_main import ImageHeatGUI

VERSION_NUM = "v0.3.7"
VERSION_NUM = "v0.3.8"

logger = get_logger("main")

Expand Down

0 comments on commit bff54e4

Please sign in to comment.