23 lines
607 B
Rust
23 lines
607 B
Rust
use crate::pool::TextureData;
|
|
|
|
pub fn load_texture_data(image_raw: &[u8]) -> TextureData {
|
|
let image_data = image::load_from_memory(image_raw).unwrap();
|
|
|
|
use image::GenericImageView;
|
|
let dimensions = image_data.dimensions();
|
|
|
|
let image_rgb = image_data.as_rgb8().unwrap().to_vec();
|
|
let mut image_rgba = Vec::<u8>::new();
|
|
for rgb in image_rgb.chunks(3) {
|
|
image_rgba.extend_from_slice(rgb);
|
|
image_rgba.push(0xff);
|
|
}
|
|
|
|
let texture_data = TextureData {
|
|
width: dimensions.0,
|
|
height: dimensions.1,
|
|
data: image_rgba,
|
|
};
|
|
|
|
texture_data
|
|
} |