ScanlinesLoader

Struct ScanlinesLoader 

Source
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: usize

The width of the image.

§height: usize

The height of the image, i.e. the number of scanlines.

Implementations§

Source§

impl<R: BufRead> ScanlinesLoader<R>

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.