From 6def4bfc7337017a7c9e18149ca5de8fd1589ddf Mon Sep 17 00:00:00 2001 From: homm Date: Wed, 30 Nov 2016 20:01:28 +0300 Subject: [PATCH] =?UTF-8?q?roi=20=E2=86=92=20box?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PIL/Image.py | 8 ++++---- Tests/test_image_resample.py | 12 ++++++------ _imaging.c | 26 +++++++++++++------------- libImaging/Imaging.h | 2 +- libImaging/Resample.c | 10 +++++----- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index 2434d54a7..9814a7392 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -1519,7 +1519,7 @@ class Image(object): return self.pyaccess.putpixel(xy, value) return self.im.putpixel(xy, value) - def resize(self, size, resample=NEAREST, roi=None): + def resize(self, size, resample=NEAREST, box=None): """ Returns a resized copy of this image. @@ -1555,10 +1555,10 @@ class Image(object): if self.mode == 'RGBA': return self.convert('RGBa').resize(size, resample).convert('RGBA') - if roi is None: - roi = (0, 0) + self.size + if box is None: + box = (0, 0) + self.size - return self._new(self.im.resize(size, resample, roi)) + return self._new(self.im.resize(size, resample, box)) def rotate(self, angle, resample=NEAREST, expand=0): """ diff --git a/Tests/test_image_resample.py b/Tests/test_image_resample.py index 680633f2c..3d37bddde 100644 --- a/Tests/test_image_resample.py +++ b/Tests/test_image_resample.py @@ -390,9 +390,9 @@ class CoreResampleRoiTest(PillowTestCase): for resample in (Image.NEAREST, Image.BOX, Image.BILINEAR, Image.HAMMING, Image.BICUBIC, Image.LANCZOS): - roi = (o[0] * sc[0], o[1] * sc[1], + box = (o[0] * sc[0], o[1] * sc[1], (o[0] + size[0]) * sc[0], (o[1] + size[1]) * sc[1]) - tile1 = im.resize(size, resample, roi) + tile1 = im.resize(size, resample, box) big_size = (im.width // sc[0], im.height // sc[1]) tile2 = im.resize(big_size, resample)\ .crop(o + (o[0] + size[0], o[1] + size[1])) @@ -403,13 +403,13 @@ class CoreResampleRoiTest(PillowTestCase): im = hopper() reference = im.crop((0, 0, 125, 125)).resize((26, 26), Image.BICUBIC) supersampled = im.resize((32, 32), Image.BOX) - without_roi = supersampled.resize((26, 26), Image.BICUBIC) - with_roi = supersampled.resize((26, 26), Image.BICUBIC, (0, 0, 31.25, 31.25)) + without_box = supersampled.resize((26, 26), Image.BICUBIC) + with_box = supersampled.resize((26, 26), Image.BICUBIC, (0, 0, 31.25, 31.25)) - self.assert_image_similar(reference, with_roi, 12) + self.assert_image_similar(reference, with_box, 12) with self.assertRaisesRegexp(AssertionError, "difference 3\d\."): - self.assert_image_similar(reference, without_roi, 10) + self.assert_image_similar(reference, without_box, 10) if __name__ == '__main__': diff --git a/_imaging.c b/_imaging.c index 40159c6a2..818826f37 100644 --- a/_imaging.c +++ b/_imaging.c @@ -1534,43 +1534,43 @@ _resize(ImagingObject* self, PyObject* args) int xsize, ysize; int filter = IMAGING_TRANSFORM_NEAREST; - float roi[4] = {0, 0, 0, 0}; + float box[4] = {0, 0, 0, 0}; imIn = self->image; - roi[2] = imIn->xsize; - roi[3] = imIn->ysize; + box[2] = imIn->xsize; + box[3] = imIn->ysize; if (!PyArg_ParseTuple(args, "(ii)|i(ffff)", &xsize, &ysize, &filter, - &roi[0], &roi[1], &roi[2], &roi[3])) + &box[0], &box[1], &box[2], &box[3])) return NULL; if (xsize < 1 || ysize < 1) { return ImagingError_ValueError("height and width must be > 0"); } - if (roi[0] < 0 || roi[1] < 0) { + if (box[0] < 0 || box[1] < 0) { return ImagingError_ValueError("region of interest offset can't be negative"); } - if (roi[2] > imIn->xsize || roi[3] > imIn->ysize) { + if (box[2] > imIn->xsize || box[3] > imIn->ysize) { return ImagingError_ValueError("region of interest can't exceed original image size"); } - if (roi[2] - roi[0] <= 0 || roi[3] - roi[1] <= 0) { + if (box[2] - box[0] <= 0 || box[3] - box[1] <= 0) { return ImagingError_ValueError("region of interest can't be empty"); } - if (roi[0] == 0 && roi[1] == 0 && roi[2] == xsize && roi[3] == ysize) { + if (box[0] == 0 && box[1] == 0 && box[2] == xsize && box[3] == ysize) { imOut = ImagingCopy(imIn); } else if (filter == IMAGING_TRANSFORM_NEAREST) { double a[6]; memset(a, 0, sizeof a); - a[0] = (double) (roi[2] - roi[0]) / xsize; - a[4] = (double) (roi[3] - roi[1]) / ysize; - a[2] = roi[0]; - a[5] = roi[1]; + a[0] = (double) (box[2] - box[0]) / xsize; + a[4] = (double) (box[3] - box[1]) / ysize; + a[2] = box[0]; + a[5] = box[1]; imOut = ImagingNew(imIn->mode, xsize, ysize); @@ -1580,7 +1580,7 @@ _resize(ImagingObject* self, PyObject* args) a, filter, 1); } else { - imOut = ImagingResample(imIn, xsize, ysize, filter, roi); + imOut = ImagingResample(imIn, xsize, ysize, filter, box); } return PyImagingNew(imOut); diff --git a/libImaging/Imaging.h b/libImaging/Imaging.h index dcdcb85b9..686bb82ec 100644 --- a/libImaging/Imaging.h +++ b/libImaging/Imaging.h @@ -290,7 +290,7 @@ extern Imaging ImagingRankFilter(Imaging im, int size, int rank); extern Imaging ImagingRotate90(Imaging imOut, Imaging imIn); extern Imaging ImagingRotate180(Imaging imOut, Imaging imIn); extern Imaging ImagingRotate270(Imaging imOut, Imaging imIn); -extern Imaging ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float roi[4]); +extern Imaging ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float box[4]); extern Imaging ImagingTranspose(Imaging imOut, Imaging imIn); extern Imaging ImagingTransform( Imaging imOut, Imaging imIn, int method, int x0, int y0, int x1, int y1, diff --git a/libImaging/Resample.c b/libImaging/Resample.c index 8abb63fb4..9b055ed17 100644 --- a/libImaging/Resample.c +++ b/libImaging/Resample.c @@ -548,7 +548,7 @@ typedef Imaging (*ResampleFunction)(Imaging imOut, Imaging imIn, Imaging -ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float roi[4]) +ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float box[4]) { Imaging imTemp = NULL; Imaging imOut = NULL; @@ -604,12 +604,12 @@ ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float roi[4]) } /* two-pass resize, first pass */ - if (roi[0] || roi[2] != xsize) { + if (box[0] || box[2] != xsize) { imTemp = ImagingNew(imIn->mode, xsize, imIn->ysize); if ( ! imTemp) { return NULL; } - if ( ! ResampleHorizontal(imTemp, imIn, roi[0], roi[2], xsize, filterp)) { + if ( ! ResampleHorizontal(imTemp, imIn, box[0], box[2], xsize, filterp)) { ImagingDelete(imTemp); return NULL; } @@ -617,13 +617,13 @@ ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float roi[4]) } /* second pass */ - if (roi[1] || roi[3] != ysize) { + if (box[1] || box[3] != ysize) { imOut = ImagingNew(imIn->mode, imIn->xsize, ysize); if ( ! imOut) { return NULL; } /* imIn can be the original image or horizontally resampled one */ - if ( ! ResampleVertical(imOut, imIn, roi[1], roi[3], ysize, filterp)) { + if ( ! ResampleVertical(imOut, imIn, box[1], box[3], ysize, filterp)) { ImagingDelete(imTemp); ImagingDelete(imOut); return NULL;