roi → box

This commit is contained in:
homm 2016-11-30 20:01:28 +03:00
parent 276fdbc78d
commit 6def4bfc73
5 changed files with 29 additions and 29 deletions

View File

@ -1519,7 +1519,7 @@ class Image(object):
return self.pyaccess.putpixel(xy, value) return self.pyaccess.putpixel(xy, value)
return self.im.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. Returns a resized copy of this image.
@ -1555,10 +1555,10 @@ class Image(object):
if self.mode == 'RGBA': if self.mode == 'RGBA':
return self.convert('RGBa').resize(size, resample).convert('RGBA') return self.convert('RGBa').resize(size, resample).convert('RGBA')
if roi is None: if box is None:
roi = (0, 0) + self.size 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): def rotate(self, angle, resample=NEAREST, expand=0):
""" """

View File

@ -390,9 +390,9 @@ class CoreResampleRoiTest(PillowTestCase):
for resample in (Image.NEAREST, Image.BOX, Image.BILINEAR, Image.HAMMING, for resample in (Image.NEAREST, Image.BOX, Image.BILINEAR, Image.HAMMING,
Image.BICUBIC, Image.LANCZOS): 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]) (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]) big_size = (im.width // sc[0], im.height // sc[1])
tile2 = im.resize(big_size, resample)\ tile2 = im.resize(big_size, resample)\
.crop(o + (o[0] + size[0], o[1] + size[1])) .crop(o + (o[0] + size[0], o[1] + size[1]))
@ -403,13 +403,13 @@ class CoreResampleRoiTest(PillowTestCase):
im = hopper() im = hopper()
reference = im.crop((0, 0, 125, 125)).resize((26, 26), Image.BICUBIC) reference = im.crop((0, 0, 125, 125)).resize((26, 26), Image.BICUBIC)
supersampled = im.resize((32, 32), Image.BOX) supersampled = im.resize((32, 32), Image.BOX)
without_roi = supersampled.resize((26, 26), Image.BICUBIC) without_box = supersampled.resize((26, 26), Image.BICUBIC)
with_roi = supersampled.resize((26, 26), Image.BICUBIC, (0, 0, 31.25, 31.25)) 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\."): 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__': if __name__ == '__main__':

View File

@ -1534,43 +1534,43 @@ _resize(ImagingObject* self, PyObject* args)
int xsize, ysize; int xsize, ysize;
int filter = IMAGING_TRANSFORM_NEAREST; int filter = IMAGING_TRANSFORM_NEAREST;
float roi[4] = {0, 0, 0, 0}; float box[4] = {0, 0, 0, 0};
imIn = self->image; imIn = self->image;
roi[2] = imIn->xsize; box[2] = imIn->xsize;
roi[3] = imIn->ysize; box[3] = imIn->ysize;
if (!PyArg_ParseTuple(args, "(ii)|i(ffff)", &xsize, &ysize, &filter, 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; return NULL;
if (xsize < 1 || ysize < 1) { if (xsize < 1 || ysize < 1) {
return ImagingError_ValueError("height and width must be > 0"); 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"); 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"); 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"); 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); imOut = ImagingCopy(imIn);
} }
else if (filter == IMAGING_TRANSFORM_NEAREST) { else if (filter == IMAGING_TRANSFORM_NEAREST) {
double a[6]; double a[6];
memset(a, 0, sizeof a); memset(a, 0, sizeof a);
a[0] = (double) (roi[2] - roi[0]) / xsize; a[0] = (double) (box[2] - box[0]) / xsize;
a[4] = (double) (roi[3] - roi[1]) / ysize; a[4] = (double) (box[3] - box[1]) / ysize;
a[2] = roi[0]; a[2] = box[0];
a[5] = roi[1]; a[5] = box[1];
imOut = ImagingNew(imIn->mode, xsize, ysize); imOut = ImagingNew(imIn->mode, xsize, ysize);
@ -1580,7 +1580,7 @@ _resize(ImagingObject* self, PyObject* args)
a, filter, 1); a, filter, 1);
} }
else { else {
imOut = ImagingResample(imIn, xsize, ysize, filter, roi); imOut = ImagingResample(imIn, xsize, ysize, filter, box);
} }
return PyImagingNew(imOut); return PyImagingNew(imOut);

View File

@ -290,7 +290,7 @@ extern Imaging ImagingRankFilter(Imaging im, int size, int rank);
extern Imaging ImagingRotate90(Imaging imOut, Imaging imIn); extern Imaging ImagingRotate90(Imaging imOut, Imaging imIn);
extern Imaging ImagingRotate180(Imaging imOut, Imaging imIn); extern Imaging ImagingRotate180(Imaging imOut, Imaging imIn);
extern Imaging ImagingRotate270(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 ImagingTranspose(Imaging imOut, Imaging imIn);
extern Imaging ImagingTransform( extern Imaging ImagingTransform(
Imaging imOut, Imaging imIn, int method, int x0, int y0, int x1, int y1, Imaging imOut, Imaging imIn, int method, int x0, int y0, int x1, int y1,

View File

@ -548,7 +548,7 @@ typedef Imaging (*ResampleFunction)(Imaging imOut, Imaging imIn,
Imaging 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 imTemp = NULL;
Imaging imOut = 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 */ /* two-pass resize, first pass */
if (roi[0] || roi[2] != xsize) { if (box[0] || box[2] != xsize) {
imTemp = ImagingNew(imIn->mode, xsize, imIn->ysize); imTemp = ImagingNew(imIn->mode, xsize, imIn->ysize);
if ( ! imTemp) { if ( ! imTemp) {
return NULL; return NULL;
} }
if ( ! ResampleHorizontal(imTemp, imIn, roi[0], roi[2], xsize, filterp)) { if ( ! ResampleHorizontal(imTemp, imIn, box[0], box[2], xsize, filterp)) {
ImagingDelete(imTemp); ImagingDelete(imTemp);
return NULL; return NULL;
} }
@ -617,13 +617,13 @@ ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float roi[4])
} }
/* second pass */ /* second pass */
if (roi[1] || roi[3] != ysize) { if (box[1] || box[3] != ysize) {
imOut = ImagingNew(imIn->mode, imIn->xsize, ysize); imOut = ImagingNew(imIn->mode, imIn->xsize, ysize);
if ( ! imOut) { if ( ! imOut) {
return NULL; return NULL;
} }
/* imIn can be the original image or horizontally resampled one */ /* 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(imTemp);
ImagingDelete(imOut); ImagingDelete(imOut);
return NULL; return NULL;