mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-22 22:19:46 +03:00
Merge pull request #2182 from wiredfool/pyside_segfault
Fix for ImageQt Segfault
This commit is contained in:
commit
9ee19f2aa9
|
@ -48,6 +48,11 @@ install:
|
||||||
# libimagequant
|
# libimagequant
|
||||||
- pushd depends && ./install_imagequant.sh && popd
|
- pushd depends && ./install_imagequant.sh && popd
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
# Qt needs a display for some of the tests, and it's only run on the system site packages install
|
||||||
|
- "export DISPLAY=:99.0"
|
||||||
|
- "sh -e /etc/init.d/xvfb start"
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- if [ "$TRAVIS_PYTHON_VERSION" != "nightly" ]; then coverage erase; fi
|
- if [ "$TRAVIS_PYTHON_VERSION" != "nightly" ]; then coverage erase; fi
|
||||||
- python setup.py clean
|
- python setup.py clean
|
||||||
|
|
|
@ -157,7 +157,6 @@ def _toqclass_helper(im):
|
||||||
else:
|
else:
|
||||||
raise ValueError("unsupported image mode %r" % im.mode)
|
raise ValueError("unsupported image mode %r" % im.mode)
|
||||||
|
|
||||||
# must keep a reference, or Qt will crash!
|
|
||||||
__data = data or align8to32(im.tobytes(), im.size[0], im.mode)
|
__data = data or align8to32(im.tobytes(), im.size[0], im.mode)
|
||||||
return {
|
return {
|
||||||
'data': __data, 'im': im, 'format': format, 'colortable': colortable
|
'data': __data, 'im': im, 'format': format, 'colortable': colortable
|
||||||
|
@ -175,8 +174,13 @@ if qt_is_installed:
|
||||||
string or a PyQt string object).
|
string or a PyQt string object).
|
||||||
"""
|
"""
|
||||||
im_data = _toqclass_helper(im)
|
im_data = _toqclass_helper(im)
|
||||||
|
# must keep a reference, or Qt will crash!
|
||||||
|
# All QImage constructors that take data operate on an existing
|
||||||
|
# buffer, so this buffer has to hang on for the life of the image.
|
||||||
|
# Fixes https://github.com/python-pillow/Pillow/issues/1370
|
||||||
|
self.__data = im_data['data']
|
||||||
QImage.__init__(self,
|
QImage.__init__(self,
|
||||||
im_data['data'], im_data['im'].size[0],
|
self.__data, im_data['im'].size[0],
|
||||||
im_data['im'].size[1], im_data['format'])
|
im_data['im'].size[1], im_data['format'])
|
||||||
if im_data['colortable']:
|
if im_data['colortable']:
|
||||||
self.setColorTable(im_data['colortable'])
|
self.setColorTable(im_data['colortable'])
|
||||||
|
|
|
@ -5,7 +5,17 @@ from PIL import ImageQt
|
||||||
|
|
||||||
|
|
||||||
if ImageQt.qt_is_installed:
|
if ImageQt.qt_is_installed:
|
||||||
from PIL.ImageQt import QImage
|
from PIL.ImageQt import QImage, QPixmap
|
||||||
|
|
||||||
|
try:
|
||||||
|
from PyQt5 import QtGui
|
||||||
|
except (ImportError, RuntimeError):
|
||||||
|
try:
|
||||||
|
from PyQt4 import QtGui
|
||||||
|
except (ImportError, RuntimeError):
|
||||||
|
from PySide import QtGui
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TestToQImage(PillowQtTestCase, PillowTestCase):
|
class TestToQImage(PillowQtTestCase, PillowTestCase):
|
||||||
|
@ -23,5 +33,41 @@ class TestToQImage(PillowQtTestCase, PillowTestCase):
|
||||||
data.save(tempfile)
|
data.save(tempfile)
|
||||||
|
|
||||||
|
|
||||||
|
def test_segfault(self):
|
||||||
|
PillowQtTestCase.setUp(self)
|
||||||
|
|
||||||
|
app = QtGui.QApplication([])
|
||||||
|
ex = Example()
|
||||||
|
|
||||||
|
|
||||||
|
if ImageQt.qt_is_installed:
|
||||||
|
class Example(QtGui.QWidget):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(Example, self).__init__()
|
||||||
|
|
||||||
|
img = hopper().resize((1000,1000))
|
||||||
|
|
||||||
|
qimage = ImageQt.ImageQt(img)
|
||||||
|
|
||||||
|
pixmap1 = QtGui.QPixmap.fromImage(qimage)
|
||||||
|
|
||||||
|
hbox = QtGui.QHBoxLayout(self)
|
||||||
|
|
||||||
|
lbl = QtGui.QLabel(self)
|
||||||
|
# Segfault in the problem
|
||||||
|
lbl.setPixmap(pixmap1.copy())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
app = QtGui.QApplication(sys.argv)
|
||||||
|
ex = Example()
|
||||||
|
sys.exit(app.exec_())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user