expose roi to precompute_coeffs (still noop)

This commit is contained in:
homm 2016-11-24 06:05:20 +03:00
parent 338610b112
commit a1fedc0f8a
4 changed files with 33 additions and 21 deletions

View File

@ -351,7 +351,7 @@ class CoreResampleCoefficientsTest(PillowTestCase):
class CoreResampleRoiTest(PillowTestCase): class CoreResampleRoiTest(PillowTestCase):
def test_wrong_arguments(self): def test_wrong_arguments(self):
im = hopper() im = hopper()
for resample in (Image.LINEAR, 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):
im.resize((32, 32), resample, (0, 0, im.width, im.height)) im.resize((32, 32), resample, (0, 0, im.width, im.height))
im.resize((32, 32), resample, (20, 20, im.width, im.height)) im.resize((32, 32), resample, (20, 20, im.width, im.height))
@ -388,7 +388,7 @@ class CoreResampleRoiTest(PillowTestCase):
im = im.resize((im.width // sc[0] * sc[0], im = im.resize((im.width // sc[0] * sc[0],
im.height // sc[1] * sc[1])) im.height // sc[1] * sc[1]))
for resample in (Image.LINEAR, 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], roi = (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])

View File

@ -1580,7 +1580,7 @@ _resize(ImagingObject* self, PyObject* args)
a, filter, 1); a, filter, 1);
} }
else { else {
imOut = ImagingResample(imIn, xsize, ysize, filter); imOut = ImagingResample(imIn, xsize, ysize, filter, roi);
} }
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); extern Imaging ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float roi[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

@ -125,8 +125,8 @@ static inline UINT8 clip8(int in)
int int
precompute_coeffs(int inSize, int outSize, struct filter *filterp, precompute_coeffs(int inSize, int in0, int in1, int outSize,
int **xboundsp, double **kkp) { struct filter *filterp, int **xboundsp, double **kkp) {
double support, scale, filterscale; double support, scale, filterscale;
double center, ww, ss; double center, ww, ss;
int xx, x, kmax, xmin, xmax; int xx, x, kmax, xmin, xmax;
@ -238,7 +238,8 @@ normalize_coeffs_8bpc(int outSize, int kmax, double *prekk, INT32 **kkp)
Imaging Imaging
ImagingResampleHorizontal_8bpc(Imaging imIn, int xsize, struct filter *filterp) ImagingResampleHorizontal_8bpc(Imaging imIn, int x0, int x1, int xsize,
struct filter *filterp)
{ {
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
Imaging imOut; Imaging imOut;
@ -248,7 +249,8 @@ ImagingResampleHorizontal_8bpc(Imaging imIn, int xsize, struct filter *filterp)
INT32 *k, *kk; INT32 *k, *kk;
double *prekk; double *prekk;
kmax = precompute_coeffs(imIn->xsize, xsize, filterp, &xbounds, &prekk); kmax = precompute_coeffs(imIn->xsize, x0, x1, xsize, filterp,
&xbounds, &prekk);
if ( ! kmax) { if ( ! kmax) {
return (Imaging) ImagingError_MemoryError(); return (Imaging) ImagingError_MemoryError();
} }
@ -343,7 +345,8 @@ ImagingResampleHorizontal_8bpc(Imaging imIn, int xsize, struct filter *filterp)
Imaging Imaging
ImagingResampleVertical_8bpc(Imaging imIn, int ysize, struct filter *filterp) ImagingResampleVertical_8bpc(Imaging imIn, int y0, int y1, int ysize,
struct filter *filterp)
{ {
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
Imaging imOut; Imaging imOut;
@ -353,7 +356,8 @@ ImagingResampleVertical_8bpc(Imaging imIn, int ysize, struct filter *filterp)
INT32 *k, *kk; INT32 *k, *kk;
double *prekk; double *prekk;
kmax = precompute_coeffs(imIn->ysize, ysize, filterp, &xbounds, &prekk); kmax = precompute_coeffs(imIn->ysize, y0, y1, ysize, filterp,
&xbounds, &prekk);
if ( ! kmax) { if ( ! kmax) {
return (Imaging) ImagingError_MemoryError(); return (Imaging) ImagingError_MemoryError();
} }
@ -448,7 +452,8 @@ ImagingResampleVertical_8bpc(Imaging imIn, int ysize, struct filter *filterp)
Imaging Imaging
ImagingResampleHorizontal_32bpc(Imaging imIn, int xsize, struct filter *filterp) ImagingResampleHorizontal_32bpc(Imaging imIn, int x0, int x1, int xsize,
struct filter *filterp)
{ {
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
Imaging imOut; Imaging imOut;
@ -457,7 +462,8 @@ ImagingResampleHorizontal_32bpc(Imaging imIn, int xsize, struct filter *filterp)
int *xbounds; int *xbounds;
double *k, *kk; double *k, *kk;
kmax = precompute_coeffs(imIn->xsize, xsize, filterp, &xbounds, &kk); kmax = precompute_coeffs(imIn->xsize, x0, x1, xsize, filterp,
&xbounds, &kk);
if ( ! kmax) { if ( ! kmax) {
return (Imaging) ImagingError_MemoryError(); return (Imaging) ImagingError_MemoryError();
} }
@ -508,7 +514,8 @@ ImagingResampleHorizontal_32bpc(Imaging imIn, int xsize, struct filter *filterp)
Imaging Imaging
ImagingResampleVertical_32bpc(Imaging imIn, int ysize, struct filter *filterp) ImagingResampleVertical_32bpc(Imaging imIn, int y0, int y1, int ysize,
struct filter *filterp)
{ {
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
Imaging imOut; Imaging imOut;
@ -517,7 +524,8 @@ ImagingResampleVertical_32bpc(Imaging imIn, int ysize, struct filter *filterp)
int *xbounds; int *xbounds;
double *k, *kk; double *k, *kk;
kmax = precompute_coeffs(imIn->ysize, ysize, filterp, &xbounds, &kk); kmax = precompute_coeffs(imIn->ysize, y0, y1, ysize, filterp,
&xbounds, &kk);
if ( ! kmax) { if ( ! kmax) {
return (Imaging) ImagingError_MemoryError(); return (Imaging) ImagingError_MemoryError();
} }
@ -567,14 +575,18 @@ ImagingResampleVertical_32bpc(Imaging imIn, int ysize, struct filter *filterp)
} }
typedef Imaging (*ResampleFunction)(Imaging imIn, int x0, int x1, int xsize,
struct filter *filterp);
Imaging Imaging
ImagingResample(Imaging imIn, int xsize, int ysize, int filter) ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float roi[4])
{ {
Imaging imTemp = NULL; Imaging imTemp = NULL;
Imaging imOut = NULL; Imaging imOut = NULL;
struct filter *filterp; struct filter *filterp;
Imaging (*ResampleHorizontal)(Imaging imIn, int xsize, struct filter *filterp); ResampleFunction ResampleHorizontal;
Imaging (*ResampleVertical)(Imaging imIn, int xsize, struct filter *filterp); ResampleFunction ResampleVertical;
if (strcmp(imIn->mode, "P") == 0 || strcmp(imIn->mode, "1") == 0) if (strcmp(imIn->mode, "P") == 0 || strcmp(imIn->mode, "1") == 0)
return (Imaging) ImagingError_ModeError(); return (Imaging) ImagingError_ModeError();
@ -624,17 +636,17 @@ ImagingResample(Imaging imIn, int xsize, int ysize, int filter)
} }
/* two-pass resize, first pass */ /* two-pass resize, first pass */
if (imIn->xsize != xsize) { if (roi[0] || roi[2] != xsize) {
imTemp = ResampleHorizontal(imIn, xsize, filterp); imTemp = ResampleHorizontal(imIn, roi[0], roi[2], xsize, filterp);
if ( ! imTemp) if ( ! imTemp)
return NULL; return NULL;
imOut = imIn = imTemp; imOut = imIn = imTemp;
} }
/* second pass */ /* second pass */
if (imIn->ysize != ysize) { if (roi[1] || roi[3] != ysize) {
/* imIn can be the original image or horizontally resampled one */ /* imIn can be the original image or horizontally resampled one */
imOut = ResampleVertical(imIn, ysize, filterp); imOut = ResampleVertical(imIn, roi[1], roi[3], ysize, filterp);
/* it's safe to call ImagingDelete with empty value /* it's safe to call ImagingDelete with empty value
if there was no previous step. */ if there was no previous step. */
ImagingDelete(imTemp); ImagingDelete(imTemp);