Image pixels negative index

This commit is contained in:
Nazime 2018-10-14 16:12:58 +02:00
parent 6a83a440d5
commit 468c405a47
2 changed files with 12 additions and 3 deletions

View File

@ -88,8 +88,12 @@ class PyAccess(object):
:returns: a pixel value for single band images, a tuple of :returns: a pixel value for single band images, a tuple of
pixel values for multiband images. pixel values for multiband images.
""" """
(x, y) = xy
(x, y) = self.check_xy(xy) if (x < 0):
x = self.xsize + x
if (y < 0):
y = self.ysize + y
(x, y) = self.check_xy((x, y))
return self.get_pixel(x, y) return self.get_pixel(x, y)
putpixel = __setitem__ putpixel = __setitem__

View File

@ -471,7 +471,12 @@ getpixel(Imaging im, ImagingAccess access, int x, int y)
INT32 i; INT32 i;
FLOAT32 f; FLOAT32 f;
} pixel; } pixel;
if (x < 0){
x = im->xsize + x;
}
if (y < 0){
y = im->ysize + y;
}
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) { if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) {
PyErr_SetString(PyExc_IndexError, outside_image); PyErr_SetString(PyExc_IndexError, outside_image);
return NULL; return NULL;