Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class Resampler
- Object
- 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.
Fields
public static final int NEAREST = 0 | Nearest neighbour: each output pixel takes the input pixel under its center. |
public static final int LANCZOS = 1 | Lanczos, a windowed sinc with a support of three pixels. |
public static final int BILINEAR = 2 | Linear interpolation (a triangle filter). |
public static final int BICUBIC = 3 | Cubic interpolation, Pillow’s a = -0.5 kernel. |
public static final int BOX = 4 | Box filter: every input pixel under an output pixel weighs the same. |
public static final int HAMMING = 5 | Hamming-windowed sinc with a support of one pixel. |
Methods
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 a w x h image to nw x nh. |
public static byte[] premultiply(byte[] d, int bands) | Premultiplies the color bands by the last (alpha) band, Pillow’s rounding (RGBA to RGBa). |
public static byte[] unpremultiply(byte[] d, int bands) | Reverses [#premultiply(byte[], int)] in place, as Pillow’s rgbA2rgba. |
Inherited methods
Field details
NEAREST
public static final int NEAREST = 0Nearest neighbour: each output pixel takes the input pixel under its center.
LANCZOS
public static final int LANCZOS = 1Lanczos, a windowed sinc with a support of three pixels.
BILINEAR
public static final int BILINEAR = 2Linear interpolation (a triangle filter).
BICUBIC
public static final int BICUBIC = 3Cubic interpolation, Pillow’s
a = -0.5 kernel.BOX
public static final int BOX = 4Box filter: every input pixel under an output pixel weighs the same.
HAMMING
public static final int HAMMING = 5Hamming-windowed sinc with a support of one pixel.
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 a w x h image to nw x nh.Parameters
srcbyte[]- the source pixels,
w * h * bandsbytes wint- source width
hint- source height
bandsint- bytes per pixel
nwint- output width
nhint- output height
boxdouble[]- the source region, four values
filterint- one of the filter constants of this class
Returns
a new array of
nw * nh * bands bytespremultiply
public static byte[] premultiply(byte[] d, int bands)Premultiplies the color bands by the last (alpha) band, Pillow’s
rounding (
RGBA to RGBa).Parameters
dbyte[]- interleaved pixels whose last band is alpha
bandsint- 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
dbyte[]- interleaved premultiplied pixels whose last band is alpha
bandsint- bytes per pixel
Returns
d