rename Antialias and stretch to resample

This commit is contained in:
homm 2014-11-19 13:59:11 +03:00
parent 1a097d2e02
commit bc0f896a47
5 changed files with 10 additions and 24 deletions

View File

@ -18,7 +18,7 @@ Changelog (Pillow)
- Use PyQt4 if it has already been imported, otherwise prefer PyQt5. #1003 - Use PyQt4 if it has already been imported, otherwise prefer PyQt5. #1003
[AurelienBallier] [AurelienBallier]
- Speedup stretch implementation up to 2.5 times. #977 - Speedup resample implementation up to 2.5 times. #977
[homm] [homm]
- Speed up rotation by using cache aware loops, added transpose to rotations. #994 - Speed up rotation by using cache aware loops, added transpose to rotations. #994

View File

@ -1531,7 +1531,7 @@ _resize(ImagingObject* self, PyObject* args)
a, filter, 1); a, filter, 1);
} }
else { else {
imOut = ImagingStretch(imIn, xsize, ysize, filter); imOut = ImagingResample(imIn, xsize, ysize, filter);
} }
return PyImagingNew(imOut); return PyImagingNew(imOut);

View File

@ -290,7 +290,7 @@ extern Imaging ImagingRotate(
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 ImagingStretch(Imaging imIn, int xsize, int ysize, int filter); extern Imaging ImagingResample(Imaging imIn, int xsize, int ysize, int filter);
extern Imaging ImagingTranspose(Imaging imOut, Imaging imIn); extern Imaging ImagingTranspose(Imaging imOut, Imaging imIn);
extern Imaging ImagingTransposeToNew(Imaging imIn); extern Imaging ImagingTransposeToNew(Imaging imIn);
extern Imaging ImagingTransformPerspective( extern Imaging ImagingTransformPerspective(

View File

@ -2,7 +2,7 @@
* The Python Imaging Library * The Python Imaging Library
* $Id$ * $Id$
* *
* pilopen antialiasing support * Pillow image resamling support
* *
* history: * history:
* 2002-03-09 fl Created (for PIL 1.1.3) * 2002-03-09 fl Created (for PIL 1.1.3)
@ -17,8 +17,6 @@
#include <math.h> #include <math.h>
/* resampling filters (from antialias.py) */
struct filter { struct filter {
float (*filter)(float x); float (*filter)(float x);
float support; float support;
@ -42,15 +40,6 @@ static inline float antialias_filter(float x)
static struct filter ANTIALIAS = { antialias_filter, 3.0 }; static struct filter ANTIALIAS = { antialias_filter, 3.0 };
static inline float nearest_filter(float x)
{
if (-0.5 <= x && x < 0.5)
return 1.0;
return 0.0;
}
static struct filter NEAREST = { nearest_filter, 0.5 };
static inline float bilinear_filter(float x) static inline float bilinear_filter(float x)
{ {
if (x < 0.0) if (x < 0.0)
@ -106,7 +95,7 @@ static float inline i2f(int v) { return (float) v; }
Imaging Imaging
ImagingStretchHorizontal(Imaging imIn, int xsize, int filter) ImagingResampleHorizontal(Imaging imIn, int xsize, int filter)
{ {
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
Imaging imOut; Imaging imOut;
@ -119,9 +108,6 @@ ImagingStretchHorizontal(Imaging imIn, int xsize, int filter)
/* check filter */ /* check filter */
switch (filter) { switch (filter) {
case IMAGING_TRANSFORM_NEAREST:
filterp = &NEAREST;
break;
case IMAGING_TRANSFORM_ANTIALIAS: case IMAGING_TRANSFORM_ANTIALIAS:
filterp = &ANTIALIAS; filterp = &ANTIALIAS;
break; break;
@ -152,7 +138,7 @@ ImagingStretchHorizontal(Imaging imIn, int xsize, int filter)
/* maximum number of coofs */ /* maximum number of coofs */
kmax = (int) ceil(support) * 2 + 1; kmax = (int) ceil(support) * 2 + 1;
/* coefficient buffer (with rounding safety margin) */ /* coefficient buffer */
kk = malloc(xsize * kmax * sizeof(float)); kk = malloc(xsize * kmax * sizeof(float));
if ( ! kk) if ( ! kk)
return (Imaging) ImagingError_MemoryError(); return (Imaging) ImagingError_MemoryError();
@ -294,7 +280,7 @@ ImagingStretchHorizontal(Imaging imIn, int xsize, int filter)
Imaging Imaging
ImagingStretch(Imaging imIn, int xsize, int ysize, int filter) ImagingResample(Imaging imIn, int xsize, int ysize, int filter)
{ {
Imaging imTemp1, imTemp2, imTemp3; Imaging imTemp1, imTemp2, imTemp3;
Imaging imOut; Imaging imOut;
@ -306,7 +292,7 @@ ImagingStretch(Imaging imIn, int xsize, int ysize, int filter)
return (Imaging) ImagingError_ModeError(); return (Imaging) ImagingError_ModeError();
/* two-pass resize, first pass */ /* two-pass resize, first pass */
imTemp1 = ImagingStretchHorizontal(imIn, xsize, filter); imTemp1 = ImagingResampleHorizontal(imIn, xsize, filter);
if ( ! imTemp1) if ( ! imTemp1)
return NULL; return NULL;
@ -317,7 +303,7 @@ ImagingStretch(Imaging imIn, int xsize, int ysize, int filter)
return NULL; return NULL;
/* second pass */ /* second pass */
imTemp3 = ImagingStretchHorizontal(imTemp2, ysize, filter); imTemp3 = ImagingResampleHorizontal(imTemp2, ysize, filter);
ImagingDelete(imTemp2); ImagingDelete(imTemp2);
if ( ! imTemp3) if ( ! imTemp3)
return NULL; return NULL;

View File

@ -26,7 +26,7 @@ _IMAGING = (
"decode", "encode", "map", "display", "outline", "path") "decode", "encode", "map", "display", "outline", "path")
_LIB_IMAGING = ( _LIB_IMAGING = (
"Access", "AlphaComposite", "Antialias", "Bands", "BitDecode", "Blend", "Access", "AlphaComposite", "Resample", "Bands", "BitDecode", "Blend",
"Chops", "Convert", "ConvertYCbCr", "Copy", "Crc32", "Crop", "Dib", "Draw", "Chops", "Convert", "ConvertYCbCr", "Copy", "Crc32", "Crop", "Dib", "Draw",
"Effects", "EpsEncode", "File", "Fill", "Filter", "FliDecode", "Effects", "EpsEncode", "File", "Fill", "Filter", "FliDecode",
"Geometry", "GetBBox", "GifDecode", "GifEncode", "HexDecode", "Geometry", "GetBBox", "GifDecode", "GifEncode", "HexDecode",