Struct radiant::ScanlinesLoader[][src]

pub struct ScanlinesLoader<R> {
    pub width: usize,
    pub height: usize,
    // some fields omitted
}

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

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.