Commit 49c342e1 authored by Michael Bebenita's avatar Michael Bebenita

Fix Clippy warninds.

parent 8d504cc2
......@@ -71,3 +71,8 @@ Check code formatting with [rustfmt](https://github.com/rust-lang-nursery/rustfm
```
cargo +nightly fmt -- --check
```
You should also try [clippy](https://github.com/rust-lang-nursery/rust-clippy).
```
cargo +nightly clippy
```
single-char-binding-names-threshold = 10
too-many-arguments-threshold = 16
cyclomatic-complexity-threshold = 40
......@@ -11,6 +11,9 @@
#![allow(non_upper_case_globals)]
#![allow(dead_code)]
#![allow(non_camel_case_types)]
#![cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
#![cfg_attr(feature = "cargo-clippy", allow(unnecessary_mut_passed))]
#![cfg_attr(feature = "cargo-clippy", allow(needless_range_loop))]
use ec;
use partition::BlockSize::*;
......@@ -973,7 +976,7 @@ pub struct CDFContext {
impl CDFContext {
pub fn new(_qindex: u8) -> CDFContext {
let c = CDFContext {
CDFContext {
partition_cdf: default_partition_cdf,
kf_y_cdf: default_kf_y_mode_cdf,
y_mode_cdf: default_if_y_mode_cdf,
......@@ -1000,9 +1003,7 @@ impl CDFContext {
coeff_base_eob_cdf: av1_default_coeff_base_eob_multi,
coeff_base_cdf: av1_default_coeff_base_multi,
coeff_br_cdf: av1_default_coeff_lps_multi
};
c
}
}
pub fn build_map(&self) -> Vec<(&'static str, usize, usize)> {
......@@ -1258,9 +1259,9 @@ impl BlockContext {
cols: self.cols,
rows: self.rows,
above_partition_context: self.above_partition_context.clone(),
left_partition_context: self.left_partition_context.clone(),
left_partition_context: self.left_partition_context,
above_coeff_context: self.above_coeff_context.clone(),
left_coeff_context: self.left_coeff_context.clone(),
left_coeff_context: self.left_coeff_context,
blocks: vec![vec![Block::default(); 0]; 0]
}
}
......@@ -1269,9 +1270,9 @@ impl BlockContext {
self.cols = checkpoint.cols;
self.rows = checkpoint.rows;
self.above_partition_context = checkpoint.above_partition_context.clone();
self.left_partition_context = checkpoint.left_partition_context.clone();
self.left_partition_context = checkpoint.left_partition_context;
self.above_coeff_context = checkpoint.above_coeff_context.clone();
self.left_coeff_context = checkpoint.left_coeff_context.clone();
self.left_coeff_context = checkpoint.left_coeff_context;
}
pub fn at(&mut self, bo: &BlockOffset) -> &mut Block {
......@@ -1868,14 +1869,12 @@ impl ContextWriter {
}
pub fn get_eob_pos_token(&mut self, eob: usize, extra: &mut u32) -> u32 {
let t: u32;
if eob < 33 {
t = eob_to_pos_small[eob] as u32;
let t = if eob < 33 {
eob_to_pos_small[eob] as u32
} else {
let e = cmp::min((eob - 1) >> 5, 16);
t = eob_to_pos_large[e as usize] as u32;
}
eob_to_pos_large[e as usize] as u32
};
assert!(eob as i32 >= k_eob_group_start[t as usize] as i32);
*extra = eob as u32 - k_eob_group_start[t as usize] as u32;
......@@ -1934,17 +1933,16 @@ impl ContextWriter {
// if (row + col < 2) return ctx + 1;
// if (row + col < 4) return 5 + ctx + 1;
// return 21 + ctx;
return ctx
+ av1_nz_map_ctx_offset[tx_size as usize][coeff_idx] as usize;
ctx + av1_nz_map_ctx_offset[tx_size as usize][coeff_idx] as usize
}
TX_CLASS_HORIZ => {
let row = coeff_idx >> bwl;
let col = coeff_idx - (row << bwl);
return ctx + nz_map_ctx_offset_1d[col as usize];
ctx + nz_map_ctx_offset_1d[col as usize]
}
TX_CLASS_VERT => {
let row = coeff_idx >> bwl;
return ctx + nz_map_ctx_offset_1d[row];
ctx + nz_map_ctx_offset_1d[row]
}
}
}
......@@ -1968,8 +1966,7 @@ impl ContextWriter {
let padded_idx = coeff_idx + ((coeff_idx >> bwl) << TX_PAD_HOR_LOG2);
let stats = self.get_nz_mag(&levels[padded_idx..], bwl, tx_class);
return self
.get_nz_map_ctx_from_stats(stats, coeff_idx, bwl, tx_size, tx_class);
self.get_nz_map_ctx_from_stats(stats, coeff_idx, bwl, tx_size, tx_class)
}
pub fn get_nz_map_contexts(
......@@ -2042,7 +2039,7 @@ impl ContextWriter {
}
}
return mag + 14;
mag + 14
}
pub fn get_level_mag_with_txclass(
......@@ -2066,7 +2063,7 @@ impl ContextWriter {
) {
let pred_mode = self.bc.get_mode(bo);
let is_inter = pred_mode >= PredictionMode::NEARESTMV;
assert!(is_inter == false);
assert!(!is_inter);
// TODO: If iner mode, scan_order should use inter version of them
let scan_order =
&av1_inter_scan_orders[tx_size as usize][tx_type as usize];
......
......@@ -9,6 +9,9 @@
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
#![allow(non_camel_case_types)]
#![cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
#![cfg_attr(feature = "cargo-clippy", allow(identity_op))]
#![cfg_attr(feature = "cargo-clippy", allow(needless_range_loop))]
use bitstream_io::{BitWriter, BE};
use std;
......@@ -197,7 +200,7 @@ impl od_ec_enc {
let mut out = vec![0 as u8; offs];
while offs > 0 {
offs -= 1;
c = self.precarry[offs] + c;
c += self.precarry[offs];
out[offs] = c as u8;
c >>= 8;
}
......@@ -398,20 +401,20 @@ impl<'a> BCodeWriter for BitWriter<'a, BE> {
fn recenter_nonneg(&mut self, r: u16, v: u16) -> u16 {
/* Recenters a non-negative literal v around a reference r */
if v > (r << 1) {
return v;
v
} else if v >= r {
return (v - r) << 1;
(v - r) << 1
} else {
return ((r - v) << 1) - 1;
((r - v) << 1) - 1
}
}
fn recenter_finite_nonneg(&mut self, n: u16, r: u16, v: u16) -> u16 {
/* Recenters a non-negative literal v in [0, n-1] around a
reference r also in [0, n-1] */
if (r << 1) <= n {
return self.recenter_nonneg(r, v);
self.recenter_nonneg(r, v)
} else {
return self.recenter_nonneg(n - 1 - r, n - 1 - v);
self.recenter_nonneg(n - 1 - r, n - 1 - v)
}
}
fn write_quniform(&mut self, n: u16, v: u16) -> Result<(), std::io::Error> {
......@@ -422,10 +425,10 @@ impl<'a> BCodeWriter for BitWriter<'a, BE> {
let l = 31 ^ ((n - 1) + 1).leading_zeros();
let m = (1 << l) - n;
if v < m {
return self.write(l - 1, v);
self.write(l - 1, v)
} else {
self.write(l - 1, m + ((v - m) >> 1))?;
return self.write_bit(((v - m) & 1) != 0);
self.write_bit(((v - m) & 1) != 0)
}
}
fn write_subexpfin(
......@@ -447,7 +450,7 @@ impl<'a> BCodeWriter for BitWriter<'a, BE> {
let t = v >= mk + a;
self.write_bit(t)?;
if t {
i = i + 1;
i += 1;
mk += a;
} else {
return self.write(b as u32, v - mk);
......@@ -462,18 +465,18 @@ impl<'a> BCodeWriter for BitWriter<'a, BE> {
parameter k based on a reference ref also in [0, n-1].
Recenters symbol around r first and then uses a finite subexponential code. */
let recentered_v = self.recenter_finite_nonneg(n, r as u16, v as u16);
return self.write_subexpfin(n, k, recentered_v);
self.write_subexpfin(n, k, recentered_v)
}
fn write_s_refsubexpfin(
&mut self, n: u16, k: u16, r: i16, v: i16
) -> Result<(), std::io::Error> {
/* Signed version of the above function */
return self.write_refsubexpfin(
self.write_refsubexpfin(
(n << 1) - 1,
k,
r + (n - 1) as i16,
v + (n - 1) as i16
);
)
}
}
......
......@@ -153,13 +153,13 @@ impl FrameInvariants {
else if speed <= 2 { BlockSize::BLOCK_8X8 }
else if speed <= 3 { BlockSize::BLOCK_16X16 }
else { BlockSize::BLOCK_32X32 };
let use_reduced_tx_set = if speed > 1 { true } else { false };
let use_reduced_tx_set = speed > 1;
FrameInvariants {
qindex: qindex,
speed: speed,
width: width,
height: height,
qindex,
speed,
width,
height,
padded_w: width.align_power_of_two(3),
padded_h: height.align_power_of_two(3),
sb_width: width.align_power_of_two_and_shift(6),
......@@ -173,10 +173,10 @@ impl FrameInvariants {
allow_high_precision_mv: true,
frame_type: FrameType::KEY,
show_existing_frame: false,
use_reduced_tx_set: use_reduced_tx_set,
use_reduced_tx_set,
reference_mode: ReferenceMode::SINGLE,
use_prev_frame_mvs: false,
min_partition_size: min_partition_size,
min_partition_size,
globalmv_transformation_type: [GlobalMVMode::IDENTITY; ALTREF_FRAME + 1],
}
}
......@@ -233,10 +233,10 @@ const SINGLE_REFS: usize = FWD_REFS + BWD_REFS;
impl fmt::Display for FrameType{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&FrameType::KEY => write!(f, "Key frame"),
&FrameType::INTER => write!(f, "Inter frame"),
&FrameType::INTRA_ONLY => write!(f, "Intra only frame"),
&FrameType::S => write!(f, "Switching frame"),
FrameType::KEY => write!(f, "Key frame"),
FrameType::INTER => write!(f, "Inter frame"),
FrameType::INTRA_ONLY => write!(f, "Intra only frame"),
FrameType::S => write!(f, "Switching frame"),
}
}
}
......@@ -291,11 +291,11 @@ impl EncoderConfig {
EncoderConfig {
input_file: match matches.value_of("INPUT").unwrap() {
"-" => Box::new(std::io::stdin()) as Box<Read>,
f @ _ => Box::new(File::open(&f).unwrap()) as Box<Read>
f => Box::new(File::open(&f).unwrap()) as Box<Read>
},
output_file: match matches.value_of("OUTPUT").unwrap() {
"-" => Box::new(std::io::stdout()) as Box<Write>,
f @ _ => Box::new(File::create(&f).unwrap()) as Box<Write>
f => Box::new(File::create(&f).unwrap()) as Box<Write>
},
rec_file: matches.value_of("RECONSTRUCTION").map(|f| {
Box::new(File::create(&f).unwrap()) as Box<Write>
......@@ -408,10 +408,10 @@ fn write_uncompressed_header(packet: &mut Write, sequence: &Sequence,
}
*/
if fi.frame_type == FrameType::KEY || fi.frame_type == FrameType::INTRA_ONLY {
assert!(fi.intra_only == true);
assert!(fi.intra_only);
}
if fi.frame_type != FrameType::KEY {
if fi.show_frame { assert!(fi.intra_only == false); }
if fi.show_frame { assert!(!fi.intra_only); }
else { bw.write_bit( fi.intra_only )?; };
};
bw.write_bit(fi.error_resilient)?; // error resilient
......@@ -477,7 +477,7 @@ fn write_uncompressed_header(packet: &mut Write, sequence: &Sequence,
bw.write_bit(fi.use_reduced_tx_set)?; // reduced tx
if fi.intra_only == false {
if !fi.intra_only {
for i in LAST_FRAME..ALTREF_FRAME+1 {
let mode = fi.globalmv_transformation_type[i];
bw.write_bit(mode != GlobalMVMode::IDENTITY)?;
......@@ -569,7 +569,7 @@ pub fn encode_tx_block(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut Conte
// Reconstruct
dequantize(fi.qindex, &coeffs, &mut rcoeffs, tx_size);
inverse_transform_add(&mut rcoeffs, &mut rec.mut_slice(po).as_mut_slice(), stride, tx_size, tx_type);
inverse_transform_add(&rcoeffs, &mut rec.mut_slice(po).as_mut_slice(), stride, tx_size, tx_type);
}
fn encode_block(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut ContextWriter,
......@@ -657,8 +657,8 @@ pub fn write_tx_blocks(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut Conte
_ => TxSize::TX_32X32
};
let mut bw_uv = bw * tx_size.width_mi() >> xdec;
let mut bh_uv = bh * tx_size.height_mi() >> ydec;
let mut bw_uv = (bw * tx_size.width_mi()) >> xdec;
let mut bh_uv = (bh * tx_size.height_mi()) >> ydec;
if (bw_uv == 0 || bh_uv == 0) && has_chroma(bo, bsize, xdec, ydec) {
bw_uv = 1;
......@@ -682,9 +682,9 @@ pub fn write_tx_blocks(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut Conte
for bx in 0..bw_uv {
let tx_bo =
BlockOffset {
x: bo.x + (bx * uv_tx_size.width_mi() << xdec) -
x: bo.x + ((bx * uv_tx_size.width_mi()) << xdec) -
((bw * tx_size.width_mi() == 1) as usize),
y: bo.y + (by * uv_tx_size.height_mi() << ydec) -
y: bo.y + ((by * uv_tx_size.height_mi()) << ydec) -
((bh * tx_size.height_mi() == 1) as usize)
};
......@@ -721,7 +721,7 @@ bsize: BlockSize, bo: &BlockOffset) -> f64 {
let mut partition = PartitionType::PARTITION_NONE;
let mut best_decision = RDOPartitionOutput {
rd_cost: rd_cost,
rd_cost,
bo: bo.clone(),
pred_mode_luma: PredictionMode::DC_PRED,
pred_mode_chroma: PredictionMode::DC_PRED,
......@@ -842,7 +842,7 @@ fn encode_partition_topdown(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut
match partition {
PartitionType::PARTITION_NONE => {
let part_decision = if rdo_output.part_modes.len() > 0 {
let part_decision = if !rdo_output.part_modes.is_empty() {
// The optimal prediction mode is known from a previous iteration
rdo_output.part_modes[0].clone()
} else {
......@@ -920,10 +920,10 @@ fn encode_frame(sequence: &Sequence, fi: &FrameInvariants, fs: &mut FrameState,
write_uncompressed_header(&mut packet, sequence, fi).unwrap();
if fi.show_existing_frame {
match last_rec {
&Some(ref rec) => for p in 0..3 {
Some(ref rec) => for p in 0..3 {
fs.rec.planes[p].data.copy_from_slice(rec.planes[p].data.as_slice());
},
&None => (),
None => (),
}
} else {
let tile = encode_tile(fi, fs);
......
......@@ -317,7 +317,7 @@ use plane::*;
use predict::*;
impl PredictionMode {
pub fn predict<'a>(&self, dst: &'a mut PlaneMutSlice<'a>, tx_size: TxSize) {
pub fn predict<'a>(self, dst: &'a mut PlaneMutSlice<'a>, tx_size: TxSize) {
match tx_size {
TxSize::TX_4X4 => self.predict_inner::<Block4x4>(dst),
TxSize::TX_8X8 => self.predict_inner::<Block8x8>(dst),
......@@ -328,7 +328,7 @@ impl PredictionMode {
}
#[inline(always)]
fn predict_inner<'a, B: Intra>(&self, dst: &'a mut PlaneMutSlice<'a>) {
fn predict_inner<'a, B: Intra>(self, dst: &'a mut PlaneMutSlice<'a>) {
// above and left arrays include above-left sample
// above array includes above-right samples
// left array includes below-left samples
......@@ -339,18 +339,18 @@ impl PredictionMode {
let x = dst.x;
let y = dst.y;
if self != &PredictionMode::H_PRED && y != 0 {
if self != PredictionMode::H_PRED && y != 0 {
above[1..B::W + 1].copy_from_slice(&dst.go_up(1).as_slice()[..B::W]);
}
if self != &PredictionMode::V_PRED && x != 0 {
if self != PredictionMode::V_PRED && x != 0 {
let left_slice = dst.go_left(1);
for i in 0..B::H {
left[i + 1] = left_slice.p(0, i);
}
}
if self == &PredictionMode::PAETH_PRED && x != 0 && y != 0 {
if self == PredictionMode::PAETH_PRED && x != 0 && y != 0 {
above[0] = dst.go_up(1).go_left(1).p(0, 0);
left[0] = above[0];
}
......@@ -359,7 +359,7 @@ impl PredictionMode {
let above_slice = &above[1..B::W + 1];
let left_slice = &left[1..B::H + 1];
match *self {
match self {
PredictionMode::DC_PRED => match (x, y) {
(0, 0) => B::pred_dc_128(slice, stride),
(_, 0) => B::pred_dc_left(slice, stride, above_slice, left_slice),
......
......@@ -7,6 +7,8 @@
// Media Patent License 1.0 was not distributed with this source code in the
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
#![cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
/// Plane-specific configuration.
pub struct PlaneConfig {
pub stride: usize,
......
......@@ -8,6 +8,8 @@
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
#![allow(non_upper_case_globals)]
#![cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
#![cfg_attr(feature = "cargo-clippy", allow(needless_range_loop))]
use libc;
......
......@@ -7,6 +7,8 @@
// Media Patent License 1.0 was not distributed with this source code in the
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
#![cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
use partition::TxSize;
extern {
......@@ -15,13 +17,11 @@ extern {
}
fn get_tx_scale(tx_size: TxSize) -> u8 {
let tx_scale = match tx_size {
match tx_size {
TxSize::TX_64X64 => 4,
TxSize::TX_32X32 => 2,
_ => 1
};
tx_scale
}
}
pub fn dc_q(qindex: usize) -> i16 {
......
......@@ -9,6 +9,7 @@
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
#![allow(non_camel_case_types)]
#![cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
use context::*;
use ec::OD_BITRES;
......@@ -98,9 +99,7 @@ fn compute_rd_cost(
// Compute rate
let rate = (bit_cost as f64) / ((1 << OD_BITRES) as f64);
let rd_cost = (distortion as f64) + lambda * rate;
rd_cost
(distortion as f64) + lambda * rate
}
// RDO-based mode decision
......@@ -139,7 +138,7 @@ pub fn rdo_mode_decision(
for &skip in [false, true].iter() {
// Don't test skipped blocks at higher speed levels
if fi.speed > 1 && skip == true {
if fi.speed > 1 && skip {
continue;
}
......@@ -218,7 +217,7 @@ pub fn rdo_mode_decision(
assert!(best_rd >= 0_f64);
let rdo_output = RDOOutput {
RDOOutput {
rd_cost: best_rd,
part_type: PartitionType::PARTITION_NONE,
part_modes: vec![RDOPartitionOutput {
......@@ -228,9 +227,7 @@ pub fn rdo_mode_decision(
rd_cost: best_rd,
skip: best_skip
}]
};
rdo_output
}
}
// RDO-based intra frame transform type decision
......@@ -402,11 +399,9 @@ pub fn rdo_partition_decision(
assert!(best_rd >= 0_f64);
let rdo_output = RDOOutput {
RDOOutput {
rd_cost: best_rd,
part_type: best_partition,
part_modes: best_pred_modes
};
rdo_output
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment