Written with emphasis on usability, portability, and efficiency. (No SIMD or threads, so it be easily outperformed by libs that use those.) Only scaling and translation is supported, no rotations or shears. Easy API downsamples w/Mitchell filter, upsamples w/cubic interpolation.
stbir_resize_uint8( input_pixels , in_w , in_h , 0,
output_pixels, out_w, out_h, 0, num_channels)
stbir_resize_float(...)
stbir_resize_uint8_srgb( input_pixels , in_w , in_h , 0,
output_pixels, out_w, out_h, 0,
num_channels , alpha_chan , 0)
stbir_resize_uint8_srgb_edgemode(
input_pixels , in_w , in_h , 0,
output_pixels, out_w, out_h, 0,
num_channels , alpha_chan , 0, STBIR_EDGE_CLAMP)
// WRAP/REFLECT/ZERO
Most of the resizing functions provide the ability to control how the alpha channel of an image is processed. The important things to know about this:
FLAG_ALPHA_PREMULTIPLIED, the resizer does not do anything special for the alpha channel; it is resampled identically to
other channels. This produces the correct results for premultiplied-alpha images, but produces less-than-ideal results for non-premultiplied-alpha
images.FLAG_ALPHA_PREMULTIPLIED, then the resizer weights the contribution of input pixels based on their alpha values, or,
equivalently, it multiplies the alpha value into the color channels, resamples, then divides by the resultant alpha value. Input pixels which have
alpha=0 do not contribute at all to output pixels unless all of the input pixels affecting that output pixel have alpha=0,
in which case the result for that pixel is the same as it would be without FLAG_ALPHA_PREMULTIPLIED. However, this is only true for input images
in integer formats. For input images in float format, input pixels with alpha=0 have no effect, and output pixels which have
alpha=0 will be 0 in all channels. (For float images, you can manually achieve the same result by adding a tiny epsilon value to the alpha
channel of every image, and then subtracting or clamping it at the end.)| Modifier and Type | Field and Description |
|---|---|
| public static final int | STBIR_ALPHA_CHANNEL_NONE
Set this flag if you have no alpha channel, or otherwise provide the index of the alpha channel. |
| public static final int | STBIR_COLORSPACE_LINEAR
Colorspace. |
| public static final int | STBIR_COLORSPACE_SRGB
Colorspace. |
| public static final int | STBIR_EDGE_CLAMP
Edge wrap mode. |
| public static final int | STBIR_EDGE_REFLECT
Edge wrap mode. |
| public static final int | STBIR_EDGE_WRAP
Edge wrap mode. |
| public static final int | STBIR_EDGE_ZERO
Edge wrap mode. |
| public static final int | STBIR_FILTER_BOX
Filters. |
| public static final int | STBIR_FILTER_CATMULLROM
Filters. |
| public static final int | STBIR_FILTER_CUBICBSPLINE
Filters. |
| public static final int | STBIR_FILTER_DEFAULT
Filters. |
| public static final int | STBIR_FILTER_MITCHELL
Filters. |
| public static final int | STBIR_FILTER_TRIANGLE
Filters. |
| public static final int | STBIR_FLAG_ALPHA_PREMULTIPLIED
Set this flag if your texture has premultiplied alpha. |
| public static final int | STBIR_FLAG_ALPHA_USES_COLORSPACE
The specified alpha channel should be handled as gamma-corrected value even when doing sRGB operations. |
| public static final int | STBIR_TYPE_FLOAT
Data type. |
| public static final int | STBIR_TYPE_UINT16
Data type. |
| public static final int | STBIR_TYPE_UINT32
Data type. |
| public static final int | STBIR_TYPE_UINT8
Data type. |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| private static int | |||||||||||||||
| public static native int | nstbir_resize(long input_pixels, int input_w, int input_h, int input_stride_in_bytes, long output_pixels, int output_w, int output_h, int output_stride_in_bytes, int datatype, int num_channels, int alpha_channel, int flags, int edge_mode_horizontal, int edge_mode_vertical, int filter_horizontal, int filter_vertical, int space, long alloc_context)
Unsafe version of: | ||||||||||||||
| public static native int | nstbir_resize_float(long input_pixels, int input_w, int input_h, int input_stride_in_bytes, long output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels)
Unsafe version of: | ||||||||||||||
| public static native int | nstbir_resize_float(float[] input_pixels, int input_w, int input_h, int input_stride_in_bytes, float[] output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels)
Array version of: | ||||||||||||||
| public static native int | nstbir_resize_float_generic(long input_pixels, int input_w, int input_h, int input_stride_in_bytes, long output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels, int alpha_channel, int flags, int edge_wrap_mode, int filter, int space, long alloc_context)
Unsafe version of: | ||||||||||||||
| public static native int | nstbir_resize_float_generic(float[] input_pixels, int input_w, int input_h, int input_stride_in_bytes, float[] output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels, int alpha_channel, int flags, int edge_wrap_mode, int filter, int space, long alloc_context)
Array version of: | ||||||||||||||
| public static native int | nstbir_resize_region(long input_pixels, int input_w, int input_h, int input_stride_in_bytes, long output_pixels, int output_w, int output_h, int output_stride_in_bytes, int datatype, int num_channels, int alpha_channel, int flags, int edge_mode_horizontal, int edge_mode_vertical, int filter_horizontal, int filter_vertical, int space, long alloc_context, float s0, float t0, float s1, float t1)
Unsafe version of: | ||||||||||||||
| public static native int | nstbir_resize_subpixel(long input_pixels, int input_w, int input_h, int input_stride_in_bytes, long output_pixels, int output_w, int output_h, int output_stride_in_bytes, int datatype, int num_channels, int alpha_channel, int flags, int edge_mode_horizontal, int edge_mode_vertical, int filter_horizontal, int filter_vertical, int space, long alloc_context, float x_scale, float y_scale, float x_offset, float y_offset)
Unsafe version of: | ||||||||||||||
| public static native int | nstbir_resize_uint16_generic(long input_pixels, int input_w, int input_h, int input_stride_in_bytes, long output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels, int alpha_channel, int flags, int edge_wrap_mode, int filter, int space, long alloc_context)
Unsafe version of: | ||||||||||||||
| public static native int | nstbir_resize_uint16_generic(short[] input_pixels, int input_w, int input_h, int input_stride_in_bytes, short[] output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels, int alpha_channel, int flags, int edge_wrap_mode, int filter, int space, long alloc_context)
Array version of: | ||||||||||||||
| public static native int | nstbir_resize_uint8(long input_pixels, int input_w, int input_h, int input_stride_in_bytes, long output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels)
Unsafe version of: | ||||||||||||||
| public static native int | nstbir_resize_uint8_generic(long input_pixels, int input_w, int input_h, int input_stride_in_bytes, long output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels, int alpha_channel, int flags, int edge_wrap_mode, int filter, int space, long alloc_context)
Unsafe version of: | ||||||||||||||
| public static native int | nstbir_resize_uint8_srgb(long input_pixels, int input_w, int input_h, int input_stride_in_bytes, long output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels, int alpha_channel, int flags)
Unsafe version of: | ||||||||||||||
| public static native int | nstbir_resize_uint8_srgb_edgemode(long input_pixels, int input_w, int input_h, int input_stride_in_bytes, long output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels, int alpha_channel, int flags, int edge_wrap_mode)
Unsafe version of: | ||||||||||||||
| public static boolean | Returns: 1 on success, 0 on failurethe source image data input_pixels, int the source image width input_w, int the source image height input_h, int the offset between successive rows of the source image data in memory, in bytes. You can specify 0 to mean packed continuously in memory input_stride_in_bytes, ByteBuffer returns the scaled image data output_pixels, int the resized image width output_w, int the resized image height output_h, int the offset between successive rows of the resized image data in memory, in bytes. You can specify 0 to mean packed continuously in memory output_stride_in_bytes, int the image data type. One of: datatype, int
the number of channels in the image (e.g. RGB=3, RGBA=4) num_channels, int the alpha channel index, or alpha_channel, int ALPHA_CHANNEL_NONE if there is no alpha channelthe alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of: flags, int
the horizontal edge wrap mode edge_mode_horizontal, int the vertical edge wrap mode edge_mode_vertical, int the horizontal scale filter filter_horizontal, int the vertical scale filter filter_vertical, int the image colorspace. One of: space)
Full-complexity version of | ||||||||||||||
| public static boolean | Returns: 1 on success, 0 on failurethe source image data input_pixels, int the source image width input_w, int the source image height input_h, int the offset between successive rows of the source image data in memory, in bytes. You can specify 0 to mean packed continuously in memory input_stride_in_bytes, FloatBuffer returns the scaled image data output_pixels, int the resized image width output_w, int the resized image height output_h, int the offset between successive rows of the resized image data in memory, in bytes. You can specify 0 to mean packed continuously in memory output_stride_in_bytes, int the number of channels in the image (e.g. RGB=3, RGBA=4) num_channels)Float version of | ||||||||||||||
| public static boolean | stbir_resize_float(float[] input_pixels, int input_w, int input_h, int input_stride_in_bytes, float[] output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels)
Array version of: | ||||||||||||||
| public static boolean | Returns: 1 on success, 0 on failurethe source image data input_pixels, int the source image width input_w, int the source image height input_h, int the offset between successive rows of the source image data in memory, in bytes. You can specify 0 to mean packed continuously in memory input_stride_in_bytes, FloatBuffer returns the scaled image data output_pixels, int the resized image width output_w, int the resized image height output_h, int the offset between successive rows of the resized image data in memory, in bytes. You can specify 0 to mean packed continuously in memory output_stride_in_bytes, int the number of channels in the image (e.g. RGB=3, RGBA=4) num_channels, int the alpha channel index, or alpha_channel, int ALPHA_CHANNEL_NONE if there is no alpha channelthe alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of: flags, int
the edge wrap mode. One of: edge_wrap_mode, int
the scale filter. One of: filter, int
the image colorspace. One of: space)
Float version of | ||||||||||||||
| public static boolean | stbir_resize_float_generic(float[] input_pixels, int input_w, int input_h, int input_stride_in_bytes, float[] output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels, int alpha_channel, int flags, int edge_wrap_mode, int filter, int space)
Array version of: | ||||||||||||||
| public static boolean | Returns: 1 on success, 0 on failurethe source image data input_pixels, int the source image width input_w, int the source image height input_h, int the offset between successive rows of the source image data in memory, in bytes. You can specify 0 to mean packed continuously in memory input_stride_in_bytes, ByteBuffer returns the scaled image data output_pixels, int the resized image width output_w, int the resized image height output_h, int the offset between successive rows of the resized image data in memory, in bytes. You can specify 0 to mean packed continuously in memory output_stride_in_bytes, int the image data type. One of: datatype, int
the number of channels in the image (e.g. RGB=3, RGBA=4) num_channels, int the alpha channel index, or alpha_channel, int ALPHA_CHANNEL_NONE if there is no alpha channelthe alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of: flags, int
the horizontal edge wrap mode edge_mode_horizontal, int the vertical edge wrap mode edge_mode_vertical, int the horizontal scale filter filter_horizontal, int the vertical scale filter filter_vertical, int the image colorspace. One of: space, float
the left texture coordinate of the region to scale s0, float the top texture coordinate of the region to scale t0, float the right texture coordinate of the region to scale s1, float the bottom texture coordinate of the region to scale t1)Region version of | ||||||||||||||
| public static boolean | Returns: 1 on success, 0 on failurethe source image data input_pixels, int the source image width input_w, int the source image height input_h, int the offset between successive rows of the source image data in memory, in bytes. You can specify 0 to mean packed continuously in memory input_stride_in_bytes, ByteBuffer returns the scaled image data output_pixels, int the resized image width output_w, int the resized image height output_h, int the offset between successive rows of the resized image data in memory, in bytes. You can specify 0 to mean packed continuously in memory output_stride_in_bytes, int the image data type. One of: datatype, int
the number of channels in the image (e.g. RGB=3, RGBA=4) num_channels, int the alpha channel index, or alpha_channel, int ALPHA_CHANNEL_NONE if there is no alpha channelthe alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of: flags, int
the horizontal edge wrap mode edge_mode_horizontal, int the vertical edge wrap mode edge_mode_vertical, int the horizontal scale filter filter_horizontal, int the vertical scale filter filter_vertical, int the image colorspace. One of: space, float
horizontal scale for subpixel correctness x_scale, float vertical scale for subpixel correctness y_scale, float horizontal offset for subpixel correctness x_offset, float vertical offset for subpixel correctness y_offset)Subpixel version of | ||||||||||||||
| public static boolean | Returns: 1 on success, 0 on failurethe source image data input_pixels, int the source image width input_w, int the source image height input_h, int the offset between successive rows of the source image data in memory, in bytes. You can specify 0 to mean packed continuously in memory input_stride_in_bytes, ShortBuffer returns the scaled image data output_pixels, int the resized image width output_w, int the resized image height output_h, int the offset between successive rows of the resized image data in memory, in bytes. You can specify 0 to mean packed continuously in memory output_stride_in_bytes, int the number of channels in the image (e.g. RGB=3, RGBA=4) num_channels, int the alpha channel index, or alpha_channel, int ALPHA_CHANNEL_NONE if there is no alpha channelthe alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of: flags, int
the edge wrap mode. One of: edge_wrap_mode, int
the scale filter. One of: filter, int
the image colorspace. One of: space)
Short version of | ||||||||||||||
| public static boolean | stbir_resize_uint16_generic(short[] input_pixels, int input_w, int input_h, int input_stride_in_bytes, short[] output_pixels, int output_w, int output_h, int output_stride_in_bytes, int num_channels, int alpha_channel, int flags, int edge_wrap_mode, int filter, int space)
Array version of: | ||||||||||||||
| public static boolean | Returns: 1 on success, 0 on failurethe source image data input_pixels, int the source image width input_w, int the source image height input_h, int the offset between successive rows of the source image data in memory, in bytes. You can specify 0 to mean packed continuously in memory input_stride_in_bytes, ByteBuffer returns the scaled image data output_pixels, int the resized image width output_w, int the resized image height output_h, int the offset between successive rows of the resized image data in memory, in bytes. You can specify 0 to mean packed continuously in memory output_stride_in_bytes, int the number of channels in the image (e.g. RGB=3, RGBA=4) num_channels)Easy-to-use API for resizing images. | ||||||||||||||
| public static boolean | Returns: 1 on success, 0 on failurethe source image data input_pixels, int the source image width input_w, int the source image height input_h, int the offset between successive rows of the source image data in memory, in bytes. You can specify 0 to mean packed continuously in memory input_stride_in_bytes, ByteBuffer returns the scaled image data output_pixels, int the resized image width output_w, int the resized image height output_h, int the offset between successive rows of the resized image data in memory, in bytes. You can specify 0 to mean packed continuously in memory output_stride_in_bytes, int the number of channels in the image (e.g. RGB=3, RGBA=4) num_channels, int the alpha channel index, or alpha_channel, int ALPHA_CHANNEL_NONE if there is no alpha channelthe alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of: flags, int
the edge wrap mode. One of: edge_wrap_mode, int
the scale filter. One of: filter, int
the image colorspace. One of: space)
Medium-complexity version of | ||||||||||||||
| public static boolean | Returns: 1 on success, 0 on failurethe source image data input_pixels, int the source image width input_w, int the source image height input_h, int the offset between successive rows of the source image data in memory, in bytes. You can specify 0 to mean packed continuously in memory input_stride_in_bytes, ByteBuffer returns the scaled image data output_pixels, int the resized image width output_w, int the resized image height output_h, int the offset between successive rows of the resized image data in memory, in bytes. You can specify 0 to mean packed continuously in memory output_stride_in_bytes, int the number of channels in the image (e.g. RGB=3, RGBA=4) num_channels, int the alpha channel index, or alpha_channel, int ALPHA_CHANNEL_NONE if there is no alpha channelthe alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of: flags)
Easy-to-use API for resizing images. | ||||||||||||||
| public static boolean | Returns: 1 on success, 0 on failurethe source image data input_pixels, int the source image width input_w, int the source image height input_h, int the offset between successive rows of the source image data in memory, in bytes. You can specify 0 to mean packed continuously in memory input_stride_in_bytes, ByteBuffer returns the scaled image data output_pixels, int the resized image width output_w, int the resized image height output_h, int the offset between successive rows of the resized image data in memory, in bytes. You can specify 0 to mean packed continuously in memory output_stride_in_bytes, int the number of channels in the image (e.g. RGB=3, RGBA=4) num_channels, int the alpha channel index, or alpha_channel, int ALPHA_CHANNEL_NONE if there is no alpha channelthe alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of: flags, int
the edge wrap mode. One of: edge_wrap_mode)
Same as |