Fixed icns parsing issue with large PNG data.
This commit is contained in:
parent
3a053fe76a
commit
b6971c5df6
1 changed files with 84 additions and 85 deletions
11
icns_info.py
11
icns_info.py
|
|
@ -1107,7 +1107,7 @@ class ICNSElement(Structure):
|
|||
icns_info.iconChannels = 4 if bpp == 32 else 1
|
||||
icns_info.iconPixelDepth = int(bpp / icns_info.iconChannels)
|
||||
icns_info.iconRawDataSize = int(width * height * 4)
|
||||
icns_info.data = bytearray(list(png_data))
|
||||
icns_info.data = bytes(png_data)
|
||||
else:
|
||||
image = Image.open(BytesIO(data))
|
||||
mode_to_bpp = {'1':1, 'L':8, 'P':8, 'RGB':24, 'RGBA':32, 'CMYK':32, 'YCbCr':24, 'I':32, 'F':32}
|
||||
|
|
@ -1124,7 +1124,7 @@ class ICNSElement(Structure):
|
|||
icns_info.iconChannels = 4 if bpp == 32 else 1
|
||||
icns_info.iconPixelDepth = int(bpp / icns_info.iconChannels)
|
||||
icns_info.iconRawDataSize = int(image.size[0] * image.size[1] * 4)
|
||||
icns_info.data = png_data
|
||||
icns_info.data = bytes(png_data)
|
||||
|
||||
else:
|
||||
icns_info = ICNSInfo.from_type(icon_type)
|
||||
|
|
@ -1264,10 +1264,9 @@ def icns_parse_family_data(icns_data):
|
|||
def get_image_with_mask(icns_data, element_type):
|
||||
element = ICNSElement.from_family(icns_data, element_type)
|
||||
icns_image = element.get_image()
|
||||
if element_type in [ICNS_256x256_32BIT_ARGB_DATA,
|
||||
if element_type not in [ICNS_256x256_32BIT_ARGB_DATA,
|
||||
ICNS_512x512_32BIT_ARGB_DATA,
|
||||
ICNS_1024x1024_32BIT_ARGB_DATA]:
|
||||
return icns_image
|
||||
mask_type = get_mask_type_for_icon_type(element_type)
|
||||
mask_element = ICNSElement.from_family(icns_data, mask_type)
|
||||
mask_image = mask_element.get_mask()
|
||||
|
|
@ -1356,11 +1355,11 @@ def get_image_with_mask(icns_data, element_type):
|
|||
color_index = 0xFF if (data_value & 0x80) else 0x00
|
||||
data_value = data_value << 1
|
||||
icns_image.data[pixel_id*4+3] = color_index
|
||||
|
||||
im = Image.frombytes('RGBA', [icns_image.iconSize.width,icns_image.iconSize.height], bytes(icns_image.data))
|
||||
#print(icns_image.data)
|
||||
output = BytesIO()
|
||||
im.save(output, format='PNG')
|
||||
icns_image.data = bytearray(output.getvalue())
|
||||
icns_image.data = bytes(output.getvalue())
|
||||
|
||||
return icns_image
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue