@@ -581,7 +581,7 @@ def get_mask_type_for_icon_type(icon_type):
581581
582582def to_bytes (n , length , endianess = 'big' ):
583583 h = '%x' % n
584- s = ( '0' * (len (h ) % 2 ) + h ).zfill (length * 2 ). decode ( 'hex' )
584+ s = bytes . fromhex (( '0' * (len (h ) % 2 ) + h ).zfill (length * 2 ))
585585 return s if endianess == 'big' else s [::- 1 ]
586586
587587
@@ -601,7 +601,7 @@ def type_to_str(type):
601601 s .append (type >> 8 & 0xff )
602602 s .append (type & 0xff )
603603 s .append (0 )
604- return str (s )
604+ return bytes (s )
605605
606606class Printable (object ):
607607 def _attrs (self ):
@@ -953,8 +953,8 @@ def from_type(cls, type):
953953 print ('Unable to parse icon type {}' .format (type_to_str (type )))
954954 icon_info .iconType = ICNS_NULL_TYPE
955955
956- icon_info .iconRawDataSize = icon_info .iconSize .height * icon_info .iconSize .width * icon_info .iconBitDepth / ICNS_BYTE_BITS
957- icon_info .data = bytearray (icon_info .iconRawDataSize )
956+ icon_info .iconRawDataSize = int ( icon_info .iconSize .height * icon_info .iconSize .width * icon_info .iconBitDepth / ICNS_BYTE_BITS )
957+ icon_info .data = bytearray (int ( icon_info .iconRawDataSize ) )
958958
959959 return icon_info
960960
@@ -999,12 +999,12 @@ def parse_image(self, image):
999999
10001000 icns_info = ICNSInfo ()
10011001 icns_info .isImage = 1
1002- icns_info .iconSize .width = icon_size
1003- icns_info .iconSize .height = icon_size
1002+ icns_info .iconSize .width = int ( icon_size )
1003+ icns_info .iconSize .height = int ( icon_size )
10041004 icns_info .iconBitDepth = bpp
10051005 icns_info .iconChannels = 4 if bpp == 32 else 1
1006- icns_info .iconPixelDepth = bpp / icns_info .iconChannels
1007- icns_info .iconRawDataSize = width * height * 4
1006+ icns_info .iconPixelDepth = int ( bpp / icns_info .iconChannels )
1007+ icns_info .iconRawDataSize = int ( width * height * 4 )
10081008 icns_info .data = bytearray (list (data ))
10091009
10101010 icon_type = icns_info .get_image_type ()
@@ -1101,12 +1101,12 @@ def get_image(self):
11011101
11021102 icns_info = ICNSInfo ()
11031103 icns_info .isImage = 1
1104- icns_info .iconSize .width = width
1105- icns_info .iconSize .height = height
1104+ icns_info .iconSize .width = int ( width )
1105+ icns_info .iconSize .height = int ( height )
11061106 icns_info .iconBitDepth = bpp
11071107 icns_info .iconChannels = 4 if bpp == 32 else 1
1108- icns_info .iconPixelDepth = bpp / icns_info .iconChannels
1109- icns_info .iconRawDataSize = width * height * 4
1108+ icns_info .iconPixelDepth = int ( bpp / icns_info .iconChannels )
1109+ icns_info .iconRawDataSize = int ( width * height * 4 )
11101110 icns_info .data = bytearray (list (png_data ))
11111111 else :
11121112 image = Image .open (BytesIO (data ))
@@ -1118,12 +1118,12 @@ def get_image(self):
11181118
11191119 icns_info = ICNSInfo ()
11201120 icns_info .isImage = 1
1121- icns_info .iconSize .width = image .size [0 ]
1122- icns_info .iconSize .height = image .size [1 ]
1121+ icns_info .iconSize .width = int ( image .size [0 ])
1122+ icns_info .iconSize .height = int ( image .size [1 ])
11231123 icns_info .iconBitDepth = bpp
11241124 icns_info .iconChannels = 4 if bpp == 32 else 1
1125- icns_info .iconPixelDepth = bpp / icns_info .iconChannels
1126- icns_info .iconRawDataSize = image .size [0 ] * image .size [1 ] * 4
1125+ icns_info .iconPixelDepth = int ( bpp / icns_info .iconChannels )
1126+ icns_info .iconRawDataSize = int ( image .size [0 ] * image .size [1 ] * 4 )
11271127 icns_info .data = png_data
11281128
11291129 else :
@@ -1185,15 +1185,15 @@ def get_mask(self):
11851185 icns_info = ICNSInfo .from_type (mask_type )
11861186 mask_bit_depth = icns_info .iconSize .width * icns_info .iconSize .height
11871187 mask_data_size = icns_info .iconRawDataSize
1188- mask_data_row_size = icns_info .iconSize .width * mask_bit_depth / ICNS_BYTE_BITS
1188+ mask_data_row_size = int ( icns_info .iconSize .width * mask_bit_depth / ICNS_BYTE_BITS )
11891189
11901190 if mask_type in [ICNS_128x128_8BIT_MASK ,
11911191 ICNS_48x48_8BIT_MASK ,
11921192 ICNS_32x32_8BIT_MASK ,
11931193 ICNS_16x16_8BIT_MASK ]:
11941194 data_count = 0
11951195 while data_count < icns_info .iconSize .height :
1196- data_pos = data_count * mask_data_row_size
1196+ data_pos = int ( data_count * mask_data_row_size )
11971197 icns_info .data [data_pos :data_pos + mask_data_row_size ] = data [data_pos :data_pos + mask_data_row_size ]
11981198 data_count += 1
11991199
@@ -1280,7 +1280,7 @@ def get_image_with_mask(icns_data, element_type):
12801280 new_data_size = new_block_size * icns_image .iconSize .height
12811281
12821282 old_data = icns_image .data
1283- new_data = bytearray (new_data_size )
1283+ new_data = bytearray (int ( new_data_size ) )
12841284
12851285 data_count = 0
12861286
@@ -1329,7 +1329,7 @@ def get_image_with_mask(icns_data, element_type):
13291329
13301330 icns_image .iconPixelDepth = 8
13311331 icns_image .iconChannels = 4
1332- icns_image .iconRawDataSize = new_data_size
1332+ icns_image .iconRawDataSize = int ( new_data_size )
13331333 icns_image .data = new_data
13341334
13351335 if mask_type in [ICNS_128x128_8BIT_MASK ,
@@ -1356,7 +1356,8 @@ def get_image_with_mask(icns_data, element_type):
13561356 color_index = 0xFF if (data_value & 0x80 ) else 0x00
13571357 data_value = data_value << 1
13581358 icns_image .data [pixel_id * 4 + 3 ] = color_index
1359- im = Image .frombytes ('RGBA' , [icns_image .iconSize .width ,icns_image .iconSize .height ],str (icns_image .data ))
1359+ im = Image .frombytes ('RGBA' , [icns_image .iconSize .width ,icns_image .iconSize .height ], bytes (icns_image .data ))
1360+ #print(icns_image.data)
13601361 output = BytesIO ()
13611362 im .save (output , format = 'PNG' )
13621363 icns_image .data = bytearray (output .getvalue ())
@@ -1398,7 +1399,7 @@ def extract_icons(all_icns_data):
13981399 image_count += 1
13991400
14001401 image_data = get_image_with_mask (icns_data , element .TypeID )
1401- image_data .data = str (image_data .data )
1402+ image_data .data = bytes (image_data .data )
14021403 data .append (image_data )
14031404
14041405 offset += element .Size
0 commit comments