compute bounds and kk before passes

This commit is contained in:
homm 2016-12-01 14:04:31 +03:00
parent 4ff7afbe16
commit d382183591

View File

@ -569,52 +569,57 @@ ImagingResampleInner(Imaging imIn, int xsize, int ysize,
Imaging imTemp = NULL; Imaging imTemp = NULL;
Imaging imOut = NULL; Imaging imOut = NULL;
int ksize; int ksize_horiz, ksize_vert;
int *bounds; int *bounds_horiz, *bounds_vert;
double *kk; double *kk_horiz, *kk_vert;
ksize_horiz = precompute_coeffs(imIn->xsize, box[0], box[2], xsize,
filterp, &bounds_horiz, &kk_horiz);
if ( ! ksize_horiz) {
return NULL;
}
ksize_vert = precompute_coeffs(imIn->ysize, box[1], box[3], ysize,
filterp, &bounds_vert, &kk_vert);
if ( ! ksize_vert) {
free(bounds_horiz);
free(kk_horiz);
return NULL;
}
/* two-pass resize, first pass */ /* two-pass resize, first pass */
if (box[0] || box[2] != xsize) { if (box[0] || box[2] != xsize) {
ksize = precompute_coeffs(imIn->xsize, box[0], box[2], xsize, filterp,
&bounds, &kk);
if ( ! ksize) {
return NULL;
}
imTemp = ImagingNew(imIn->mode, xsize, imIn->ysize); imTemp = ImagingNew(imIn->mode, xsize, imIn->ysize);
if (imTemp) {
ResampleHorizontal(imTemp, imIn,
ksize_horiz, bounds_horiz, kk_horiz);
}
free(bounds_horiz);
free(kk_horiz);
if ( ! imTemp) { if ( ! imTemp) {
free(bounds); free(bounds_vert);
free(kk); free(kk_vert);
return NULL; return NULL;
} }
ResampleHorizontal(imTemp, imIn, ksize, bounds, kk);
free(bounds);
free(kk);
imOut = imIn = imTemp; imOut = imIn = imTemp;
} }
/* second pass */ /* second pass */
if (box[1] || box[3] != ysize) { if (box[1] || box[3] != ysize) {
ksize = precompute_coeffs(imIn->ysize, box[1], box[3], ysize, filterp,
&bounds, &kk);
if ( ! ksize) {
ImagingDelete(imTemp);
return NULL;
}
imOut = ImagingNew(imIn->mode, imIn->xsize, ysize); imOut = ImagingNew(imIn->mode, imIn->xsize, ysize);
if ( ! imOut) { if (imOut) {
free(bounds); /* imIn can be the original image or horizontally resampled one */
free(kk); ResampleVertical(imOut, imIn,
return NULL; ksize_vert, bounds_vert, kk_vert);
} }
/* imIn can be the original image or horizontally resampled one */
ResampleVertical(imOut, imIn, ksize, bounds, kk);
/* it's safe to call ImagingDelete with empty value /* it's safe to call ImagingDelete with empty value
if previous step was not performed. */ if previous step was not performed. */
ImagingDelete(imTemp); ImagingDelete(imTemp);
free(bounds); free(bounds_vert);
free(kk); free(kk_vert);
if ( ! imOut) {
return NULL;
}
} }
/* none of the previous steps are performed, copying */ /* none of the previous steps are performed, copying */