[−][src]Module fna3d::img
FNA3D_Image.h
with some helpers
Iternally, FNA3D_Image
uses stb_image
(stbi
) with callback functions where arbitrary IO
is allowed.
Other options than fna3d::img
are raw stb_image
(with or without callbacks), SDL_RWops
(SDL2) or else.
Example
pub struct MyTexture2d { raw: *mut fna3d::Texture, w: u32, h: u32, } impl MyTexture2d { pub fn from_path( device: &fna3d::Device, path: impl AsRef<std::path::Path>, ) -> Option<Self> { let (pixels_ptr, len, [w, h]) = fna3d::img::from_path(path, None); if pixels_ptr == std::ptr::null_mut() { return None; } let pixels: &[u8] = unsafe { std::slice::from_raw_parts(pixels_ptr, len as usize) }; let raw = device.create_texture_2d( fna3d::SurfaceFormat::Color, w, h, 1, // mipmap level (do not set it to zero) false, ); let texture = MyTexture2d { raw, w, h }; fna3d::img::free(pixels_ptr as *mut _); Some(texture) } }
Functions
free | Frees pixels loaded with a helper method in this module |
from_encoded_bytes | Decodes PNG/JPG/GIF data into raw RGBA8 texture data |
from_path | Decodes PNG/JPG/GIF data into raw RGBA8 texture data |
from_reader | Decodes PNG/JPG/GIF data into raw RGBA8 texture data |
save_png | Encodes RGBA8 image data into PNG data with a writer |
save_png_to | Encodes RGBA8 image data into PNG data to some path |