mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-01 18:33:05 +03:00
Fixed a bug with channel 4 population in ImageQt.py
1. Fixed a bug with channel 4 population and format inconsistencies: lines 164, 167. 2. Added PyQt5 support. The changes have been tested.
This commit is contained in:
parent
1654eeacba
commit
b9701b0d52
|
@ -26,6 +26,7 @@ from ._util import is_path
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import PyQt6
|
import PyQt6
|
||||||
|
import PyQt5
|
||||||
import PySide6
|
import PySide6
|
||||||
|
|
||||||
from . import ImageFile
|
from . import ImageFile
|
||||||
|
@ -39,6 +40,7 @@ if TYPE_CHECKING:
|
||||||
qt_version: str | None
|
qt_version: str | None
|
||||||
qt_versions = [
|
qt_versions = [
|
||||||
["6", "PyQt6"],
|
["6", "PyQt6"],
|
||||||
|
["5", "PyQt5"],
|
||||||
["side6", "PySide6"],
|
["side6", "PySide6"],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -50,6 +52,9 @@ for version, qt_module in qt_versions:
|
||||||
if qt_module == "PyQt6":
|
if qt_module == "PyQt6":
|
||||||
from PyQt6.QtCore import QBuffer, QIODevice
|
from PyQt6.QtCore import QBuffer, QIODevice
|
||||||
from PyQt6.QtGui import QImage, QPixmap, qRgba
|
from PyQt6.QtGui import QImage, QPixmap, qRgba
|
||||||
|
elif qt_module == "PyQt5":
|
||||||
|
from PyQt5.QtCore import QBuffer, QIODevice
|
||||||
|
from PyQt5.QtGui import QImage, QPixmap, qRgba
|
||||||
elif qt_module == "PySide6":
|
elif qt_module == "PySide6":
|
||||||
from PySide6.QtCore import QBuffer, QIODevice
|
from PySide6.QtCore import QBuffer, QIODevice
|
||||||
from PySide6.QtGui import QImage, QPixmap, qRgba
|
from PySide6.QtGui import QImage, QPixmap, qRgba
|
||||||
|
@ -155,11 +160,11 @@ def _toqclass_helper(im: Image.Image | str | QByteArray) -> dict[str, Any]:
|
||||||
assert palette is not None
|
assert palette is not None
|
||||||
colortable = [rgb(*palette[i : i + 3]) for i in range(0, len(palette), 3)]
|
colortable = [rgb(*palette[i : i + 3]) for i in range(0, len(palette), 3)]
|
||||||
elif im.mode == "RGB":
|
elif im.mode == "RGB":
|
||||||
# Populate the 4th channel with 255
|
# Populate the 4th channel with 255 #!
|
||||||
im = im.convert("RGBA")
|
im = im.convert("RGBA")
|
||||||
|
|
||||||
data = im.tobytes("raw", "BGRA")
|
data = im.tobytes("raw", "BGRA")
|
||||||
format = getattr(qt_format, "Format_RGB32")
|
format = getattr(qt_format, "Format_ARGB32") # 4th channel was populated in line 164
|
||||||
elif im.mode == "RGBA":
|
elif im.mode == "RGBA":
|
||||||
data = im.tobytes("raw", "BGRA")
|
data = im.tobytes("raw", "BGRA")
|
||||||
format = getattr(qt_format, "Format_ARGB32")
|
format = getattr(qt_format, "Format_ARGB32")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user