Fix transparency missing with indexed color

This commit is contained in:
Mike L 2025-04-30 00:14:20 +02:00
parent b4e2de09b2
commit d57a50bedd
Signed by: mikeslab
GPG key ID: 48CCD1768D862D40
3 changed files with 35 additions and 5 deletions

View file

@ -14,7 +14,15 @@ def scaleImage(img, scale):
def readCUR(f, width=-1.0, height=-1.0):
frameImage = Image.open(f, formats=['cur', 'ico']).convert('RGBA')
frameImage = Image.open(f, formats=['cur', 'ico'])
if (frameImage.mode == 'P'):
palette = list(frameImage.palette.getdata()[1])
for i in range(4, len(palette), 4):
if sum(palette[i:i + 3]) == 0:
break
palette[i + 3] = 255
frameImage.putpalette(palette, 'BGRA')
frameImage = frameImage.convert('RGBA')
if (width, height) == (-1.0, -1.0):
return frameImage, (float(frameImage.width), float(frameImage.height))
if -1 in (width, height):