use std::string::*;
use std::fmt;
-#[derive(Debug,Copy,Clone)]
+#[derive(Debug,Copy,Clone,PartialEq)]
pub struct NASoniton {
bits: u8,
be: bool,
pub fn is_planar(&self) -> bool { self.planar }
pub fn is_float(&self) -> bool { self.float }
pub fn is_signed(&self) -> bool { self.signed }
+
+ pub fn get_audio_size(&self, length: u64) -> usize {
+ if self.packed {
+ ((length * (self.bits as u64) + 7) >> 3) as usize
+ } else {
+ (length * (((self.bits + 7) >> 3) as u64)) as usize
+ }
+ }
}
impl fmt::Display for NASoniton {
}
}
-#[derive(Debug,Clone,Copy)]
+#[derive(Debug,Clone,Copy,PartialEq)]
pub enum NAChannelType {
C, L, R, Cs, Ls, Rs, Lss, Rss, LFE, Lc, Rc, Lh, Rh, Ch, LFE2, Lw, Rw, Ov, Lhs, Rhs, Chs, Ll, Rl, Cl, Lt, Rt, Lo, Ro
}
}
}
+#[derive(Clone)]
pub struct NAChannelMap {
ids: Vec<NAChannelType>,
}
pub fn add_channel(&mut self, ch: NAChannelType) {
self.ids.push(ch);
}
+ pub fn add_channels(&mut self, chs: &[NAChannelType]) {
+ for i in 0..chs.len() {
+ self.ids.push(chs[i]);
+ }
+ }
pub fn num_channels(&self) -> usize {
self.ids.len()
}
}
}
-#[derive(Debug,Clone,Copy)]
+#[derive(Debug,Clone,Copy,PartialEq)]
pub enum RGBSubmodel {
RGB,
SRGB,
}
}
-#[derive(Debug,Clone,Copy)]
+#[derive(Debug,Clone,Copy,PartialEq)]
pub enum YUVSubmodel {
YCbCr,
YIQ,
}
}
-#[derive(Debug, Clone,Copy)]
+#[derive(Debug, Clone,Copy,PartialEq)]
pub enum ColorModel {
RGB(RGBSubmodel),
YUV(YUVSubmodel),
}
}
-#[derive(Clone,Copy)]
+#[derive(Clone,Copy,PartialEq)]
pub struct NAPixelChromaton {
h_ss: u8,
v_ss: u8,
}
-#[derive(Clone,Copy)]
+#[derive(Clone,Copy,PartialEq)]
pub struct NAPixelFormaton {
model: ColorModel,
components: u8,
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),
None, None],
elem_size: 2, be: false, alpha: false, palette: false };
+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),
+ None, None],
+ elem_size: 3, be: false, alpha: false, palette: false };
+
impl NAPixelChromaton {
pub fn get_subsampling(&self) -> (u8, u8) { (self.h_ss, self.v_ss) }
pub fn is_packed(&self) -> bool { self.packed }
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_width(&self, width: usize) -> usize {
+ (width + ((1 << self.h_ss) - 1)) >> self.h_ss
+ }
+ pub fn get_height(&self, height: usize) -> usize {
+ (height + ((1 << self.v_ss) - 1)) >> self.v_ss
+ }
+ pub fn get_linesize(&self, width: usize) -> usize {
+ let d = self.depth as usize;
+ (self.get_width(width) * 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 {
}
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<NAPixelChromaton> {
if idx < self.comp_info.len() { return self.comp_info[idx]; }
None