mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-28 19:06:18 +03:00
move precompute_coeffs to ImagingResampleInner
This commit is contained in:
parent
2c2bdd80ef
commit
02e1ae3d8f
|
@ -238,26 +238,16 @@ normalize_coeffs_8bpc(int outSize, int kmax, double *prekk, INT32 **kkp)
|
||||||
|
|
||||||
|
|
||||||
Imaging
|
Imaging
|
||||||
ImagingResampleHorizontal_8bpc(Imaging imOut, Imaging imIn, float x0, float x1,
|
ImagingResampleHorizontal_8bpc(Imaging imOut, Imaging imIn,
|
||||||
struct filter *filterp)
|
int kmax, int *xbounds, double *prekk)
|
||||||
{
|
{
|
||||||
ImagingSectionCookie cookie;
|
ImagingSectionCookie cookie;
|
||||||
int ss0, ss1, ss2, ss3;
|
int ss0, ss1, ss2, ss3;
|
||||||
int xx, yy, x, kmax, xmin, xmax;
|
int xx, yy, x, xmin, xmax;
|
||||||
int *xbounds;
|
|
||||||
INT32 *k, *kk;
|
INT32 *k, *kk;
|
||||||
double *prekk;
|
|
||||||
|
|
||||||
kmax = precompute_coeffs(imIn->xsize, x0, x1, imOut->xsize, filterp,
|
|
||||||
&xbounds, &prekk);
|
|
||||||
if ( ! kmax) {
|
|
||||||
return (Imaging) ImagingError_MemoryError();
|
|
||||||
}
|
|
||||||
|
|
||||||
kmax = normalize_coeffs_8bpc(imOut->xsize, kmax, prekk, &kk);
|
kmax = normalize_coeffs_8bpc(imOut->xsize, kmax, prekk, &kk);
|
||||||
free(prekk);
|
|
||||||
if ( ! kmax) {
|
if ( ! kmax) {
|
||||||
free(xbounds);
|
|
||||||
return (Imaging) ImagingError_MemoryError();
|
return (Imaging) ImagingError_MemoryError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,32 +321,21 @@ ImagingResampleHorizontal_8bpc(Imaging imOut, Imaging imIn, float x0, float x1,
|
||||||
ImagingSectionLeave(&cookie);
|
ImagingSectionLeave(&cookie);
|
||||||
|
|
||||||
free(kk);
|
free(kk);
|
||||||
free(xbounds);
|
|
||||||
return imOut;
|
return imOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Imaging
|
Imaging
|
||||||
ImagingResampleVertical_8bpc(Imaging imOut, Imaging imIn, float y0, float y1,
|
ImagingResampleVertical_8bpc(Imaging imOut, Imaging imIn,
|
||||||
struct filter *filterp)
|
int kmax, int *xbounds, double *prekk)
|
||||||
{
|
{
|
||||||
ImagingSectionCookie cookie;
|
ImagingSectionCookie cookie;
|
||||||
int ss0, ss1, ss2, ss3;
|
int ss0, ss1, ss2, ss3;
|
||||||
int xx, yy, y, kmax, ymin, ymax;
|
int xx, yy, y, ymin, ymax;
|
||||||
int *xbounds;
|
|
||||||
INT32 *k, *kk;
|
INT32 *k, *kk;
|
||||||
double *prekk;
|
|
||||||
|
|
||||||
kmax = precompute_coeffs(imIn->ysize, y0, y1, imOut->ysize, filterp,
|
|
||||||
&xbounds, &prekk);
|
|
||||||
if ( ! kmax) {
|
|
||||||
return (Imaging) ImagingError_MemoryError();
|
|
||||||
}
|
|
||||||
|
|
||||||
kmax = normalize_coeffs_8bpc(imOut->ysize, kmax, prekk, &kk);
|
kmax = normalize_coeffs_8bpc(imOut->ysize, kmax, prekk, &kk);
|
||||||
free(prekk);
|
|
||||||
if ( ! kmax) {
|
if ( ! kmax) {
|
||||||
free(xbounds);
|
|
||||||
return (Imaging) ImagingError_MemoryError();
|
return (Imaging) ImagingError_MemoryError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,26 +409,18 @@ ImagingResampleVertical_8bpc(Imaging imOut, Imaging imIn, float y0, float y1,
|
||||||
ImagingSectionLeave(&cookie);
|
ImagingSectionLeave(&cookie);
|
||||||
|
|
||||||
free(kk);
|
free(kk);
|
||||||
free(xbounds);
|
|
||||||
return imOut;
|
return imOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Imaging
|
Imaging
|
||||||
ImagingResampleHorizontal_32bpc(Imaging imOut, Imaging imIn, float x0, float x1,
|
ImagingResampleHorizontal_32bpc(Imaging imOut, Imaging imIn,
|
||||||
struct filter *filterp)
|
int kmax, int *xbounds, double *kk)
|
||||||
{
|
{
|
||||||
ImagingSectionCookie cookie;
|
ImagingSectionCookie cookie;
|
||||||
double ss;
|
double ss;
|
||||||
int xx, yy, x, kmax, xmin, xmax;
|
int xx, yy, x, xmin, xmax;
|
||||||
int *xbounds;
|
double *k;
|
||||||
double *k, *kk;
|
|
||||||
|
|
||||||
kmax = precompute_coeffs(imIn->xsize, x0, x1, imOut->xsize, filterp,
|
|
||||||
&xbounds, &kk);
|
|
||||||
if ( ! kmax) {
|
|
||||||
return (Imaging) ImagingError_MemoryError();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImagingSectionEnter(&cookie);
|
ImagingSectionEnter(&cookie);
|
||||||
switch(imIn->type) {
|
switch(imIn->type) {
|
||||||
|
@ -483,27 +454,18 @@ ImagingResampleHorizontal_32bpc(Imaging imOut, Imaging imIn, float x0, float x1,
|
||||||
}
|
}
|
||||||
ImagingSectionLeave(&cookie);
|
ImagingSectionLeave(&cookie);
|
||||||
|
|
||||||
free(kk);
|
|
||||||
free(xbounds);
|
|
||||||
return imOut;
|
return imOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Imaging
|
Imaging
|
||||||
ImagingResampleVertical_32bpc(Imaging imOut, Imaging imIn, float y0, float y1,
|
ImagingResampleVertical_32bpc(Imaging imOut, Imaging imIn,
|
||||||
struct filter *filterp)
|
int kmax, int *xbounds, double *kk)
|
||||||
{
|
{
|
||||||
ImagingSectionCookie cookie;
|
ImagingSectionCookie cookie;
|
||||||
double ss;
|
double ss;
|
||||||
int xx, yy, y, kmax, ymin, ymax;
|
int xx, yy, y, ymin, ymax;
|
||||||
int *xbounds;
|
double *k;
|
||||||
double *k, *kk;
|
|
||||||
|
|
||||||
kmax = precompute_coeffs(imIn->ysize, y0, y1, imOut->ysize, filterp,
|
|
||||||
&xbounds, &kk);
|
|
||||||
if ( ! kmax) {
|
|
||||||
return (Imaging) ImagingError_MemoryError();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImagingSectionEnter(&cookie);
|
ImagingSectionEnter(&cookie);
|
||||||
switch(imIn->type) {
|
switch(imIn->type) {
|
||||||
|
@ -537,14 +499,12 @@ ImagingResampleVertical_32bpc(Imaging imOut, Imaging imIn, float y0, float y1,
|
||||||
}
|
}
|
||||||
ImagingSectionLeave(&cookie);
|
ImagingSectionLeave(&cookie);
|
||||||
|
|
||||||
free(kk);
|
|
||||||
free(xbounds);
|
|
||||||
return imOut;
|
return imOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef Imaging (*ResampleFunction)(Imaging imOut, Imaging imIn,
|
typedef Imaging (*ResampleFunction)(Imaging imOut, Imaging imIn,
|
||||||
float x0, float x1, struct filter *filterp);
|
int kmax, int *xbounds, double *kk);
|
||||||
|
|
||||||
|
|
||||||
Imaging
|
Imaging
|
||||||
|
@ -622,34 +582,62 @@ ImagingResampleInner(Imaging imIn, int xsize, int ysize,
|
||||||
Imaging imTemp = NULL;
|
Imaging imTemp = NULL;
|
||||||
Imaging imOut = NULL;
|
Imaging imOut = NULL;
|
||||||
|
|
||||||
|
int kmax;
|
||||||
|
int *xbounds;
|
||||||
|
double *kk;
|
||||||
|
|
||||||
/* two-pass resize, first pass */
|
/* two-pass resize, first pass */
|
||||||
if (box[0] || box[2] != xsize) {
|
if (box[0] || box[2] != xsize) {
|
||||||
|
kmax = precompute_coeffs(imIn->xsize, box[0], box[2], xsize, filterp,
|
||||||
|
&xbounds, &kk);
|
||||||
|
if ( ! kmax) {
|
||||||
|
return (Imaging) ImagingError_MemoryError();
|
||||||
|
}
|
||||||
|
|
||||||
imTemp = ImagingNew(imIn->mode, xsize, imIn->ysize);
|
imTemp = ImagingNew(imIn->mode, xsize, imIn->ysize);
|
||||||
if ( ! imTemp) {
|
if ( ! imTemp) {
|
||||||
|
free(xbounds);
|
||||||
|
free(kk);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if ( ! ResampleHorizontal(imTemp, imIn, box[0], box[2], filterp)) {
|
if ( ! ResampleHorizontal(imTemp, imIn, kmax, xbounds, kk)) {
|
||||||
ImagingDelete(imTemp);
|
ImagingDelete(imTemp);
|
||||||
|
free(xbounds);
|
||||||
|
free(kk);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
free(xbounds);
|
||||||
|
free(kk);
|
||||||
imOut = imIn = imTemp;
|
imOut = imIn = imTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* second pass */
|
/* second pass */
|
||||||
if (box[1] || box[3] != ysize) {
|
if (box[1] || box[3] != ysize) {
|
||||||
|
kmax = precompute_coeffs(imIn->ysize, box[1], box[3], ysize, filterp,
|
||||||
|
&xbounds, &kk);
|
||||||
|
if ( ! kmax) {
|
||||||
|
return (Imaging) ImagingError_MemoryError();
|
||||||
|
}
|
||||||
|
|
||||||
imOut = ImagingNew(imIn->mode, imIn->xsize, ysize);
|
imOut = ImagingNew(imIn->mode, imIn->xsize, ysize);
|
||||||
if ( ! imOut) {
|
if ( ! imOut) {
|
||||||
|
free(xbounds);
|
||||||
|
free(kk);
|
||||||
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, box[1], box[3], filterp)) {
|
if ( ! ResampleVertical(imOut, imIn, kmax, xbounds, kk)) {
|
||||||
ImagingDelete(imTemp);
|
ImagingDelete(imTemp);
|
||||||
ImagingDelete(imOut);
|
ImagingDelete(imOut);
|
||||||
|
free(xbounds);
|
||||||
|
free(kk);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* 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(xbounds);
|
||||||
|
free(kk);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* none of the previous steps are performed, copying */
|
/* none of the previous steps are performed, copying */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user