#[derive(Debug,Copy,Clone,PartialEq)]
pub struct NASoniton {
- bits: u8,
- be: bool,
- packed: bool,
- planar: bool,
- float: bool,
- signed: bool,
+ pub bits: u8,
+ pub be: bool,
+ pub packed: bool,
+ pub planar: bool,
+ pub float: bool,
+ pub signed: bool,
}
pub const SONITON_FLAG_BE :u32 = 0x01;
let is_pl = (flags & SONITON_FLAG_PLANAR) != 0;
let is_fl = (flags & SONITON_FLAG_FLOAT) != 0;
let is_sg = (flags & SONITON_FLAG_SIGNED) != 0;
- NASoniton { bits: bits, be: is_be, packed: is_pk, planar: is_pl, float: is_fl, signed: is_sg }
+ NASoniton { bits, be: is_be, packed: is_pk, planar: is_pl, float: is_fl, signed: is_sg }
}
- pub fn get_bits(&self) -> u8 { self.bits }
- pub fn is_be(&self) -> bool { self.be }
- pub fn is_packed(&self) -> bool { self.packed }
- 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_bits(self) -> u8 { self.bits }
+ pub fn is_be(self) -> bool { self.be }
+ pub fn is_packed(self) -> bool { self.packed }
+ 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 {
+ pub fn get_audio_size(self, length: u64) -> usize {
if self.packed {
- ((length * (self.bits as u64) + 7) >> 3) as usize
+ ((length * u64::from(self.bits) + 7) >> 3) as usize
} else {
- (length * (((self.bits + 7) >> 3) as u64)) as usize
+ (length * u64::from((self.bits + 7) >> 3)) as usize
}
}
}
}
impl NAChannelType {
- pub fn is_center(&self) -> bool {
- match *self {
+ pub fn is_center(self) -> bool {
+ match self {
NAChannelType::C => true, NAChannelType::Ch => true,
NAChannelType::Cl => true, NAChannelType::Ov => true,
NAChannelType::LFE => true, NAChannelType::LFE2 => true,
_ => false,
}
}
- pub fn is_left(&self) -> bool {
- match *self {
+ pub fn is_left(self) -> bool {
+ match self {
NAChannelType::L => true, NAChannelType::Ls => true,
NAChannelType::Lss => true, NAChannelType::Lc => true,
NAChannelType::Lh => true, NAChannelType::Lw => true,
_ => false,
}
}
- pub fn is_right(&self) -> bool {
- match *self {
+ pub fn is_right(self) -> bool {
+ match self {
NAChannelType::R => true, NAChannelType::Rs => true,
NAChannelType::Rss => true, NAChannelType::Rc => true,
NAChannelType::Rh => true, NAChannelType::Rw => true,
}
}
-#[derive(Clone)]
+#[derive(Clone,Default)]
pub struct NAChannelMap {
ids: Vec<NAChannelType>,
}
self.ids.push(ch);
}
pub fn add_channels(&mut self, chs: &[NAChannelType]) {
- for i in 0..chs.len() {
- self.ids.push(chs[i]);
+ for e in chs.iter() {
+ self.ids.push(*e);
}
}
pub fn num_channels(&self) -> usize {
}
pub fn from_ms_mapping(chmap: u32) -> Self {
let mut cm = NAChannelMap::new();
- for i in 0..MS_CHANNEL_MAP.len() {
+ for (i, ch) in MS_CHANNEL_MAP.iter().enumerate() {
if ((chmap >> i) & 1) != 0 {
- cm.add_channel(MS_CHANNEL_MAP[i]);
+ cm.add_channel(*ch);
}
}
cm
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut map = String::new();
for el in self.ids.iter() {
- if map.len() > 0 { map.push(','); }
+ if !map.is_empty() { map.push(','); }
map.push_str(&*el.to_string());
}
write!(f, "{}", map)
}
impl ColorModel {
- pub fn get_default_components(&self) -> usize {
- match *self {
+ pub fn get_default_components(self) -> usize {
+ match self {
ColorModel::CMYK => 4,
_ => 3,
}
}
- pub fn is_rgb(&self) -> bool {
- match *self {
+ pub fn is_rgb(self) -> bool {
+ match self {
ColorModel::RGB(_) => true,
_ => false,
}
}
- pub fn is_yuv(&self) -> bool {
- match *self {
+ pub fn is_yuv(self) -> bool {
+ match self {
ColorModel::YUV(_) => true,
_ => false,
}
}
- pub fn get_short_name(&self) -> &'static str {
- match *self {
+ pub fn get_short_name(self) -> &'static str {
+ match self {
ColorModel::RGB(_) => "rgb",
ColorModel::YUV(_) => "yuv",
ColorModel::CMYK => "cmyk",
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 };
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 }
- 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_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 }
+ 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 {
+ 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 {
+ 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 {
+ pub fn get_linesize(self, width: usize) -> usize {
let d = self.depth as usize;
if self.packed {
(self.get_width(width) * d + d - 1) >> 3
self.get_width(width)
}
}
- pub fn get_data_size(&self, width: usize, height: usize) -> usize {
+ 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
}
if let Some(c) = comp3 { chromatons[2] = Some(c); ncomp += 1; }
if let Some(c) = comp4 { chromatons[3] = Some(c); ncomp += 1; }
if let Some(c) = comp5 { chromatons[4] = Some(c); ncomp += 1; }
- NAPixelFormaton { model: model,
+ NAPixelFormaton { model,
components: ncomp,
comp_info: chromatons,
- elem_size: elem_size,
- be: be, alpha: alpha, palette: palette }
+ elem_size,
+ be, alpha, palette }
}
pub fn get_model(&self) -> ColorModel { self.model }
if idx < self.comp_info.len() { return self.comp_info[idx]; }
None
}
- pub fn is_be(&self) -> bool { self.be }
- 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_be(self) -> bool { self.be }
+ 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; }