mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 01:34:24 +03:00
Merge pull request #2359 from wiredfool/issue_1902
Fix for issue ImageTk Integer Overflow error
This commit is contained in:
commit
2d06d8550f
|
@ -32,6 +32,13 @@ except ImportError:
|
||||||
tkinter = Tkinter
|
tkinter = Tkinter
|
||||||
del Tkinter
|
del Tkinter
|
||||||
|
|
||||||
|
# required for pypy, which always has cffi installed
|
||||||
|
try:
|
||||||
|
from cffi import FFI
|
||||||
|
ffi = FFI()
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
@ -184,7 +191,13 @@ class PhotoImage(object):
|
||||||
try:
|
try:
|
||||||
from . import _imagingtk
|
from . import _imagingtk
|
||||||
try:
|
try:
|
||||||
_imagingtk.tkinit(tk.interpaddr(), 1)
|
if hasattr(tk, 'interp'):
|
||||||
|
# Pypy is using a ffi cdata element
|
||||||
|
# (Pdb) self.tk.interp
|
||||||
|
# <cdata 'Tcl_Interp *' 0x3061b50>
|
||||||
|
_imagingtk.tkinit(int(ffi.cast("uintptr_t", tk.interp)), 1)
|
||||||
|
else:
|
||||||
|
_imagingtk.tkinit(tk.interpaddr(), 1)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
_imagingtk.tkinit(id(tk), 0)
|
_imagingtk.tkinit(id(tk), 0)
|
||||||
tk.call("PyImagingPhoto", self.__photo, block.id)
|
tk.call("PyImagingPhoto", self.__photo, block.id)
|
||||||
|
@ -264,6 +277,8 @@ class BitmapImage(object):
|
||||||
|
|
||||||
|
|
||||||
def getimage(photo):
|
def getimage(photo):
|
||||||
|
""" This function is unimplemented """
|
||||||
|
|
||||||
"""Copies the contents of a PhotoImage to a PIL image memory."""
|
"""Copies the contents of a PhotoImage to a PIL image memory."""
|
||||||
photo.tk.call("PyImagingPhotoGet", photo)
|
photo.tk.call("PyImagingPhotoGet", photo)
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,29 @@
|
||||||
from helper import unittest, PillowTestCase
|
from helper import unittest, PillowTestCase, hopper
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from PIL import ImageTk
|
from PIL import ImageTk
|
||||||
|
import Tkinter as tk
|
||||||
dir(ImageTk)
|
dir(ImageTk)
|
||||||
|
HAS_TK = True
|
||||||
except (OSError, ImportError) as v:
|
except (OSError, ImportError) as v:
|
||||||
# Skipped via setUp()
|
# Skipped via setUp()
|
||||||
pass
|
HAS_TK = False
|
||||||
|
|
||||||
|
TK_MODES = ('1', 'L', 'P', 'RGB', 'RGBA')
|
||||||
|
|
||||||
class TestImageTk(PillowTestCase):
|
class TestImageTk(PillowTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
if not HAS_TK:
|
||||||
|
self.skipTest("Tk not installed")
|
||||||
try:
|
try:
|
||||||
from PIL import ImageTk
|
# setup tk
|
||||||
dir(ImageTk)
|
app = tk.Frame()
|
||||||
except (OSError, ImportError) as v:
|
#root = tk.Tk()
|
||||||
self.skipTest(v)
|
except (tk.TclError) as v:
|
||||||
|
self.skipTest("TCL Error: %s" % v)
|
||||||
|
|
||||||
def test_kw(self):
|
def test_kw(self):
|
||||||
TEST_JPG = "Tests/images/hopper.jpg"
|
TEST_JPG = "Tests/images/hopper.jpg"
|
||||||
|
@ -40,5 +47,47 @@ class TestImageTk(PillowTestCase):
|
||||||
self.assertEqual(im, None)
|
self.assertEqual(im, None)
|
||||||
|
|
||||||
|
|
||||||
|
def test_photoimage(self):
|
||||||
|
for mode in TK_MODES:
|
||||||
|
# test as image:
|
||||||
|
im = hopper(mode)
|
||||||
|
|
||||||
|
# this should not crash
|
||||||
|
im_tk = ImageTk.PhotoImage(im)
|
||||||
|
|
||||||
|
self.assertEqual(im_tk.width(), im.width)
|
||||||
|
self.assertEqual(im_tk.height(), im.height)
|
||||||
|
|
||||||
|
# _tkinter.TclError: this function is not yet supported
|
||||||
|
#reloaded = ImageTk.getimage(im_tk)
|
||||||
|
#self.assert_image_equal(reloaded, im)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_photoimage_blank(self):
|
||||||
|
# test a image using mode/size:
|
||||||
|
for mode in TK_MODES:
|
||||||
|
im_tk = ImageTk.PhotoImage(mode, (100,100))
|
||||||
|
|
||||||
|
self.assertEqual(im_tk.width(), 100)
|
||||||
|
self.assertEqual(im_tk.height(), 100)
|
||||||
|
|
||||||
|
#reloaded = ImageTk.getimage(im_tk)
|
||||||
|
#self.assert_image_equal(reloaded, im)
|
||||||
|
|
||||||
|
def test_bitmapimage(self):
|
||||||
|
im = hopper('1')
|
||||||
|
|
||||||
|
# this should not crash
|
||||||
|
im_tk = ImageTk.BitmapImage(im)
|
||||||
|
|
||||||
|
self.assertEqual(im_tk.width(), im.width)
|
||||||
|
self.assertEqual(im_tk.height(), im.height)
|
||||||
|
|
||||||
|
#reloaded = ImageTk.getimage(im_tk)
|
||||||
|
#self.assert_image_equal(reloaded, im)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -24,10 +24,7 @@
|
||||||
* This registers a Tcl command called "PyImagingPhoto", which is used
|
* This registers a Tcl command called "PyImagingPhoto", which is used
|
||||||
* to communicate between PIL and Tk's PhotoImage handler.
|
* to communicate between PIL and Tk's PhotoImage handler.
|
||||||
*
|
*
|
||||||
* Compile and link tkImaging.c with tkappinit.c and _tkinter (see the
|
|
||||||
* Setup file for details on how to use tkappinit.c). Note that
|
|
||||||
* _tkinter.c must be compiled with WITH_APPINIT.
|
|
||||||
*
|
|
||||||
* History:
|
* History:
|
||||||
* 1995-09-12 fl Created
|
* 1995-09-12 fl Created
|
||||||
* 1996-04-08 fl Ready for release
|
* 1996-04-08 fl Ready for release
|
||||||
|
@ -169,7 +166,7 @@ PyImagingPhotoPut(ClientData clientdata, Tcl_Interp* interp,
|
||||||
return TCL_OK;
|
return TCL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Warning -- this does not work at all */
|
||||||
static int
|
static int
|
||||||
PyImagingPhotoGet(ClientData clientdata, Tcl_Interp* interp,
|
PyImagingPhotoGet(ClientData clientdata, Tcl_Interp* interp,
|
||||||
int argc, const char **argv)
|
int argc, const char **argv)
|
||||||
|
|
|
@ -36,18 +36,18 @@ _tkinit(PyObject* self, PyObject* args)
|
||||||
{
|
{
|
||||||
Tcl_Interp* interp;
|
Tcl_Interp* interp;
|
||||||
|
|
||||||
Py_ssize_t arg;
|
PyObject* arg;
|
||||||
int is_interp;
|
int is_interp;
|
||||||
if (!PyArg_ParseTuple(args, "ni", &arg, &is_interp))
|
if (!PyArg_ParseTuple(args, "Oi", &arg, &is_interp))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (is_interp)
|
if (is_interp)
|
||||||
interp = (Tcl_Interp*) arg;
|
interp = (Tcl_Interp*)PyLong_AsVoidPtr(arg);
|
||||||
else {
|
else {
|
||||||
TkappObject* app;
|
TkappObject* app;
|
||||||
/* Do it the hard way. This will break if the TkappObject
|
/* Do it the hard way. This will break if the TkappObject
|
||||||
layout changes */
|
layout changes */
|
||||||
app = (TkappObject*) arg;
|
app = (TkappObject*)PyLong_AsVoidPtr(arg);
|
||||||
interp = app->interp;
|
interp = app->interp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user