Top Description Fields Constructors Methods
org.lwjgl.stb

public Class STBImageResize

extends Object
Class Inheritance
Imports
java.nio.*, org.lwjgl.system.*

Native bindings to stb_image_resize.h from the stb library.

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.

QUICKSTART


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

ALPHA CHANNEL

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:

  1. The best mathematically-behaved version of alpha to use is called "premultiplied alpha", in which the other color channels have had the alpha value multiplied in. If you use premultiplied alpha, linear filtering (such as image resampling done by this library, or performed in texture units on GPUs) does the "right thing". While premultiplied alpha is standard in the movie CGI industry, it is still uncommon in the videogame/real-time world. If you linearly filter non-premultiplied alpha, strange effects occur. (For example, the average of 1% opaque bright green and 99% opaque black produces 50% transparent dark green when non-premultiplied, whereas premultiplied it produces 50% transparent near-black. The former introduces green energy that doesn't exist in the source image.)
  2. Artists should not edit premultiplied-alpha images; artists want non-premultiplied alpha images. Thus, art tools generally output non-premultiplied alpha images.
  3. You will get best results in most cases by converting images to premultiplied alpha before processing them mathematically.
  4. If you pass the flag 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.
  5. If you do not pass the flag 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.)
  6. You can separately control whether the alpha channel is interpreted as linear or affected by the colorspace. By default it is linear; you almost never want to apply the colorspace. (For example, graphics hardware does not apply sRGB conversion to the alpha channel.)

Field Summary

Modifier and TypeField 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
public static final int
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
public static final int
public static final int
public static final int
public static final int
public static final int
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
public static final int
public static final int
STBIR_TYPE_UINT8

Data type.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
private static int
getTypeShift(int type)

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: resize

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: resize_float

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: nstbir_resize_float

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: resize_float_generic

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: nstbir_resize_float_generic

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: resize_region

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: resize_subpixel

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: resize_uint16_generic

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: nstbir_resize_uint16_generic

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: resize_uint8

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: resize_uint8_generic

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: resize_uint8_srgb

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: resize_uint8_srgb_edgemode

public static boolean

Returns:

1 on success, 0 on failure
stbir_resize
(ByteBuffer
the 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:
TYPE_UINT8TYPE_UINT16TYPE_UINT32TYPE_FLOAT
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_NONE if there is no alpha channel
alpha_channel
,
int
the alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of:
FLAG_ALPHA_PREMULTIPLIEDFLAG_ALPHA_USES_COLORSPACE
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:
COLORSPACE_LINEARCOLORSPACE_SRGB
space
)

Full-complexity version of resize_uint8_generic.

public static boolean

Returns:

1 on success, 0 on failure
stbir_resize_float
(FloatBuffer
the 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 resize_uint8.

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: resize_float

public static boolean

Returns:

1 on success, 0 on failure
stbir_resize_float_generic
(FloatBuffer
the 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_NONE if there is no alpha channel
alpha_channel
,
int
the alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of:
FLAG_ALPHA_PREMULTIPLIEDFLAG_ALPHA_USES_COLORSPACE
flags
,
int
the edge wrap mode. One of:
EDGE_CLAMPEDGE_REFLECTEDGE_WRAPEDGE_ZERO
edge_wrap_mode
,
int filter, int
the image colorspace. One of:
COLORSPACE_LINEARCOLORSPACE_SRGB
space
)

Float version of resize_uint8_generic.

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: resize_float_generic

public static boolean

Returns:

1 on success, 0 on failure
stbir_resize_region
(ByteBuffer
the 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:
TYPE_UINT8TYPE_UINT16TYPE_UINT32TYPE_FLOAT
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_NONE if there is no alpha channel
alpha_channel
,
int
the alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of:
FLAG_ALPHA_PREMULTIPLIEDFLAG_ALPHA_USES_COLORSPACE
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:
COLORSPACE_LINEARCOLORSPACE_SRGB
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 resize, using texture coordinates.

public static boolean

Returns:

1 on success, 0 on failure
stbir_resize_subpixel
(ByteBuffer
the 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:
TYPE_UINT8TYPE_UINT16TYPE_UINT32TYPE_FLOAT
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_NONE if there is no alpha channel
alpha_channel
,
int
the alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of:
FLAG_ALPHA_PREMULTIPLIEDFLAG_ALPHA_USES_COLORSPACE
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:
COLORSPACE_LINEARCOLORSPACE_SRGB
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 resize.

public static boolean

Returns:

1 on success, 0 on failure
stbir_resize_uint16_generic
(ShortBuffer
the 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_NONE if there is no alpha channel
alpha_channel
,
int
the alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of:
FLAG_ALPHA_PREMULTIPLIEDFLAG_ALPHA_USES_COLORSPACE
flags
,
int
the edge wrap mode. One of:
EDGE_CLAMPEDGE_REFLECTEDGE_WRAPEDGE_ZERO
edge_wrap_mode
,
int filter, int
the image colorspace. One of:
COLORSPACE_LINEARCOLORSPACE_SRGB
space
)

Short version of resize_uint8_generic.

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: resize_uint16_generic

public static boolean

Returns:

1 on success, 0 on failure
stbir_resize_uint8
(ByteBuffer
the 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 failure
stbir_resize_uint8_generic
(ByteBuffer
the 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_NONE if there is no alpha channel
alpha_channel
,
int
the alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of:
FLAG_ALPHA_PREMULTIPLIEDFLAG_ALPHA_USES_COLORSPACE
flags
,
int
the edge wrap mode. One of:
EDGE_CLAMPEDGE_REFLECTEDGE_WRAPEDGE_ZERO
edge_wrap_mode
,
int filter, int
the image colorspace. One of:
COLORSPACE_LINEARCOLORSPACE_SRGB
space
)

Medium-complexity version of resize_uint8.

public static boolean

Returns:

1 on success, 0 on failure
stbir_resize_uint8_srgb
(ByteBuffer
the 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_NONE if there is no alpha channel
alpha_channel
,
int
the alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of:
FLAG_ALPHA_PREMULTIPLIEDFLAG_ALPHA_USES_COLORSPACE
flags
)

Easy-to-use API for resizing images.

public static boolean

Returns:

1 on success, 0 on failure
stbir_resize_uint8_srgb_edgemode
(ByteBuffer
the 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_NONE if there is no alpha channel
alpha_channel
,
int
the alpha channel flags. 0 will propably do the right thing if you're not sure what the flags mean. One of:
FLAG_ALPHA_PREMULTIPLIEDFLAG_ALPHA_USES_COLORSPACE
flags
,
int
the edge wrap mode. One of:
EDGE_CLAMPEDGE_REFLECTEDGE_WRAPEDGE_ZERO
edge_wrap_mode
)

Same as resize_uint8_srgb, but adds the ability to specify how requests to sample off the edge of the image are handled.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait