Extract a function into a submodule

This commit is contained in:
Josh Holmer 2018-01-30 22:21:31 -05:00
parent 3497040b78
commit 348c7dbc56
2 changed files with 11 additions and 6 deletions

View file

@ -44,6 +44,16 @@ impl ColorType {
ColorType::RGBA => 6,
}
}
#[inline]
pub fn channels_per_pixel(&self) -> u8 {
match *self {
ColorType::Grayscale | ColorType::Indexed => 1,
ColorType::GrayscaleAlpha => 2,
ColorType::RGB => 3,
ColorType::RGBA => 4,
}
}
}
#[derive(Debug, PartialEq, Clone, Copy)]

View file

@ -172,12 +172,7 @@ impl PngData {
/// Return the number of channels in the image, based on color type
#[inline]
pub fn channels_per_pixel(&self) -> u8 {
match self.ihdr_data.color_type {
ColorType::Grayscale | ColorType::Indexed => 1,
ColorType::GrayscaleAlpha => 2,
ColorType::RGB => 3,
ColorType::RGBA => 4,
}
self.ihdr_data.color_type.channels_per_pixel()
}
/// Format the `PngData` struct into a valid PNG bytestream