pub struct Header {
pub width: u32,
pub height: u32,
pub channels: Channels,
pub colorspace: ColorSpace,
}
Expand description
Image header: dimensions, channels, color space.
§Notes
A valid image header must satisfy the following conditions:
- Both width and height must be non-zero.
- Maximum number of pixels is 400Mp (=4e8 pixels).
Fields§
§width: u32
Image width in pixels
height: u32
Image height in pixels
channels: Channels
Number of 8-bit channels per pixel
colorspace: ColorSpace
Color space (informative field, doesn’t affect encoding)
Implementations§
source§impl Header
impl Header
sourcepub const fn try_new(
width: u32,
height: u32,
channels: Channels,
colorspace: ColorSpace,
) -> Result<Self>
pub const fn try_new( width: u32, height: u32, channels: Channels, colorspace: ColorSpace, ) -> Result<Self>
Creates a new header and validates image dimensions.
sourcepub const fn with_channels(self, channels: Channels) -> Self
pub const fn with_channels(self, channels: Channels) -> Self
Creates a new header with modified channels.
sourcepub const fn with_colorspace(self, colorspace: ColorSpace) -> Self
pub const fn with_colorspace(self, colorspace: ColorSpace) -> Self
Creates a new header with modified color space.
sourcepub(crate) fn decode(data: impl AsRef<[u8]>) -> Result<Self>
pub(crate) fn decode(data: impl AsRef<[u8]>) -> Result<Self>
Deserializes the header from a byte array.
sourcepub const fn n_bytes(&self) -> usize
pub const fn n_bytes(&self) -> usize
Returns the total number of bytes in the raw pixel array.
This may come useful when pre-allocating a buffer to decode the image into.
sourcepub fn encode_max_len(&self) -> usize
pub fn encode_max_len(&self) -> usize
The maximum number of bytes the encoded image will take.
Can be used to pre-allocate the buffer to encode the image into.
Trait Implementations§
impl Copy for Header
impl Eq for Header
impl StructuralPartialEq for Header
Auto Trait Implementations§
impl Freeze for Header
impl RefUnwindSafe for Header
impl Send for Header
impl Sync for Header
impl Unpin for Header
impl UnwindSafe for Header
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)