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.
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, comp int, buf &u8) !
stbi_write_png write on path a BMP file
fn stbi_write_jpg #
fn stbi_write_jpg(path string, w int, h int, comp int, buf &u8, quality int) !
stbi_write_png write on path a JPG file quality select the compression quality of the JPG quality is between 1 and 100. Higher quality looks better but results in a bigger image.
fn stbi_write_png #
fn stbi_write_png(path string, w int, h int, comp int, buf &u8, row_stride_in_bytes int) !
stbi_write_png write on path a PNG file row_stride_in_bytes is usually equal to: w * comp
fn stbi_write_tga #
fn stbi_write_tga(path string, w int, h int, comp int, buf &u8) !
stbi_write_png write on path a TGA file
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.
}