mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
nearest and copy ROI
This commit is contained in:
parent
f828416752
commit
338610b112
|
@ -378,6 +378,25 @@ class CoreResampleRoiTest(PillowTestCase):
|
||||||
with self.assertRaisesRegexp(ValueError, "can't exceed"):
|
with self.assertRaisesRegexp(ValueError, "can't exceed"):
|
||||||
im.resize((32, 32), resample, (0, 0, im.width, im.height + 1))
|
im.resize((32, 32), resample, (0, 0, im.width, im.height + 1))
|
||||||
|
|
||||||
|
def test_tiles(self):
|
||||||
|
im = hopper()
|
||||||
|
# should not be fractional
|
||||||
|
size = (28, 14)
|
||||||
|
sc = (3, 4) # scale
|
||||||
|
o = (5, 10) # offset
|
||||||
|
# fixed size divisible by scale
|
||||||
|
im = im.resize((im.width // sc[0] * sc[0],
|
||||||
|
im.height // sc[1] * sc[1]))
|
||||||
|
|
||||||
|
for resample in (Image.LINEAR, Image.BOX, Image.BILINEAR, Image.HAMMING,
|
||||||
|
Image.BICUBIC, Image.LANCZOS):
|
||||||
|
roi = (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)
|
||||||
|
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]))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -1560,15 +1560,17 @@ _resize(ImagingObject* self, PyObject* args)
|
||||||
return ImagingError_ValueError("region of interest can't be empty");
|
return ImagingError_ValueError("region of interest can't be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imIn->xsize == xsize && imIn->ysize == ysize) {
|
if (roi[0] == 0 && roi[1] == 0 && roi[2] == xsize && roi[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) imIn->xsize / xsize;
|
a[0] = (double) (roi[2] - roi[0]) / xsize;
|
||||||
a[4] = (double) imIn->ysize / ysize;
|
a[4] = (double) (roi[3] - roi[1]) / ysize;
|
||||||
|
a[2] = roi[0];
|
||||||
|
a[5] = roi[1];
|
||||||
|
|
||||||
imOut = ImagingNew(imIn->mode, xsize, ysize);
|
imOut = ImagingNew(imIn->mode, xsize, ysize);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user