Skip to content

Commit

Permalink
fix broken packs/unpacks in ttf/png (#819)
Browse files Browse the repository at this point in the history
  • Loading branch information
kilimnik committed May 3, 2023
1 parent 6e895ac commit dbd866f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions pyglet/extlibs/png.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ def unpack_rows(rows):
to being a sequence of bytes.
"""
for row in rows:
fmt = f'!{len(row)}'
fmt = f'!{len(row)}H'
yield bytearray(struct.pack(fmt, *row))


Expand Down Expand Up @@ -1722,7 +1722,7 @@ def _process_bKGD(self, data):
"PLTE chunk is required before bKGD chunk.")
self.background = struct.unpack('B', data)
else:
self.background = struct.unpack(f"!{self.color_planes}",
self.background = struct.unpack(f"!{self.color_planes}H",
data)
except struct.error:
raise FormatError("bKGD chunk has incorrect length.")
Expand All @@ -1744,7 +1744,7 @@ def _process_tRNS(self, data):
f"tRNS chunk is not valid with colour type {self.color_type}.")
try:
self.transparent = \
struct.unpack(f"!{self.color_planes}", data)
struct.unpack(f"!{self.color_planes}H", data)
except struct.error:
raise FormatError("tRNS chunk has incorrect length.")

Expand Down Expand Up @@ -1977,7 +1977,7 @@ def itertrns(pixels):
pixels = itertrns(pixels)
targetbitdepth = None
if self.sbit:
sbit = struct.unpack(f'{len(self.sbit)}', self.sbit)
sbit = struct.unpack(f'{len(self.sbit)}B', self.sbit)
targetbitdepth = max(sbit)
if targetbitdepth > info['bitdepth']:
raise Error(f'sBIT chunk {sbit!r} exceeds bitdepth {self.bitdepth}')
Expand Down
10 changes: 5 additions & 5 deletions pyglet/font/ttf.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,16 @@ def _get_character_map_format4(self, offset):
# a fuckwit.
header = _read_cmap_format4Header(self._data, offset)
seg_count = header.seg_count_x2 // 2
array_size = struct.calcsize(f'>{seg_count}')
end_count = self._read_array(f'>{seg_count}',
array_size = struct.calcsize(f'>{seg_count}H')
end_count = self._read_array(f'>{seg_count}H',
offset + header.size)
start_count = self._read_array(f'>{seg_count}',
start_count = self._read_array(f'>{seg_count}H',
offset + header.size + array_size + 2)
id_delta = self._read_array(f'>{seg_count}',
id_delta = self._read_array(f'>{seg_count}H',
offset + header.size + array_size + 2 + array_size)
id_range_offset_address = \
offset + header.size + array_size + 2 + array_size + array_size
id_range_offset = self._read_array(f'>{seg_count}',
id_range_offset = self._read_array(f'>{seg_count}H',
id_range_offset_address)
character_map = {}
for i in range(0, seg_count):
Expand Down

0 comments on commit dbd866f

Please sign in to comment.