Skip to content

Commit 8734980

Browse files
committed
Add a method to determine the size in pixels for a given format
1 parent c8e2525 commit 8734980

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/decoder.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ pub enum PixelFormat {
3636
CMYK32,
3737
}
3838

39+
impl PixelFormat {
40+
/// Determine the size in bytes of each pixel in this format
41+
pub fn pixel_size(&self) -> usize {
42+
match self {
43+
Self::L8 => 1,
44+
Self::RGB24 => 3,
45+
Self::CMYK32 => 4,
46+
}
47+
}
48+
}
49+
3950
/// Represents metadata of an image.
4051
#[derive(Clone, Copy, Debug, PartialEq)]
4152
pub struct ImageInfo {

0 commit comments

Comments
 (0)