Merge pull request #437 from wiredfool/2gigapix-image

2gigapix image fixes
This commit is contained in:
Alex Clark ☺ 2013-12-05 02:06:50 -08:00
commit c2aca35872
2 changed files with 36 additions and 8 deletions

View File

@ -0,0 +1,27 @@
from tester import *
# This test is not run automatically.
#
# It requires > 2gb memory for the >2 gigapixel image generated in the
# second test. Running this automatically would amount to a denial of
# service on our testing infrastructure. I expect this test to fail
# on any 32 bit machine, as well as any smallish things (like
# raspberrypis). It does succeed on a 3gb Ubuntu 12.04x64 VM on python
# 2.7 an 3.2
from PIL import Image
ydim = 32769
xdim = 48000
f = tempfile('temp.png')
def _write_png(xdim,ydim):
im = Image.new('L',(xdim,ydim),(0))
im.save(f)
success()
def test_large():
""" succeeded prepatch"""
_write_png(xdim,ydim)
def test_2gpx():
"""failed prepatch"""
_write_png(xdim,xdim)

View File

@ -1234,7 +1234,8 @@ static PyObject*
_putdata(ImagingObject* self, PyObject* args)
{
Imaging image;
int n, i, x, y;
// i & n are # pixels, require py_ssize_t. x can be as large as n. y, just because.
Py_ssize_t n, i, x, y;
PyObject* data;
double scale = 1.0;
@ -1244,16 +1245,16 @@ _putdata(ImagingObject* self, PyObject* args)
return NULL;
if (!PySequence_Check(data)) {
PyErr_SetString(PyExc_TypeError, must_be_sequence);
return NULL;
PyErr_SetString(PyExc_TypeError, must_be_sequence);
return NULL;
}
image = self->image;
n = PyObject_Length(data);
if (n > (int) (image->xsize * image->ysize)) {
PyErr_SetString(PyExc_TypeError, "too many data entries");
return NULL;
if (n > (Py_ssize_t) (image->xsize * image->ysize)) {
PyErr_SetString(PyExc_TypeError, "too many data entries");
return NULL;
}
if (image->image8) {
@ -1648,7 +1649,7 @@ _stretch(ImagingObject* self, PyObject* args)
imIn = self->image;
/* two-pass resize: minimize size of intermediate image */
if (imIn->xsize * ysize < xsize * imIn->ysize)
if ((Py_ssize_t) imIn->xsize * ysize < (Py_ssize_t) xsize * imIn->ysize)
imTemp = ImagingNew(imIn->mode, imIn->xsize, ysize);
else
imTemp = ImagingNew(imIn->mode, xsize, imIn->ysize);
@ -3073,7 +3074,7 @@ image_length(ImagingObject *self)
{
Imaging im = self->image;
return im->xsize * im->ysize;
return (Py_ssize_t) im->xsize * im->ysize;
}
static PyObject *