Primarily of interest to game developers and other people who can avoid problematic images and only need the trivial interface. Supported formats:
Animated GIF still needs a proper API, but here's one way to do it.
Features:
Limitations:
Basic usage (see HDR discussion below for HDR usage):
int x,y,n;
unsigned char *data = stbi_load(filename, &x, &y, &n, 0);
// ... process data if not NULL ...
// ... x = width, y = height, n = # 8-bit components per pixel ...
// ... replace '0' with '1'..'4' to force that many components per pixel
// ... but 'n' will always be the number that it would have been if you said 0
stbi_image_free(data)
stb_image supports loading HDR images in general, and currently the Radiance .HDR file format specifically. You can still load any file through the existing interface; if you attempt to load an HDR file, it will be automatically remapped to LDR, assuming gamma 2.2 and an arbitrary scale factor defaulting to 1; both of these constants can be reconfigured through this interface:
stbi_hdr_to_ldr_gamma(2.2f);
stbi_hdr_to_ldr_scale(1.0f);
(note, do not use inverse constants; stbi_image will invert them appropriately).
Additionally, there is a new, parallel interface for loading files as (linear) floats to preserve the full dynamic range:
float *data = stbi_loadf(filename, &x, &y, &n, 0);
If you load LDR images through this interface, those images will be promoted to floating point values, run through the inverse of constants corresponding to the above:
stbi_ldr_to_hdr_scale(1.0f);
stbi_ldr_to_hdr_gamma(2.2f);
Finally, given a filename (or an open file or memory block) containing image data, you can query for the "most appropriate" interface to use (that is, whether the image is HDR or not), using:
stbi_is_hdr(char *filename);
We optionally support converting iPhone-formatted PNGs (which store premultiplied BGRA) back to RGB, even though they're internally encoded
differently. To enable this conversion, call convert_iphone_png_to_rgb(1).
Call set_unpremultiply_on_load(1) as well to force a divide per pixel to remove any premultiplied alpha *only* if the image file explicitly says
there's premultiplied data (currently only happens in iPhone images, and only if iPhone convert-to-rgb processing is on).
| Modifier and Type | Field and Description |
|---|---|
| public static final int | STBI_default
Component count. |
| public static final int | STBI_grey
Component count. |
| public static final int | STBI_grey_alpha
Component count. |
| public static final int | STBI_rgb
Component count. |
| public static final int | STBI_rgb_alpha
Component count. |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description | |||||
|---|---|---|---|---|---|---|
| public static native void | nstbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert)
Unsafe version of: | |||||
| public static native void | nstbi_convert_iphone_png_to_rgb_thread(int flag_true_if_should_convert)
Unsafe version of: | |||||
| public static native long | ||||||
| public static native void | ||||||
| public static native int | ||||||
| public static native int | ||||||
| public static native int | nstbi_info_from_callbacks(long clbk, long user, long x, long y, long comp)
Unsafe version of: | |||||
| public static native int | nstbi_info_from_callbacks(long clbk, long user, int[] x, int[] y, int[] comp)
Array version of: | |||||
| public static native int | nstbi_info_from_memory(long buffer, int
the buffer length, in bytes len, long x, long y, long comp)Unsafe version of: | |||||
| public static native int | nstbi_info_from_memory(long buffer, int len, int[] x, int[] y, int[] comp)
Array version of: | |||||
| public static native int | ||||||
| public static native int | ||||||
| public static native int | nstbi_is_16_bit_from_memory(long buffer, int
the buffer length, in bytes len)Unsafe version of: | |||||
| public static native int | ||||||
| public static native int | ||||||
| public static native int | nstbi_is_hdr_from_memory(long buffer, int
the buffer length, in bytes len)Unsafe version of: | |||||
| public static native long | nstbi_load(long filename, long x, long y, long channels_in_file, int desired_channels)
Unsafe version of: | |||||
| public static native long | nstbi_load(long filename, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static native long | nstbi_load_16(long filename, long x, long y, long channels_in_file, int desired_channels)
Unsafe version of: | |||||
| public static native long | nstbi_load_16(long filename, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static native long | nstbi_load_16_from_callbacks(long clbk, long user, long x, long y, long channels_in_file, int desired_channels)
Unsafe version of: | |||||
| public static native long | nstbi_load_16_from_callbacks(long clbk, long user, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static native long | nstbi_load_16_from_memory(long buffer, int
the buffer length, in bytes len, long x, long y, long channels_in_file, int desired_channels)Unsafe version of: | |||||
| public static native long | nstbi_load_16_from_memory(long buffer, int len, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static native long | nstbi_load_from_callbacks(long clbk, long user, long x, long y, long channels_in_file, int desired_channels)
Unsafe version of: | |||||
| public static native long | nstbi_load_from_callbacks(long clbk, long user, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static native long | nstbi_load_from_memory(long buffer, int
the buffer length, in bytes len, long x, long y, long channels_in_file, int desired_channels)Unsafe version of: | |||||
| public static native long | nstbi_load_from_memory(long buffer, int len, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static native long | nstbi_load_gif_from_memory(long buffer, int
the buffer length, in bytes len, long delays, long x, long y, long z, long channels_in_file, int desired_channels)Unsafe version of: | |||||
| public static native long | nstbi_load_gif_from_memory(long buffer, int len, long delays, int[] x, int[] y, int[] z, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static native long | nstbi_loadf(long filename, long x, long y, long channels_in_file, int desired_channels)
Unsafe version of: | |||||
| public static native long | nstbi_loadf(long filename, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static native long | nstbi_loadf_from_callbacks(long clbk, long user, long x, long y, long channels_in_file, int desired_channels)
Unsafe version of: | |||||
| public static native long | nstbi_loadf_from_callbacks(long clbk, long user, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static native long | nstbi_loadf_from_memory(long buffer, int
the buffer length, in bytes len, long x, long y, long channels_in_file, int desired_channels)Unsafe version of: | |||||
| public static native long | nstbi_loadf_from_memory(long buffer, int len, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static native void | nstbi_set_flip_vertically_on_load(int flag_true_if_should_flip)
Unsafe version of: | |||||
| public static native void | nstbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply)
Unsafe version of: | |||||
| public static native void | nstbi_set_unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply)
Unsafe version of: | |||||
| public static native int | nstbi_zlib_decode_buffer(long obuffer, int olen, long ibuffer, int ilen)
Unsafe version of: | |||||
| public static native long | ||||||
| public static native long | nstbi_zlib_decode_malloc_guesssize(long buffer, int len, int initial_size, long outlen)
Unsafe version of: | |||||
| public static native long | nstbi_zlib_decode_malloc_guesssize_headerflag(long buffer, int len, int initial_size, long outlen, int parse_header)
Unsafe version of: | |||||
| public static native int | nstbi_zlib_decode_noheader_buffer(long obuffer, int olen, long ibuffer, int ilen)
Unsafe version of: | |||||
| public static native long | nstbi_zlib_decode_noheader_malloc(long buffer, int len, long outlen)
Unsafe version of: | |||||
| public static void | stbi_convert_iphone_png_to_rgb(boolean
the convert iPhone PNG to RGB flag flag_true_if_should_convert)Indicate whether we should process iPhone images back to canonical format, or just pass them through "as-is". | |||||
| public static void | stbi_convert_iphone_png_to_rgb_thread(boolean flag_true_if_should_convert)
As | |||||
| public static String | ||||||
| public static native void | stbi_hdr_to_ldr_gamma(float
the gamma value gamma)Changes the gamma value used when converting HDR images to LDR. | |||||
| public static native void | stbi_hdr_to_ldr_scale(float
the scale factor scale)Changes the scale factor used when converting HDR images to LDR. | |||||
| public static void | ||||||
| public static void | ||||||
| public static void | ||||||
| public static boolean | Returns: 1 on success, 0 on failurethe file name filename, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs number of components in image comp)Returns image dimensions & components without fully decoding the image. | |||||
| public static boolean | Returns: 1 on success, 0 on failurethe file name filename, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs number of components in image comp)Returns image dimensions & components without fully decoding the image. | |||||
| public static boolean | ||||||
| public static boolean | ||||||
| public static boolean | stbi_info_from_callbacks(STBIIOCallbacks
an clbk, long STBIIOCallbacks structa pointer to user data user, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs number of components in image comp)Callback version of | |||||
| public static boolean | stbi_info_from_callbacks(STBIIOCallbacks clbk, long user, int[] x, int[] y, int[] comp)
Array version of: | |||||
| public static boolean | stbi_info_from_memory(ByteBuffer
the buffer from which to load the image data buffer, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs number of components in image comp)In-memory version of | |||||
| public static boolean | stbi_info_from_memory(ByteBuffer buffer, int[] x, int[] y, int[] comp)
Array version of: | |||||
| public static boolean | ||||||
| public static boolean | ||||||
| public static boolean | stbi_is_16_bit_from_callbacks(STBIIOCallbacks
an clbk, long STBIIOCallbacks structa pointer to user data user)Callback version of | |||||
| public static boolean | stbi_is_16_bit_from_memory(ByteBuffer
the buffer from which to load the image data buffer)In-memory version of | |||||
| public static boolean | Returns: 1 if the image is HDR, 0 otherwisethe file name filename)Checks if the specified file contains an HDR image. | |||||
| public static boolean | Returns: 1 if the image is HDR, 0 otherwisethe file name filename)Checks if the specified file contains an HDR image. | |||||
| public static boolean | stbi_is_hdr_from_callbacks(STBIIOCallbacks
an clbk, long STBIIOCallbacks structa pointer to user data user)Callback version of | |||||
| public static boolean | stbi_is_hdr_from_memory(ByteBuffer
the buffer from which to load the image data buffer)In-memory version of | |||||
| public static native void | stbi_ldr_to_hdr_gamma(float
the gamma value gamma)Changes the gamma value used when converting LDR images to HDR. | |||||
| public static native void | stbi_ldr_to_hdr_scale(float
the scale factor scale)Changes the scale value used when converting LDR images to HDR. | |||||
| public static ByteBuffer | stbi_load(ByteBuffer
the file name filename, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs number of components in image channels_in_file, int 0 or 1..4 to force that many components per pixel. One of: desired_channels)
Loads an image from the specified file. | |||||
| public static ByteBuffer | stbi_load(CharSequence
the file name filename, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs number of components in image channels_in_file, int 0 or 1..4 to force that many components per pixel. One of: desired_channels)
Loads an image from the specified file. | |||||
| public static ByteBuffer | stbi_load(ByteBuffer filename, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static ByteBuffer | stbi_load(CharSequence filename, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static ShortBuffer | stbi_load_16(ByteBuffer
the file name filename, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs number of components in image channels_in_file, int 0 or 1..4 to force that many components per pixel. One of: desired_channels)
16-bits-per-channel version of | |||||
| public static ShortBuffer | stbi_load_16(CharSequence
the file name filename, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs number of components in image channels_in_file, int 0 or 1..4 to force that many components per pixel. One of: desired_channels)
16-bits-per-channel version of | |||||
| public static ShortBuffer | stbi_load_16(ByteBuffer filename, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static ShortBuffer | stbi_load_16(CharSequence filename, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static ShortBuffer | stbi_load_16_from_callbacks(STBIIOCallbacks
an clbk, long STBIIOCallbacks structa pointer to user data user, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs number of components in image channels_in_file, int 0 or 1..4 to force that many components per pixel. One of: desired_channels)
Callback version of | |||||
| public static ShortBuffer | stbi_load_16_from_callbacks(STBIIOCallbacks clbk, long user, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static ShortBuffer | stbi_load_16_from_memory(ByteBuffer
the buffer from which to load the image data buffer, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs number of components in image channels_in_file, int 0 or 1..4 to force that many components per pixel. One of: desired_channels)
In-memory version of | |||||
| public static ShortBuffer | stbi_load_16_from_memory(ByteBuffer buffer, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static ByteBuffer | stbi_load_from_callbacks(STBIIOCallbacks
an clbk, long STBIIOCallbacks structa pointer to user data user, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs number of components in image channels_in_file, int 0 or 1..4 to force that many components per pixel. One of: desired_channels)
Callback version of | |||||
| public static ByteBuffer | stbi_load_from_callbacks(STBIIOCallbacks clbk, long user, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static ByteBuffer | stbi_load_from_memory(ByteBuffer
the buffer from which to load the image data buffer, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs number of components in image channels_in_file, int 0 or 1..4 to force that many components per pixel. One of: desired_channels)
In-memory version of | |||||
| public static ByteBuffer | stbi_load_from_memory(ByteBuffer buffer, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static ByteBuffer | stbi_load_gif_from_memory(ByteBuffer
the buffer from which to load the image data buffer, PointerBuffer output the delays of each layer in the image delays, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs the number of layers in the image z, IntBuffer outputs number of components in image channels_in_file, int 0 or 1..4 to force that many components per pixel. One of: desired_channels)
gif version of | |||||
| public static ByteBuffer | stbi_load_gif_from_memory(ByteBuffer buffer, PointerBuffer delays, int[] x, int[] y, int[] z, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static FloatBuffer | stbi_loadf(ByteBuffer
the file name filename, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs number of components in image channels_in_file, int 0 or 1..4 to force that many components per pixel. One of: desired_channels)
Floating-point version of | |||||
| public static FloatBuffer | stbi_loadf(CharSequence
the file name filename, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs number of components in image channels_in_file, int 0 or 1..4 to force that many components per pixel. One of: desired_channels)
Floating-point version of | |||||
| public static FloatBuffer | stbi_loadf(ByteBuffer filename, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static FloatBuffer | stbi_loadf(CharSequence filename, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static FloatBuffer | stbi_loadf_from_callbacks(STBIIOCallbacks
an clbk, long STBIIOCallbacks structa pointer to user data user, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs number of components in image channels_in_file, int 0 or 1..4 to force that many components per pixel. One of: desired_channels)
Floating-point version of | |||||
| public static FloatBuffer | stbi_loadf_from_callbacks(STBIIOCallbacks clbk, long user, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static FloatBuffer | stbi_loadf_from_memory(ByteBuffer
the buffer from which to load the image data buffer, IntBuffer outputs the image width in pixels x, IntBuffer outputs the image height in pixels y, IntBuffer outputs number of components in image channels_in_file, int 0 or 1..4 to force that many components per pixel. One of: desired_channels)
Floating-point version of | |||||
| public static FloatBuffer | stbi_loadf_from_memory(ByteBuffer buffer, int[] x, int[] y, int[] channels_in_file, int desired_channels)
Array version of: | |||||
| public static void | stbi_set_flip_vertically_on_load(boolean
the flip vertically on load flag flag_true_if_should_flip)Flips the image vertically, so the first pixel in the output array is the bottom left. | |||||
| public static native void | stbi_set_flip_vertically_on_load_thread(int
the flip vertically on load flag flag_true_if_should_flip)As | |||||
| public static void | stbi_set_unpremultiply_on_load(boolean
the unpremultiply flag flag_true_if_should_unpremultiply)For image formats that explicitly notate that they have premultiplied alpha, we just return the colors as stored in the file. | |||||
| public static void | stbi_set_unpremultiply_on_load_thread(boolean flag_true_if_should_unpremultiply)
As | |||||
| public static int | stbi_zlib_decode_buffer(ByteBuffer obuffer, ByteBuffer ibuffer)
ZLIB client - used by PNG, available for other purposes | |||||
| public static ByteBuffer | ||||||
| public static ByteBuffer | stbi_zlib_decode_malloc_guesssize(ByteBuffer buffer, int initial_size)
ZLIB client - used by PNG, available for other purposes | |||||
| public static ByteBuffer | stbi_zlib_decode_malloc_guesssize_headerflag(ByteBuffer buffer, int initial_size, boolean parse_header)
ZLIB client - used by PNG, available for other purposes | |||||
| public static int | stbi_zlib_decode_noheader_buffer(ByteBuffer obuffer, ByteBuffer ibuffer)
ZLIB client - used by PNG, available for other purposes | |||||
| public static ByteBuffer | stbi_zlib_decode_noheader_malloc(ByteBuffer buffer)
ZLIB client - used by PNG, available for other purposes |