Commit 79c3756f authored by gibix's avatar gibix Committed by Luca Barbato

fix rust 2018 idioms

parent a7813d78
......@@ -7,9 +7,9 @@ use std::slice;
use clap::{App, Arg};
pub struct EncoderIO {
pub input: Box<Read>,
pub output: Box<Write>,
pub rec: Option<Box<Write>>,
pub input: Box<dyn Read>,
pub output: Box<dyn Write>,
pub rec: Option<Box<dyn Write>>,
}
pub trait FromCli {
......@@ -62,15 +62,15 @@ impl FromCli for EncoderConfig {
let io = EncoderIO {
input: match matches.value_of("INPUT").unwrap() {
"-" => Box::new(io::stdin()) as Box<Read>,
f => Box::new(File::open(&f).unwrap()) as Box<Read>
"-" => Box::new(io::stdin()) as Box<dyn Read>,
f => Box::new(File::open(&f).unwrap()) as Box<dyn Read>
},
output: match matches.value_of("OUTPUT").unwrap() {
"-" => Box::new(io::stdout()) as Box<Write>,
f => Box::new(File::create(&f).unwrap()) as Box<Write>
"-" => Box::new(io::stdout()) as Box<dyn Write>,
f => Box::new(File::create(&f).unwrap()) as Box<dyn Write>
},
rec: matches.value_of("RECONSTRUCTION").map(|f| {
Box::new(File::create(&f).unwrap()) as Box<Write>
Box::new(File::create(&f).unwrap()) as Box<dyn Write>
})
};
......@@ -94,9 +94,9 @@ impl FromCli for EncoderConfig {
/// Encode and write a frame.
pub fn process_frame(sequence: &mut Sequence, fi: &mut FrameInvariants,
output_file: &mut Write,
y4m_dec: &mut y4m::Decoder<Box<Read>>,
y4m_enc: Option<&mut y4m::Encoder<Box<Write>>>) -> bool {
output_file: &mut dyn Write,
y4m_dec: &mut y4m::Decoder<'_, Box<dyn Read>>,
y4m_enc: Option<&mut y4m::Encoder<'_, Box<dyn Write>>>) -> bool {
unsafe {
av1_rtcd();
aom_dsp_rtcd();
......
......@@ -856,9 +856,9 @@ pub struct CDFContext {
impl CDFContext {
pub fn new(quantizer: u8) -> CDFContext {
let qctx = match quantizer {
0...20 => 0,
21...60 => 1,
61...120 => 2,
0..=20 => 0,
21..=60 => 1,
61..=120 => 2,
_ => 3
};
CDFContext {
......@@ -1667,7 +1667,7 @@ impl ContextWriter {
}
pub fn write_partition(
&mut self, w: &mut Writer, bo: &BlockOffset, p: PartitionType, bsize: BlockSize
&mut self, w: &mut dyn Writer, bo: &BlockOffset, p: PartitionType, bsize: BlockSize
) {
assert!(bsize >= BlockSize::BLOCK_8X8 );
let hbs = bsize.width_mi() / 2;
......@@ -1708,7 +1708,7 @@ impl ContextWriter {
}
}
pub fn write_intra_mode_kf(
&mut self, w: &mut Writer, bo: &BlockOffset, mode: PredictionMode
&mut self, w: &mut dyn Writer, bo: &BlockOffset, mode: PredictionMode
) {
static intra_mode_context: [usize; INTRA_MODES] =
[0, 1, 2, 3, 4, 4, 4, 4, 3, 0, 1, 2, 0];
......@@ -1719,13 +1719,13 @@ impl ContextWriter {
let cdf = &mut self.fc.kf_y_cdf[above_ctx][left_ctx];
symbol_with_update!(self, w, mode as u32, cdf);
}
pub fn write_intra_mode(&mut self, w: &mut Writer, bsize: BlockSize, mode: PredictionMode) {
pub fn write_intra_mode(&mut self, w: &mut dyn Writer, bsize: BlockSize, mode: PredictionMode) {
let cdf =
&mut self.fc.y_mode_cdf[size_group_lookup[bsize as usize] as usize];
symbol_with_update!(self, w, mode as u32, cdf);
}
pub fn write_intra_uv_mode(
&mut self, w: &mut Writer, uv_mode: PredictionMode, y_mode: PredictionMode, bs: BlockSize
&mut self, w: &mut dyn Writer, uv_mode: PredictionMode, y_mode: PredictionMode, bs: BlockSize
) {
let cdf =
&mut self.fc.uv_mode_cdf[bs.cfl_allowed() as usize][y_mode as usize];
......@@ -1735,7 +1735,7 @@ impl ContextWriter {
symbol_with_update!(self, w, uv_mode as u32, &mut cdf[..UV_INTRA_MODES]);
}
}
pub fn write_angle_delta(&mut self, w: &mut Writer, angle: i8, mode: PredictionMode) {
pub fn write_angle_delta(&mut self, w: &mut dyn Writer, angle: i8, mode: PredictionMode) {
symbol_with_update!(
self,
w,
......@@ -1744,7 +1744,7 @@ impl ContextWriter {
[mode as usize - PredictionMode::V_PRED as usize]
);
}
pub fn write_use_filter_intra(&mut self, w: &mut Writer, enable: bool, block_size: BlockSize) {
pub fn write_use_filter_intra(&mut self, w: &mut dyn Writer, enable: bool, block_size: BlockSize) {
symbol_with_update!(self, w, enable as u32, &mut self.fc.filter_intra_cdfs[block_size as usize]);
}
......@@ -1871,7 +1871,7 @@ impl ContextWriter {
}
}
pub fn write_ref_frames(&mut self, w: &mut Writer, bo: &BlockOffset) {
pub fn write_ref_frames(&mut self, w: &mut dyn Writer, bo: &BlockOffset) {
let rf = self.bc.at(bo).ref_frames;
assert!(rf[0] == LAST_FRAME);
......@@ -1911,7 +1911,7 @@ impl ContextWriter {
}
}
pub fn write_inter_mode(&mut self, w: &mut Writer, mode: PredictionMode, ctx: usize) {
pub fn write_inter_mode(&mut self, w: &mut dyn Writer, mode: PredictionMode, ctx: usize) {
let newmv_ctx = ctx & NEWMV_CTX_MASK;
symbol_with_update!(self, w, (mode != PredictionMode::NEWMV) as u32, &mut self.fc.newmv_cdf[newmv_ctx]);
if mode != PredictionMode::NEWMV {
......@@ -1925,7 +1925,7 @@ impl ContextWriter {
}
pub fn write_tx_type(
&mut self, w: &mut Writer, tx_size: TxSize, tx_type: TxType, y_mode: PredictionMode,
&mut self, w: &mut dyn Writer, tx_size: TxSize, tx_type: TxType, y_mode: PredictionMode,
is_inter: bool, use_reduced_tx_set: bool
) {
let square_tx_size = tx_size.sqr();
......@@ -1964,16 +1964,16 @@ impl ContextWriter {
}
}
}
pub fn write_skip(&mut self, w: &mut Writer, bo: &BlockOffset, skip: bool) {
pub fn write_skip(&mut self, w: &mut dyn Writer, bo: &BlockOffset, skip: bool) {
let ctx = self.bc.skip_context(bo);
symbol_with_update!(self, w, skip as u32, &mut self.fc.skip_cdfs[ctx]);
}
pub fn write_cdef(&mut self, w: &mut Writer, strength_index: u8, bits: u8) {
pub fn write_cdef(&mut self, w: &mut dyn Writer, strength_index: u8, bits: u8) {
w.literal(bits, strength_index as u32);
}
pub fn write_is_inter(&mut self, w: &mut Writer, bo: &BlockOffset, is_inter: bool) {
pub fn write_is_inter(&mut self, w: &mut dyn Writer, bo: &BlockOffset, is_inter: bool) {
let ctx = self.bc.intra_inter_context(bo);
symbol_with_update!(self, w, is_inter as u32, &mut self.fc.intra_inter_cdfs[ctx]);
}
......@@ -2208,7 +2208,7 @@ impl ContextWriter {
}
pub fn write_coeffs_lv_map(
&mut self, w: &mut Writer, plane: usize, bo: &BlockOffset, coeffs_in: &[i32],
&mut self, w: &mut dyn Writer, plane: usize, bo: &BlockOffset, coeffs_in: &[i32],
tx_size: TxSize, tx_type: TxType, plane_bsize: BlockSize, xdec: usize,
ydec: usize, use_reduced_tx_set: bool
) -> bool {
......
......@@ -390,7 +390,7 @@ impl WriterBase<WriterRecorder> {
/// Replays the partially-computed range tokens out of the Recorder's
/// storage and into the passed in Writer, which may be an Encoder
/// or another Recorder. Clears the Recorder after replay.
pub fn replay(&mut self, dest: &mut StorageBackend) {
pub fn replay(&mut self, dest: &mut dyn StorageBackend) {
for i in 0..self.s.storage.len() {
let (fl, fh, nms) = self.s.storage[i];
dest.store(fl, fh, nms);
......
......@@ -380,7 +380,7 @@ impl FrameInvariants {
}
impl fmt::Display for FrameInvariants{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Frame {} - {}", self.number, self.frame_type)
}
}
......@@ -407,7 +407,7 @@ pub enum ReferenceMode {
pub const ALL_REF_FRAMES_MASK: u32 = (1 << REF_FRAMES) - 1;
impl fmt::Display for FrameType{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
FrameType::KEY => write!(f, "Key frame"),
FrameType::INTER => write!(f, "Inter frame"),
......@@ -436,7 +436,7 @@ impl Default for EncoderConfig {
}
}
pub fn write_ivf_header(output_file: &mut Write, width: usize, height: usize, num: usize, den: usize) {
pub fn write_ivf_header(output_file: &mut dyn Write, width: usize, height: usize, num: usize, den: usize) {
let mut bw = BitWriter::<LE>::new(output_file);
bw.write_bytes(b"DKIF").unwrap();
bw.write(16, 0).unwrap(); // version
......@@ -450,7 +450,7 @@ pub fn write_ivf_header(output_file: &mut Write, width: usize, height: usize, nu
bw.write(32, 0).unwrap();
}
pub fn write_ivf_frame(output_file: &mut Write, pts: u64, data: &[u8]) {
pub fn write_ivf_frame(output_file: &mut dyn Write, pts: u64, data: &[u8]) {
let mut bw = BitWriter::<LE>::new(output_file);
bw.write(32, data.len() as u32).unwrap();
bw.write(64, pts).unwrap();
......@@ -1015,7 +1015,7 @@ fn aom_uleb_encode(mut value: u64, coded_value: &mut [u8]) -> usize {
leb_size
}
fn write_obus(packet: &mut Write, sequence: &mut Sequence,
fn write_obus(packet: &mut dyn Write, sequence: &mut Sequence,
fi: &mut FrameInvariants) -> Result<(), std::io::Error> {
//let mut uch = BitWriter::<BE>::new(packet);
let obu_extension = 0 as u32;
......@@ -1095,7 +1095,7 @@ fn write_obus(packet: &mut Write, sequence: &mut Sequence,
}
/// Write into `dst` the difference between the blocks at `src1` and `src2`
fn diff(dst: &mut [i16], src1: &PlaneSlice, src2: &PlaneSlice, width: usize, height: usize) {
fn diff(dst: &mut [i16], src1: &PlaneSlice<'_>, src2: &PlaneSlice<'_>, width: usize, height: usize) {
for j in 0..height {
for i in 0..width {
dst[j*width + i] = (src1.p(i, j) as i16) - (src2.p(i, j) as i16);
......@@ -1106,7 +1106,7 @@ fn diff(dst: &mut [i16], src1: &PlaneSlice, src2: &PlaneSlice, width: usize, hei
// For a transform block,
// predict, transform, quantize, write coefficients to a bitstream,
// dequantize, inverse-transform.
pub fn encode_tx_block(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut ContextWriter, w: &mut Writer,
pub fn encode_tx_block(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut ContextWriter, w: &mut dyn Writer,
p: usize, bo: &BlockOffset, mode: PredictionMode, tx_size: TxSize, tx_type: TxType,
plane_bsize: BlockSize, po: &PlaneOffset, skip: bool, bit_depth: usize) -> bool {
let rec = &mut fs.rec.planes[p];
......@@ -1143,7 +1143,7 @@ pub fn encode_tx_block(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut Conte
}
fn encode_block_a(seq: &Sequence,
cw: &mut ContextWriter, w: &mut Writer,
cw: &mut ContextWriter, w: &mut dyn Writer,
bsize: BlockSize, bo: &BlockOffset, skip: bool) -> bool {
cw.bc.set_skip(bo, bsize, skip);
cw.write_skip(w, bo, skip);
......@@ -1154,7 +1154,7 @@ fn encode_block_a(seq: &Sequence,
}
fn encode_block_b(fi: &FrameInvariants, fs: &mut FrameState,
cw: &mut ContextWriter, w: &mut Writer,
cw: &mut ContextWriter, w: &mut dyn Writer,
luma_mode: PredictionMode, chroma_mode: PredictionMode,
bsize: BlockSize, bo: &BlockOffset, skip: bool, bit_depth: usize) {
let is_inter = !luma_mode.is_intra();
......@@ -1240,7 +1240,7 @@ fn encode_block_b(fi: &FrameInvariants, fs: &mut FrameState,
}
pub fn write_tx_blocks(fi: &FrameInvariants, fs: &mut FrameState,
cw: &mut ContextWriter, w: &mut Writer,
cw: &mut ContextWriter, w: &mut dyn Writer,
luma_mode: PredictionMode, chroma_mode: PredictionMode, bo: &BlockOffset,
bsize: BlockSize, tx_size: TxSize, tx_type: TxType, skip: bool, bit_depth: usize) {
let bw = bsize.width_mi() / tx_size.width_mi();
......@@ -1312,7 +1312,7 @@ pub fn write_tx_blocks(fi: &FrameInvariants, fs: &mut FrameState,
// FIXME: For now, assume tx_mode is LARGEST_TX, so var-tx is not implemented yet
// but only one tx block exist for a inter mode partition.
pub fn write_tx_tree(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut ContextWriter, w: &mut Writer,
pub fn write_tx_tree(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut ContextWriter, w: &mut dyn Writer,
luma_mode: PredictionMode, chroma_mode: PredictionMode, bo: &BlockOffset,
bsize: BlockSize, tx_size: TxSize, tx_type: TxType, skip: bool, bit_depth: usize) {
let bw = bsize.width_mi() / tx_size.width_mi();
......@@ -1366,7 +1366,7 @@ pub fn write_tx_tree(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut Context
}
fn encode_partition_bottomup(seq: &Sequence, fi: &FrameInvariants, fs: &mut FrameState,
cw: &mut ContextWriter, w_pre_cdef: &mut Writer, w_post_cdef: &mut Writer,
cw: &mut ContextWriter, w_pre_cdef: &mut dyn Writer, w_post_cdef: &mut dyn Writer,
bsize: BlockSize, bo: &BlockOffset) -> f64 {
let mut rd_cost = std::f64::MAX;
......@@ -1405,7 +1405,7 @@ fn encode_partition_bottomup(seq: &Sequence, fi: &FrameInvariants, fs: &mut Fram
partition = PartitionType::PARTITION_NONE;
if bsize >= BlockSize::BLOCK_8X8 {
let w: &mut Writer = if cw.bc.cdef_coded {w_post_cdef} else {w_pre_cdef};
let w: &mut dyn Writer = if cw.bc.cdef_coded {w_post_cdef} else {w_pre_cdef};
cw.write_partition(w, bo, partition, bsize);
}
let mode_decision = rdo_mode_decision(seq, fi, fs, cw, bsize, bo).part_modes[0].clone();
......@@ -1434,7 +1434,7 @@ fn encode_partition_bottomup(seq: &Sequence, fi: &FrameInvariants, fs: &mut Fram
let nosplit_rd_cost = rd_cost;
if bsize >= BlockSize::BLOCK_8X8 {
let w: &mut Writer = if cw.bc.cdef_coded {w_post_cdef} else {w_pre_cdef};
let w: &mut dyn Writer = if cw.bc.cdef_coded {w_post_cdef} else {w_pre_cdef};
cw.write_partition(w, bo, partition, bsize);
}
......@@ -1456,7 +1456,7 @@ fn encode_partition_bottomup(seq: &Sequence, fi: &FrameInvariants, fs: &mut Fram
partition = PartitionType::PARTITION_NONE;
if bsize >= BlockSize::BLOCK_8X8 {
let w: &mut Writer = if cw.bc.cdef_coded {w_post_cdef} else {w_pre_cdef};
let w: &mut dyn Writer = if cw.bc.cdef_coded {w_post_cdef} else {w_pre_cdef};
cw.write_partition(w, bo, partition, bsize);
}
......@@ -1482,7 +1482,7 @@ fn encode_partition_bottomup(seq: &Sequence, fi: &FrameInvariants, fs: &mut Fram
}
fn encode_partition_topdown(seq: &Sequence, fi: &FrameInvariants, fs: &mut FrameState,
cw: &mut ContextWriter, w_pre_cdef: &mut Writer, w_post_cdef: &mut Writer,
cw: &mut ContextWriter, w_pre_cdef: &mut dyn Writer, w_post_cdef: &mut dyn Writer,
bsize: BlockSize, bo: &BlockOffset, block_output: &Option<RDOOutput>) {
if bo.x >= cw.bc.cols || bo.y >= cw.bc.rows {
......@@ -1523,7 +1523,7 @@ fn encode_partition_topdown(seq: &Sequence, fi: &FrameInvariants, fs: &mut Frame
let subsize = get_subsize(bsize, partition);
if bsize >= BlockSize::BLOCK_8X8 {
let w: &mut Writer = if cw.bc.cdef_coded {w_post_cdef} else {w_pre_cdef};
let w: &mut dyn Writer = if cw.bc.cdef_coded {w_post_cdef} else {w_pre_cdef};
cw.write_partition(w, bo, partition, bsize);
}
......
......@@ -52,7 +52,7 @@ pub struct RDOPartitionOutput {
}
#[allow(unused)]
fn cdef_dist_wxh_8x8(src1: &PlaneSlice, src2: &PlaneSlice, bit_depth: usize) -> u64 {
fn cdef_dist_wxh_8x8(src1: &PlaneSlice<'_>, src2: &PlaneSlice<'_>, bit_depth: usize) -> u64 {
let coeff_shift = bit_depth - 8;
let mut sum_s: i32 = 0;
......@@ -82,7 +82,7 @@ fn cdef_dist_wxh_8x8(src1: &PlaneSlice, src2: &PlaneSlice, bit_depth: usize) ->
#[allow(unused)]
fn cdef_dist_wxh(
src1: &PlaneSlice, src2: &PlaneSlice, w: usize, h: usize, bit_depth: usize
src1: &PlaneSlice<'_>, src2: &PlaneSlice<'_>, w: usize, h: usize, bit_depth: usize
) -> u64 {
assert!(w & 0x7 == 0);
assert!(h & 0x7 == 0);
......@@ -101,7 +101,7 @@ fn cdef_dist_wxh(
}
// Sum of Squared Error for a wxh block
fn sse_wxh(src1: &PlaneSlice, src2: &PlaneSlice, w: usize, h: usize) -> u64 {
fn sse_wxh(src1: &PlaneSlice<'_>, src2: &PlaneSlice<'_>, w: usize, h: usize) -> u64 {
let mut sse: u64 = 0;
for j in 0..h {
for i in 0..w {
......@@ -211,7 +211,7 @@ pub fn rdo_mode_decision(
if is_chroma_block && fi.config.speed <= 3 && luma_mode.is_intra() {
// Find the best chroma prediction mode for the current luma prediction mode
for &chroma_mode in RAV1E_INTRA_MODES {
let mut wr: &mut Writer = &mut WriterCounter::new();
let mut wr: &mut dyn Writer = &mut WriterCounter::new();
let tell = wr.tell_frac();
encode_block_a(seq, cw, wr, bsize, bo, skip);
......@@ -240,7 +240,7 @@ pub fn rdo_mode_decision(
cw.rollback(&cw_checkpoint);
}
} else {
let mut wr: &mut Writer = &mut WriterCounter::new();
let mut wr: &mut dyn Writer = &mut WriterCounter::new();
let tell = wr.tell_frac();
encode_block_a(seq, cw, wr, bsize, bo, skip);
encode_block_b(fi, fs, cw, wr, luma_mode, luma_mode, bsize, bo, skip, seq.bit_depth);
......@@ -317,7 +317,7 @@ pub fn rdo_tx_type_decision(
continue;
}
let mut wr: &mut Writer = &mut WriterCounter::new();
let mut wr: &mut dyn Writer = &mut WriterCounter::new();
let tell = wr.tell_frac();
if is_inter {
write_tx_tree(
......
......@@ -39,7 +39,7 @@ macro_rules! arg_enum {
}
}
impl ::std::fmt::Display for $e {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
$($e::$v => write!(f, stringify!($v)),)+
}
......
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