Struct omf::file::Writer

source ·
pub struct Writer { /* private fields */ }
Expand description

OMF writer object.

To use the writer:

  1. Create the writer object.
  2. Create an empty Project and fill in the details.
  3. For each element you want to store:
    1. Write the arrays and image with the writer.
    2. Fill in the required struct with the array pointers and other details then add it to the project.
    3. Repeat for the attributes, adding them to the newly created element.
  4. Call writer.finish(project) to validate everything inside the the project and write it.

Implementations§

source§

impl Writer

source

pub fn image_png(&mut self, image: &DynamicImage) -> Result<Array<Image>, Error>

Write an image in PNG encoding.

This supports grayscale, grayscale + alpha, RGB, and RGBA, in 8 or 16 bits per channel.

source

pub fn image_jpeg( &mut self, image: &RgbImage, quality: u8, ) -> Result<Array<Image>, Error>

Write an image in JPEG encoding.

Unlike PNG this is limited to 8-bit RGB and compression is lossy, but it will give much better compression ratios. The JPEG compression level is set by the quality argument, from 1 to 100. 90 is a reasonable level for preserving fine detail in the image, while lower values will give a smaller file.

If you have an existing image in JPEG encoding you shouldn’t be using this method, instead add the raw bytes of the file with writer.image_bytes(&bytes) to avoid recompressing the image and losing more detail.

source§

impl Writer

source

pub fn array_scalars<I, T>(&mut self, data: I) -> Result<Array<Scalar>, Error>
where I: IntoIterator<Item = T>, T: FloatType,

Write an array_type::Scalar array.

Values can be f32 or f64.

source

pub fn array_vertices<I, T>(&mut self, data: I) -> Result<Array<Vertex>, Error>
where I: IntoIterator<Item = [T; 3]>, T: FloatType,

Write an array_type::Vertex array.

source

pub fn array_segments<I>(&mut self, data: I) -> Result<Array<Segment>, Error>
where I: IntoIterator<Item = [u32; 2]>,

Write an array_type::Segment array.

Values can be [u8; 2], [u16; 2], or [u32; 2] and all indices must be less than the number of vertices.

source

pub fn array_triangles<I>(&mut self, data: I) -> Result<Array<Triangle>, Error>
where I: IntoIterator<Item = [u32; 3]>,

Write an array_type::Triangle array.

Values can be [u8; 3], [u16; 3], or [u32; 3] and all indices must be less than the number of vertices.

source

pub fn array_names<I>(&mut self, data: I) -> Result<Array<Name>, Error>
where I: IntoIterator<Item = String>,

Write an array_type::Name array.

source

pub fn array_gradient<I>(&mut self, data: I) -> Result<Array<Gradient>, Error>
where I: IntoIterator<Item = [u8; 4]>,

Write an array_type::Gradient array.

Values are [u8; 4] with channels in RGBA color.

source

pub fn array_texcoords<I, T>( &mut self, data: I, ) -> Result<Array<Texcoord>, Error>
where I: IntoIterator<Item = [T; 2]>, T: FloatType,

Write an array_type::Texcoord array.

Values can be either [f32; 2] or [f64; 2] containing normalized texture coordinates.

source

pub fn array_boundaries<I, T>( &mut self, data: I, ) -> Result<Array<Boundary>, Error>
where I: IntoIterator<Item = Boundary<T>>, T: NumberType,

Write an array_type::Boundary array.

The boundary value type T can be f64, i64, chrono::NaiveDate, or chrono::DateTime<Utc>.

source

pub fn array_regular_subblocks<I>( &mut self, data: I, ) -> Result<Array<RegularSubblock>, Error>
where I: IntoIterator<Item = ([u32; 3], [u32; 6])>,

Write an array_type::RegularSubblock array.

The parent_indices and corners iterators must be the same length. Each row is [parent_i, parent_j, parent_k, min_corner_i, min_corner_j, min_corner_k, max_corner_i, max_corner_j, max_corner_k]. The parent and corner indices can be different types.

Parent indices can be [u8; 3], [u16; 3], or [u32; 3]. Sub-block corners can separately be [u8; 6], [u16; 6], or [u32; 6] which each row storing $(u_{min}, v_{min}, w_{min}, u_{max}, v_{max}, w_{max})$ as indices into the regular grid within the parent block.

source

