#[repr(C)]pub struct Dimensions {
pub width: u32,
pub height: u32,
}Expand description
Width and height of an image, in pixels.
#[repr(C)]: the layout — width then height, two u32s — is a public guarantee so the
value can cross the C ABI boundary as-is (issue #242).
Fields§
§width: u32Image width in pixels.
height: u32Image height in pixels.
Implementations§
Source§impl Dimensions
impl Dimensions
Sourcepub fn new(width: u32, height: u32) -> Result<Self>
pub fn new(width: u32, height: u32) -> Result<Self>
Creates dimensions, rejecting a zero width or height.
The fields stay public for ergonomic struct literals; this constructor is the validated
path that buffer types (crate::ImageRef) and codecs use so an empty image is caught
once, at the boundary, rather than re-checked in every encoder.
§Errors
Returns Error::InvalidInput if either dimension is zero.
Sourcepub fn num_pixels(self) -> Option<usize>
pub fn num_pixels(self) -> Option<usize>
The pixel count width * height, or None if it overflows usize.
Sourcepub fn sample_count(self, channels: usize) -> Option<usize>
pub fn sample_count(self, channels: usize) -> Option<usize>
The sample count for an interleaved buffer of channels samples per pixel
(width * height * channels), or None on overflow. The length an crate::ImageRef
validates against.