pub struct ScanlinesLoader<R> {
pub width: usize,
pub height: usize,
/* private fields */
}Expand description
An image loader that decodes images line by line, through an iterative API.
use radiant::{Rgb, Loader};
use std::io::BufReader;
use std::fs::File;
let f = File::open("assets/colorful_studio_2k.hdr").expect("failed to open file");
let f = BufReader::new(f);
let mut loader = Loader::new(f)
.expect("failed to read image")
.scanlines();
let height = loader.height;
let width = loader.width;
// Allocate a buffer that fits one whole scanline (or more)
let mut buffer = vec![Rgb::zero(); width];
for y in 0..height {
loader.read_scanline(&mut buffer).expect("failed to read image");
// do something with the decoded scanline, such as uploading it to a GPU texture
}
// If you enable the "impl-bytemuck" feature,
// you can use the bytemuck crate to cast the buffer to another plain-old-data type.
// This layout is guaranteed, so you can also do this using `unsafe`.
let buffer: &[[f32; 3]] = bytemuck::cast_slice(&buffer);Fields§
§width: usizeThe width of the image.
height: usizeThe height of the image, i.e. the number of scanlines.
Implementations§
Source§impl<R: BufRead> ScanlinesLoader<R>
impl<R: BufRead> ScanlinesLoader<R>
Sourcepub fn read_scanline(&mut self, scanline: &mut [Rgb]) -> Result<(), IoError>
pub fn read_scanline(&mut self, scanline: &mut [Rgb]) -> Result<(), IoError>
Decode image data into the next horizontal scanline of the image. The provided scanline
buffer must be at least as long as the width of the image, otherwise an error of the kind
std::io::ErrorKind::InvalidInput will be returned.
Auto Trait Implementations§
impl<R> Freeze for ScanlinesLoader<R>where
R: Freeze,
impl<R> RefUnwindSafe for ScanlinesLoader<R>where
R: RefUnwindSafe,
impl<R> Send for ScanlinesLoader<R>where
R: Send,
impl<R> Sync for ScanlinesLoader<R>where
R: Sync,
impl<R> Unpin for ScanlinesLoader<R>where
R: Unpin,
impl<R> UnwindSafe for ScanlinesLoader<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more