Merge pull request #418 from wiredfool/AurelienBallier-master

PyQT5 Support
This commit is contained in:
Alex Clark ☺ 2013-12-28 05:50:49 -08:00
commit e4ae62ae59
4 changed files with 47 additions and 11 deletions

View File

@ -1,12 +1,16 @@
language: python
# for python-qt4
virtualenv:
system_site_packages: true
python:
- 2.6
- 2.7
- 3.2
- 3.3
install: "sudo apt-get -qq install libfreetype6-dev liblcms2-dev libwebp-dev ghostscript"
install: "sudo apt-get -qq install libfreetype6-dev liblcms2-dev libwebp-dev python-qt4 ghostscript""
script:
- python setup.py clean

View File

@ -8,6 +8,7 @@
# 2006-06-03 fl: created
# 2006-06-04 fl: inherit from QImage instead of wrapping it
# 2006-06-05 fl: removed toimage helper; move string support to ImageQt
# 2013-11-13 fl: add support for Qt5 (aurelien.ballier@cyclonit.com)
#
# Copyright (c) 2006 by Secret Labs AB
# Copyright (c) 2006 by Fredrik Lundh
@ -18,15 +19,18 @@
from PIL import Image
from PIL._util import isPath
from PyQt4.QtGui import QImage, qRgb
try:
from PyQt5.QtGui import QImage, qRgba
except:
from PyQt4.QtGui import QImage, qRgba
##
# (Internal) Turns an RGB color into a Qt compatible color integer.
def rgb(r, g, b):
def rgb(r, g, b, a=255):
# use qRgb to pack the colors, and then turn the resulting long
# into a negative integer with the same bitpattern.
return (qRgb(r, g, b) & 0xffffff) - 0x1000000
return (qRgba(r, g, b, a) & 0xffffffff)
##
# An PIL image wrapper for Qt. This is a subclass of PyQt4's QImage

View File

@ -1,9 +1,37 @@
from tester import *
from PIL import Image
try:
from PIL import ImageQt
except ImportError as v:
skip(v)
success()
try:
from PyQt5.QtGui import QImage, qRgb, qRgba
except:
try:
from PyQt4.QtGui import QImage, qRgb, qRgba
except:
skip('PyQT4 or 5 not installed')
from PIL import ImageQt
def test_rgb():
# from https://qt-project.org/doc/qt-4.8/qcolor.html
# typedef QRgb
# An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int.
assert_equal(qRgb(0,0,0), qRgba(0,0,0,255))
def checkrgb(r,g,b):
val = ImageQt.rgb(r,g,b)
val = val % 2**24 # drop the alpha
assert_equal(val >> 16, r)
assert_equal(((val >> 8 ) % 2**8), g)
assert_equal(val % 2**8, b)
checkrgb(0,0,0)
checkrgb(255,0,0)
checkrgb(0,255,0)
checkrgb(0,0,255)
def test_image():
for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):
assert_no_exception(lambda: ImageQt.ImageQt(lena(mode)))

View File

@ -4,7 +4,7 @@
:py:mod:`ImageQt` Module
========================
The :py:mod:`ImageQt` module contains support for creating PyQt4 QImage objects
The :py:mod:`ImageQt` module contains support for creating PyQt4 or PyQt5 QImage objects
from PIL images.
.. versionadded:: 1.1.6
@ -14,7 +14,7 @@ from PIL images.
Creates an :py:class:`~PIL.ImageQt.ImageQt` object from a PIL
:py:class:`~PIL.Image.Image` object. This class is a subclass of
QtGui.QImage, which means that you can pass the resulting objects directly
to PyQt4 API functions and methods.
to PyQt4/5 API functions and methods.
This operation is currently supported for mode 1, L, P, RGB, and RGBA
images. To handle other modes, you need to convert the image first.