Skip to content

Commit

Permalink
Fix sometimes-mismatched width in uncompressed bitmap.
Browse files Browse the repository at this point in the history
  • Loading branch information
npjg committed Jul 25, 2024
1 parent ff920fb commit 699f7ef
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/MediaStation/Assets/Bitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def __init__(self, stream):
self.compression_type = Bitmap.CompressionType(Datum(stream).d)
# TODO: Figure out what this is.
# This has something to do with the width of the bitmap but is always
# a few pixels off from the width.
# a few pixels off from the width. And in rare cases it seems to be
# the true width!
self.unk2 = Datum(stream).d

@property
Expand Down Expand Up @@ -76,6 +77,20 @@ def __init__(self, chunk, header_class = BitmapHeader):
raise BinaryParsingError(f'First two bitmap bytes were {first_bitmap_bytes}, not 00 00', chunk.stream)
self._pixels = chunk.read(chunk.bytes_remaining_count)

# VERIFY THAT THE WIDTH IS CORRECT.
if len(self._pixels) != (self._width * self._height):
# TODO: This was to enable
# Hunchback:346.CXT:img_q13_BackgroundPanelA to export
# properly. It turns out the true width was in fact
# what's in the header rather than what's actually stored
# in the width. I don't know the other cases where this might
# happen, or what regressions might be caused.
if len(self._pixels) == (self.header.unk2 * self._height):
self._width = self.header.unk2
print(f'WARNING: Found and corrected mismatched width in uncompressed bitmap. Header: {self.header.unk2}. Width: {self._width}. Resetting width to header.')
else:
print(f'WARNING: Found mismatched width in uncompressed bitmap. Header: {self.header.unk2}. Width: {self._width}. This image might not be exported correctly.')

@property
def has_transparency(self):
return (len(self.transparency_region) > 0)
Expand Down

0 comments on commit 699f7ef

Please sign in to comment.