Struct radiant::ScanlinesLoader [−][src]
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: usize
The width of the image.
height: usize
The height of the image, i.e. the number of scanlines.
Implementations
impl<R: BufRead> ScanlinesLoader<R>
[src]
pub fn read_scanline(&mut self, scanline: &mut [Rgb]) -> Result<(), IoError>
[src]
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> RefUnwindSafe for ScanlinesLoader<R> where
R: RefUnwindSafe,
R: RefUnwindSafe,
impl<R> Send for ScanlinesLoader<R> where
R: Send,
R: Send,
impl<R> Sync for ScanlinesLoader<R> where
R: Sync,
R: Sync,
impl<R> Unpin for ScanlinesLoader<R> where
R: Unpin,
R: Unpin,
impl<R> UnwindSafe for ScanlinesLoader<R> where
R: UnwindSafe,
R: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,