return Err(DecompressError::InvalidData);
}
let cstart = (self.bpos.wrapping_sub(offset)) & mask;
- for i in 0..len {
+ for (i, out) in dst[..len].iter_mut().enumerate() {
self.buf[(self.bpos + i) & mask] = self.buf[(cstart + i) & mask];
- dst[i] = self.buf[(cstart + i) & mask];
+ *out = self.buf[(cstart + i) & mask];
}
self.bpos = (self.bpos + len) & mask;
self.full_pos += len;
}
impl GzipCRC32 {
- #[allow(clippy::unreadable_literal)]
fn new() -> Self {
let mut tab = [0u32; 256];
- for i in 0..256 {
+ for (i, el) in tab.iter_mut().enumerate() {
let mut c = i as u32;
for _ in 0..8 {
if (c & 1) != 0 {
c >>= 1;
}
}
- tab[i] = c;
+ *el = c;
}
Self { tab, crc: 0 }
}
for i in 0..shift_len {
tail[i] = tail[i + inlen];
}
- for i in shift_len..8 {
- tail[i] = inblk[i - shift_len];
- }
+ tail[shift_len..8].copy_from_slice(&inblk[..8 - shift_len]);
}
}
if !skip_crc {
}
fn write_len_bits(&mut self, len: u16) {
let llen = len - 3;
- if llen >= 8 && llen < 255 {
+ if (8..255).contains(&llen) {
let bits = (16 - llen.leading_zeros() - 3) as u8;
self.write(llen & ((1 << bits) - 1), bits);
}
//! Various compression formats support.
#[cfg(feature="deflate")]
-#[allow(clippy::manual_range_contains)]
pub mod deflate;
use crate::io::byteio::ByteIOError;
start_shift = start_shift.min(comp.shift);
if comp.comp_offs != 0 { use_shift = false; }
}
- for component in 0..(self.components as usize) {
+ for dname in name[..(self.components as usize)].iter_mut() {
for (comp, cname) in self.comp_info.iter().zip(b"rgba".iter()) {
if let Some(comp) = comp {
if use_shift {
if comp.shift == start_shift {
- name[component] = *cname;
+ *dname = *cname;
start_shift += comp.depth;
}
} else if comp.comp_offs == start_off {
- name[component] = *cname;
+ *dname = *cname;
if planar {
start_off += 1;
} else {
},
5551 => {
let mut offs = [0; 4];
- let depth = [ 5, 5, 5, 1 ];
let mut cur_off = 0;
- for comp in 0..4 {
+ for (comp, &depth) in [ 5, 5, 5, 1 ].iter().enumerate() {
for (off, ord) in offs.iter_mut().zip(order.iter()) {
if *ord == comp {
*off = cur_off;
- cur_off += depth[comp];
+ cur_off += depth;
break;
}
}
self.flush();
}
/// Writes `bits` bits of `val` value to the output.
- #[allow(clippy::collapsible_if)]
#[allow(clippy::collapsible_else_if)]
pub fn write(&mut self, val: u32, bits: u8) {
if bits == 0 {
Ok(read_size)
}
- #[allow(unused_variables)]
- fn write_buf(&mut self, buf: &[u8]) -> ByteIOResult<()> {
+ fn write_buf(&mut self, _buf: &[u8]) -> ByteIOResult<()> {
Err(ByteIOError::NotImplemented)
}
Ok(size)
}
- #[allow(unused_variables)]
- fn write_buf(&mut self, buf: &[u8]) -> ByteIOResult<()> {
+ fn write_buf(&mut self, _buf: &[u8]) -> ByteIOResult<()> {
Err(ByteIOError::NotImplemented)
}
Ok(size)
}
- #[allow(unused_variables)]
- fn write_buf(&mut self, buf: &[u8]) -> ByteIOResult<()> {
+ fn write_buf(&mut self, _buf: &[u8]) -> ByteIOResult<()> {
Err(ByteIOError::NotImplemented)
}
}
impl<'a> ByteIO for MemoryWriter<'a> {
- #[allow(unused_variables)]
fn read_byte(&mut self) -> ByteIOResult<u8> {
Err(ByteIOError::NotImplemented)
}
- #[allow(unused_variables)]
fn peek_byte(&mut self) -> ByteIOResult<u8> {
Err(ByteIOError::NotImplemented)
}
- #[allow(unused_variables)]
- fn read_buf(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+ fn read_buf(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
Err(ByteIOError::NotImplemented)
}
- #[allow(unused_variables)]
- fn read_buf_some(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+ fn read_buf_some(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
Err(ByteIOError::NotImplemented)
}
- #[allow(unused_variables)]
- fn peek_buf(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+ fn peek_buf(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
Err(ByteIOError::NotImplemented)
}
}
impl<'a> ByteIO for GrowableMemoryWriter<'a> {
- #[allow(unused_variables)]
fn read_byte(&mut self) -> ByteIOResult<u8> {
Err(ByteIOError::NotImplemented)
}
- #[allow(unused_variables)]
fn peek_byte(&mut self) -> ByteIOResult<u8> {
Err(ByteIOError::NotImplemented)
}
- #[allow(unused_variables)]
- fn read_buf(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+ fn read_buf(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
Err(ByteIOError::NotImplemented)
}
- #[allow(unused_variables)]
- fn read_buf_some(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+ fn read_buf_some(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
Err(ByteIOError::NotImplemented)
}
- #[allow(unused_variables)]
- fn peek_buf(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+ fn peek_buf(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
Err(ByteIOError::NotImplemented)
}
}
impl<T: Write+Seek> ByteIO for FileWriter<T> {
- #[allow(unused_variables)]
fn read_byte(&mut self) -> ByteIOResult<u8> {
Err(ByteIOError::NotImplemented)
}
- #[allow(unused_variables)]
fn peek_byte(&mut self) -> ByteIOResult<u8> {
Err(ByteIOError::NotImplemented)
}
- #[allow(unused_variables)]
- fn read_buf(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+ fn read_buf(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
Err(ByteIOError::NotImplemented)
}
- #[allow(unused_variables)]
- fn read_buf_some(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+ fn read_buf_some(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
Err(ByteIOError::NotImplemented)
}
- #[allow(unused_variables)]
- fn peek_buf(&mut self, buf: &mut [u8]) -> ByteIOResult<usize> {
+ fn peek_buf(&mut self, _buf: &mut [u8]) -> ByteIOResult<usize> {
Err(ByteIOError::NotImplemented)
}
}
impl<'a, S: Copy> CodebookReader<S> for BitReader<'a> {
- #[allow(unused_variables)]
fn read_cb(&mut self, cb: &Codebook<S>) -> CodebookResult<S> {
let mut esc = true;
let mut idx = 0;
UintCodeType::GammaP => read_gammap(self),
}
}
- #[allow(unused_variables)]
fn read_code_signed(&mut self, t: IntCodeType) -> BitReaderResult<i32> {
let uval =
match t {
IntCodeType::GammaP => read_gammap(self)?,
};
match t {
- IntCodeType::Golomb(m) => Ok(uval_to_sval0mp(uval)),
- IntCodeType::Rice(k) => Ok(uval_to_sval0mp(uval)),
+ IntCodeType::Golomb(_) => Ok(uval_to_sval0mp(uval)),
+ IntCodeType::Rice(_) => Ok(uval_to_sval0mp(uval)),
IntCodeType::Gamma => Ok(uval_to_sval0pm(uval)),
IntCodeType::GammaP => Ok(uval_to_sval0pm(uval)),
}
//! Core functionality of NihAV intended to be used by both crates implementing format support and users.
#[cfg(feature="decoders")]
#[allow(clippy::upper_case_acronyms)]
-#[allow(clippy::cast_lossless)]
-#[allow(clippy::identity_op)]
#[allow(clippy::too_many_arguments)]
-#[allow(clippy::unreadable_literal)]
pub mod codecs;
#[cfg(feature="compr")]
-#[allow(clippy::manual_memcpy)]
-#[allow(clippy::needless_range_loop)]
pub mod compr;
#[cfg(feature="muxers")]
#[cfg(feature="demuxers")]
pub mod demuxers;
-#[allow(clippy::needless_range_loop)]
#[allow(clippy::too_many_arguments)]
pub mod formats;
pub mod frame;
pub mod refs;
pub mod reorder;
#[allow(clippy::upper_case_acronyms)]
-#[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;
#[allow(dead_code)]
pub fn new(initial_pal: &[[u8; 3]; 256]) -> Self {
let mut clusters = Vec::with_capacity(256);
- for i in 0..256 {
- let pix = Pixel { r: initial_pal[i][0], g: initial_pal[i][1], b: initial_pal[i][2] };
+ for clr in initial_pal.iter() {
+ let pix = Pixel { r: clr[0], g: clr[1], b: clr[2] };
let cluster = Cluster::new(pix);
clusters.push(cluster);
}
let mut do_elbg_step = true;
while (iterations < 10) && (dist < prev_dist - prev_dist / 100) {
prev_dist = dist;
- for i in 0..256 {
- old_cb[i] = self.clusters[i].centroid;
- self.clusters[i].reset();
+ for (cb, cluster) in old_cb.iter_mut().zip(self.clusters.iter_mut()) {
+ *cb = cluster.centroid;
+ cluster.reset();
}
// put pixels into the nearest clusters
indices.clear();
let mut closest_idx = *low_idx;
let mut closest_dist = std::u32::MAX;
let low_centr = self.clusters[*low_idx].centroid;
- for i in 0..256 {//low_u.iter() {
- if i == *low_idx || used[i] {
+ for (i, (cluster, &used)) in self.clusters.iter().zip(used.iter()).enumerate() {//low_u.iter() {
+ if i == *low_idx || used {
continue;
}
- let dist = self.clusters[i].centroid.dist(low_centr);
+ let dist = cluster.centroid.dist(low_centr);
if closest_dist > dist {
closest_dist = dist;
closest_idx = i;
iterations += 1;
}
if dist < prev_dist {
- for i in 0..256 {
- old_cb[i] = self.clusters[i].centroid;
+ for (cb, cluster) in old_cb.iter_mut().zip(self.clusters.iter()) {
+ *cb = cluster.centroid;
}
}
for i in 0..256 {
for pix in arr.iter() {
counts[idx(pix)] += 1;
}
- for i in 0..256 {
- buckets.push(Vec::with_capacity(counts[i]));
+ for &count in counts.iter() {
+ buckets.push(Vec::with_capacity(count));
}
for pix in arr.iter() {
buckets[idx(pix)].push(*pix);
const SPECIAL_NODES: usize = 2;
impl NeuQuantQuantiser {
+ #[allow(clippy::needless_range_loop)]
pub fn new(factor: usize) -> Self {
let mut weights = [[0.0; 3]; 256];
if SPECIAL_NODES > 1 {
}
let mut min = [255u8; 3];
let mut max = [0u8; 3];
- for i in start..end {
- for comp in 0..3 {
- min[comp] = min[comp].min(pal[i][comp]);
- max[comp] = max[comp].max(pal[i][comp]);
+ for clr in pal[start..end].iter() {
+ for ((mi, ma), &c) in min.iter_mut().zip(max.iter_mut()).zip(clr.iter()) {
+ *mi = (*mi).min(c);
+ *ma = (*ma).max(c);
}
}
let dr = max[0] - min[0];
if let Some(ref buf) = pic_in.get_vbuf() {
let step = buf.get_info().get_format().elem_size as usize;
let mut soff: [usize; MAX_CHROMATONS] = [0; MAX_CHROMATONS];
- for i in 0..self.ncomps {
- soff[i] = buf.get_info().get_format().get_chromaton(i).unwrap().get_offset() as usize;
+ for (i, off) in soff[..self.ncomps].iter_mut().enumerate() {
+ *off = buf.get_info().get_format().get_chromaton(i).unwrap().get_offset() as usize;
}
let (w, h) = buf.get_dimensions(0);
let ioff = buf.get_offset(0);
if ychr.next_elem == 0 || usize::from(ychr.next_elem) == step {
for src in sdata.chunks(istride).take(h) {
for x in 0..w {
- for i in 0..self.ncomps {
- dst[offs[i] + x] = src[x * step + soff[i]];
+ for (&doff, &soff) in offs[..self.ncomps].iter().zip(soff.iter()) {
+ dst[doff + x] = src[x * step + soff];
}
}
- for i in 0..self.ncomps { offs[i] += ostride[i]; }
+ for (off, &stride) in offs[..self.ncomps].iter_mut().zip(ostride.iter()) {
+ *off += stride;
+ }
}
} else {
let mut steps: [usize; MAX_CHROMATONS] = [0; MAX_CHROMATONS];
- for i in 0..self.ncomps {
- steps[i] = buf.get_info().get_format().get_chromaton(i).unwrap().next_elem as usize;
+ for (i, step) in steps[..self.ncomps].iter_mut().enumerate() {
+ *step = buf.get_info().get_format().get_chromaton(i).unwrap().next_elem as usize;
}
for src in sdata.chunks(istride).take(h) {
let norm = std::f32::consts::PI * std::f32::consts::PI;
let frac = (num as f32) / (den as f32);
let a = order as f32;
- for i in 0..(order * 2) {
+ for (i, coef) in coeffs[..order * 2].iter_mut().enumerate() {
let x = frac - ((i as f32) + 1.0 - a);
let fp = std::f32::consts::PI * x;
- coeffs[i] = a * fp.sin() * (fp / a).sin() / (norm * x * x);
+ *coef = a * fp.sin() * (fp / a).sin() / (norm * x * x);
}
}
fn create_cache(order: usize, den: usize) -> Vec<Vec<f32>> {