else if idx < 280 { 7 }
else { 8 }
}
+ #[allow(clippy::identity_op)]
fn code(&mut self, idx: usize) -> u32 {
let base = idx as u32;
let bits = self.bits(idx);
///! [`DecompressError::ShortData`]: ../enum.DecompressError.html#variant.ShortData
///! [`DecompressError::OutputFull`]: ../enum.DecompressError.html#variant.OutputFull
pub fn decompress_data(&mut self, src: &[u8], dst: &mut [u8], continue_block: bool) -> DecompressResult<usize> {
- if src.len() == 0 || dst.len() == 0 {
+ if src.is_empty() || dst.is_empty() {
return Err(DecompressError::InvalidArgument);
}
let mut csrc = if !continue_block {
self.state = InflateState::End;
return Err(DecompressError::InvalidHeader);
}
- let rpt;
- if mode == 0 {
- if self.cur_len_idx == 0 {
- self.state = InflateState::End;
- return Err(DecompressError::InvalidHeader);
- }
- rpt = self.all_lengths[self.cur_len_idx - 1];
- } else {
- rpt = 0;
- }
+ let rpt = if mode == 0 {
+ if self.cur_len_idx == 0 {
+ self.state = InflateState::End;
+ return Err(DecompressError::InvalidHeader);
+ }
+ self.all_lengths[self.cur_len_idx - 1]
+ } else {
+ 0
+ };
for _ in 0..len {
self.all_lengths[self.cur_len_idx] = rpt;
self.cur_len_idx += 1;
}
}
+impl Default for Inflate {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
fn lengths_to_codes(lens: &[u8], codes: &mut [ShortCodebookDesc]) -> DecompressResult<()> {
let mut bits = [0u32; 32];
let mut pfx = [0u32; 33];
}
impl GzipCRC32 {
+ #[allow(clippy::unreadable_literal)]
fn new() -> Self {
let mut tab = [0u32; 256];
for i in 0..256 {
/// Converts time in given scale into timestamp in given base.
pub fn time_to_ts(time: u64, base: u64, tb_num: u32, tb_den: u32) -> u64 {
- let tb_num = tb_num as u64;
- let tb_den = tb_den as u64;
+ let tb_num = u64::from(tb_num);
+ let tb_den = u64::from(tb_den);
let tmp = time.checked_mul(tb_num);
if let Some(tmp) = tmp {
tmp / base / tb_den
}
/// Converts timestamp in given base into time in given scale.
pub fn ts_to_time(ts: u64, base: u64, tb_num: u32, tb_den: u32) -> u64 {
- let tb_num = tb_num as u64;
- let tb_den = tb_den as u64;
+ let tb_num = u64::from(tb_num);
+ let tb_den = u64::from(tb_den);
let tmp = ts.checked_mul(base);
if let Some(tmp) = tmp {
let tmp2 = tmp.checked_mul(tb_num);
/// # Ok(())
/// # }
/// ````
+#[allow(clippy::identity_op)]
pub fn write_u24be(dst: &mut [u8], val: u32) -> ByteIOResult<()> {
if dst.len() < 3 { return Err(ByteIOError::WriteError); }
dst[0] = (val >> 16) as u8;
Ok(())
}
/// Writes 24-bit little-endian integer to the provided buffer.
+#[allow(clippy::identity_op)]
pub fn write_u24le(dst: &mut [u8], val: u32) -> ByteIOResult<()> {
if dst.len() < 3 { return Err(ByteIOError::WriteError); }
dst[0] = (val >> 0) as u8;
fn write_buf(&mut self, buf: &[u8]) -> ByteIOResult<()> {
if self.pos + buf.len() > self.buf.len() { return Err(ByteIOError::WriteError); }
- for i in 0..buf.len() {
- self.buf[self.pos + i] = buf[i];
- }
+ self.buf[self.pos..][..buf.len()].copy_from_slice(buf);
self.pos += buf.len();
Ok(())
}
if self.pos + buf.len() > self.buf.len() {
self.buf.resize(self.pos + buf.len(), 0);
}
- for i in 0..buf.len() {
- self.buf[self.pos + i] = buf[i];
- }
+ self.buf[self.pos..][..buf.len()].copy_from_slice(buf);
self.pos += buf.len();
Ok(())
}
///
/// [`ShortCodebookDescReader`]: ./struct.ShortCodebookDescReader.html
/// [`TableCodebookDescReader`]: ./struct.TableCodebookDescReader.html
+#[allow(clippy::len_without_is_empty)]
pub trait CodebookDescReader<S> {
/// Returns the codeword length for the provided index.
fn bits(&mut self, idx: usize) -> u8;
pub mod codecs;
#[cfg(feature="compr")]
+#[allow(clippy::manual_memcpy)]
+#[allow(clippy::needless_range_loop)]
pub mod compr;
#[cfg(feature="muxers")]
pub mod options;
pub mod refs;
pub mod reorder;
+#[allow(clippy::collapsible_if)]
+#[allow(clippy::many_single_char_names)]
+#[allow(clippy::needless_range_loop)]
+#[allow(clippy::trivially_copy_pass_by_ref)]
pub mod scale;
+#[allow(clippy::unreadable_literal)]
pub mod soundcvt;
use std::fmt;
/// Common name for keyframe interval option.
-pub const KEYFRAME_OPTION: &'static str = "key_int";
+pub const KEYFRAME_OPTION: &str = "key_int";
/// Common description for keyframe interval option.
-pub const KEYFRAME_OPTION_DESC: &'static str = "Keyframe interval (0 - automatic)";
+pub const KEYFRAME_OPTION_DESC: &str = "Keyframe interval (0 - automatic)";
/// Common name for frame skipping mode.
-pub const FRAME_SKIP_OPTION: &'static str = "frame_skip";
+pub const FRAME_SKIP_OPTION: &str = "frame_skip";
/// Common description for frame skipping mode.
-pub const FRAME_SKIP_OPTION_DESC: &'static str = "Frame skipping mode";
+pub const FRAME_SKIP_OPTION_DESC: &str = "Frame skipping mode";
/// Frame skipping option value for no skipped frames.
-pub const FRAME_SKIP_OPTION_VAL_NONE: &'static str = "none";
+pub const FRAME_SKIP_OPTION_VAL_NONE: &str = "none";
/// Frame skipping option value for decoding only keyframes.
-pub const FRAME_SKIP_OPTION_VAL_KEYFRAME: &'static str = "keyframes";
+pub const FRAME_SKIP_OPTION_VAL_KEYFRAME: &str = "keyframes";
/// Frame skipping option value for decoding only intra frames.
-pub const FRAME_SKIP_OPTION_VAL_INTRA: &'static str = "intra";
+pub const FRAME_SKIP_OPTION_VAL_INTRA: &str = "intra";
/// A list specifying option parsing and validating errors.
#[derive(Clone,Copy,Debug,PartialEq)]
impl NAOptionDefinition {
/// Tries to parse input string(s) as an option and returns new option and number of arguments used (1 or 2) on success.
- pub fn parse(&self, name: &String, value: Option<&String>) -> OptionResult<(NAOption, usize)> {
+ pub fn parse(&self, name: &str, value: Option<&String>) -> OptionResult<(NAOption, usize)> {
let no_name = "no".to_owned() + self.name;
let opt_no_name = "--no".to_owned() + self.name;
- if name == &no_name || name == &opt_no_name {
+ if name == no_name || name == opt_no_name {
match self.opt_type {
NAOptionDefinitionType::Bool => return Ok((NAOption { name: self.name, value: NAValue::Bool(false) }, 1)),
_ => return Err(OptionError::InvalidFormat),
};
}
let opt_name = "--".to_owned() + self.name;
- if self.name != name && &opt_name != name {
+ if self.name != name && opt_name != name {
return Err(OptionError::WrongName);
}
match self.opt_type {
#[test]
fn test_option_parsing() {
let mut def = NAOptionDefinition { name: "option", description: "", opt_type: NAOptionDefinitionType::Float(None, None) };
- assert_eq!(def.parse(&"--option".to_string(), None), Err(OptionError::ParseError));
- assert_eq!(def.parse(&"--nooption".to_string(), None), Err(OptionError::InvalidFormat));
- assert_eq!(def.parse(&"--option".to_string(), Some(&"42".to_string())),
+ assert_eq!(def.parse("--option", None), Err(OptionError::ParseError));
+ assert_eq!(def.parse("--nooption", None), Err(OptionError::InvalidFormat));
+ assert_eq!(def.parse("--option", Some(&"42".to_string())),
Ok((NAOption{name:"option",value: NAValue::Float(42.0)}, 2)));
def.opt_type = NAOptionDefinitionType::Float(None, Some(40.0));
- assert_eq!(def.parse(&"--option".to_string(), Some(&"42".to_string())),
+ assert_eq!(def.parse("--option", Some(&"42".to_string())),
Err(OptionError::InvalidValue));
let def = NAOptionDefinition { name: "option", description: "", opt_type: NAOptionDefinitionType::Bool };
- assert_eq!(def.parse(&"option".to_string(), None),
+ assert_eq!(def.parse("option", None),
Ok((NAOption{name: "option", value: NAValue::Bool(true) }, 1)));
- assert_eq!(def.parse(&"nooption".to_string(), None),
+ assert_eq!(def.parse("nooption", None),
Ok((NAOption{name: "option", value: NAValue::Bool(false) }, 1)));
}
}
}
}
+impl Default for NoReorderer {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl FrameReorderer for NoReorderer {
fn add_frame(&mut self, fref: NAFrameRef) -> bool {
if self.fref.is_none() {
let mut voff = sbuf.get_offset(2);
let src = sbuf.get_data();
let dst = dbuf.get_data_mut().unwrap();
- if self.yscale.len() > 0 {
+ if !self.yscale.is_empty() {
for y in 0..h {
for x in 0..w {
let y = self.yscale[src[yoff + x] as usize];
let mut yoff = sbuf.get_offset(0);
let src = sbuf.get_data();
let dst = dbuf.get_data_mut().unwrap();
- if self.yscale.len() > 0 {
+ if !self.yscale.is_empty() {
for _y in 0..h {
for x in 0..w {
let y = self.yscale[src[yoff + x] as usize];
mod colorcvt;
mod repack;
+#[allow(clippy::module_inception)]
mod scale;
mod palette;
fn new() -> Self { Self { seed: 0x1234 } }
fn next(&mut self) -> u8 {
if (self.seed & 0x8000) != 0 {
- self.seed = (self.seed & 0x7FFF) * 2 ^ 0x1B2B;
+ self.seed = ((self.seed & 0x7FFF) * 2) ^ 0x1B2B;
} else {
self.seed <<= 1;
}
clu1.calc_dist();
clu0.dist + clu1.dist
}
+ #[allow(clippy::cyclomatic_complexity)]
pub fn quantise(&mut self, src: &[Pixel], dst: &mut [[u8; 3]; 256]) {
if src.len() < 3 {
return;
if do_elbg_step {
do_elbg_step = false;
for low_idx in low_u.iter() {
- if high_u.len() == 0 {
+ if high_u.is_empty() {
break;
}
let high_idx_idx = (rng.next() as usize) % high_u.len();
let mut range = 0;
let sqradius = (radius * radius) as f64;
while (idx0 < high) || (idx1 > low) {
- let sqrng = (range * range) as f64;
+ let sqrng = f64::from(range * range);
let a = alpha * (sqradius - sqrng) / sqradius;
range += 1;
if idx0 < high {
pub fn learn(&mut self, src: &[Pixel]) {
let mut bias_radius = (256 / 8) << 6;
let alphadec = (30 + (self.factor - 1) / 3) as f64;
- let initial_alpha = (1 << 10) as f64;
+ let initial_alpha = f64::from(1 << 10);
let npixels = src.len();
}
for i in 0..samples {
- let clr = [src[pos].r as f64, src[pos].g as f64, src[pos].b as f64];
+ let clr = [f64::from(src[pos].r), f64::from(src[pos].g), f64::from(src[pos].b)];
let idx = self.find_node(&clr);
if idx >= SPECIAL_NODES {
let new_alpha = alphadec / initial_alpha;
chr.push(Some(dchr));
}
let mut df = in_fmt.fmt;
- for i in 0..self.ncomps {
- df.comp_info[i] = chr[i];
- }
+ df.comp_info[..self.ncomps].clone_from_slice(&chr[..self.ncomps]);
df.palette = false;
println!(" [intermediate format {}]", df);
let res = alloc_video_buffer(NAVideoInfo::new(in_fmt.width, in_fmt.height, false, df), 3);
}
let mut df = in_fmt.fmt;
df.palette = false;
- for i in 0..self.ncomps {
- df.comp_info[i] = chr[i];
- }
+ df.comp_info[..self.ncomps].clone_from_slice(&chr[..self.ncomps]);
println!(" [intermediate format {}]", df);
let res = alloc_video_buffer(NAVideoInfo::new(in_fmt.width, in_fmt.height, false, df), 3);
if res.is_err() { return Err(ScaleError::AllocError); }
}
}
-fn apply_channel_op<T:Copy>(ch_op: &ChannelOp, src: &Vec<T>, dst: &mut Vec<T>) {
+fn apply_channel_op<T:Copy>(ch_op: &ChannelOp, src: &[T], dst: &mut Vec<T>) {
match *ch_op {
ChannelOp::Passthrough => {
- dst.copy_from_slice(src.as_slice());
+ dst.copy_from_slice(src);
},
ChannelOp::Reorder(ref reorder) => {
for (out, idx) in dst.iter_mut().zip(reorder.iter()) {
};
}
-fn remix_i32(ch_op: &ChannelOp, src: &Vec<i32>, dst: &mut Vec<i32>) {
+fn remix_i32(ch_op: &ChannelOp, src: &[i32], dst: &mut Vec<i32>) {
if let ChannelOp::Remix(ref remix_mat) = ch_op {
let sch = src.len();
for (out, coeffs) in dst.iter_mut().zip(remix_mat.chunks(sch)) {
}
}
-fn remix_f32(ch_op: &ChannelOp, src: &Vec<f32>, dst: &mut Vec<f32>) {
+fn remix_f32(ch_op: &ChannelOp, src: &[f32], dst: &mut Vec<f32>) {
if let ChannelOp::Remix(ref remix_mat) = ch_op {
let sch = src.len();
for (out, coeffs) in dst.iter_mut().zip(remix_mat.chunks(sch)) {
fn cvt_from(val: u8) -> u8 { val }
}
impl FromFmt<u8> for i16 {
- fn cvt_from(val: u8) -> i16 { ((val as i16) - 128).wrapping_mul(0x101) }
+ fn cvt_from(val: u8) -> i16 { (i16::from(val) - 128).wrapping_mul(0x101) }
}
impl FromFmt<u8> for i32 {
- fn cvt_from(val: u8) -> i32 { ((val as i32) - 128).wrapping_mul(0x01010101) }
+ fn cvt_from(val: u8) -> i32 { (i32::from(val) - 128).wrapping_mul(0x01010101) }
}
impl FromFmt<u8> for f32 {
- fn cvt_from(val: u8) -> f32 { ((val as f32) - 128.0) / 128.0 }
+ fn cvt_from(val: u8) -> f32 { (f32::from(val) - 128.0) / 128.0 }
}
impl FromFmt<i16> for u8 {
fn cvt_from(val: i16) -> i16 { val }
}
impl FromFmt<i16> for i32 {
- fn cvt_from(val: i16) -> i32 { (val as i32).wrapping_mul(0x10001) }
+ fn cvt_from(val: i16) -> i32 { i32::from(val).wrapping_mul(0x10001) }
}
impl FromFmt<i16> for f32 {
- fn cvt_from(val: i16) -> f32 { (val as f32) / 32768.0 }
+ fn cvt_from(val: i16) -> f32 { f32::from(val) / 32768.0 }
}
impl FromFmt<i32> for u8 {
}
trait SampleWriter {
- fn store_samples_i32(&mut self, pos: usize, src: &Vec<i32>);
- fn store_samples_f32(&mut self, pos: usize, src: &Vec<f32>);
+ fn store_samples_i32(&mut self, pos: usize, src: &[i32]);
+ fn store_samples_f32(&mut self, pos: usize, src: &[f32]);
}
struct GenericSampleWriter<'a, T:Copy> {
}
impl<'a, T:Copy+FromFmt<i32>+FromFmt<f32>> SampleWriter for GenericSampleWriter<'a, T> {
- fn store_samples_i32(&mut self, pos: usize, src: &Vec<i32>) {
+ fn store_samples_i32(&mut self, pos: usize, src: &[i32]) {
let mut off = pos;
for el in src.iter() {
self.data[off] = (*el).cvt_into();
off += self.stride;
}
}
- fn store_samples_f32(&mut self, pos: usize, src: &Vec<f32>) {
+ fn store_samples_f32(&mut self, pos: usize, src: &[f32]) {
let mut off = pos;
for el in src.iter() {
self.data[off] = (*el).cvt_into();
Self { data, fmt, bpp }
}
- fn store_samples<T:Copy>(&mut self, pos: usize, src: &Vec<T>) where u8: FromFmt<T>, i16: FromFmt<T>, i32: FromFmt<T>, f32: FromFmt<T> {
+ fn store_samples<T:Copy>(&mut self, pos: usize, src: &[T]) where u8: FromFmt<T>, i16: FromFmt<T>, i32: FromFmt<T>, f32: FromFmt<T> {
let mut offset = pos * self.bpp * src.len();
for el in src.iter() {
let dst = &mut self.data[offset..];
match (self.bpp, self.fmt.be) {
(4, true) => write_f32be(dst, f32::cvt_from(*el)).unwrap(),
(4, false) => write_f32le(dst, f32::cvt_from(*el)).unwrap(),
- (8, true) => write_f64be(dst, f32::cvt_from(*el) as f64).unwrap(),
- (8, false) => write_f64le(dst, f32::cvt_from(*el) as f64).unwrap(),
+ (8, true) => write_f64be(dst, f64::from(f32::cvt_from(*el))).unwrap(),
+ (8, false) => write_f64le(dst, f64::from(f32::cvt_from(*el))).unwrap(),
(_, _) => unreachable!(),
};
}
}
impl SampleWriter for PackedSampleWriter<'_> {
- fn store_samples_i32(&mut self, pos: usize, src: &Vec<i32>) {
+ fn store_samples_i32(&mut self, pos: usize, src: &[i32]) {
self.store_samples(pos, src);
}
- fn store_samples_f32(&mut self, pos: usize, src: &Vec<f32>) {
+ fn store_samples_f32(&mut self, pos: usize, src: &[f32]) {
self.store_samples(pos, src);
}
}
return Ok(src.clone());
}
- let ret = alloc_audio_buffer(dst_info.clone(), nsamples, dst_chmap.clone());
+ let ret = alloc_audio_buffer(*dst_info, nsamples, dst_chmap.clone());
if ret.is_err() {
return Err(SoundConvertError::AllocError);
}