projects
/
nihav.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
36ce88b
)
core: fix or silence clippy warnings
author
Kostya Shishkov
<kostya.shishkov@gmail.com>
Tue, 16 Jun 2020 10:08:29 +0000
(12:08 +0200)
committer
Kostya Shishkov
<kostya.shishkov@gmail.com>
Tue, 16 Jun 2020 10:08:29 +0000
(12:08 +0200)
13 files changed:
nihav-core/src/compr/deflate.rs
patch
|
blob
|
blame
|
history
nihav-core/src/frame.rs
patch
|
blob
|
blame
|
history
nihav-core/src/io/byteio.rs
patch
|
blob
|
blame
|
history
nihav-core/src/io/codebook.rs
patch
|
blob
|
blame
|
history
nihav-core/src/lib.rs
patch
|
blob
|
blame
|
history
nihav-core/src/options.rs
patch
|
blob
|
blame
|
history
nihav-core/src/reorder.rs
patch
|
blob
|
blame
|
history
nihav-core/src/scale/colorcvt.rs
patch
|
blob
|
blame
|
history
nihav-core/src/scale/mod.rs
patch
|
blob
|
blame
|
history
nihav-core/src/scale/palette/elbg.rs
patch
|
blob
|
blame
|
history
nihav-core/src/scale/palette/neuquant.rs
patch
|
blob
|
blame
|
history
nihav-core/src/scale/repack.rs
patch
|
blob
|
blame
|
history
nihav-core/src/soundcvt/mod.rs
patch
|
blob
|
blame
|
history
diff --git
a/nihav-core/src/compr/deflate.rs
b/nihav-core/src/compr/deflate.rs
index 1b3dc68290ccdde1977025d9e2623c21abf9109a..89e8b6874ea4ae71005f8130fd92818697bb76eb 100644
(file)
--- a/
nihav-core/src/compr/deflate.rs
+++ b/
nihav-core/src/compr/deflate.rs
@@
-72,6
+72,7
@@
impl CodebookDescReader<u16> for FixedLenCodeReader {
else if idx < 280 { 7 }
else { 8 }
}
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);
fn code(&mut self, idx: usize) -> u32 {
let base = idx as u32;
let bits = self.bits(idx);
@@
-355,7
+356,7
@@
impl Inflate {
///! [`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> {
///! [`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 {
return Err(DecompressError::InvalidArgument);
}
let mut csrc = if !continue_block {
@@
-597,16
+598,15
@@
impl Inflate {
self.state = InflateState::End;
return Err(DecompressError::InvalidHeader);
}
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;
for _ in 0..len {
self.all_lengths[self.cur_len_idx] = rpt;
self.cur_len_idx += 1;
@@
-720,6
+720,12
@@
impl Inflate {
}
}
}
}
+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];
fn lengths_to_codes(lens: &[u8], codes: &mut [ShortCodebookDesc]) -> DecompressResult<()> {
let mut bits = [0u32; 32];
let mut pfx = [0u32; 33];
@@
-757,6
+763,7
@@
struct GzipCRC32 {
}
impl GzipCRC32 {
}
impl GzipCRC32 {
+ #[allow(clippy::unreadable_literal)]
fn new() -> Self {
let mut tab = [0u32; 256];
for i in 0..256 {
fn new() -> Self {
let mut tab = [0u32; 256];
for i in 0..256 {
diff --git
a/nihav-core/src/frame.rs
b/nihav-core/src/frame.rs
index 6386d6f80902c7b2c7ba9e72487e9b2c396dc029..8944f45bf5de6453c0990aec892f283cfc778b68 100644
(file)
--- a/
nihav-core/src/frame.rs
+++ b/
nihav-core/src/frame.rs
@@
-927,8
+927,8
@@
impl NATimeInfo {
/// 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 {
/// 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
let tmp = time.checked_mul(tb_num);
if let Some(tmp) = tmp {
tmp / base / tb_den
@@
-949,8
+949,8
@@
impl NATimeInfo {
}
/// 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 {
}
/// 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);
let tmp = ts.checked_mul(base);
if let Some(tmp) = tmp {
let tmp2 = tmp.checked_mul(tb_num);
diff --git
a/nihav-core/src/io/byteio.rs
b/nihav-core/src/io/byteio.rs
index ff899fc8a0d95b0b0e457813340bfb5c87c42eaa..7da5e2232a902d5307813b0ae2a1a237fcb76d2b 100644
(file)
--- a/
nihav-core/src/io/byteio.rs
+++ b/
nihav-core/src/io/byteio.rs
@@
-200,6
+200,7
@@
write_int_func!(write_u64le, u64, 8, to_le);
/// # Ok(())
/// # }
/// ````
/// # 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;
pub fn write_u24be(dst: &mut [u8], val: u32) -> ByteIOResult<()> {
if dst.len() < 3 { return Err(ByteIOError::WriteError); }
dst[0] = (val >> 16) as u8;
@@
-208,6
+209,7
@@
pub fn write_u24be(dst: &mut [u8], val: u32) -> ByteIOResult<()> {
Ok(())
}
/// Writes 24-bit little-endian integer to the provided buffer.
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;
pub fn write_u24le(dst: &mut [u8], val: u32) -> ByteIOResult<()> {
if dst.len() < 3 { return Err(ByteIOError::WriteError); }
dst[0] = (val >> 0) as u8;
@@
-807,9
+809,7
@@
impl<'a> ByteIO for MemoryWriter<'a> {
fn write_buf(&mut self, buf: &[u8]) -> ByteIOResult<()> {
if self.pos + buf.len() > self.buf.len() { return Err(ByteIOError::WriteError); }
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(())
}
self.pos += buf.len();
Ok(())
}
@@
-887,9
+887,7
@@
impl<'a> ByteIO for GrowableMemoryWriter<'a> {
if self.pos + buf.len() > self.buf.len() {
self.buf.resize(self.pos + buf.len(), 0);
}
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(())
}
self.pos += buf.len();
Ok(())
}
diff --git
a/nihav-core/src/io/codebook.rs
b/nihav-core/src/io/codebook.rs
index d835ce31501af39b963a0e6985a09299ca0da690..384a743e06191689042923ce1b03032f6ccbe72b 100644
(file)
--- a/
nihav-core/src/io/codebook.rs
+++ b/
nihav-core/src/io/codebook.rs
@@
-113,6
+113,7
@@
pub struct ShortCodebookDesc {
///
/// [`ShortCodebookDescReader`]: ./struct.ShortCodebookDescReader.html
/// [`TableCodebookDescReader`]: ./struct.TableCodebookDescReader.html
///
/// [`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 trait CodebookDescReader<S> {
/// Returns the codeword length for the provided index.
fn bits(&mut self, idx: usize) -> u8;
diff --git
a/nihav-core/src/lib.rs
b/nihav-core/src/lib.rs
index 303fb244ddb01a1fc9164b13bb480b2c571f497b..d3104a4a54b5c9bafdcd81b0f76b62843a1f1656 100644
(file)
--- a/
nihav-core/src/lib.rs
+++ b/
nihav-core/src/lib.rs
@@
-7,6
+7,8
@@
pub mod codecs;
#[cfg(feature="compr")]
pub mod codecs;
#[cfg(feature="compr")]
+#[allow(clippy::manual_memcpy)]
+#[allow(clippy::needless_range_loop)]
pub mod compr;
#[cfg(feature="muxers")]
pub mod compr;
#[cfg(feature="muxers")]
@@
-23,5
+25,10
@@
pub mod io;
pub mod options;
pub mod refs;
pub mod reorder;
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;
pub mod scale;
+#[allow(clippy::unreadable_literal)]
pub mod soundcvt;
pub mod soundcvt;
diff --git
a/nihav-core/src/options.rs
b/nihav-core/src/options.rs
index ea5b32933ad790b5e00e5d51797e20c1b4c0132a..96e093e4f95976a564d979d42b3fe6d06c5ea3e4 100644
(file)
--- a/
nihav-core/src/options.rs
+++ b/
nihav-core/src/options.rs
@@
-9,20
+9,20
@@
use std::sync::Arc;
use std::fmt;
/// Common name for keyframe interval option.
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.
/// 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.
/// 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.
/// 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.
/// 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.
/// 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.
/// 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)]
/// A list specifying option parsing and validating errors.
#[derive(Clone,Copy,Debug,PartialEq)]
@@
-70,17
+70,17
@@
pub struct NAOptionDefinition {
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.
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;
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;
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 {
return Err(OptionError::WrongName);
}
match self.opt_type {
@@
-293,17
+293,17
@@
mod test {
#[test]
fn test_option_parsing() {
let mut def = NAOptionDefinition { name: "option", description: "", opt_type: NAOptionDefinitionType::Float(None, None) };
#[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));
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 };
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)));
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)));
}
}
Ok((NAOption{name: "option", value: NAValue::Bool(false) }, 1)));
}
}
diff --git
a/nihav-core/src/reorder.rs
b/nihav-core/src/reorder.rs
index 83896df5958394fc9d665d02244ab57949cc28a9..625e759952caa7cfb656d7141cad7cc4b894dc61 100644
(file)
--- a/
nihav-core/src/reorder.rs
+++ b/
nihav-core/src/reorder.rs
@@
-32,6
+32,12
@@
impl NoReorderer {
}
}
}
}
+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() {
impl FrameReorderer for NoReorderer {
fn add_frame(&mut self, fref: NAFrameRef) -> bool {
if self.fref.is_none() {
diff --git
a/nihav-core/src/scale/colorcvt.rs
b/nihav-core/src/scale/colorcvt.rs
index 056c0504dc5f8db4e50772f3f47ebc68b996fb5b..0343bdddf27dee3aa301b8a4d26778ba0ad478a1 100644
(file)
--- a/
nihav-core/src/scale/colorcvt.rs
+++ b/
nihav-core/src/scale/colorcvt.rs
@@
-369,7
+369,7
@@
println!(" [intermediate format {}]", df);
let mut voff = sbuf.get_offset(2);
let src = sbuf.get_data();
let dst = dbuf.get_data_mut().unwrap();
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];
for y in 0..h {
for x in 0..w {
let y = self.yscale[src[yoff + x] as usize];
@@
-432,7
+432,7
@@
impl YuvToRgb {
let mut yoff = sbuf.get_offset(0);
let src = sbuf.get_data();
let dst = dbuf.get_data_mut().unwrap();
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];
for _y in 0..h {
for x in 0..w {
let y = self.yscale[src[yoff + x] as usize];
diff --git
a/nihav-core/src/scale/mod.rs
b/nihav-core/src/scale/mod.rs
index e66d393c0733917fc8c08beac3b2c98cc8302e73..2192b187dfe14c1054baff8c412c1fb5889ea7af 100644
(file)
--- a/
nihav-core/src/scale/mod.rs
+++ b/
nihav-core/src/scale/mod.rs
@@
-21,6
+21,7
@@
mod kernel;
mod colorcvt;
mod repack;
mod colorcvt;
mod repack;
+#[allow(clippy::module_inception)]
mod scale;
mod palette;
mod scale;
mod palette;
diff --git
a/nihav-core/src/scale/palette/elbg.rs
b/nihav-core/src/scale/palette/elbg.rs
index 09269010aa71843c667d6f499be42d1ee6078038..300b3f1610b5dc33f8a52c05df64099e2e671344 100644
(file)
--- a/
nihav-core/src/scale/palette/elbg.rs
+++ b/
nihav-core/src/scale/palette/elbg.rs
@@
-8,7
+8,7
@@
impl RNG {
fn new() -> Self { Self { seed: 0x1234 } }
fn next(&mut self) -> u8 {
if (self.seed & 0x8000) != 0 {
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;
}
} else {
self.seed <<= 1;
}
@@
-198,6
+198,7
@@
impl ELBG {
clu1.calc_dist();
clu0.dist + clu1.dist
}
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;
pub fn quantise(&mut self, src: &[Pixel], dst: &mut [[u8; 3]; 256]) {
if src.len() < 3 {
return;
@@
-284,7
+285,7
@@
impl ELBG {
if do_elbg_step {
do_elbg_step = false;
for low_idx in low_u.iter() {
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();
break;
}
let high_idx_idx = (rng.next() as usize) % high_u.len();
diff --git
a/nihav-core/src/scale/palette/neuquant.rs
b/nihav-core/src/scale/palette/neuquant.rs
index 7b19eb5fdd52283180fe6ed6a67e45122a64a800..73d2a3acbd58134bdd4de9e20d83c6cad2bdee40 100644
(file)
--- a/
nihav-core/src/scale/palette/neuquant.rs
+++ b/
nihav-core/src/scale/palette/neuquant.rs
@@
-39,7
+39,7
@@
impl NeuQuantQuantiser {
let mut range = 0;
let sqradius = (radius * radius) as f64;
while (idx0 < high) || (idx1 > low) {
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 {
let a = alpha * (sqradius - sqrng) / sqradius;
range += 1;
if idx0 < high {
@@
-85,7
+85,7
@@
impl NeuQuantQuantiser {
pub fn learn(&mut self, src: &[Pixel]) {
let mut bias_radius = (256 / 8) << 6;
let alphadec = (30 + (self.factor - 1) / 3) as f64;
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();
let npixels = src.len();
@@
-105,7
+105,7
@@
impl NeuQuantQuantiser {
}
for i in 0..samples {
}
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;
let idx = self.find_node(&clr);
if idx >= SPECIAL_NODES {
let new_alpha = alphadec / initial_alpha;
diff --git
a/nihav-core/src/scale/repack.rs
b/nihav-core/src/scale/repack.rs
index faa5fe72dc58270376c943d5c455087f44b03817..f0e59564f9215038079cc6e5c377cfe9c3300938 100644
(file)
--- a/
nihav-core/src/scale/repack.rs
+++ b/
nihav-core/src/scale/repack.rs
@@
-143,9
+143,7
@@
impl Kernel for UnpackKernel {
chr.push(Some(dchr));
}
let mut df = in_fmt.fmt;
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);
df.palette = false;
println!(" [intermediate format {}]", df);
let res = alloc_video_buffer(NAVideoInfo::new(in_fmt.width, in_fmt.height, false, df), 3);
@@
-253,9
+251,7
@@
impl Kernel for DepalKernel {
}
let mut df = in_fmt.fmt;
df.palette = false;
}
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); }
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); }
diff --git
a/nihav-core/src/soundcvt/mod.rs
b/nihav-core/src/soundcvt/mod.rs
index 6864f7e14a9ea179ea4e486b07782dea68f85dda..b218e4ae588d61b2f9c60ffed77fe4ba230adac9 100644
(file)
--- a/
nihav-core/src/soundcvt/mod.rs
+++ b/
nihav-core/src/soundcvt/mod.rs
@@
-37,10
+37,10
@@
impl ChannelOp {
}
}
}
}
-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 => {
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()) {
},
ChannelOp::Reorder(ref reorder) => {
for (out, idx) in dst.iter_mut().zip(reorder.iter()) {
@@
-51,7
+51,7
@@
fn apply_channel_op<T:Copy>(ch_op: &ChannelOp, src: &Vec<T>, dst: &mut Vec<T>) {
};
}
};
}
-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)) {
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)) {
@@
-70,7
+70,7
@@
fn remix_i32(ch_op: &ChannelOp, src: &Vec<i32>, dst: &mut Vec<i32>) {
}
}
}
}
-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)) {
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)) {
@@
-97,13
+97,13
@@
impl FromFmt<u8> for u8 {
fn cvt_from(val: u8) -> u8 { val }
}
impl FromFmt<u8> for i16 {
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 {
}
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 {
}
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 {
}
impl FromFmt<i16> for u8 {
@@
-113,10
+113,10
@@
impl FromFmt<i16> for i16 {
fn cvt_from(val: i16) -> i16 { val }
}
impl FromFmt<i16> for i32 {
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 {
}
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 {
}
impl FromFmt<i32> for u8 {
@@
-233,8
+233,8
@@
impl SampleReader for PackedSampleReader<'_> {
}
trait SampleWriter {
}
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> {
}
struct GenericSampleWriter<'a, T:Copy> {
@@
-243,14
+243,14
@@
struct GenericSampleWriter<'a, T:Copy> {
}
impl<'a, T:Copy+FromFmt<i32>+FromFmt<f32>> SampleWriter for GenericSampleWriter<'a, T> {
}
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;
}
}
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();
let mut off = pos;
for el in src.iter() {
self.data[off] = (*el).cvt_into();
@@
-272,7
+272,7
@@
impl<'a> PackedSampleWriter<'a> {
Self { data, fmt, bpp }
}
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..];
let mut offset = pos * self.bpp * src.len();
for el in src.iter() {
let dst = &mut self.data[offset..];
@@
-293,8
+293,8
@@
impl<'a> PackedSampleWriter<'a> {
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(),
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, f
32::cvt_from(*el) as f64
).unwrap(),
- (8, false) => write_f64le(dst, f
32::cvt_from(*el) as f64
).unwrap(),
+ (8, true) => write_f64be(dst, f
64::from(f32::cvt_from(*el))
).unwrap(),
+ (8, false) => write_f64le(dst, f
64::from(f32::cvt_from(*el))
).unwrap(),
(_, _) => unreachable!(),
};
}
(_, _) => unreachable!(),
};
}
@@
-304,10
+304,10
@@
impl<'a> PackedSampleWriter<'a> {
}
impl SampleWriter for PackedSampleWriter<'_> {
}
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);
}
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);
}
}
self.store_samples(pos, src);
}
}
@@
-362,7
+362,7
@@
Result<NABufferType, SoundConvertError> {
return Ok(src.clone());
}
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);
}
if ret.is_err() {
return Err(SoundConvertError::AllocError);
}