Commit b5936344 authored by Raphaël Zumer's avatar Raphaël Zumer
Browse files

Move TxSet, TxSize and TxType to the transform module

parent eae72f99
......@@ -18,6 +18,7 @@ use rav1e::bench::context::*;
use rav1e::bench::ec::*;
use rav1e::bench::partition::*;
use rav1e::bench::predict::*;
use rav1e::bench::transform::*;
use rav1e::bench::rdo::*;
use crate::transform::transform;
......
......@@ -20,9 +20,10 @@ use crate::header::ReferenceMode;
use crate::partition::BlockSize::*;
use crate::partition::PredictionMode::*;
use crate::partition::RefType::*;
use crate::partition::TxSize::*;
use crate::partition::TxType::*;
use crate::partition::*;
use crate::transform::TxSize::*;
use crate::transform::TxType::*;
use crate::transform::*;
use crate::lrf::*;
use crate::plane::*;
use crate::scan_order::*;
......
......@@ -11,6 +11,7 @@
use crate::context::*;
use crate::partition::*;
use crate::transform::*;
const PALATTE_BSIZE_CTXS: usize = 7;
const PALETTE_Y_MODE_CONTEXTS: usize = 3;
......
......@@ -19,6 +19,7 @@ use crate::mc::*;
use crate::plane::*;
use crate::predict::*;
use crate::tiling::*;
use crate::transform::TxSize;
use crate::util::*;
// LAST_FRAME through ALTREF_FRAME correspond to slots 0-6.
......@@ -367,189 +368,6 @@ impl BlockSize {
}
}
/// Transform Size
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
#[repr(C)]
pub enum TxSize {
TX_4X4,
TX_8X8,
TX_16X16,
TX_32X32,
TX_64X64,
TX_4X8,
TX_8X4,
TX_8X16,
TX_16X8,
TX_16X32,
TX_32X16,
TX_32X64,
TX_64X32,
TX_4X16,
TX_16X4,
TX_8X32,
TX_32X8,
TX_16X64,
TX_64X16
}
impl TxSize {
/// Number of square transform sizes
pub const TX_SIZES: usize = 5;
/// Number of transform sizes (including non-square sizes)
pub const TX_SIZES_ALL: usize = 14 + 5;
pub fn width(self) -> usize {
1 << self.width_log2()
}
pub fn width_log2(self) -> usize {
match self {
TX_4X4 | TX_4X8 | TX_4X16 => 2,
TX_8X8 | TX_8X4 | TX_8X16 | TX_8X32 => 3,
TX_16X16 | TX_16X8 | TX_16X32 | TX_16X4 | TX_16X64 => 4,
TX_32X32 | TX_32X16 | TX_32X64 | TX_32X8 => 5,
TX_64X64 | TX_64X32 | TX_64X16 => 6
}
}
pub fn width_index(self) -> usize {
self.width_log2() - TX_4X4.width_log2()
}
pub fn height(self) -> usize {
1 << self.height_log2()
}
pub fn height_log2(self) -> usize {
match self {
TX_4X4 | TX_8X4 | TX_16X4 => 2,
TX_8X8 | TX_4X8 | TX_16X8 | TX_32X8 => 3,
TX_16X16 | TX_8X16 | TX_32X16 | TX_4X16 | TX_64X16 => 4,
TX_32X32 | TX_16X32 | TX_64X32 | TX_8X32 => 5,
TX_64X64 | TX_32X64 | TX_16X64 => 6
}
}
pub fn height_index(self) -> usize {
self.height_log2() - TX_4X4.height_log2()
}
pub fn width_mi(self) -> usize {
self.width() >> MI_SIZE_LOG2
}
pub fn area(self) -> usize {
1 << self.area_log2()
}
pub fn area_log2(self) -> usize {
self.width_log2() + self.height_log2()
}
pub fn height_mi(self) -> usize {
self.height() >> MI_SIZE_LOG2
}
pub fn block_size(self) -> BlockSize {
match self {
TX_4X4 => BLOCK_4X4,
TX_8X8 => BLOCK_8X8,
TX_16X16 => BLOCK_16X16,
TX_32X32 => BLOCK_32X32,
TX_64X64 => BLOCK_64X64,
TX_4X8 => BLOCK_4X8,
TX_8X4 => BLOCK_8X4,
TX_8X16 => BLOCK_8X16,
TX_16X8 => BLOCK_16X8,
TX_16X32 => BLOCK_16X32,
TX_32X16 => BLOCK_32X16,
TX_32X64 => BLOCK_32X64,
TX_64X32 => BLOCK_64X32,
TX_4X16 => BLOCK_4X16,
TX_16X4 => BLOCK_16X4,
TX_8X32 => BLOCK_8X32,
TX_32X8 => BLOCK_32X8,
TX_16X64 => BLOCK_16X64,
TX_64X16 => BLOCK_64X16
}
}
pub fn sqr(self) -> TxSize {
match self {
TX_4X4 | TX_4X8 | TX_8X4 | TX_4X16 | TX_16X4 => TX_4X4,
TX_8X8 | TX_8X16 | TX_16X8 | TX_8X32 | TX_32X8 => TX_8X8,
TX_16X16 | TX_16X32 | TX_32X16 | TX_16X64 | TX_64X16 => TX_16X16,
TX_32X32 | TX_32X64 | TX_64X32 => TX_32X32,
TX_64X64 => TX_64X64
}
}
pub fn sqr_up(self) -> TxSize {
match self {
TX_4X4 => TX_4X4,
TX_8X8 | TX_4X8 | TX_8X4 => TX_8X8,
TX_16X16 | TX_8X16 | TX_16X8 | TX_4X16 | TX_16X4 => TX_16X16,
TX_32X32 | TX_16X32 | TX_32X16 | TX_8X32 | TX_32X8 => TX_32X32,
TX_64X64 | TX_32X64 | TX_64X32 | TX_16X64 | TX_64X16 => TX_64X64
}
}
pub fn by_dims(w: usize, h: usize) -> TxSize {
match (w, h) {
(4, 4) => TX_4X4,
(8, 8) => TX_8X8,
(16, 16) => TX_16X16,
(32, 32) => TX_32X32,
(64, 64) => TX_64X64,
(4, 8) => TX_4X8,
(8, 4) => TX_8X4,
(8, 16) => TX_8X16,
(16, 8) => TX_16X8,
(16, 32) => TX_16X32,
(32, 16) => TX_32X16,
(32, 64) => TX_32X64,
(64, 32) => TX_64X32,
(4, 16) => TX_4X16,
(16, 4) => TX_16X4,
(8, 32) => TX_8X32,
(32, 8) => TX_32X8,
(16, 64) => TX_16X64,
(64, 16) => TX_64X16,
_ => unreachable!()
}
}
pub fn is_rect(self) -> bool {
self.width_log2() != self.height_log2()
}
}
pub const TX_TYPES: usize = 16;
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd)]
#[repr(C)]
pub enum TxType {
DCT_DCT = 0, // DCT in both horizontal and vertical
ADST_DCT = 1, // ADST in vertical, DCT in horizontal
DCT_ADST = 2, // DCT in vertical, ADST in horizontal
ADST_ADST = 3, // ADST in both directions
FLIPADST_DCT = 4,
DCT_FLIPADST = 5,
FLIPADST_FLIPADST = 6,
ADST_FLIPADST = 7,
FLIPADST_ADST = 8,
IDTX = 9,
V_DCT = 10,
H_DCT = 11,
V_ADST = 12,
H_ADST = 13,
V_FLIPADST = 14,
H_FLIPADST = 15
}
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
pub enum PredictionMode {
DC_PRED, // Average of above and left pixels
......@@ -591,6 +409,7 @@ pub enum InterIntraMode {
II_SMOOTH_PRED,
INTERINTRA_MODES
}
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
pub enum CompoundType {
COMPOUND_AVERAGE,
......@@ -694,16 +513,6 @@ pub static RAV1E_PARTITION_TYPES: &'static [PartitionType] =
&[PartitionType::PARTITION_NONE, PartitionType::PARTITION_HORZ,
PartitionType::PARTITION_VERT, PartitionType::PARTITION_SPLIT];
pub static RAV1E_TX_TYPES: &'static [TxType] = &[
TxType::DCT_DCT,
TxType::ADST_DCT,
TxType::DCT_ADST,
TxType::ADST_ADST,
TxType::IDTX,
TxType::V_DCT,
TxType::H_DCT
];
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
pub enum GlobalMVMode {
IDENTITY = 0, // identity transformation, 0-parameter
......@@ -1121,30 +930,6 @@ impl PredictionMode {
}
}
#[derive(Copy, Clone, PartialEq, PartialOrd)]
pub enum TxSet {
// DCT only
TX_SET_DCTONLY,
// DCT + Identity only
TX_SET_DCT_IDTX,
// Discrete Trig transforms w/o flip (4) + Identity (1)
TX_SET_DTT4_IDTX,
// Discrete Trig transforms w/o flip (4) + Identity (1) + 1D Hor/vert DCT (2)
// for 16x16 only
TX_SET_DTT4_IDTX_1DDCT_16X16,
// Discrete Trig transforms w/o flip (4) + Identity (1) + 1D Hor/vert DCT (2)
TX_SET_DTT4_IDTX_1DDCT,
// Discrete Trig transforms w/ flip (9) + Identity (1)
TX_SET_DTT9_IDTX,
// Discrete Trig transforms w/ flip (9) + Identity (1) + 1D Hor/Ver DCT (2)
TX_SET_DTT9_IDTX_1DDCT,
// Discrete Trig transforms w/ flip (9) + Identity (1) + 1D Hor/Ver (6)
// for 16x16 only
TX_SET_ALL16_16X16,
// Discrete Trig transforms w/ flip (9) + Identity (1) + 1D Hor/Ver (6)
TX_SET_ALL16
}
pub fn has_tr(bo: BlockOffset, bsize: BlockSize) -> bool {
let sb_mi_size = BLOCK_64X64.width_mi(); /* Assume 64x64 for now */
let mask_row = bo.y & LOCAL_BLOCK_MASK;
......
......@@ -9,7 +9,7 @@
#![allow(non_upper_case_globals)]
use crate::partition::TxSize;
use crate::transform::TxSize;
use crate::util::*;
use num_traits::*;
......@@ -143,7 +143,7 @@ fn divu_pair(x: i32, d: (u32, u32, u32)) -> i32 {
#[cfg(test)]
mod test {
use super::*;
use crate::partition::TxSize::*;
use crate::transform::TxSize::*;
#[test]
fn test_divu_pair() {
......
......@@ -32,6 +32,7 @@ use crate::Tune;
use crate::write_tx_blocks;
use crate::write_tx_tree;
use crate::tiling::*;
use crate::transform::{RAV1E_TX_TYPES, TxSet, TxSize, TxType};
use crate::util::{AlignedArray, CastFromPrimitive, Pixel, UninitializedAlignedArray};
use crate::rdo_tables::*;
......
pub const RDO_NUM_BINS: usize = 50;
#[allow(unused)]
pub const RDO_MAX_BIN: usize = 10000;
......@@ -9,7 +8,7 @@ pub const RDO_QUANT_DIV: usize = 256/RDO_QUANT_BINS;
pub const RDO_BIN_SIZE: u64 = (RDO_MAX_BIN / RDO_NUM_BINS) as u64;
pub const RATE_EST_BIN_SIZE: u64 = (RATE_EST_MAX_BIN / RDO_NUM_BINS) as u64;
use crate::partition::*;
use crate::transform::TxSize;
pub static RDO_RATE_TABLE: [[[u64; RDO_NUM_BINS]; TxSize::TX_SIZES_ALL]; RDO_QUANT_BINS] = [
[[99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,99999,104,],
......
......@@ -14,7 +14,7 @@
const MAX_NEIGHBORS: usize = 2;
use crate::partition::*;
use crate::transform::*;
#[repr(C)]
pub struct SCAN_ORDER {
......
......@@ -9,6 +9,7 @@
use crate::context::*;
use crate::partition::*;
use crate::transform::*;
use std::cmp;
use std::marker::PhantomData;
......
......@@ -10,7 +10,7 @@
#![allow(non_upper_case_globals)]
use crate::context::*;
use crate::partition::*;
use crate::transform::*;
const TOKEN_CDF_Q_CTXS: usize = 4;
......
......@@ -8,7 +8,6 @@
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
use super::*;
use crate::partition::{TxSize, TxType};
type TxfmShift = [i8; 3];
type TxfmShifts = [TxfmShift; 3];
......
......@@ -15,7 +15,6 @@ pub use self::native::*;
// TODO: move 1d txfm code to native module.
use super::*;
use crate::partition::TxType;
static COSPI_INV: [i32; 64] = [
4096, 4095, 4091, 4085, 4076, 4065, 4052, 4036, 4017, 3996, 3973, 3948,
......@@ -1510,7 +1509,6 @@ static INV_TXFM_FNS: [[InvTxfmFn; 5]; 4] = [
#[cfg(all(target_arch = "x86_64", feature = "nasm"))]
mod nasm {
use super::*;
use crate::partition::TxType;
type InvTxfmFunc =
unsafe extern fn(*mut u8, libc::ptrdiff_t, *const i16, i32);
......@@ -1653,7 +1651,6 @@ mod nasm {
mod native {
use super::*;
use crate::partition::TxType;
use crate::util::clamp;
use std::cmp;
......
......@@ -7,21 +7,245 @@
// 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.
#![allow(non_camel_case_types)]
#![allow(dead_code)]
pub use self::forward::*;
pub use self::inverse::*;
use crate::partition::{TxSize, TxType, TX_TYPES};
use crate::context::*;
use crate::partition::*;
use crate::partition::BlockSize::*;
use crate::predict::*;
use crate::tiling::*;
use crate::util::*;
use TxSize::*;
mod forward;
mod inverse;
pub static RAV1E_TX_TYPES: &'static [TxType] = &[
TxType::DCT_DCT,
TxType::ADST_DCT,
TxType::DCT_ADST,
TxType::ADST_ADST,
TxType::IDTX,
TxType::V_DCT,
TxType::H_DCT
];
static SQRT2_BITS: usize = 12;
static SQRT2: i32 = 5793; // 2^12 * sqrt(2)
static INV_SQRT2: i32 = 2896; // 2^12 / sqrt(2)
pub const TX_TYPES: usize = 16;
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd)]
#[repr(C)]
pub enum TxType {
DCT_DCT = 0, // DCT in both horizontal and vertical
ADST_DCT = 1, // ADST in vertical, DCT in horizontal
DCT_ADST = 2, // DCT in vertical, ADST in horizontal
ADST_ADST = 3, // ADST in both directions
FLIPADST_DCT = 4,
DCT_FLIPADST = 5,
FLIPADST_FLIPADST = 6,
ADST_FLIPADST = 7,
FLIPADST_ADST = 8,
IDTX = 9,
V_DCT = 10,
H_DCT = 11,
V_ADST = 12,
H_ADST = 13,
V_FLIPADST = 14,
H_FLIPADST = 15
}
/// Transform Size
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
#[repr(C)]
pub enum TxSize {
TX_4X4,
TX_8X8,
TX_16X16,
TX_32X32,
TX_64X64,
TX_4X8,
TX_8X4,
TX_8X16,
TX_16X8,
TX_16X32,
TX_32X16,
TX_32X64,
TX_64X32,
TX_4X16,
TX_16X4,
TX_8X32,
TX_32X8,
TX_16X64,
TX_64X16
}
impl TxSize {
/// Number of square transform sizes
pub const TX_SIZES: usize = 5;
/// Number of transform sizes (including non-square sizes)
pub const TX_SIZES_ALL: usize = 14 + 5;
pub fn width(self) -> usize {
1 << self.width_log2()
}
pub fn width_log2(self) -> usize {
match self {
TX_4X4 | TX_4X8 | TX_4X16 => 2,
TX_8X8 | TX_8X4 | TX_8X16 | TX_8X32 => 3,
TX_16X16 | TX_16X8 | TX_16X32 | TX_16X4 | TX_16X64 => 4,
TX_32X32 | TX_32X16 | TX_32X64 | TX_32X8 => 5,
TX_64X64 | TX_64X32 | TX_64X16 => 6
}
}
pub fn width_index(self) -> usize {
self.width_log2() - TX_4X4.width_log2()
}
pub fn height(self) -> usize {
1 << self.height_log2()
}
pub fn height_log2(self) -> usize {
match self {
TX_4X4 | TX_8X4 | TX_16X4 => 2,
TX_8X8 | TX_4X8 | TX_16X8 | TX_32X8 => 3,
TX_16X16 | TX_8X16 | TX_32X16 | TX_4X16 | TX_64X16 => 4,
TX_32X32 | TX_16X32 | TX_64X32 | TX_8X32 => 5,
TX_64X64 | TX_32X64 | TX_16X64 => 6
}
}
pub fn height_index(self) -> usize {
self.height_log2() - TX_4X4.height_log2()
}
pub fn width_mi(self) -> usize {
self.width() >> MI_SIZE_LOG2
}
pub fn area(self) -> usize {
1 << self.area_log2()
}
pub fn area_log2(self) -> usize {
self.width_log2() + self.height_log2()
}
pub fn height_mi(self) -> usize {
self.height() >> MI_SIZE_LOG2
}
pub fn block_size(self) -> BlockSize {
match self {
TX_4X4 => BLOCK_4X4,
TX_8X8 => BLOCK_8X8,
TX_16X16 => BLOCK_16X16,
TX_32X32 => BLOCK_32X32,
TX_64X64 => BLOCK_64X64,
TX_4X8 => BLOCK_4X8,
TX_8X4 => BLOCK_8X4,
TX_8X16 => BLOCK_8X16,
TX_16X8 => BLOCK_16X8,
TX_16X32 => BLOCK_16X32,
TX_32X16 => BLOCK_32X16,
TX_32X64 => BLOCK_32X64,
TX_64X32 => BLOCK_64X32,
TX_4X16 => BLOCK_4X16,
TX_16X4 => BLOCK_16X4,
TX_8X32 => BLOCK_8X32,
TX_32X8 => BLOCK_32X8,
TX_16X64 => BLOCK_16X64,
TX_64X16 => BLOCK_64X16
}
}
pub fn sqr(self) -> TxSize {
match self {
TX_4X4 | TX_4X8 | TX_8X4 | TX_4X16 | TX_16X4 => TX_4X4,
TX_8X8 | TX_8X16 | TX_16X8 | TX_8X32 | TX_32X8 => TX_8X8,
TX_16X16 | TX_16X32 | TX_32X16 | TX_16X64 | TX_64X16 => TX_16X16,
TX_32X32 | TX_32X64 | TX_64X32 => TX_32X32,
TX_64X64 => TX_64X64
}
}
pub fn sqr_up(self) -> TxSize {
match self {
TX_4X4 => TX_4X4,
TX_8X8 | TX_4X8 | TX_8X4 => TX_8X8,
TX_16X16 | TX_8X16 | TX_16X8 | TX_4X16 | TX_16X4 => TX_16X16,
TX_32X32 | TX_16X32 | TX_32X16 | TX_8X32 | TX_32X8 => TX_32X32,
TX_64X64 | TX_32X64 | TX_64X32 | TX_16X64 | TX_64X16 => TX_64X64
}
}
pub fn by_dims(w: usize, h: usize) -> TxSize {
match (w, h) {
(4, 4) => TX_4X4,
(8, 8) => TX_8X8,
(16, 16) => TX_16X16,
(32, 32) => TX_32X32,
(64, 64) => TX_64X64,
(4, 8) => TX_4X8,
(8, 4) => TX_8X4,
(8, 16) => TX_8X16,
(16, 8) => TX_16X8,
(16, 32) => TX_16X32,
(32, 16) => TX_32X16,
(32, 64) => TX_32X64,
(64, 32) => TX_64X32,
(4, 16) => TX_4X16,
(16, 4) => TX_16X4,
(8, 32) => TX_8X32,
(32, 8) => TX_32X8,
(16, 64) => TX_16X64,
(64, 16) => TX_64X16,
_ => unreachable!()
}
}
pub fn is_rect(self) -> bool {
self.width_log2() != self.height_log2()
}
}
#[derive(Copy, Clone, PartialEq, PartialOrd)]
pub enum TxSet {
// DCT only
TX_SET_DCTONLY,
// DCT + Identity only
TX_SET_DCT_IDTX,
// Discrete Trig transforms w/o flip (4) + Identity (1)
TX_SET_DTT4_IDTX,
// Discrete Trig transforms w/o flip (4) + Identity (1) + 1D Hor/vert DCT (2)
// for 16x16 only