Enum cameraunit::DynamicSerialImage
source · pub enum DynamicSerialImage {
U8(SerialImageBuffer<u8>),
U16(SerialImageBuffer<u16>),
F32(SerialImageBuffer<f32>),
}
Expand description
Dynamic serial image enumeration. This data type encapsulates the specific serial image data types.
The enumeration variants are DynamicSerialImage::U8
, DynamicSerialImage::U16
, DynamicSerialImage::F32
.
§Traits
DynamicSerialImage
implements the std::clone::Clone
, std::convert::From
, std::convert::TryFrom
, std::convert::Into
and std::fmt::Debug
traits.
Specifically, the following conversions are implemented:
With std::convert::From
:
DynamicSerialImage
<->DynamicImage
DynamicSerialImage
<-SerialImageBuffer<u8>
DynamicSerialImage
<-SerialImageBuffer<u16>
DynamicSerialImage
<-SerialImageBuffer<f32>
With std::convert::TryFrom
:
Variants§
U8(SerialImageBuffer<u8>)
8-bit unsigned integer image data.
U16(SerialImageBuffer<u16>)
16-bit unsigned integer image data.
F32(SerialImageBuffer<f32>)
32-bit floating point image data.
Implementations§
source§impl DynamicSerialImage
impl DynamicSerialImage
sourcepub fn get_metadata(&self) -> Option<ImageMetaData>
pub fn get_metadata(&self) -> Option<ImageMetaData>
Get the image metadata.
sourcepub fn set_metadata(&mut self, meta: ImageMetaData)
pub fn set_metadata(&mut self, meta: ImageMetaData)
Update the image metadata.
sourcepub fn as_u8(&self) -> Option<&SerialImageBuffer<u8>>
pub fn as_u8(&self) -> Option<&SerialImageBuffer<u8>>
Get the underlying SerialImageBuffer<u8>
if the image is of type DynamicSerialImage::U8
.
sourcepub fn as_u16(&self) -> Option<&SerialImageBuffer<u16>>
pub fn as_u16(&self) -> Option<&SerialImageBuffer<u16>>
Get the underlying SerialImageBuffer<u16>
if the image is of type DynamicSerialImage::U16
.
sourcepub fn as_f32(&self) -> Option<&SerialImageBuffer<f32>>
pub fn as_f32(&self) -> Option<&SerialImageBuffer<f32>>
Get the underlying SerialImageBuffer<f32>
if the image is of type DynamicSerialImage::F32
.
sourcepub fn into_luma(&self) -> SerialImageBuffer<u16>
pub fn into_luma(&self) -> SerialImageBuffer<u16>
Convert the image to grayscale. The transformation used is 0.2162 * red + 0.7152 * green + 0.0722 * blue
for converting RGB to grayscale (see here).
sourcepub fn into_luma_alpha(&self) -> SerialImageBuffer<u16>
pub fn into_luma_alpha(&self) -> SerialImageBuffer<u16>
Convert the image to grayscale with alpha channel. The transformation used is 0.2162 * red + 0.7152 * green + 0.0722 * blue
for converting RGB to grayscale (see here).
sourcepub fn resize(
self,
nwidth: usize,
nheight: usize,
filter: FilterType
) -> DynamicSerialImage
pub fn resize( self, nwidth: usize, nheight: usize, filter: FilterType ) -> DynamicSerialImage
Resize this image using the specified filter algorithm.
Returns a new image. The image’s aspect ratio is preserved.
The image is scaled to the maximum possible size that fits
within the bounds specified by nwidth
and nheight
.
sourcepub fn save(&self, path: &str) -> Result<(), ImageError>
pub fn save(&self, path: &str) -> Result<(), ImageError>
Saves the buffer to a file at the path specified.
The image format is derived from the file extension.
png
, jpg
, bmp
, ico
, tiff
and exr
files are supported.
sourcepub fn savefits(
&self,
dir_prefix: &Path,
file_prefix: &str,
progname: Option<&str>,
compress: bool,
overwrite: bool
) -> Result<PathBuf, Error>
pub fn savefits( &self, dir_prefix: &Path, file_prefix: &str, progname: Option<&str>, compress: bool, overwrite: bool ) -> Result<PathBuf, Error>
Save the image data to a FITS file.
§Arguments
dir_prefix
- The directory where the file will be saved.file_prefix
- The prefix of the file name. The file name will be of the form{file_prefix}_{timestamp}.fits
.progname
- The name of the program that generated the image.compress
- Whether to compress the FITS file.overwrite
- Whether to overwrite the file if it already exists.
§Errors
fitsio::errors::Error
with the error description.
source§impl DynamicSerialImage
impl DynamicSerialImage
sourcepub fn from_vec_u8(
width: usize,
height: usize,
data: Vec<u8>
) -> Result<DynamicSerialImage, &'static str>
pub fn from_vec_u8( width: usize, height: usize, data: Vec<u8> ) -> Result<DynamicSerialImage, &'static str>
Create a new image from a vector of u8
pixels.
§Arguments
width
- The width of the image.height
- The height of the image.data
- The image data as a vector ofu8
pixels.
§Errors
- Error messages as strings.
Note: The length of the vector must be width * height * channels
.
- For grayscale images,
channels
is 1. - For grayscale images with alpha channel,
channels
is 2. - For RGB images,
channels
is 3. - For RGBA images,
channels
is 4.
sourcepub fn from_vec_u16(
width: usize,
height: usize,
data: Vec<u16>
) -> Result<DynamicSerialImage, &'static str>
pub fn from_vec_u16( width: usize, height: usize, data: Vec<u16> ) -> Result<DynamicSerialImage, &'static str>
Create a new image from a vector of u16
pixels.
§Arguments
width
- The width of the image.height
- The height of the image.data
- The image data as a vector ofu16
pixels.
§Errors
- Error messages as strings.
Note: The length of the vector must be width * height * channels
.
- For grayscale images,
channels
is 1. - For grayscale images with alpha channel,
channels
is 2. - For RGB images,
channels
is 3. - For RGBA images,
channels
is 4.
sourcepub fn from_vec_f32(
width: usize,
height: usize,
data: Vec<f32>
) -> Result<DynamicSerialImage, &'static str>
pub fn from_vec_f32( width: usize, height: usize, data: Vec<f32> ) -> Result<DynamicSerialImage, &'static str>
Create a new image from a vector of f32
pixels.
§Arguments
width
- The width of the image.height
- The height of the image.data
- The image data as a vector off32
pixels.
§Errors
- Error messages as strings.
Note: The length of the vector must be width * height * channels
. Grayscale images are not supported.
- For RGB images,
channels
is 3. - For RGBA images,
channels
is 4.
Trait Implementations§
source§impl Clone for DynamicSerialImage
impl Clone for DynamicSerialImage
source§fn clone(&self) -> DynamicSerialImage
fn clone(&self) -> DynamicSerialImage
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for DynamicSerialImage
impl Debug for DynamicSerialImage
source§impl<'de> Deserialize<'de> for DynamicSerialImage
impl<'de> Deserialize<'de> for DynamicSerialImage
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<DynamicSerialImage, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<DynamicSerialImage, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl From<&DynamicImage> for DynamicSerialImage
impl From<&DynamicImage> for DynamicSerialImage
source§fn from(value: &DynamicImage) -> DynamicSerialImage
fn from(value: &DynamicImage) -> DynamicSerialImage
source§impl From<&SerialImageBuffer<f32>> for DynamicSerialImage
impl From<&SerialImageBuffer<f32>> for DynamicSerialImage
source§fn from(value: &SerialImageBuffer<f32>) -> DynamicSerialImage
fn from(value: &SerialImageBuffer<f32>) -> DynamicSerialImage
source§impl From<&SerialImageBuffer<u16>> for DynamicSerialImage
impl From<&SerialImageBuffer<u16>> for DynamicSerialImage
source§fn from(value: &SerialImageBuffer<u16>) -> DynamicSerialImage
fn from(value: &SerialImageBuffer<u16>) -> DynamicSerialImage
source§impl From<&SerialImageBuffer<u8>> for DynamicSerialImage
impl From<&SerialImageBuffer<u8>> for DynamicSerialImage
source§fn from(value: &SerialImageBuffer<u8>) -> DynamicSerialImage
fn from(value: &SerialImageBuffer<u8>) -> DynamicSerialImage
source§impl From<DynamicImage> for DynamicSerialImage
impl From<DynamicImage> for DynamicSerialImage
source§fn from(value: DynamicImage) -> DynamicSerialImage
fn from(value: DynamicImage) -> DynamicSerialImage
source§impl From<SerialImageBuffer<f32>> for DynamicSerialImage
impl From<SerialImageBuffer<f32>> for DynamicSerialImage
source§fn from(value: SerialImageBuffer<f32>) -> DynamicSerialImage
fn from(value: SerialImageBuffer<f32>) -> DynamicSerialImage
source§impl From<SerialImageBuffer<u16>> for DynamicSerialImage
impl From<SerialImageBuffer<u16>> for DynamicSerialImage
source§fn from(value: SerialImageBuffer<u16>) -> DynamicSerialImage
fn from(value: SerialImageBuffer<u16>) -> DynamicSerialImage
source§impl From<SerialImageBuffer<u8>> for DynamicSerialImage
impl From<SerialImageBuffer<u8>> for DynamicSerialImage
source§fn from(value: SerialImageBuffer<u8>) -> DynamicSerialImage
fn from(value: SerialImageBuffer<u8>) -> DynamicSerialImage
source§impl PartialEq for DynamicSerialImage
impl PartialEq for DynamicSerialImage
source§fn eq(&self, other: &DynamicSerialImage) -> bool
fn eq(&self, other: &DynamicSerialImage) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for DynamicSerialImage
impl Serialize for DynamicSerialImage
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
source§impl TryInto<SerialImageBuffer<f32>> for &DynamicSerialImage
impl TryInto<SerialImageBuffer<f32>> for &DynamicSerialImage
source§impl TryInto<SerialImageBuffer<f32>> for DynamicSerialImage
impl TryInto<SerialImageBuffer<f32>> for DynamicSerialImage
source§impl TryInto<SerialImageBuffer<u16>> for &DynamicSerialImage
impl TryInto<SerialImageBuffer<u16>> for &DynamicSerialImage
source§impl TryInto<SerialImageBuffer<u16>> for DynamicSerialImage
impl TryInto<SerialImageBuffer<u16>> for DynamicSerialImage
source§impl TryInto<SerialImageBuffer<u8>> for &DynamicSerialImage
impl TryInto<SerialImageBuffer<u8>> for &DynamicSerialImage
source§impl TryInto<SerialImageBuffer<u8>> for DynamicSerialImage
impl TryInto<SerialImageBuffer<u8>> for DynamicSerialImage
impl StructuralPartialEq for DynamicSerialImage
Auto Trait Implementations§
impl Freeze for DynamicSerialImage
impl RefUnwindSafe for DynamicSerialImage
impl Send for DynamicSerialImage
impl Sync for DynamicSerialImage
impl Unpin for DynamicSerialImage
impl UnwindSafe for DynamicSerialImage
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more