fix conversion from Indexed PNG-image

This commit is contained in:
relikd
2021-10-11 18:57:17 +02:00
parent 01b94459cb
commit 2515060807

View File

@@ -112,26 +112,18 @@ class ArgbImage:
def _load_png(self, fname: str) -> None: def _load_png(self, fname: str) -> None:
if not PIL_ENABLED: if not PIL_ENABLED:
raise ImportError('Install Pillow to support PNG conversion.') raise ImportError('Install Pillow to support PNG conversion.')
img = Image.open(fname, mode='r') img = Image.open(fname, mode='r').convert('RGBA')
self.size = img.size self.size = img.size
self.channels = 4 self.channels = 4
self.a = [] self.a = []
self.r = [] self.r = []
self.g = [] self.g = []
self.b = [] self.b = []
w, h = img.size for r, g, b, a in img.getdata():
for y in range(h): self.a.append(a)
for x in range(w): self.r.append(r)
px = img.getpixel((x, y)) self.g.append(g)
if type(px) == int: self.b.append(b)
px = (px, px, px) # convert mono to rgb
if len(px) == 3:
px = px + (0xFF,) # convert rgb to rgba
r, g, b, a = px
self.a.append(a)
self.r.append(r)
self.g.append(g)
self.b.append(b)
def write_png(self, fname: str) -> None: def write_png(self, fname: str) -> None:
if not PIL_ENABLED: if not PIL_ENABLED: