mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 01:04:29 +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
|
||||
del Tkinter
|
||||
|
||||
# required for pypy, which always has cffi installed
|
||||
try:
|
||||
from cffi import FFI
|
||||
ffi = FFI()
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from . import Image
|
||||
from io import BytesIO
|
||||
|
||||
|
@ -184,7 +191,13 @@ class PhotoImage(object):
|
|||
try:
|
||||
from . import _imagingtk
|
||||
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:
|
||||
_imagingtk.tkinit(id(tk), 0)
|
||||
tk.call("PyImagingPhoto", self.__photo, block.id)
|
||||
|
@ -264,6 +277,8 @@ class BitmapImage(object):
|
|||
|
||||
|
||||
def getimage(photo):
|
||||
""" This function is unimplemented """
|
||||
|
||||
"""Copies the contents of a PhotoImage to a PIL image memory."""
|
||||
photo.tk.call("PyImagingPhotoGet", photo)
|
||||
|
||||
|
|
|
@ -1,22 +1,29 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
from helper import unittest, PillowTestCase, hopper
|
||||
from PIL import Image
|
||||
|
||||
|
||||
try:
|
||||
from PIL import ImageTk
|
||||
import Tkinter as tk
|
||||
dir(ImageTk)
|
||||
HAS_TK = True
|
||||
except (OSError, ImportError) as v:
|
||||
# Skipped via setUp()
|
||||
pass
|
||||
|
||||
HAS_TK = False
|
||||
|
||||
TK_MODES = ('1', 'L', 'P', 'RGB', 'RGBA')
|
||||
|
||||
class TestImageTk(PillowTestCase):
|
||||
|
||||
def setUp(self):
|
||||
if not HAS_TK:
|
||||
self.skipTest("Tk not installed")
|
||||
try:
|
||||
from PIL import ImageTk
|
||||
dir(ImageTk)
|
||||
except (OSError, ImportError) as v:
|
||||
self.skipTest(v)
|
||||
# setup tk
|
||||
app = tk.Frame()
|
||||
#root = tk.Tk()
|
||||
except (tk.TclError) as v:
|
||||
self.skipTest("TCL Error: %s" % v)
|
||||
|
||||
def test_kw(self):
|
||||
TEST_JPG = "Tests/images/hopper.jpg"
|
||||
|
@ -40,5 +47,47 @@ class TestImageTk(PillowTestCase):
|
|||
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__':
|
||||
unittest.main()
|
||||
|
|
|
@ -24,10 +24,7 @@
|
|||
* This registers a Tcl command called "PyImagingPhoto", which is used
|
||||
* 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:
|
||||
* 1995-09-12 fl Created
|
||||
* 1996-04-08 fl Ready for release
|
||||
|
@ -169,7 +166,7 @@ PyImagingPhotoPut(ClientData clientdata, Tcl_Interp* interp,
|
|||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
/* Warning -- this does not work at all */
|
||||
static int
|
||||
PyImagingPhotoGet(ClientData clientdata, Tcl_Interp* interp,
|
||||
int argc, const char **argv)
|
||||
|
|
|
@ -36,18 +36,18 @@ _tkinit(PyObject* self, PyObject* args)
|
|||
{
|
||||
Tcl_Interp* interp;
|
||||
|
||||
Py_ssize_t arg;
|
||||
PyObject* arg;
|
||||
int is_interp;
|
||||
if (!PyArg_ParseTuple(args, "ni", &arg, &is_interp))
|
||||
if (!PyArg_ParseTuple(args, "Oi", &arg, &is_interp))
|
||||
return NULL;
|
||||
|
||||
if (is_interp)
|
||||
interp = (Tcl_Interp*) arg;
|
||||
interp = (Tcl_Interp*)PyLong_AsVoidPtr(arg);
|
||||
else {
|
||||
TkappObject* app;
|
||||
/* Do it the hard way. This will break if the TkappObject
|
||||
layout changes */
|
||||
app = (TkappObject*) arg;
|
||||
app = (TkappObject*)PyLong_AsVoidPtr(arg);
|
||||
interp = app->interp;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user