Class Resampler
Resampling of interleaved 8-bit band data, the two-pass fixed-point
convolution of Pillow's Resample.c.
The results match Pillow byte for byte, which is why the Python runtime's
PIL.Image.resize delegates here. Pixels are bands consecutive bytes
(L, LA, RGB, RGBA, ...), rows packed with no padding. Images with
alpha should be premultiplied first ([#premultiply(byte[], int)]) and
unpremultiplied afterwards, as Pillow does, so transparent pixels do not
bleed their color into their neighbours.
RasterImage.scale(int, int, int) wraps this for ARGB images.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intCubic interpolation, Pillow'sa = -0.5kernel.static final intLinear interpolation (a triangle filter).static final intBox filter: every input pixel under an output pixel weighs the same.static final intHamming-windowed sinc with a support of one pixel.static final intLanczos, a windowed sinc with a support of three pixels.static final intNearest neighbour: each output pixel takes the input pixel under its center. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]premultiply(byte[] d, int bands) Premultiplies the color bands by the last (alpha) band, Pillow's rounding (RGBAtoRGBa).static byte[]resample(byte[] src, int w, int h, int bands, int nw, int nh, double[] box, int filter) Resamples the regionbox(x0, y0, x1, y1, in source pixels, may be fractional) of awxhimage tonwxnh.static byte[]unpremultiply(byte[] d, int bands) Reverses [#premultiply(byte[], int)] in place, as Pillow'srgbA2rgba.
-
Field Details
-
NEAREST
public static final int NEARESTNearest neighbour: each output pixel takes the input pixel under its center.- See Also:
-
LANCZOS
public static final int LANCZOSLanczos, a windowed sinc with a support of three pixels.- See Also:
-
BILINEAR
public static final int BILINEARLinear interpolation (a triangle filter).- See Also:
-
BICUBIC
public static final int BICUBICCubic interpolation, Pillow'sa = -0.5kernel.- See Also:
-
BOX
public static final int BOXBox filter: every input pixel under an output pixel weighs the same.- See Also:
-
HAMMING
public static final int HAMMINGHamming-windowed sinc with a support of one pixel.- See Also:
-
-
Method Details
-
resample
public static byte[] resample(byte[] src, int w, int h, int bands, int nw, int nh, double[] box, int filter) Resamples the region
box(x0, y0, x1, y1, in source pixels, may be fractional) of awxhimage tonwxnh.Parameters
src: the source pixels,w * h * bandsbytesw: source widthh: source heightbands: bytes per pixelnw: output widthnh: output heightbox: the source region, four valuesfilter: one of the filter constants of this class
Returns
a new array of
nw * nh * bandsbytes -
premultiply
public static byte[] premultiply(byte[] d, int bands) Premultiplies the color bands by the last (alpha) band, Pillow's rounding (
RGBAtoRGBa).Parameters
d: interleaved pixels whose last band is alphabands: bytes per pixel
Returns
a new premultiplied array
-
unpremultiply
public static byte[] unpremultiply(byte[] d, int bands) Reverses [#premultiply(byte[], int)] in place, as Pillow's
rgbA2rgba.Parameters
d: interleaved premultiplied pixels whose last band is alphabands: bytes per pixel
Returns
d
-