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

Use pattern matching in BlockSize::subsize()

parent 4334d7ca
......@@ -228,7 +228,6 @@ impl BlockSize {
pub fn largest_uv_tx_size(self, xdec: usize, ydec: usize) -> TxSize {
let plane_bsize = get_plane_block_size(self, xdec, ydec);
debug_assert!((plane_bsize as usize) < BlockSize::BLOCK_SIZES_ALL);
let uv_tx = max_txsize_rect_lookup[plane_bsize as usize];
av1_get_coded_tx_size(uv_tx)
......@@ -259,203 +258,49 @@ impl BlockSize {
(self.width() == other.width() && self.height() == other.height())
}
#[rustfmt::skip]
const SUBSIZE_LOOKUP: [[BlockSize; BlockSize::BLOCK_SIZES_ALL];
EXT_PARTITION_TYPES] = [
// PARTITION_NONE
[
// 4X4
BLOCK_4X4,
// 4X8, 8X4, 8X8
BLOCK_4X8, BLOCK_8X4, BLOCK_8X8,
// 8X16, 16X8, 16X16
BLOCK_8X16, BLOCK_16X8, BLOCK_16X16,
// 16X32, 32X16, 32X32
BLOCK_16X32, BLOCK_32X16, BLOCK_32X32,
// 32X64, 64X32, 64X64
BLOCK_32X64, BLOCK_64X32, BLOCK_64X64,
// 64x128, 128x64, 128x128
BLOCK_64X128, BLOCK_128X64, BLOCK_128X128,
// 4X16, 16X4, 8X32
BLOCK_4X16, BLOCK_16X4, BLOCK_8X32,
// 32X8, 16X64, 64X16
BLOCK_32X8, BLOCK_16X64, BLOCK_64X16
],
// PARTITION_HORZ
[
// 4X4
BLOCK_INVALID,
// 4X8, 8X4, 8X8
BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X4,
// 8X16, 16X8, 16X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X8,
// 16X32, 32X16, 32X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X16,
// 32X64, 64X32, 64X64
BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X32,
// 64x128, 128x64, 128x128
BLOCK_INVALID, BLOCK_INVALID, BLOCK_128X64,
// 4X16, 16X4, 8X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
// 32X8, 16X64, 64X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID
],
// PARTITION_VERT
[
// 4X4
BLOCK_INVALID,
// 4X8, 8X4, 8X8
BLOCK_INVALID, BLOCK_INVALID, BLOCK_4X8,
// 8X16, 16X8, 16X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X16,
// 16X32, 32X16, 32X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X32,
// 32X64, 64X32, 64X64
BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X64,
// 64x128, 128x64, 128x128
BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X128,
// 4X16, 16X4, 8X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
// 32X8, 16X64, 64X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID
],
// PARTITION_SPLIT
[
// 4X4
BLOCK_INVALID,
// 4X8, 8X4, 8X8
BLOCK_INVALID, BLOCK_INVALID, BLOCK_4X4,
// 8X16, 16X8, 16X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X8,
// 16X32, 32X16, 32X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X16,
// 32X64, 64X32, 64X64
BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X32,
// 64x128, 128x64, 128x128
BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X64,
// 4X16, 16X4, 8X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
// 32X8, 16X64, 64X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID
],
// PARTITION_HORZ_A
[
// 4X4
BLOCK_INVALID,
// 4X8, 8X4, 8X8
BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X4,
// 8X16, 16X8, 16X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X8,
// 16X32, 32X16, 32X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X16,
// 32X64, 64X32, 64X64
BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X32,
// 64x128, 128x64, 128x128
BLOCK_INVALID, BLOCK_INVALID, BLOCK_128X64,
// 4X16, 16X4, 8X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
// 32X8, 16X64, 64X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
],
// PARTITION_HORZ_B
[
// 4X4
BLOCK_INVALID,
// 4X8, 8X4, 8X8
BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X4,
// 8X16, 16X8, 16X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X8,
// 16X32, 32X16, 32X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X16,
// 32X64, 64X32, 64X64
BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X32,
// 64x128, 128x64, 128x128
BLOCK_INVALID, BLOCK_INVALID, BLOCK_128X64,
// 4X16, 16X4, 8X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
// 32X8, 16X64, 64X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID
],
// PARTITION_VERT_A
[
// 4X4
BLOCK_INVALID,
// 4X8, 8X4, 8X8
BLOCK_INVALID, BLOCK_INVALID, BLOCK_4X8,
// 8X16, 16X8, 16X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X16,
// 16X32, 32X16, 32X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X32,
// 32X64, 64X32, 64X64
BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X64,
// 64x128, 128x64, 128x128
BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X128,
// 4X16, 16X4, 8X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
// 32X8, 16X64, 64X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID
],
// PARTITION_VERT_B
[
// 4X4
BLOCK_INVALID,
// 4X8, 8X4, 8X8
BLOCK_INVALID, BLOCK_INVALID, BLOCK_4X8,
// 8X16, 16X8, 16X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X16,
// 16X32, 32X16, 32X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X32,
// 32X64, 64X32, 64X64
BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X64,
// 64x128, 128x64, 128x128
BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X128,
// 4X16, 16X4, 8X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
// 32X8, 16X64, 64X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID
],
// PARTITION_HORZ_4
[
// 4X4
BLOCK_INVALID,
// 4X8, 8X4, 8X8
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
// 8X16, 16X8, 16X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X4,
// 16X32, 32X16, 32X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X8,
// 32X64, 64X32, 64X64
BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X16,
// 64x128, 128x64, 128x128
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
// 4X16, 16X4, 8X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
// 32X8, 16X64, 64X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID
],
// PARTITION_VERT_4
[
// 4X4
BLOCK_INVALID,
// 4X8, 8X4, 8X8
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
// 8X16, 16X8, 16X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_4X16,
// 16X32, 32X16, 32X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X32,
// 32X64, 64X32, 64X64
BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X64,
// 64x128, 128x64, 128x128
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
// 4X16, 16X4, 8X32
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
// 32X8, 16X64, 64X16
BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID
]
];
pub fn subsize(self, partition: PartitionType) -> BlockSize {
BlockSize::SUBSIZE_LOOKUP[partition as usize][self as usize]
use PartitionType::*;
match partition {
PARTITION_NONE => self,
PARTITION_SPLIT => match self {
BLOCK_8X8 => BLOCK_4X4,
BLOCK_16X16 => BLOCK_8X8,
BLOCK_32X32 => BLOCK_16X16,
BLOCK_64X64 => BLOCK_32X32,
BLOCK_128X128 => BLOCK_64X64,
_ => BLOCK_INVALID
}
PARTITION_HORZ | PARTITION_HORZ_A | PARTITION_HORZ_B => match self {
BLOCK_8X8 => BLOCK_8X4,
BLOCK_16X16 => BLOCK_16X8,
BLOCK_32X32 => BLOCK_32X16,
BLOCK_64X64 => BLOCK_64X32,
BLOCK_128X128 => BLOCK_128X64,
_ => BLOCK_INVALID
},
PARTITION_VERT | PARTITION_VERT_A | PARTITION_VERT_B => match self {
BLOCK_8X8 => BLOCK_4X8,
BLOCK_16X16 => BLOCK_8X16,
BLOCK_32X32 => BLOCK_16X32,
BLOCK_64X64 => BLOCK_32X64,
BLOCK_128X128 => BLOCK_64X128,
_ => BLOCK_INVALID
},
PARTITION_HORZ_4 => match self {
BLOCK_16X16 => BLOCK_16X4,
BLOCK_32X32 => BLOCK_32X8,
BLOCK_64X64 => BLOCK_64X16,
_ => BLOCK_INVALID
},
PARTITION_VERT_4 => match self {
BLOCK_16X16 => BLOCK_4X16,
BLOCK_32X32 => BLOCK_8X32,
BLOCK_64X64 => BLOCK_16X64,
_ => BLOCK_INVALID
},
_ => BLOCK_INVALID
}
}
pub fn is_rect_tx_allowed(self) -> bool {
......
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