diff options
author | Kostya Shishkov <kostya.shishkov@gmail.com> | 2019-02-14 14:35:29 +0100 |
---|---|---|
committer | Kostya Shishkov <kostya.shishkov@gmail.com> | 2019-04-29 14:36:04 +0200 |
commit | 8efb7386391c5605a81acb38d588ff5111765f05 (patch) | |
tree | 78ba516af871df26a2356213edd24dcf7e026560 /nihav-core/src/formats.rs | |
parent | 171860fcc4a4ba3ec28bc4b720b9f582377be4cf (diff) | |
download | nihav-8efb7386391c5605a81acb38d588ff5111765f05.tar.gz |
formats: some enhancements for upcoming rescale
Diffstat (limited to 'nihav-core/src/formats.rs')
-rw-r--r-- | nihav-core/src/formats.rs | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/nihav-core/src/formats.rs b/nihav-core/src/formats.rs index 0cc24a1..20404bd 100644 --- a/nihav-core/src/formats.rs +++ b/nihav-core/src/formats.rs @@ -309,6 +309,16 @@ impl ColorModel { _ => false, } } + pub fn get_short_name(&self) -> &'static str { + match *self { + ColorModel::RGB(_) => "rgb", + ColorModel::YUV(_) => "yuv", + ColorModel::CMYK => "cmyk", + ColorModel::HSV => "hsv", + ColorModel::LAB => "lab", + ColorModel::XYZ => "xyz", + } + } } impl fmt::Display for ColorModel { @@ -340,12 +350,13 @@ pub const FORMATON_FLAG_BE :u32 = 0x01; pub const FORMATON_FLAG_ALPHA :u32 = 0x02; pub const FORMATON_FLAG_PALETTE :u32 = 0x04; +pub const MAX_CHROMATONS: usize = 5; #[derive(Clone,Copy,PartialEq)] pub struct NAPixelFormaton { pub model: ColorModel, pub components: u8, - pub comp_info: [Option<NAPixelChromaton>; 5], + pub comp_info: [Option<NAPixelChromaton>; MAX_CHROMATONS], pub elem_size: u8, pub be: bool, pub alpha: bool, @@ -466,7 +477,7 @@ impl NAPixelFormaton { comp4: Option<NAPixelChromaton>, comp5: Option<NAPixelChromaton>, flags: u32, elem_size: u8) -> Self { - let mut chromatons: [Option<NAPixelChromaton>; 5] = [None; 5]; + let mut chromatons: [Option<NAPixelChromaton>; MAX_CHROMATONS] = [None; MAX_CHROMATONS]; let mut ncomp = 0; let be = (flags & FORMATON_FLAG_BE) != 0; let alpha = (flags & FORMATON_FLAG_ALPHA) != 0; @@ -493,6 +504,33 @@ impl NAPixelFormaton { pub fn has_alpha(&self) -> bool { self.alpha } pub fn is_paletted(&self) -> bool { self.palette } pub fn get_elem_size(&self) -> u8 { self.elem_size } + pub fn is_unpacked(&self) -> bool { + for chr in self.comp_info.iter() { + if let Some(ref chromaton) = chr { + if chromaton.is_packed() { return false; } + } + } + true + } + pub fn get_max_depth(&self) -> u8 { + let mut mdepth = 0; + for chr in self.comp_info.iter() { + if let Some(ref chromaton) = chr { + mdepth = mdepth.max(chromaton.depth); + } + } + mdepth + } + pub fn get_max_subsampling(&self) -> u8 { + let mut ssamp = 0; + for chr in self.comp_info.iter() { + if let Some(ref chromaton) = chr { + let (ss_v, ss_h) = chromaton.get_subsampling(); + ssamp = ssamp.max(ss_v).max(ss_h); + } + } + ssamp + } } impl fmt::Display for NAPixelFormaton { |