1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
//! Rust bindings for the [OpenEXR](http://openexr.com) C++ library. //! //! OpenEXR is a bitmap image file format that can store high dynamic range //! (HDR) images along with other arbitrary per-pixel data. It is used heavily //! in the VFX and 3D animation industries. //! //! Although this wrapper's API differs a little from the C++ library, it tries //! not to differ wildly. Therefore the //! [C++ OpenEXR documentation](https://github.com/openexr/openexr/tree/develop/OpenEXR/doc) //! is still useful as an introduction and rough reference. Moreover, the //! file format itself is also documented there. //! //! # Overview //! //! There are three primary parts to this crate: //! //! * The various [input](input/index.html) and [output](output/index.html) //! types. These are used for reading and writing OpenEXR files. They //! utilize the Header and FrameBuffer(Mut) types, listed below. //! //! * [`Header`](header/struct.Header.html): this is used for querying and specifying //! the properties of an OpenEXR file (such as resolution, channels, etc.), for //! reading and writing respectively. //! //! * [`FrameBuffer`](frame_buffer/struct.FrameBuffer.html) and //! [`FrameBufferMut`](frame_buffer/struct.FrameBufferMut.html): //! these are intermediaries that tell the OpenEXR APIs how to interpret //! your in-memory image data. Rather than passing your image data to the //! APIs directly, you construct a `FrameBuffer` that points at and //! describes it, and then you pass that FrameBuffer. //! //! # Examples //! //! Writing a scanline floating point RGB file. //! //! ```no_run //! # use openexr::{FrameBuffer, Header, ScanlineOutputFile, PixelType}; //! # //! // Pixel data for a 256x256 floating point RGB image. //! let pixel_data = vec![(0.82f32, 1.78f32, 0.21f32); 256 * 256]; //! //! // Create a file to write to. The `Header` determines the properties of the //! // file, like resolution and what channels it has. //! let mut file = std::fs::File::create("output_file.exr").unwrap(); //! let mut output_file = ScanlineOutputFile::new( //! &mut file, //! Header::new() //! .set_resolution(256, 256) //! .add_channel("R", PixelType::FLOAT) //! .add_channel("G", PixelType::FLOAT) //! .add_channel("B", PixelType::FLOAT)).unwrap(); //! //! // Create a `FrameBuffer` that points at our pixel data and describes it as //! // RGB data. //! let mut fb = FrameBuffer::new(256, 256); //! fb.insert_channels(&["R", "G", "B"], &pixel_data); //! //! // Write pixel data to the file. //! output_file.write_pixels(&fb).unwrap(); //! ``` //! //! Reading a floating point RGB file. //! //! ```no_run //! # use openexr::{FrameBufferMut, InputFile}; //! //! // Open the EXR file. //! let mut file = std::fs::File::open("input_file.exr").unwrap(); //! let mut input_file = InputFile::new(&mut file).unwrap(); //! //! // Get the image dimensions, so we know how large of a buffer to make. //! let (width, height) = input_file.header().data_dimensions(); //! //! // Buffer to read pixel data into. //! let mut pixel_data = vec![(0.0f32, 0.0f32, 0.0f32); (width*height) as usize]; //! //! // New scope because `FrameBufferMut` mutably borrows `pixel_data`, so we //! // need it to go out of scope before we can access our `pixel_data` again. //! { //! // Get the input file data origin, which we need to properly construct //! // the `FrameBufferMut`. //! let (origin_x, origin_y) = input_file.header().data_origin(); //! //! // Create a `FrameBufferMut` that points at our pixel data and describes //! // it as RGB data. //! let mut fb = FrameBufferMut::new_with_origin( //! origin_x, //! origin_y, //! width, //! height, //! ); //! fb.insert_channels(&[("R", 0.0), ("G", 0.0), ("B", 0.0)], &mut pixel_data); //! //! // Read pixel data from the file. //! input_file.read_pixels(&mut fb).unwrap(); //! } //! ``` #![warn(missing_docs)] #![cfg_attr(feature = "unstable", feature(plugin))] #![cfg_attr(feature = "unstable", plugin(clippy))] extern crate half; extern crate libc; extern crate openexr_sys; mod cexr_type_aliases; mod stream_io; pub mod error; pub mod frame_buffer; pub mod header; pub mod input; pub mod output; pub mod threads; pub use cexr_type_aliases::{Box2i, PixelType}; pub use error::{Error, Result}; pub use frame_buffer::{FrameBuffer, FrameBufferMut}; pub use header::{Envmap, Header}; pub use input::InputFile; pub use output::ScanlineOutputFile;