#image #jpeg #png #bmp #gif

stb_image_rust

Rust port of the stb_image

3 stable releases

Uses old Rust 2015

2.27.2 Jan 6, 2022
2.27.1 Jan 3, 2022
2.27.0 Jan 1, 2022

#462 in Images

Download history 28/week @ 2023-10-19 28/week @ 2023-10-26 28/week @ 2023-11-02 27/week @ 2023-11-09 26/week @ 2023-11-16 30/week @ 2023-11-23 37/week @ 2023-11-30 35/week @ 2023-12-07 33/week @ 2023-12-14 30/week @ 2023-12-21 17/week @ 2023-12-28 25/week @ 2024-01-04 34/week @ 2024-01-11 28/week @ 2024-01-18 35/week @ 2024-01-25 16/week @ 2024-02-01

117 downloads per month
Used in 3 crates

Unlicense

305KB
8K SLoC

About

stb_image_rust is Rust port of the stb_image.h, which is C library to load images in JPG, PNG, BMP, TGA, PSD and GIF formats.

It is important to note, that this project is port, not wrapper. Original C code had been ported to Rust. Therefore stb_image_rust doesnt require any native binaries.

The porting hasn't been done by hand, but using Hebron.

Crate

https://crates.io/crates/stb_image_rust

Sample Code

        // Load file into memory
        let mut f = File::open(path).expect("file not found");
        let mut contents = vec![];
        f.read_to_end(&mut contents);

	// Load the image
        let mut x: i32 = 0;
        let mut y: i32 = 0;
        let mut comp: i32 = 0;
        let img: *mut u8;
		
        unsafe {
            img = stb_image_rust::stbi_load_from_memory(
                contents.as_mut_ptr(),
                contents.len() as i32,
                &mut x,
                &mut y,
                &mut comp,
                stb_image_rust::STBI_rgb_alpha,
            );
        }
		
	// Do something with it
	...
		
	// Free the allocated memory
        unsafe {
            stb_image_rust::c_runtime::free(img);
        }		

License

Public Domain

No runtime deps