File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ def load(
4848 :param object palette: Type to store the palette. Must have API similar to
4949 `displayio.Palette`. Will be skipped if None.
5050 """
51- # pylint: disable=too-many-locals,too-many-branches
51+ # pylint: disable=too-many-locals,too-many-branches, consider-using-enumerate, too-many-statements
5252 header = file .read (8 )
5353 if header != b"\x89 PNG\r \n \x1a \n " :
5454 raise ValueError ("Not a PNG file" )
@@ -87,10 +87,12 @@ def load(
8787 for i in range (pal_size ):
8888 pal [i ] = file .read (3 )
8989 elif chunk == b"tRNS" :
90- trns_list = list (file .read (size ))
91- indices = [i for i , x in enumerate (trns_list ) if x == 0 ]
92- for index in indices :
93- pal .make_transparent (index )
90+ if size > len (pal ):
91+ raise ValueError ("More transparency entries than palette entries" )
92+ trns_data = file .read (size )
93+ for i in range (len (trns_data )):
94+ if trns_data [i ] == 0 :
95+ pal .make_transparent (i )
9496 elif chunk == b"IDAT" :
9597 data .extend (file .read (size ))
9698 elif chunk == b"IEND" :
You can’t perform that action at this time.
0 commit comments