From 82c567f77712542a8e09d8b3af6ad47ab9b28b03 Mon Sep 17 00:00:00 2001 From: nymiro Date: Wed, 3 Jun 2026 18:36:28 +1200 Subject: [PATCH] chore: initial Gitea migration with .gitignore --- .gitignore | 9 +++++++++ pyheic_struct/heic_file.py | 29 ++++++++++++++--------------- pyheic_struct/heic_types.py | 2 +- 3 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a58fad0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +__pycache__/ +*.pyc +*.pyo +temp_libs/ +test_output/ +*.jpg +*.txt +dist/ +*.egg-info/ diff --git a/pyheic_struct/heic_file.py b/pyheic_struct/heic_file.py index cd6e146..66b246b 100644 --- a/pyheic_struct/heic_file.py +++ b/pyheic_struct/heic_file.py @@ -607,24 +607,23 @@ class HEICFile: print("Info: No 'thmb' references found in 'iref' box.") return None - target_id = primary_id - if primary_id not in self._iref_box.references['thmb']: - shifted_primary_id = primary_id << 16 - if shifted_primary_id not in self._iref_box.references['thmb']: - print(f"Info: Primary item ID {primary_id} (or shifted) has no 'thmb' reference.") - return None + # Search all 'thmb' references to find which item points TO our primary_id. + thumbnail_id = None + for from_id, to_ids in self._iref_box.references['thmb'].items(): + if primary_id in to_ids: + thumbnail_id = from_id + break - print("Info: Using shifted primary ID to find thumbnail.") - target_id = shifted_primary_id - - - thumbnail_ids = self._iref_box.references['thmb'][target_id] - if not thumbnail_ids: - print(f"Info: Primary item ID {target_id} has 'thmb' reference, but no target IDs.") + # Also check shifted variant of primary_id + if (primary_id << 16) in to_ids: + thumbnail_id = from_id + break + + if thumbnail_id is None: + print(f"Info: No 'thmb' reference points to primary item ID {primary_id}.") return None - thumbnail_id = thumbnail_ids[0] - print(f"Found thumbnail reference: Primary ID {target_id} -> Thumbnail ID {thumbnail_id}") + print(f"Found thumbnail reference: Thumbnail ID {thumbnail_id} -> Primary ID {primary_id}") thumbnail_data = self.get_item_data(thumbnail_id) diff --git a/pyheic_struct/heic_types.py b/pyheic_struct/heic_types.py index 59d7c46..25c2f5b 100644 --- a/pyheic_struct/heic_types.py +++ b/pyheic_struct/heic_types.py @@ -619,7 +619,7 @@ class ItemReferenceBox(FullBox): ref_box_type = ref_box.type self.references[ref_box_type] = {} - stream = ref_box.raw_data[4:] + stream = ref_box.raw_data pos = 0 if pos + item_id_size > len(stream):