[−][src]Struct openexr::input::InputFile
Reads any kind of OpenEXR file.
InputFile
is a bit unique in that it doesn't care what kind of OpenEXR
file is being read. Regardless of the type being read, it presents an API
as if it were a basic scanline OpenEXR file.
Special features like tiles, mipmaps, and deep image data will not be available even if they are present in the file. To gain access to those features you need to use the other input file types (not yet implemented, sorry!).
Examples
Load image data from a floating point RGB image file named "input_file.exr".
// Open file and get its resolution. let mut file = std::fs::File::open("input_file.exr").unwrap(); let mut input_file = InputFile::new(&mut file).unwrap(); let (width, height) = input_file.header().data_dimensions(); // Allocate a buffer for the image data and read it in. let mut pixel_data: Vec<[f32; 4]> = vec![[0.0, 0.0, 0.0, 0.0]; (width*height) as usize]; let mut fb = FrameBufferMut::new(width, height); fb.insert_channels(&[("R", 0.0), ("G", 0.0), ("B", 0.0), ("A", 0.0)], &mut pixel_data); input_file.read_pixels(&mut fb).unwrap();
Methods
impl<'a> InputFile<'a>
[src]
pub fn new<T: 'a>(reader: &mut T) -> Result<InputFile> where
T: Read + Seek,
[src]
T: Read + Seek,
Creates a new InputFile
from any Read + Seek
type (typically a
std::fs::File
).
Note: this seeks to byte 0 before reading.
pub fn from_slice(slice: &[u8]) -> Result<InputFile>
[src]
Creates a new InputFile
from a slice of bytes, reading from memory.
Note: although you can do essentially the same thing by passing a
std::io::Cursor<&[u8]>
to new()
, using this method is more
efficient because it allows the underlying APIs to avoid reading data
into intermediate buffers.
pub fn read_pixels(&mut self, framebuffer: &mut FrameBufferMut) -> Result<()>
[src]
Reads the entire image into framebuffer
at once.
Any channels in framebuffer
that are not present in the file will be
filled with their default fill value.
Errors
This function expects framebuffer
to have the same resolution as the
file, and for any same-named channels to have matching types and
subsampling.
It will also return an error if there is an I/O error.
pub fn read_pixels_partial(
&mut self,
starting_scanline: u32,
framebuffer: &mut FrameBufferMut
) -> Result<()>
[src]
&mut self,
starting_scanline: u32,
framebuffer: &mut FrameBufferMut
) -> Result<()>
Reads a contiguous chunk of scanlines into framebuffer
.
framebuffer
may have a different vertical resolution than the image,
but must have the same horizontal resolution. Scanlines are read from
the image starting at starting_scanline
and are written to
framebuffer
until it's filled.
For example, to read the last 50 scanlines of a 200-pixel-tall image, you would pass a 50-pixel-tall FrameBufferMut and a starting scanline of 150.
Any channels in framebuffer
that are not present in the file will be
filled with their default fill value.
Errors
This function expects framebuffer
to have the same horizontal
resolution as the file, and for any same-named channels to have
matching types and subsampling.
It will also return an error if:
- There aren't enough scanlines starting at
starting_scanline
to fillframebuffer
. fromstarting_scanline
. - There is an I/O error.
pub fn header(&self) -> &Header
[src]
Access to the file's header.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
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.
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,