Commit 8d504cc2 authored by Michael Bebenita's avatar Michael Bebenita Committed by Thomas Daede

Enable code formatting.

Format.
parent 1df94eda
......@@ -63,3 +63,11 @@ make -j8
* src/bin/rav1e.rs - rav1e command line tool.
* src/bin/rav1erepl.rs - Command line tool for debugging.
* aom_build/ - Local submodule of libaom. Some C functions and constants are used directly. Also used for benchmarking and testing.
# Contributing
Check code formatting with [rustfmt](https://github.com/rust-lang-nursery/rustfmt) before submitting a PR.
```
cargo +nightly fmt -- --check
```
Subproject commit 7998e06764a7a043f245cc8539a5d998aa85f7f8
Subproject commit 75c82453995fb9f4b8974dde91f672281d96c343
This diff is collapsed.
// Copyright (c) 2017-2018, The rav1e contributors. All rights reserved
//
// This source code is subject to the terms of the BSD 2 Clause License and
// the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
// was not distributed with this source code in the LICENSE file, you can
// obtain it at www.aomedia.org/license/software. If the Alliance for Open
// 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.
# rustfmt configuration, not actually used because of
# https://github.com/rust-lang-nursery/rustfmt/issues/2418
# rustfmt configuration, only used for some files
max_width = 79
comment_width = 79
control_brace_style = "ClosingNextLine"
force_explicit_abi = false
fn_args_density = "Compressed"
use_small_heuristics = "Off"
match_arm_blocks = false
max_width = 79
reorder_imported_names = true
reorder_imports = true
reorder_imports_in_group = true
reorder_extern_crates = true
reorder_extern_crates_in_group = true
tab_spaces = 2
use_field_init_shorthand = true
wrap_comments = true
trailing_comma = "Never"
ignore = [
"build.rs",
"src/context.rs", # Partial
# "src/ec.rs", # Clean
"src/lib.rs", # Did not clean yet to avoid conflicts with open PRs.
# "src/partition.rs", # Clean
# "src/plane.rs", # Clean
# "src/predict.rs", # Clean
# "src/quantize.rs", # Clean
# "src/rdo.rs", # Clean
# "src/transform.rs", # Clean
# "benches/bench.rs", # Clean
# "src/bin/rav1e.rs", # Clean
# "src/bin/rav1repl.rs", # Clean
"tests/aom.rs",
]
......@@ -13,40 +13,57 @@ extern crate y4m;
use rav1e::*;
fn main() {
let mut files = EncoderConfig::from_cli();
let mut y4m_dec = y4m::decode(&mut files.input_file).unwrap();
let width = y4m_dec.get_width();
let height = y4m_dec.get_height();
let framerate = y4m_dec.get_framerate();
let mut y4m_enc = match files.rec_file.as_mut() {
Some(rec_file) => Some(y4m::encode(width, height, framerate).write_header(rec_file).unwrap()),
None => None
};
let mut files = EncoderConfig::from_cli();
let mut y4m_dec = y4m::decode(&mut files.input_file).unwrap();
let width = y4m_dec.get_width();
let height = y4m_dec.get_height();
let framerate = y4m_dec.get_framerate();
let mut y4m_enc = match files.rec_file.as_mut() {
Some(rec_file) => Some(
y4m::encode(width, height, framerate).write_header(rec_file).unwrap()
),
None => None
};
let mut fi = FrameInvariants::new(width, height, files.quantizer, files.speed);
let sequence = Sequence::new();
write_ivf_header(&mut files.output_file, width, height, framerate.num, framerate.den);
let mut fi =
FrameInvariants::new(width, height, files.quantizer, files.speed);
let sequence = Sequence::new();
write_ivf_header(
&mut files.output_file,
width,
height,
framerate.num,
framerate.den
);
let mut last_rec: Option<Frame> = None;
loop {
//fi.frame_type = FrameType::KEY;
fi.frame_type = if fi.number % 30 == 0 {
FrameType::KEY }
else {
FrameType::INTER };
let mut last_rec: Option<Frame> = None;
loop {
//fi.frame_type = FrameType::KEY;
fi.frame_type = if fi.number % 30 == 0 {
FrameType::KEY
} else {
FrameType::INTER
};
fi.intra_only = fi.frame_type == FrameType::KEY ||
fi.frame_type == FrameType::INTRA_ONLY;
fi.use_prev_frame_mvs = !(fi.intra_only || fi.error_resilient);
fi.intra_only = fi.frame_type == FrameType::KEY
|| fi.frame_type == FrameType::INTRA_ONLY;
fi.use_prev_frame_mvs = !(fi.intra_only || fi.error_resilient);
if !process_frame(&sequence, &fi, &mut files.output_file, &mut y4m_dec, y4m_enc.as_mut(), &mut last_rec) {
break;
}
fi.number += 1;
//fi.show_existing_frame = fi.number % 2 == 1;
if fi.number == files.limit {
break;
}
files.output_file.flush().unwrap();
if !process_frame(
&sequence,
&fi,
&mut files.output_file,
&mut y4m_dec,
y4m_enc.as_mut(),
&mut last_rec
) {
break;
}
fi.number += 1;
//fi.show_existing_frame = fi.number % 2 == 1;
if fi.number == files.limit {
break;
}
files.output_file.flush().unwrap();
}
}
......@@ -17,46 +17,62 @@ use rustyline::error::ReadlineError;
use rustyline::Editor;
fn main() {
let mut files = EncoderConfig::from_cli();
let mut y4m_dec = y4m::decode(&mut files.input_file).unwrap();
let width = y4m_dec.get_width();
let height = y4m_dec.get_height();
let framerate = y4m_dec.get_framerate();
let mut y4m_enc = match files.rec_file.as_mut() {
Some(rec_file) => Some(y4m::encode(width, height, framerate).write_header(rec_file).unwrap()),
None => None
};
let mut fi = FrameInvariants::new(width, height, files.quantizer, files.speed);
let sequence = Sequence::new();
write_ivf_header(&mut files.output_file, fi.padded_w, fi.padded_h, framerate.num, framerate.den);
let mut files = EncoderConfig::from_cli();
let mut y4m_dec = y4m::decode(&mut files.input_file).unwrap();
let width = y4m_dec.get_width();
let height = y4m_dec.get_height();
let framerate = y4m_dec.get_framerate();
let mut y4m_enc = match files.rec_file.as_mut() {
Some(rec_file) => Some(
y4m::encode(width, height, framerate).write_header(rec_file).unwrap()
),
None => None
};
let mut fi =
FrameInvariants::new(width, height, files.quantizer, files.speed);
let sequence = Sequence::new();
write_ivf_header(
&mut files.output_file,
fi.padded_w,
fi.padded_h,
framerate.num,
framerate.den
);
let mut rl = Editor::<()>::new();
let _ = rl.load_history(".rav1e-history");
let mut last_rec: Option<Frame> = None;
loop {
let readline = rl.readline(">> ");
match readline {
Ok(line) => {
rl.add_history_entry(&line);
match line.split_whitespace().next() {
Some("process_frame") => {
process_frame(&sequence, &fi, &mut files.output_file, &mut y4m_dec, y4m_enc.as_mut(), &mut last_rec);
fi.number += 1;
if fi.number == files.limit {
break;
}
},
Some("quit") => break,
Some("exit") => break,
Some(cmd) => {
println!("Unrecognized command: {:?}", cmd);
},
None => {}
}
},
Err(ReadlineError::Eof) => break,
_ => {}
let mut rl = Editor::<()>::new();
let _ = rl.load_history(".rav1e-history");
let mut last_rec: Option<Frame> = None;
loop {
let readline = rl.readline(">> ");
match readline {
Ok(line) => {
rl.add_history_entry(&line);
match line.split_whitespace().next() {
Some("process_frame") => {
process_frame(
&sequence,
&fi,
&mut files.output_file,
&mut y4m_dec,
y4m_enc.as_mut(),
&mut last_rec
);
fi.number += 1;
if fi.number == files.limit {
break;
}
}
Some("quit") => break,
Some("exit") => break,
Some(cmd) => {
println!("Unrecognized command: {:?}", cmd);
}
None => {}
}
}
Err(ReadlineError::Eof) => break,
_ => {}
}
rl.save_history(".rav1e-history").unwrap();
}
rl.save_history(".rav1e-history").unwrap();
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
......@@ -9,149 +9,151 @@
/// Plane-specific configuration.
pub struct PlaneConfig {
pub stride: usize,
pub xdec: usize,
pub ydec: usize,
pub stride: usize,
pub xdec: usize,
pub ydec: usize
}
/// Absolute offset in pixels inside a plane
pub struct PlaneOffset {
pub x: usize,
pub y: usize
pub x: usize,
pub y: usize
}
pub struct Plane {
pub data: Vec<u16>,
pub cfg: PlaneConfig,
pub data: Vec<u16>,
pub cfg: PlaneConfig
}
impl Plane {
pub fn new(width: usize, height: usize, xdec: usize, ydec: usize) -> Plane {
Plane {
data: vec![128; width*height],
cfg: PlaneConfig {
stride: width,
xdec,
ydec,
},
}
pub fn new(width: usize, height: usize, xdec: usize, ydec: usize) -> Plane {
Plane {
data: vec![128; width * height],
cfg: PlaneConfig {
stride: width,
xdec,
ydec
}
}
}
pub fn slice<'a>(&'a self, po: &PlaneOffset) -> PlaneSlice<'a> {
PlaneSlice {
plane: self,
x: po.x,
y: po.y
}
pub fn slice<'a>(&'a self, po: &PlaneOffset) -> PlaneSlice<'a> {
PlaneSlice {
plane: self,
x: po.x,
y: po.y
}
}
pub fn mut_slice<'a>(&'a mut self, po: &PlaneOffset) -> PlaneMutSlice<'a> {
PlaneMutSlice {
plane: self,
x: po.x,
y: po.y
}
pub fn mut_slice<'a>(&'a mut self, po: &PlaneOffset) -> PlaneMutSlice<'a> {
PlaneMutSlice {
plane: self,
x: po.x,
y: po.y
}
pub fn p(&self, x: usize, y: usize) -> u16 {
self.data[y*self.cfg.stride + x]
}
pub fn copy_from_raw_u8(&mut self,
source: &[u8],
source_stride: usize,
source_bytewidth: usize) {
let stride = self.cfg.stride;
for (self_row, source_row) in self.data.chunks_mut(stride).zip(source.chunks(source_stride)) {
match source_bytewidth {
1 =>
for (self_pixel, source_pixel) in self_row.iter_mut().zip(source_row.iter()) {
*self_pixel = *source_pixel as u16;
},
2 => {
for (self_pixel, bytes) in self_row.iter_mut().zip(source_row.chunks(2)) {
*self_pixel = (bytes[1] as u16) << 8 | (bytes[0] as u16);
}
},
_ => {}
}
}
}
pub fn p(&self, x: usize, y: usize) -> u16 {
self.data[y * self.cfg.stride + x]
}
pub fn copy_from_raw_u8(
&mut self, source: &[u8], source_stride: usize, source_bytewidth: usize
) {
let stride = self.cfg.stride;
for (self_row, source_row) in
self.data.chunks_mut(stride).zip(source.chunks(source_stride))
{
match source_bytewidth {
1 => for (self_pixel, source_pixel) in
self_row.iter_mut().zip(source_row.iter())
{
*self_pixel = *source_pixel as u16;
},
2 => for (self_pixel, bytes) in
self_row.iter_mut().zip(source_row.chunks(2))
{
*self_pixel = (bytes[1] as u16) << 8 | (bytes[0] as u16);
},
_ => {}
}
}
}
}
pub struct PlaneSlice<'a> {
pub plane: &'a Plane,
pub x: usize,
pub y: usize
pub plane: &'a Plane,
pub x: usize,
pub y: usize
}
impl<'a> PlaneSlice<'a> {
pub fn as_slice(&'a self) -> &'a [u16] {
let stride = self.plane.cfg.stride;
&self.plane.data[self.y*stride+self.x..]
pub fn as_slice(&'a self) -> &'a [u16] {
let stride = self.plane.cfg.stride;
&self.plane.data[self.y * stride + self.x..]
}
/// A slice starting i pixels above the current one.
pub fn go_up(&'a self, i: usize) -> PlaneSlice<'a> {
PlaneSlice {
plane: self.plane,
x: self.x,
y: self.y - i
}
/// A slice starting i pixels above the current one.
pub fn go_up(&'a self, i: usize) -> PlaneSlice<'a> {
PlaneSlice {
plane: self.plane,
x: self.x,
y: self.y - i,
}
}
/// A slice starting i pixels to the left of the current one.
pub fn go_left(&'a self, i: usize) -> PlaneSlice<'a> {
PlaneSlice {
plane: self.plane,
x: self.x - i,
y: self.y,
}
}
/// A slice starting i pixels to the left of the current one.
pub fn go_left(&'a self, i: usize) -> PlaneSlice<'a> {
PlaneSlice {
plane: self.plane,
x: self.x - i,
y: self.y
}
}
pub fn p(&self, add_x: usize, add_y: usize) -> u16 {
let new_y = self.y + add_y;
let new_x = self.x + add_x;
self.plane.data[new_y*self.plane.cfg.stride + new_x]
}
pub fn p(&self, add_x: usize, add_y: usize) -> u16 {
let new_y = self.y + add_y;
let new_x = self.x + add_x;
self.plane.data[new_y * self.plane.cfg.stride + new_x]
}
}
pub struct PlaneMutSlice<'a> {
pub plane: &'a mut Plane,
pub x: usize,
pub y: usize
pub plane: &'a mut Plane,
pub x: usize,
pub y: usize
}
impl<'a> PlaneMutSlice<'a> {
pub fn as_mut_slice(&'a mut self) -> &'a mut [u16] {
let stride = self.plane.cfg.stride;
&mut self.plane.data[self.y*stride+self.x..]
}
// FIXME: code duplication with PlaneSlice
/// A slice starting i pixels above the current one.
pub fn go_up(&'a self, i: usize) -> PlaneSlice<'a> {
PlaneSlice {
plane: self.plane,
x: self.x,
y: self.y - i,
}
pub fn as_mut_slice(&'a mut self) -> &'a mut [u16] {
let stride = self.plane.cfg.stride;
&mut self.plane.data[self.y * stride + self.x..]
}
// FIXME: code duplication with PlaneSlice
/// A slice starting i pixels above the current one.
pub fn go_up(&'a self, i: usize) -> PlaneSlice<'a> {
PlaneSlice {
plane: self.plane,
x: self.x,
y: self.y - i
}
/// A slice starting i pixels to the left of the current one.
pub fn go_left(&'a self, i: usize) -> PlaneSlice<'a> {
PlaneSlice {
plane: self.plane,
x: self.x - i,
y: self.y,
}
}
/// A slice starting i pixels to the left of the current one.
pub fn go_left(&'a self, i: usize) -> PlaneSlice<'a> {
PlaneSlice {
plane: self.plane,
x: self.x - i,
y: self.y
}
}
pub fn p(&self, add_x: usize, add_y: usize) -> u16 {
let new_y = self.y + add_y;
let new_x = self.x + add_x;
self.plane.data[new_y*self.plane.cfg.stride + new_x]
}
pub fn p(&self, add_x: usize, add_y: usize) -> u16 {
let new_y = self.y + add_y;
let new_x = self.x + add_x;
self.plane.data[new_y * self.plane.cfg.stride + new_x]
}
}
This diff is collapsed.
......@@ -10,60 +10,58 @@
use partition::TxSize;
extern {
static dc_qlookup_Q3: [i16; 256];
static ac_qlookup_Q3: [i16; 256];
static dc_qlookup_Q3: [i16; 256];
static ac_qlookup_Q3: [i16; 256];
}
fn get_tx_scale(tx_size: TxSize) -> u8 {
let tx_scale = match tx_size {
TxSize::TX_64X64 => 4,
TxSize::TX_32X32 => 2,
_ => 1
};
let tx_scale = match tx_size {
TxSize::TX_64X64 => 4,
TxSize::TX_32X32 => 2,
_ => 1
};
tx_scale
tx_scale
}
pub fn dc_q(qindex: usize) -> i16 {
unsafe {
dc_qlookup_Q3[qindex]
}
unsafe { dc_qlookup_Q3[qindex] }
}
pub fn ac_q(qindex: usize) -> i16 {
unsafe {
ac_qlookup_Q3[qindex]
}
unsafe { ac_qlookup_Q3[qindex] }
}
pub fn quantize_in_place(qindex: usize, coeffs: &mut [i32], tx_size: TxSize) {
let tx_scale = get_tx_scale(tx_size) as i32;
let tx_scale = get_tx_scale(tx_size) as i32;
let dc_quant = dc_q(qindex) as i32;
let ac_quant = ac_q(qindex) as i32;
let dc_quant = dc_q(qindex) as i32;
let ac_quant = ac_q(qindex) as i32;
// using 21/64=0.328125 as rounding offset. To be tuned
let dc_offset = dc_quant * 21 / 64 as i32;
let ac_offset = ac_quant * 21 / 64 as i32;
// using 21/64=0.328125 as rounding offset. To be tuned
let dc_offset = dc_quant * 21 / 64 as i32;
let ac_offset = ac_quant * 21 / 64 as i32;
coeffs[0] *= tx_scale;
coeffs[0] += coeffs[0].signum() * dc_offset;
coeffs[0] /= dc_quant;
coeffs[0] *= tx_scale;
coeffs[0] += coeffs[0].signum() * dc_offset;
coeffs[0] /= dc_quant;
for c in coeffs[1..].iter_mut() {
*c *= tx_scale;
*c += c.signum() * ac_offset;
*c /= ac_quant;
}
for c in coeffs[1..].iter_mut() {
*c *= tx_scale;
*c += c.signum() * ac_offset;
*c /= ac_quant;
}
}
pub fn dequantize(qindex:usize, coeffs: &[i32], rcoeffs: &mut [i32], tx_size: TxSize) {
let tx_scale = get_tx_scale(tx_size) as i32;
pub fn dequantize(
qindex: usize, coeffs: &[i32], rcoeffs: &mut [i32], tx_size: TxSize
) {
let tx_scale = get_tx_scale(tx_size) as i32;
rcoeffs[0] = (coeffs[0] * dc_q(qindex) as i32) / tx_scale;
let ac_quant = ac_q(qindex) as i32;
rcoeffs[0] = (coeffs[0] * dc_q(qindex) as i32) / tx_scale;
let ac_quant = ac_q(qindex) as i32;
for (r, &c) in rcoeffs.iter_mut().zip(coeffs.iter()).skip(1) {
*r = c * ac_quant / tx_scale;
}
for (r, &c) in rcoeffs.iter_mut().zip(coeffs.iter()).skip(1) {
*r = c * ac_quant / tx_scale;
}
}
This diff is collapsed.
This diff is collapsed.
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