mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +03:00 
			
		
		
		
	allocate new image outside of ResampleHorizontal/ResampleVertical
This commit is contained in:
		
							parent
							
								
									44e443fa75
								
							
						
					
					
						commit
						4079c7f192
					
				| 
						 | 
					@ -238,11 +238,10 @@ normalize_coeffs_8bpc(int outSize, int kmax, double *prekk, INT32 **kkp)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Imaging
 | 
					Imaging
 | 
				
			||||||
ImagingResampleHorizontal_8bpc(Imaging imIn, float x0, float x1, int xsize,
 | 
					ImagingResampleHorizontal_8bpc(Imaging imOut, Imaging imIn, float x0, float x1,
 | 
				
			||||||
                               struct filter *filterp)
 | 
					                               int xsize, struct filter *filterp)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ImagingSectionCookie cookie;
 | 
					    ImagingSectionCookie cookie;
 | 
				
			||||||
    Imaging imOut;
 | 
					 | 
				
			||||||
    int ss0, ss1, ss2, ss3;
 | 
					    int ss0, ss1, ss2, ss3;
 | 
				
			||||||
    int xx, yy, x, kmax, xmin, xmax;
 | 
					    int xx, yy, x, kmax, xmin, xmax;
 | 
				
			||||||
    int *xbounds;
 | 
					    int *xbounds;
 | 
				
			||||||
