From: Kostya Shishkov Date: Wed, 17 May 2017 14:15:29 +0000 (+0200) Subject: extend formats functionality a bit X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=b68ff5ae2df5af3cc07a8842dcdf949f286618b1;p=nihav.git extend formats functionality a bit --- diff --git a/src/formats.rs b/src/formats.rs index c477723..8e6bc68 100644 --- a/src/formats.rs +++ b/src/formats.rs @@ -1,7 +1,7 @@ use std::string::*; use std::fmt; -#[derive(Debug,Copy,Clone)] +#[derive(Debug,Copy,Clone,PartialEq)] pub struct NASoniton { bits: u8, be: bool, @@ -147,7 +147,7 @@ impl NAChannelMap { } } -#[derive(Debug,Clone,Copy)] +#[derive(Debug,Clone,Copy,PartialEq)] pub enum RGBSubmodel { RGB, SRGB, @@ -163,7 +163,7 @@ impl fmt::Display for RGBSubmodel { } } -#[derive(Debug,Clone,Copy)] +#[derive(Debug,Clone,Copy,PartialEq)] pub enum YUVSubmodel { YCbCr, YIQ, @@ -181,7 +181,7 @@ impl fmt::Display for YUVSubmodel { } } -#[derive(Debug, Clone,Copy)] +#[derive(Debug, Clone,Copy,PartialEq)] pub enum ColorModel { RGB(RGBSubmodel), YUV(YUVSubmodel), @@ -214,7 +214,7 @@ impl fmt::Display for ColorModel { } } -#[derive(Clone,Copy)] +#[derive(Clone,Copy,PartialEq)] pub struct NAPixelChromaton { h_ss: u8, v_ss: u8, @@ -234,7 +234,7 @@ bitflags! { } -#[derive(Clone,Copy)] +#[derive(Clone,Copy,PartialEq)] pub struct NAPixelFormaton { model: ColorModel, components: u8, @@ -268,6 +268,14 @@ pub const YUV420_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel:: None, None], elem_size: 0, be: false, alpha: false, palette: false }; +pub const YUV410_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::YUV(YUVSubmodel::YUVJ), components: 3, + comp_info: [ + chromaton!(0, 0, false, 8, 0, 0, 1), + chromaton!(yuv8; 2, 2, 1), + chromaton!(yuv8; 2, 2, 2), + None, None], + elem_size: 0, be: false, alpha: false, palette: false }; + pub const PAL8_FORMAT: NAPixelFormaton = NAPixelFormaton { model: ColorModel::RGB(RGBSubmodel::RGB), components: 3, comp_info: [ chromaton!(pal8; 0), @@ -299,6 +307,16 @@ impl NAPixelChromaton { pub fn get_shift(&self) -> u8 { self.shift } pub fn get_offset(&self) -> u8 { self.comp_offs } pub fn get_step(&self) -> u8 { self.next_elem } + + pub fn get_linesize(&self, width: usize) -> usize { + let nw = (width + ((1 << self.h_ss) - 1)) >> self.h_ss; + let d = self.depth as usize; + (nw * d + d - 1) >> 3 + } + pub fn get_data_size(&self, width: usize, height: usize) -> usize { + let nh = (height + ((1 << self.v_ss) - 1)) >> self.v_ss; + self.get_linesize(width) * nh + } } impl fmt::Display for NAPixelChromaton { @@ -339,7 +357,7 @@ impl NAPixelFormaton { } pub fn get_model(&self) -> ColorModel { self.model } - pub fn get_num_comp(&self) -> u8 { self.components } + pub fn get_num_comp(&self) -> usize { self.components as usize } pub fn get_chromaton(&self, idx: usize) -> Option { if idx < self.comp_info.len() { return self.comp_info[idx]; } None