stbi #
Description
stbi is a thin wrapper around stb's stb_image.h, which in turn is "a public domain image loader" for popular graphics image file formats.
By default, stbi.load and stbi.load_from_memory convert images to 4-channel RGBA pixel data. Image.nr_channels reflects that in-memory layout, while Image.original_nr_channels keeps the channel count from the source file as metadata.
When uploading to sokol.gfx, size the upload from width * height * nr_channels. If you load with desired_channels: 0, convert the data yourself or use a matching pixel format before creating a texture.
Constants #
const C.STBI_rgb_alpha int
fn load #
fn load(path string, params LoadParams) !Image
load loads an image from path If you do not pass desired_channels: explicitly, it will default to 4 (RGBA), The image, will get converted into that internal format, no matter what it was on disk. Use desired_channels:0, if you need to keep the channels of the image on disk. Note that displaying such an image, with gg/sokol later, can be a problem. Converting/resizing it, should work fine though.
fn load_from_memory #
fn load_from_memory(buf &u8, bufsize int, params LoadParams) !Image
load_from_memory load an image from a memory buffer If you do not pass desired_channels: explicitly, it will default to 4 (RGBA), and the image will get converted into that internal format, no matter what it was originally. Use desired_channels:0, if you need to keep the channels of the image as they were. Note that displaying such an image, with gg/sokol later, can be a problem. Converting/resizing it, should work fine though.
fn resize_uint8 #
fn resize_uint8(img &Image, output_w int, output_h int) !Image
resize_uint8 resizes img to dimensions of output_w and output_h
fn set_flip_vertically_on_load #
fn set_flip_vertically_on_load(val bool)
fn set_flip_vertically_on_write #
fn set_flip_vertically_on_write(val bool)
fn set_png_compression_level #
fn set_png_compression_level(level int)
set_png_compression_level set the PNG compression level during the writing process defaults to 8; set to higher for more compression
fn stbi_write_bmp #
fn stbi_write_bmp(path string, w int, h int, nr_channels int, buf &u8) !
stbi_write_bmp writes a BMP file to path. nr_channels is the number of channels in buf.
fn stbi_write_jpg #
fn stbi_write_jpg(path string, w int, h int, nr_channels int, buf &u8, quality int) !
stbi_write_jpg writes a JPG file to path. nr_channels is the number of channels in buf. quality controls the JPG compression quality and must be between 1 and 100.
fn stbi_write_png #
fn stbi_write_png(path string, w int, h int, nr_channels int, buf &u8, row_stride_in_bytes int) !
stbi_write_png writes a PNG file to path. nr_channels is the number of channels in buf. row_stride_in_bytes is usually w * nr_channels.
fn stbi_write_tga #
fn stbi_write_tga(path string, w int, h int, nr_channels int, buf &u8) !
stbi_write_tga writes a TGA file to path. nr_channels is the number of channels in buf.
fn write_force_png_filter #
fn write_force_png_filter(level int)
write_force_png_filter defaults to -1; set to 0..5 to force a filter mode the filter algorithms that can be applied before compression. The purpose of these filters is to prepare the image data for optimum compression. Type Name
0 None 1 Sub 2 Up 3 Average 4 Paeth
fn write_tga_with_rle #
fn write_tga_with_rle(flag bool)
stbi_write_tga_with_rle enable/disable the TGA RLE during the writing process defaults to true; set to false to disable RLE in tga
struct Image #
struct Image {
pub mut:
width int // the width in pixels in the .data
height int // the height in pixels in the .data
nr_channels int // the number of color channels in the .data
ok bool // if the image was loaded successfully
data &u8 = unsafe { nil } // the actual data/pixels in the image, after reading and potentially converting the image
ext string // the extension of the file, from which the image was loaded
//
original_nr_channels int // when loaded from memory/disk, this field will contain the original number of channels, based on the data, prior to any conversions. Use only as metadata, not for further conversions.
}
Image represents an image loaded from file or memory, or an image, produced after resizing
fn (Image) free #
fn (img &Image) free()
struct LoadParams #
struct LoadParams {
pub:
desired_channels int = C.STBI_rgb_alpha // 4 by default (RGBA); desired_channels is the number of color channels, that will be used for representing the image in memory. If set to 0, stbi will figure out the number of channels, based on the original image data.
}
- README
- Constants
- fn load
- fn load_from_memory
- fn resize_uint8
- fn set_flip_vertically_on_load
- fn set_flip_vertically_on_write
- fn set_png_compression_level
- fn stbi_write_bmp
- fn stbi_write_jpg
- fn stbi_write_png
- fn stbi_write_tga
- fn write_force_png_filter
- fn write_tga_with_rle
- struct Image
- struct LoadParams