Expand description
§serialimage
This crate extends the image
crate with serializable DynamicImage
s: the DynamicSerialImage
s.
Additionally, it implements an ImageMetaData
struct to pack additional metadata information.
Note, however, the metadata information is lost on conversion from DynamicSerialImage
to DynamicImage
.
The DynamicSerialImage
struct stores the image data internally in separate channels without additional overhead.
Similar to the image
crate, the internal image buffer (SerialImageBuffer
for serialimage
) supports base data
types of u8
, u16
and f32
. SerialImageBuffer<u8>
and SerialImageBuffer<u16>
structs support both grayscale
and RGB images. The SerialImageBuffer<f32>
struct only supports RGB images. Alpha channels are supported for all three types.
Conversions between image
and serialimage
data types incur memory copy overheads only when the channel
count is > 1, i.e. the images are RGB or contain transparency data due to the differences in memory layout.
§Usage
Add the following to your Cargo.toml
:
[dependencies]
serialimage = "4.1"
and the following to your source code:
use serialimage::{DynamicSerialImage, ImageMetaData};
Then, you can create a new image metadata object:
let meta = ImageMetaData::new(...);
Then, a DynamicSerialImage
can be created from a DynamicImage
. For example, with a DynamicImage
from a Luma<u16>
pixel type image buffer,
let img = DynamicImage::from(ImageBuffer::<Luma<u16>, Vec<u16>>::new(10, 10)); // create DynamicImage
let mut img = DynamicSerialImage::from(img); // create DynamicSerialImage
img.set_metadata(meta); // set the metadata
let imgstr = serde_json::to_string(&img).unwrap(); // serialize
let simg: DynamicSerialImage = serde_json::from_str(&imgstr).unwrap(); // deserialize
assert_eq!(img, simg);
Now img
can be sent on its merry way with full serialization
§Traits
DynamicSerialImage
and SerialImageBuffer
implements the TryFrom
and TryInto
traits
for image::DynamicImage
and image::ImageBuffer
.
§Optional Features
Additionally, the Serial
image types optionally support saving as FITS images (method savefits()
).
This feature is not enabled by default, and is available behind the fitsio
feature flag.
This feature flag can be enabled to allow for FITS image storage.
Add the following to your Cargo.toml
to enable this:
[dependencies]
serialimage = { version = "3.0.0", features = ["fitsio"] }
The FITS I/O is hidden behind a feature flag to avoid compilation errors on wasm
targets.
Structs§
- Image
Meta Data - Image metadata structure.
This structure implements the
std::fmt::Display
andstd::clone::Clone
traits. - Optimum
Exposure - Configuration used to find the optimum exposure.
- Optimum
Exposure Builder - Builder for the [
serialimage::OptimumExposure
] calculator. - Serial
Image Buffer - A serializable image data container for
u8
,u16
andf32
pixel types.
Enums§
- Dynamic
Serial Image - Dynamic serial image enumeration. This data type encapsulates the specific serial image data types.
- Image
Format - An enumeration of supported image formats. Not all formats support both encoding and decoding.
Traits§
- Primitive
- The type of each channel in a pixel. For example, this can be
u8
,u16
,f32
.
Type Aliases§
- Image
Result - Result of an image decoding/encoding process
- Option
Vec - Optional vector type alias.
- Tuple
Option Vec - Optional vector tuple type alias.