]> git.nihav.org Git - nihav.git/blobdiff - nihav-core/src/formats.rs
detect: fix paths for test samples
[nihav.git] / nihav-core / src / formats.rs
index 53b28dcfcdb9ede589ad8c3ee2b3d0d6e0aeb8e8..f7ef8d881caedeb4a8f7062293cb089d49fea814 100644 (file)
@@ -297,6 +297,28 @@ impl ColorModel {
             _                => 3,
         }
     }
+    pub fn is_rgb(&self) -> bool {
+        match *self {
+            ColorModel::RGB(_) => true,
+            _ => false,
+        }
+    }
+    pub fn is_yuv(&self) -> bool {
+        match *self {
+            ColorModel::YUV(_) => true,
+            _ => 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 {
@@ -315,29 +337,30 @@ impl fmt::Display for ColorModel {
 
 #[derive(Clone,Copy,PartialEq)]
 pub struct NAPixelChromaton {
-    h_ss:           u8,
-    v_ss:           u8,
-    packed:         bool,
-    depth:          u8,
-    shift:          u8,
-    comp_offs:      u8,
-    next_elem:      u8,
+    pub h_ss:           u8,
+    pub v_ss:           u8,
+    pub packed:         bool,
+    pub depth:          u8,
+    pub shift:          u8,
+    pub comp_offs:      u8,
+    pub next_elem:      u8,
 }
 
 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 {
-    model:      ColorModel,
-    components: u8,
-    comp_info:  [Option<NAPixelChromaton>; 5],
-    elem_size:  u8,
-    be:         bool,
-    alpha:      bool,
-    palette:    bool,
+    pub model:      ColorModel,
+    pub components: u8,
+    pub comp_info:  [Option<NAPixelChromaton>; MAX_CHROMATONS],
+    pub elem_size:  u8,
+    pub be:         bool,
+    pub alpha:      bool,
+    pub palette:    bool,
 }
 
 macro_rules! chromaton {
@@ -397,13 +420,16 @@ pub const RGB565_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::
 
 pub const RGB24_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::RGB(RGBSubmodel::RGB), components: 3,
                                         comp_info: [
-                                            chromaton!(packrgb; 8, 0, 2, 3),
-                                            chromaton!(packrgb; 8, 0, 1, 3),
                                             chromaton!(packrgb; 8, 0, 0, 3),
+                                            chromaton!(packrgb; 8, 0, 1, 3),
+                                            chromaton!(packrgb; 8, 0, 2, 3),
                                             None, None],
                                         elem_size: 3, be: false, alpha: false, palette: false };
 
 impl NAPixelChromaton {
+    pub fn new(h_ss: u8, v_ss: u8, packed: bool, depth: u8, shift: u8, comp_offs: u8, next_elem: u8) -> Self {
+        Self { h_ss, v_ss, packed, depth, shift, comp_offs, next_elem }
+    }
     pub fn get_subsampling(&self) -> (u8, u8) { (self.h_ss, self.v_ss) }
     pub fn is_packed(&self) -> bool { self.packed }
     pub fn get_depth(&self) -> u8   { self.depth }
@@ -451,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;
@@ -478,6 +504,34 @@ 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 {
+        if self.palette { return false; }
+        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 {