mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Handle PIL images in any mode by converting to RGBA
This commit is contained in:
parent
8db9707e2e
commit
dc1daee516
@ -694,9 +694,6 @@ def convert_PIL_image_to_pixmap(im, device_pixel_ratio=1.0):
|
|||||||
if im.mode == "RGBA":
|
if im.mode == "RGBA":
|
||||||
fmt = QImage.Format.Format_RGBA8888
|
fmt = QImage.Format.Format_RGBA8888
|
||||||
data = im.tobytes("raw", "RGBA")
|
data = im.tobytes("raw", "RGBA")
|
||||||
elif im.mode in ("RGB", "CMYK"):
|
|
||||||
fmt = QImage.Format.Format_RGBX8888
|
|
||||||
data = im.convert("RGBA").tobytes("raw", "RGBA")
|
|
||||||
elif im.mode == "1":
|
elif im.mode == "1":
|
||||||
fmt = QImage.Format.Format_Mono
|
fmt = QImage.Format.Format_Mono
|
||||||
elif im.mode == "L":
|
elif im.mode == "L":
|
||||||
@ -710,7 +707,8 @@ def convert_PIL_image_to_pixmap(im, device_pixel_ratio=1.0):
|
|||||||
im = im.point(lambda i: i * 256)
|
im = im.point(lambda i: i * 256)
|
||||||
fmt = QImage.Format.Format_Grayscale16
|
fmt = QImage.Format.Format_Grayscale16
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"unsupported image mode {repr(im.mode)}")
|
fmt = QImage.Format.Format_RGBX8888
|
||||||
|
data = im.convert("RGBA").tobytes("raw", "RGBA")
|
||||||
|
|
||||||
size = im.size
|
size = im.size
|
||||||
data = data or align8to32(im.tobytes(), size[0], im.mode)
|
data = data or align8to32(im.tobytes(), size[0], im.mode)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user