mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
add constants for filters: BOX, HAMMING, MITCHELL
rearrange filters everywhere
This commit is contained in:
parent
4f4c982229
commit
0e9beed76d
24
PIL/Image.py
24
PIL/Image.py
|
@ -168,13 +168,15 @@ MESH = 4
|
|||
|
||||
# resampling filters
|
||||
NEAREST = NONE = 0
|
||||
LANCZOS = ANTIALIAS = 1
|
||||
BOX = 4
|
||||
BILINEAR = LINEAR = 2
|
||||
HAMMING = 5
|
||||
BICUBIC = CUBIC = 3
|
||||
MITCHELL = 6
|
||||
LANCZOS = ANTIALIAS = 1
|
||||
|
||||
# dithers
|
||||
NONE = 0
|
||||
NEAREST = 0
|
||||
NEAREST = NONE = 0
|
||||
ORDERED = 1 # Not yet implemented
|
||||
RASTERIZE = 2 # Not yet implemented
|
||||
FLOYDSTEINBERG = 3 # default
|
||||
|
@ -1518,16 +1520,20 @@ class Image(object):
|
|||
:param size: The requested size in pixels, as a 2-tuple:
|
||||
(width, height).
|
||||
:param resample: An optional resampling filter. This can be
|
||||
one of :py:attr:`PIL.Image.NEAREST` (use nearest neighbour),
|
||||
:py:attr:`PIL.Image.BILINEAR` (linear interpolation),
|
||||
:py:attr:`PIL.Image.BICUBIC` (cubic spline interpolation), or
|
||||
:py:attr:`PIL.Image.LANCZOS` (a high-quality downsampling filter).
|
||||
one of :py:attr:`PIL.Image.NEAREST`, :py:attr:`PIL.Image.BOX`,
|
||||
:py:attr:`PIL.Image.BILINEAR`, :py:attr:`PIL.Image.HAMMING`,
|
||||
:py:attr:`PIL.Image.BICUBIC`, :py:attr:`PIL.Image.MITCHELL` or
|
||||
:py:attr:`PIL.Image.LANCZOS`.
|
||||
If omitted, or if the image has mode "1" or "P", it is
|
||||
set :py:attr:`PIL.Image.NEAREST`.
|
||||
See: :ref:`concept-filters`.
|
||||
:returns: An :py:class:`~PIL.Image.Image` object.
|
||||
"""
|
||||
|
||||
if resample not in (NEAREST, BILINEAR, BICUBIC, LANCZOS):
|
||||
if resample not in (
|
||||
NEAREST, BILINEAR, BICUBIC, LANCZOS,
|
||||
BOX, HAMMING, MITCHELL,
|
||||
):
|
||||
raise ValueError("unknown resampling filter")
|
||||
|
||||
self.load()
|
||||
|
@ -1560,7 +1566,7 @@ class Image(object):
|
|||
environment), or :py:attr:`PIL.Image.BICUBIC`
|
||||
(cubic spline interpolation in a 4x4 environment).
|
||||
If omitted, or if the image has mode "1" or "P", it is
|
||||
set :py:attr:`PIL.Image.NEAREST`.
|
||||
set :py:attr:`PIL.Image.NEAREST`. See :ref:`concept-filters`.
|
||||
:param expand: Optional expansion flag. If true, expands the output
|
||||
image to make it large enough to hold the entire rotated image.
|
||||
If false or omitted, make the output image the same size as the
|
||||
|
|
|
@ -229,9 +229,12 @@ extern void ImagingError_Clear(void);
|
|||
|
||||
/* standard filters */
|
||||
#define IMAGING_TRANSFORM_NEAREST 0
|
||||
#define IMAGING_TRANSFORM_LANCZOS 1
|
||||
#define IMAGING_TRANSFORM_BOX 4
|
||||
#define IMAGING_TRANSFORM_BILINEAR 2
|
||||
#define IMAGING_TRANSFORM_HAMMING 5
|
||||
#define IMAGING_TRANSFORM_BICUBIC 3
|
||||
#define IMAGING_TRANSFORM_MITCHELL 6
|
||||
#define IMAGING_TRANSFORM_LANCZOS 1
|
||||
|
||||
typedef int (*ImagingTransformMap)(double* X, double* Y,
|
||||
int x, int y, void* data);
|
||||
|
|
|
@ -5,28 +5,11 @@
|
|||
|
||||
#define ROUND_UP(f) ((int) ((f) >= 0.0 ? (f) + 0.5F : (f) - 0.5F))
|
||||
|
||||
|
||||
struct filter {
|
||||
double (*filter)(double x);
|
||||
double support;
|
||||
};
|
||||
|
||||
static inline double sinc_filter(double x)
|
||||
{
|
||||
if (x == 0.0)
|
||||
return 1.0;
|
||||
x = x * M_PI;
|
||||
return sin(x) / x;
|
||||
}
|
||||
|
||||
static inline double lanczos_filter(double x)
|
||||
{
|
||||
/* truncated sinc */
|
||||
if (-3.0 <= x && x < 3.0)
|
||||
return sinc_filter(x) * sinc_filter(x/3);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
static inline double bilinear_filter(double x)
|
||||
{
|
||||
if (x < 0.0)
|
||||
|
@ -50,9 +33,25 @@ static inline double bicubic_filter(double x)
|
|||
#undef a
|
||||
}
|
||||
|
||||
static struct filter LANCZOS = { lanczos_filter, 3.0 };
|
||||
static inline double sinc_filter(double x)
|
||||
{
|
||||
if (x == 0.0)
|
||||
return 1.0;
|
||||
x = x * M_PI;
|
||||
return sin(x) / x;
|
||||
}
|
||||
|
||||
static inline double lanczos_filter(double x)
|
||||
{
|
||||
/* truncated sinc */
|
||||
if (-3.0 <= x && x < 3.0)
|
||||
return sinc_filter(x) * sinc_filter(x/3);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
static struct filter BILINEAR = { bilinear_filter, 1.0 };
|
||||
static struct filter BICUBIC = { bicubic_filter, 2.0 };
|
||||
static struct filter LANCZOS = { lanczos_filter, 3.0 };
|
||||
|
||||
|
||||
|
||||
|
@ -524,15 +523,15 @@ ImagingResample(Imaging imIn, int xsize, int ysize, int filter)
|
|||
|
||||
/* check filter */
|
||||
switch (filter) {
|
||||
case IMAGING_TRANSFORM_LANCZOS:
|
||||
filterp = &LANCZOS;
|
||||
break;
|
||||
case IMAGING_TRANSFORM_BILINEAR:
|
||||
filterp = &BILINEAR;
|
||||
break;
|
||||
case IMAGING_TRANSFORM_BICUBIC:
|
||||
filterp = &BICUBIC;
|
||||
break;
|
||||
case IMAGING_TRANSFORM_LANCZOS:
|
||||
filterp = &LANCZOS;
|
||||
break;
|
||||
default:
|
||||
return (Imaging) ImagingError_ValueError(
|
||||
"unsupported resampling filter"
|
||||
|
|
Loading…
Reference in New Issue
Block a user