pub fn array_freeform_subblocks<I, C>( &mut self, data: I, ) -> Result<Array<FreeformSubblock>, Error>
where I: IntoIterator<Item = ([u32; 3], [C; 6])>, C: FloatType,

Write an array_type::FreeformSubblock array.

The parent_indices and corners iterators must be the same length. Each row is [parent_i, parent_j, parent_k, min_corner_x, min_corner_y, min_corner_z, max_corner_x, max_corner_y, max_corner_z].

Parent indices can be [u8; 3], [u16; 3], or [u32; 3]. Sub-block corners can be [f32; 6] or [f64; 6] which each row storing $(u_{min}, v_{min}, w_{min}, u_{max}, v_{max}, w_{max})$ in the range [0, 1] relative to the parent block.

source

pub fn array_numbers<I, T>(&mut self, data: I) -> Result<Array<Number>, Error>
where I: IntoIterator<Item = Option<T>>, T: NumberType,

Write an array_type::Number array.

Values are Option<T> where T can be f32, f64, i32, i64, chrono::NaiveDate, or chrono::DateTime<Utc>. Use None to represent null values rather than NaN or any flag values like −9999.

source

pub fn array_indices<I>(&mut self, data: I) -> Result<Array<Index>, Error>
where I: IntoIterator<Item = Option<u32>>,

Write an array_type::Index array.

Values are Option<T> where T can be Option<u8>, Option<u16>, or Option<u32>. Smaller types won’t compress much better but will let other applications allocate less memory when reading the array. Use None to represent null values.

source

pub fn array_vectors<I, T, V>( &mut self, data: I, ) -> Result<Array<Vector>, Error>
where I: IntoIterator<Item = Option<V>>, V: VectorSource<T>, T: FloatType,

Write a array_type::Vector array.

Values are Option<T> where T can be [f32; 2], [f64; 2], [f32; 3], or [f64; 3].

source

pub fn array_text<I>(&mut self, data: I) -> Result<Array<Text>, Error>
where I: IntoIterator<Item = Option<String>>,

Write a array_type::Text array.

source

pub fn array_booleans<I>(&mut self, data: I) -> Result<Array<Boolean>, Error>
where I: IntoIterator<Item = Option<bool>>,

Write a array_type::Boolean array.

source

pub fn array_colors<I>(&mut self, data: I) -> Result<Array<Color>, Error>
where I: IntoIterator<Item = Option<[u8; 4]>>,

Write a array_type::Color array.

Values are Option<[u8; 4]> with channels in RGBA order.

source§

impl Writer

source

pub fn new(file: File) -> Result<Self, Error>

Creates a writer that writes into a file-like object.

source

pub fn open(path: impl AsRef<Path>) -> Result<Self, Error>

Creates a writer by opening a file.

The file will be created if it doesn’t exist, and truncated and replaced if it does.

source

pub fn compression(&self) -> Compression

Return the current compression.

source

pub fn set_compression(&mut self, compression: Compression)

Set the compression to use.

This affects Parquet data and the JSON index, but not images. The default is Compression::default().

source

pub fn array_bytes<A: ArrayType>( &mut self, length: u64, bytes: &[u8], ) -> Result<Array<A>, Error>

Write an array from already-encoded bytes.

Returns the new Array on success or an error if file IO fails.

source

pub fn array_bytes_from<A: ArrayType>( &mut self, length: u64, read: impl Read, ) -> Result<Array<A>, Error>

Consumes everything from read and writes it as a new array.

The bytes must already be encoded in Parquet, PNG, or JPEG depending on the array type. Returns the new Array on success or an error if file IO fails on either side.

source

pub fn image_bytes(&mut self, bytes: &[u8]) -> Result<Array<Image>, Error>

Write an existing PNG or JPEG image from a slice without re-encoding it.

source

pub fn image_bytes_from( &mut self, read: impl Read, ) -> Result<Array<Image>, Error>

Write an existing PNG or JPEG image from a file without re-encoding it.

source

pub fn finish(self, project: Project) -> Result<(File, Problems), Error>

Validate and write the project and close the file.

Returns validation warnings on success or an Error on failure, which can be a validation failure or a file IO error.

Auto Trait Implementations§

§

impl Freeze for Writer

§

impl RefUnwindSafe for Writer

§

impl Send for Writer

§

impl Sync for Writer

§

impl Unpin for Writer

§

impl UnwindSafe for Writer

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.