From 348c7dbc56ffbe490be4cdfb51d886379ea2008f Mon Sep 17 00:00:00 2001 From: Josh Holmer Date: Tue, 30 Jan 2018 22:21:31 -0500 Subject: [PATCH] Extract a function into a submodule --- src/colors.rs | 10 ++++++++++ src/png/mod.rs | 7 +------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/colors.rs b/src/colors.rs index dd6e7866..c06e7dd9 100644 --- a/src/colors.rs +++ b/src/colors.rs @@ -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)] diff --git a/src/png/mod.rs b/src/png/mod.rs index ebc38d25..5f1e9a90 100644 --- a/src/png/mod.rs +++ b/src/png/mod.rs @@ -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