| 
						 | 
					@ -262,13 +261,6 @@ ImagingResampleHorizontal_8bpc(Imaging imIn, float x0, float x1, int xsize,
 | 
				
			||||||
        return (Imaging) ImagingError_MemoryError();
 | 
					        return (Imaging) ImagingError_MemoryError();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    imOut = ImagingNew(imIn->mode, xsize, imIn->ysize);
 | 
					 | 
				
			||||||
    if ( ! imOut) {
 | 
					 | 
				
			||||||
        free(kk);
 | 
					 | 
				
			||||||
        free(xbounds);
 | 
					 | 
				
			||||||
        return NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ImagingSectionEnter(&cookie);
 | 
					    ImagingSectionEnter(&cookie);
 | 
				
			||||||
    if (imIn->image8) {
 | 
					    if (imIn->image8) {
 | 
				
			||||||
        for (yy = 0; yy < imOut->ysize; yy++) {
 | 
					        for (yy = 0; yy < imOut->ysize; yy++) {
 | 
				
			||||||
| 
						 | 
					@ -336,8 +328,8 @@ ImagingResampleHorizontal_8bpc(Imaging imIn, float x0, float x1, int xsize,
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    ImagingSectionLeave(&cookie);
 | 
					    ImagingSectionLeave(&cookie);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    free(kk);
 | 
					    free(kk);
 | 
				
			||||||
    free(xbounds);
 | 
					    free(xbounds);
 | 
				
			||||||
    return imOut;
 | 
					    return imOut;
 | 
				
			||||||
| 
						 | 
					@ -345,11 +337,10 @@ ImagingResampleHorizontal_8bpc(Imaging imIn, float x0, float x1, int xsize,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Imaging
 | 
					Imaging
 | 
				
			||||||
ImagingResampleVertical_8bpc(Imaging imIn, float y0, float y1, int ysize,
 | 
					ImagingResampleVertical_8bpc(Imaging imOut, Imaging imIn, float y0, float y1,
 | 
				
			||||||
                             struct filter *filterp)
 | 
					                             int ysize, struct filter *filterp)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ImagingSectionCookie cookie;
 | 
					    ImagingSectionCookie cookie;
 | 
				
			||||||
    Imaging imOut;
 | 
					 | 
				
			||||||
    int ss0, ss1, ss2, ss3;
 | 
					    int ss0, ss1, ss2, ss3;
 | 
				
			||||||
    int xx, yy, y, kmax, ymin, ymax;
 | 
					    int xx, yy, y, kmax, ymin, ymax;
 | 
				
			||||||
    int *xbounds;
 | 
					    int *xbounds;
 | 
				
			||||||
| 
						 | 
					@ -369,13 +360,6 @@ ImagingResampleVertical_8bpc(Imaging imIn, float y0, float y1, int ysize,
 | 
				
			||||||
        return (Imaging) ImagingError_MemoryError();
 | 
					        return (Imaging) ImagingError_MemoryError();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    imOut = ImagingNew(imIn->mode, imIn->xsize, ysize);
 | 
					 | 
				
			||||||
    if ( ! imOut) {
 | 
					 | 
				
			||||||
        free(kk);
 | 
					 | 
				
			||||||
        free(xbounds);
 | 
					 | 
				
			||||||
        return NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ImagingSectionEnter(&cookie);
 | 
					    ImagingSectionEnter(&cookie);
 | 
				
			||||||
    if (imIn->image8) {
 | 
					    if (imIn->image8) {
 | 
				
			||||||
        for (yy = 0; yy < ysize; yy++) {
 | 
					        for (yy = 0; yy < ysize; yy++) {
 | 
				
			||||||
| 
						 | 
					@ -443,8 +427,8 @@ ImagingResampleVertical_8bpc(Imaging imIn, float y0, float y1, int ysize,
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    ImagingSectionLeave(&cookie);
 | 
					    ImagingSectionLeave(&cookie);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    free(kk);
 | 
					    free(kk);
 | 
				
			||||||
    free(xbounds);
 | 
					    free(xbounds);
 | 
				
			||||||
    return imOut;
 | 
					    return imOut;
 | 
				
			||||||
| 
						 | 
					@ -452,11 +436,10 @@ ImagingResampleVertical_8bpc(Imaging imIn, float y0, float y1, int ysize,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Imaging
 | 
					Imaging
 | 
				
			||||||
ImagingResampleHorizontal_32bpc(Imaging imIn, float x0, float x1, int xsize,
 | 
					ImagingResampleHorizontal_32bpc(Imaging imOut, Imaging imIn, float x0, float x1,
 | 
				
			||||||
                                struct filter *filterp)
 | 
					                                int xsize, struct filter *filterp)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ImagingSectionCookie cookie;
 | 
					    ImagingSectionCookie cookie;
 | 
				
			||||||
    Imaging imOut;
 | 
					 | 
				
			||||||
    double ss;
 | 
					    double ss;
 | 
				
			||||||
    int xx, yy, x, kmax, xmin, xmax;
 | 
					    int xx, yy, x, kmax, xmin, xmax;
 | 
				
			||||||
    int *xbounds;
 | 
					    int *xbounds;
 | 
				
			||||||
| 
						 | 
					@ -468,13 +451,6 @@ ImagingResampleHorizontal_32bpc(Imaging imIn, float x0, float x1, int xsize,
 | 
				
			||||||
        return (Imaging) ImagingError_MemoryError();
 | 
					        return (Imaging) ImagingError_MemoryError();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    imOut = ImagingNew(imIn->mode, xsize, imIn->ysize);
 | 
					 | 
				
			||||||
    if ( ! imOut) {
 | 
					 | 
				
			||||||
        free(kk);
 | 
					 | 
				
			||||||
        free(xbounds);
 | 
					 | 
				
			||||||
        return NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ImagingSectionEnter(&cookie);
 | 
					    ImagingSectionEnter(&cookie);
 | 
				
			||||||
    switch(imIn->type) {
 | 
					    switch(imIn->type) {
 | 
				
			||||||
        case IMAGING_TYPE_INT32:
 | 
					        case IMAGING_TYPE_INT32:
 | 
				
			||||||
| 
						 | 
					@ -505,8 +481,8 @@ ImagingResampleHorizontal_32bpc(Imaging imIn, float x0, float x1, int xsize,
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    ImagingSectionLeave(&cookie);
 | 
					    ImagingSectionLeave(&cookie);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    free(kk);
 | 
					    free(kk);
 | 
				
			||||||
    free(xbounds);
 | 
					    free(xbounds);
 | 
				
			||||||
    return imOut;
 | 
					    return imOut;
 | 
				
			||||||
| 
						 | 
					@ -514,11 +490,10 @@ ImagingResampleHorizontal_32bpc(Imaging imIn, float x0, float x1, int xsize,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Imaging
 | 
					Imaging
 | 
				
			||||||
ImagingResampleVertical_32bpc(Imaging imIn, float y0, float y1, int ysize,
 | 
					ImagingResampleVertical_32bpc(Imaging imOut, Imaging imIn, float y0, float y1,
 | 
				
			||||||
                              struct filter *filterp)
 | 
					                              int ysize, struct filter *filterp)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ImagingSectionCookie cookie;
 | 
					    ImagingSectionCookie cookie;
 | 
				
			||||||
    Imaging imOut;
 | 
					 | 
				
			||||||
    double ss;
 | 
					    double ss;
 | 
				
			||||||
    int xx, yy, y, kmax, ymin, ymax;
 | 
					    int xx, yy, y, kmax, ymin, ymax;
 | 
				
			||||||
    int *xbounds;
 | 
					    int *xbounds;
 | 
				
			||||||
| 
						 | 
					@ -530,13 +505,6 @@ ImagingResampleVertical_32bpc(Imaging imIn, float y0, float y1, int ysize,
 | 
				
			||||||
        return (Imaging) ImagingError_MemoryError();
 | 
					        return (Imaging) ImagingError_MemoryError();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    imOut = ImagingNew(imIn->mode, imIn->xsize, ysize);
 | 
					 | 
				
			||||||
    if ( ! imOut) {
 | 
					 | 
				
			||||||
        free(kk);
 | 
					 | 
				
			||||||
        free(xbounds);
 | 
					 | 
				
			||||||
        return NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    ImagingSectionEnter(&cookie);
 | 
					    ImagingSectionEnter(&cookie);
 | 
				
			||||||
    switch(imIn->type) {
 | 
					    switch(imIn->type) {
 | 
				
			||||||
        case IMAGING_TYPE_INT32:
 | 
					        case IMAGING_TYPE_INT32:
 | 
				
			||||||
| 
						 | 
					@ -567,16 +535,16 @@ ImagingResampleVertical_32bpc(Imaging imIn, float y0, float y1, int ysize,
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    ImagingSectionLeave(&cookie);
 | 
					    ImagingSectionLeave(&cookie);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    free(kk);
 | 
					    free(kk);
 | 
				
			||||||
    free(xbounds);
 | 
					    free(xbounds);
 | 
				
			||||||
    return imOut;
 | 
					    return imOut;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef Imaging (*ResampleFunction)(Imaging imIn, float x0, float x1, int xsize,
 | 
					typedef Imaging (*ResampleFunction)(Imaging imOut, Imaging imIn,
 | 
				
			||||||
                                    struct filter *filterp);
 | 
					    float x0, float x1, int xsize, struct filter *filterp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Imaging
 | 
					Imaging
 | 
				
			||||||
| 
						 | 
					@ -637,21 +605,32 @@ 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 (roi[0] || roi[2] != xsize) {
 | 
				
			||||||
        imTemp = ResampleHorizontal(imIn, roi[0], roi[2], xsize, filterp);
 | 
					        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)) {
 | 
				
			||||||
 | 
					            ImagingDelete(imTemp);
 | 
				
			||||||
 | 
					            return NULL;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        imOut = imIn = imTemp;
 | 
					        imOut = imIn = imTemp;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* second pass */
 | 
					    /* second pass */
 | 
				
			||||||
    if (roi[1] || roi[3] != ysize) {
 | 
					    if (roi[1] || roi[3] != ysize) {
 | 
				
			||||||
        /* imIn can be the original image or horizontally resampled one */
 | 
					        imOut = ImagingNew(imIn->mode, imIn->xsize, ysize);
 | 
				
			||||||
        imOut = ResampleVertical(imIn, roi[1], roi[3], ysize, filterp);
 | 
					        if ( ! imOut) {
 | 
				
			||||||
        /* it's safe to call ImagingDelete with empty value
 | 
					 | 
				
			||||||
           if there was no previous step. */
 | 
					 | 
				
			||||||
        ImagingDelete(imTemp);
 | 
					 | 
				
			||||||
        if ( ! imOut)
 | 
					 | 
				
			||||||
            return NULL;
 | 
					            return NULL;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        /* imIn can be the original image or horizontally resampled one */
 | 
				
			||||||
 | 
					        if ( ! ResampleVertical(imOut, imIn, roi[1], roi[3], ysize, filterp)) {
 | 
				
			||||||
 | 
					            ImagingDelete(imTemp);
 | 
				
			||||||
 | 
					            ImagingDelete(imOut);
 | 
				
			||||||
 | 
					            return NULL;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        /* it's safe to call ImagingDelete with empty value
 | 
				
			||||||
 | 
					           if previous step was not performed. */
 | 
				
			||||||
 | 
					        ImagingDelete(imTemp);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* none of the previous steps are performed, copying */
 | 
					    /* none of the previous steps are performed, copying */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user