pub struct Writer { /* private fields */ }
Expand description
OMF writer object.
To use the writer:
- Create the writer object.
- Create an empty
Project
and fill in the details. - For each element you want to store:
- Write the arrays and image with the writer.
- Fill in the required struct with the array pointers and other details then add it to the project.
- Repeat for the attributes, adding them to the newly created element.
- Call
writer.finish(project)
to validate everything inside the the project and write it.
Implementations§
source§impl Writer
impl Writer
sourcepub fn image_png(&mut self, image: &DynamicImage) -> Result<Array<Image>, Error>
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.
sourcepub fn image_jpeg(
&mut self,
image: &RgbImage,
quality: u8,
) -> Result<Array<Image>, Error>
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
impl Writer
sourcepub fn array_scalars<I, T>(&mut self, data: I) -> Result<Array<Scalar>, Error>where
I: IntoIterator<Item = T>,
T: FloatType,
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
.
sourcepub fn array_vertices<I, T>(&mut self, data: I) -> Result<Array<Vertex>, Error>
pub fn array_vertices<I, T>(&mut self, data: I) -> Result<Array<Vertex>, Error>
Write an array_type::Vertex
array.
sourcepub fn array_segments<I>(&mut self, data: I) -> Result<Array<Segment>, Error>
pub fn array_segments<I>(&mut self, data: I) -> Result<Array<Segment>, Error>
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.
sourcepub fn array_triangles<I>(&mut self, data: I) -> Result<Array<Triangle>, Error>
pub fn array_triangles<I>(&mut self, data: I) -> Result<Array<Triangle>, Error>
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.
sourcepub fn array_names<I>(&mut self, data: I) -> Result<Array<Name>, Error>where
I: IntoIterator<Item = String>,
pub fn array_names<I>(&mut self, data: I) -> Result<Array<Name>, Error>where
I: IntoIterator<Item = String>,
Write an array_type::Name
array.
sourcepub fn array_gradient<I>(&mut self, data: I) -> Result<Array<Gradient>, Error>
pub fn array_gradient<I>(&mut self, data: I) -> Result<Array<Gradient>, Error>
Write an array_type::Gradient
array.
Values are [u8; 4]
with channels in RGBA color.
sourcepub fn array_texcoords<I, T>(
&mut self,
data: I,
) -> Result<Array<Texcoord>, Error>
pub fn array_texcoords<I, T>( &mut self, data: I, ) -> Result<Array<Texcoord>, Error>
Write an array_type::Texcoord
array.
Values can be either [f32; 2]
or [f64; 2]
containing normalized texture coordinates.
sourcepub fn array_boundaries<I, T>(
&mut self,
data: I,
) -> Result<Array<Boundary>, Error>
pub fn array_boundaries<I, T>( &mut self, data: I, ) -> Result<Array<Boundary>, Error>
Write an array_type::Boundary
array.
The boundary value type T
can be f64
, i64
, chrono::NaiveDate
, or chrono::DateTime<Utc>
.
sourcepub fn array_regular_subblocks<I>(
&mut self,
data: I,
) -> Result<Array<RegularSubblock>, Error>
pub fn array_regular_subblocks<I>( &mut self, data: I, ) -> Result<Array<RegularSubblock>, Error>
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.
sourcepub fn array_freeform_subblocks<I, C>(
&mut self,
data: I,
) -> Result<Array<FreeformSubblock>, Error>
pub fn array_freeform_subblocks<I, C>( &mut self, data: I, ) -> Result<Array<FreeformSubblock>, Error>
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.
sourcepub fn array_numbers<I, T>(&mut self, data: I) -> Result<Array<Number>, Error>
pub fn array_numbers<I, T>(&mut self, data: I) -> Result<Array<Number>, Error>
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.
sourcepub fn array_indices<I>(&mut self, data: I) -> Result<Array<Index>, Error>
pub fn array_indices<I>(&mut self, data: I) -> Result<Array<Index>, Error>
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.
sourcepub fn array_vectors<I, T, V>(
&mut self,
data: I,
) -> Result<Array<Vector>, Error>
pub fn array_vectors<I, T, V>( &mut self, data: I, ) -> Result<Array<Vector>, Error>
Write a array_type::Vector
array.
Values are Option<T>
where T
can be [f32; 2]
, [f64; 2]
, [f32; 3]
, or [f64; 3]
.
sourcepub fn array_text<I>(&mut self, data: I) -> Result<Array<Text>, Error>
pub fn array_text<I>(&mut self, data: I) -> Result<Array<Text>, Error>
Write a array_type::Text
array.
sourcepub fn array_booleans<I>(&mut self, data: I) -> Result<Array<Boolean>, Error>
pub fn array_booleans<I>(&mut self, data: I) -> Result<Array<Boolean>, Error>
Write a array_type::Boolean
array.
sourcepub fn array_colors<I>(&mut self, data: I) -> Result<Array<Color>, Error>
pub fn array_colors<I>(&mut self, data: I) -> Result<Array<Color>, Error>
Write a array_type::Color
array.
Values are Option<[u8; 4]>
with channels in RGBA order.
source§impl Writer
impl Writer
sourcepub fn new(file: File) -> Result<Self, Error>
pub fn new(file: File) -> Result<Self, Error>
Creates a writer that writes into a file-like object.
sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, Error>
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.
sourcepub fn compression(&self) -> Compression
pub fn compression(&self) -> Compression
Return the current compression.
sourcepub fn set_compression(&mut self, compression: Compression)
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()
.
sourcepub fn array_bytes<A: ArrayType>(
&mut self,
length: u64,
bytes: &[u8],
) -> Result<Array<A>, Error>
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.
sourcepub fn array_bytes_from<A: ArrayType>(
&mut self,
length: u64,
read: impl Read,
) -> Result<Array<A>, Error>
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.
sourcepub fn image_bytes(&mut self, bytes: &[u8]) -> Result<Array<Image>, Error>
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.