Skip to content

Commit 8bf618a

Browse files
author
HeroicKatora
authored
Merge pull request #113 from danieldulaney/pixel-format-sizes
Add a method to determine the size in pixels for a given format
2 parents e2d3aa2 + 4d0081a commit 8bf618a

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_bytes(&self) -> usize {
42+
match self {
43+
PixelFormat::L8 => 1,
44+
PixelFormat::RGB24 => 3,
45+
PixelFormat::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)