Commit 6147b1b6 authored by Debargha Mukherjee's avatar Debargha Mukherjee
Browse files

Change tx_size encoding for intra modes

Conveys depth from the largest transform size instead of the
actual transform size. Besides, the max depth is now limited
by the macro MAX_TX_DPETH set at 2.

Results: BDRATE lowres (30 frames): -0.005%

Change-Id: I1ccbac8ee18c77b816a6a8f500abfaa7892b21de
parent db82c288
...@@ -1201,12 +1201,17 @@ static INLINE TX_TYPE av1_get_tx_type(PLANE_TYPE plane_type, ...@@ -1201,12 +1201,17 @@ static INLINE TX_TYPE av1_get_tx_type(PLANE_TYPE plane_type,
void av1_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y); void av1_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y);
static INLINE int tx_size_to_depth(TX_SIZE tx_size) { static INLINE int tx_size_cat_to_max_depth(int tx_size_cat) {
return (int)(tx_size - TX_SIZE_LUMA_MIN); return AOMMIN(tx_size_cat + 1, MAX_TX_DEPTH);
} }
static INLINE TX_SIZE depth_to_tx_size(int depth) { static INLINE int tx_size_to_depth(TX_SIZE tx_size, int tx_size_cat) {
return (TX_SIZE)(depth + TX_SIZE_LUMA_MIN); return (int)(tx_size_cat + 1 - (int)tx_size);
}
static INLINE TX_SIZE depth_to_tx_size(int depth, int tx_size_cat) {
assert(tx_size_cat + 1 - depth >= 0 && tx_size_cat + 1 - depth < TX_SIZES);
return (TX_SIZE)(tx_size_cat + 1 - depth);
} }
static INLINE TX_SIZE av1_get_uv_tx_size(const MB_MODE_INFO *mbmi, static INLINE TX_SIZE av1_get_uv_tx_size(const MB_MODE_INFO *mbmi,
......
...@@ -1757,15 +1757,31 @@ static const aom_cdf_prob ...@@ -1757,15 +1757,31 @@ static const aom_cdf_prob
#endif #endif
static const aom_cdf_prob static const aom_cdf_prob
default_tx_size_cdf[MAX_TX_DEPTH][TX_SIZE_CONTEXTS][CDF_SIZE(MAX_TX_DEPTH + default_tx_size_cdf[MAX_TX_CATS][TX_SIZE_CONTEXTS][CDF_SIZE(MAX_TX_DEPTH +
1)] = { 1)] = {
{ { AOM_CDF2(12800) }, { AOM_CDF2(8448) } }, #if MAX_TX_DEPTH == 2
{ { AOM_CDF3(2560, 20496) }, { AOM_CDF3(1920, 14091) } }, { { AOM_CDF2(19968) }, { AOM_CDF2(24320) } },
{ { AOM_CDF4(384, 17588, 19782) }, { AOM_CDF4(640, 7166, 8466) } }, { { AOM_CDF3(12272, 30172) }, { AOM_CDF3(18677, 30848) } },
{ { AOM_CDF3(12986, 15180) }, { AOM_CDF3(24302, 25602) } },
#if CONFIG_TX64X64 #if CONFIG_TX64X64
{ { AOM_CDF5(128, 8288, 21293, 26986) }, { { AOM_CDF3(5782, 11475) }, { AOM_CDF3(16803, 22759) } },
{ AOM_CDF5(128, 4208, 10009, 15965) } }, #endif // CONFIG_TX64X64
#endif #elif MAX_TX_DEPTH == 3
{ { AOM_CDF2(19968) }, { AOM_CDF2(24320) } },
{ { AOM_CDF3(12272, 30172) }, { AOM_CDF3(18677, 30848) } },
{ { AOM_CDF4(12986, 15180, 32384) }, { AOM_CDF4(24302, 25602, 32128) } },
#if CONFIG_TX64X64
{ { AOM_CDF4(5782, 11475, 24480) }, { AOM_CDF4(16803, 22759, 28560) } },
#endif // CONFIG_TX64X64
#else
{ { AOM_CDF2(19968) }, { AOM_CDF2(24320) } },
{ { AOM_CDF3(12272, 30172) }, { AOM_CDF3(18677, 30848) } },
{ { AOM_CDF4(12986, 15180, 32384) }, { AOM_CDF4(24302, 25602, 32128) } },
#if CONFIG_TX64X64
{ { AOM_CDF5(5782, 11475, 24480, 32640) },
{ AOM_CDF5(16803, 22759, 28560, 32640) } },
#endif // CONFIG_TX64X64
#endif // MAX_TX_DEPTH == 2
}; };
static const aom_cdf_prob static const aom_cdf_prob
......
...@@ -326,7 +326,7 @@ typedef struct frame_contexts { ...@@ -326,7 +326,7 @@ typedef struct frame_contexts {
[CDF_SIZE(2 * MAX_ANGLE_DELTA + 1)]; [CDF_SIZE(2 * MAX_ANGLE_DELTA + 1)];
#endif // CONFIG_EXT_INTRA_MOD #endif // CONFIG_EXT_INTRA_MOD
aom_cdf_prob tx_size_cdf[MAX_TX_DEPTH][TX_SIZE_CONTEXTS] aom_cdf_prob tx_size_cdf[MAX_TX_CATS][TX_SIZE_CONTEXTS]
[CDF_SIZE(MAX_TX_DEPTH + 1)]; [CDF_SIZE(MAX_TX_DEPTH + 1)];
aom_cdf_prob delta_q_cdf[CDF_SIZE(DELTA_Q_PROBS + 1)]; aom_cdf_prob delta_q_cdf[CDF_SIZE(DELTA_Q_PROBS + 1)];
#if CONFIG_EXT_DELTA_Q #if CONFIG_EXT_DELTA_Q
......
...@@ -246,7 +246,9 @@ typedef enum ATTRIBUTE_PACKED { ...@@ -246,7 +246,9 @@ typedef enum ATTRIBUTE_PACKED {
one more than the minimum. */ one more than the minimum. */
#define TX_SIZE_CTX_MIN (TX_SIZE_LUMA_MIN + 1) #define TX_SIZE_CTX_MIN (TX_SIZE_LUMA_MIN + 1)
#define MAX_TX_DEPTH (TX_SIZES - TX_SIZE_CTX_MIN) // Maximum tx_size categories
#define MAX_TX_CATS (TX_SIZES - TX_SIZE_CTX_MIN)
#define MAX_TX_DEPTH 2
#define MAX_TX_SIZE_LOG2 (5 + CONFIG_TX64X64) #define MAX_TX_SIZE_LOG2 (5 + CONFIG_TX64X64)
#define MAX_TX_SIZE (1 << MAX_TX_SIZE_LOG2) #define MAX_TX_SIZE (1 << MAX_TX_SIZE_LOG2)
......
...@@ -510,13 +510,15 @@ static void read_tx_size_vartx(AV1_COMMON *cm, MACROBLOCKD *xd, ...@@ -510,13 +510,15 @@ static void read_tx_size_vartx(AV1_COMMON *cm, MACROBLOCKD *xd,
static TX_SIZE read_selected_tx_size(AV1_COMMON *cm, MACROBLOCKD *xd, static TX_SIZE read_selected_tx_size(AV1_COMMON *cm, MACROBLOCKD *xd,
int32_t tx_size_cat, aom_reader *r) { int32_t tx_size_cat, aom_reader *r) {
const int max_depths = tx_size_cat_to_max_depth(tx_size_cat);
const int ctx = get_tx_size_context(xd); const int ctx = get_tx_size_context(xd);
FRAME_CONTEXT *ec_ctx = xd->tile_ctx; FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
(void)cm; (void)cm;
const int depth = aom_read_symbol(r, ec_ctx->tx_size_cdf[tx_size_cat][ctx], const int depth = aom_read_symbol(r, ec_ctx->tx_size_cdf[tx_size_cat][ctx],
tx_size_cat + 2, ACCT_STR); max_depths + 1, ACCT_STR);
const TX_SIZE tx_size = depth_to_tx_size(depth); assert(depth >= 0 && depth <= max_depths);
const TX_SIZE tx_size = depth_to_tx_size(depth, tx_size_cat);
assert(!is_rect_tx(tx_size)); assert(!is_rect_tx(tx_size));
return tx_size; return tx_size;
} }
......
...@@ -322,18 +322,22 @@ static void write_selected_tx_size(const AV1_COMMON *cm, const MACROBLOCKD *xd, ...@@ -322,18 +322,22 @@ static void write_selected_tx_size(const AV1_COMMON *cm, const MACROBLOCKD *xd,
(void)cm; (void)cm;
if (block_signals_txsize(bsize)) { if (block_signals_txsize(bsize)) {
const TX_SIZE tx_size = mbmi->tx_size; const TX_SIZE tx_size = mbmi->tx_size;
const int is_inter = is_inter_block(mbmi);
const int tx_size_ctx = get_tx_size_context(xd); const int tx_size_ctx = get_tx_size_context(xd);
const int32_t tx_size_cat = is_inter ? inter_tx_size_cat_lookup[bsize] const int32_t tx_size_cat = intra_tx_size_cat_lookup[bsize];
: intra_tx_size_cat_lookup[bsize];
const TX_SIZE coded_tx_size = txsize_sqr_up_map[tx_size]; const TX_SIZE coded_tx_size = txsize_sqr_up_map[tx_size];
const int depth = tx_size_to_depth(coded_tx_size); const int depth = tx_size_to_depth(coded_tx_size, tx_size_cat);
const int max_depths = tx_size_cat_to_max_depth(tx_size_cat);
assert(coded_tx_size <= tx_size_cat + 1);
assert(depth >= 0 && depth <= max_depths);
assert(!is_inter_block(mbmi));
assert(IMPLIES(is_rect_tx(tx_size), is_rect_tx_allowed(xd, mbmi))); assert(IMPLIES(is_rect_tx(tx_size), is_rect_tx_allowed(xd, mbmi)));
aom_write_symbol(w, depth, ec_ctx->tx_size_cdf[tx_size_cat][tx_size_ctx], aom_write_symbol(w, depth, ec_ctx->tx_size_cdf[tx_size_cat][tx_size_ctx],
tx_size_cat + 2); max_depths + 1);
#if CONFIG_RECT_TX_EXT #if CONFIG_RECT_TX_EXT
if (is_quarter_tx_allowed(xd, mbmi, is_inter) && tx_size != coded_tx_size) if (is_quarter_tx_allowed(xd, mbmi, 0) && tx_size != coded_tx_size)
#if CONFIG_NEW_MULTISYMBOL #if CONFIG_NEW_MULTISYMBOL
aom_write_symbol(w, tx_size == quarter_txsize_lookup[bsize], aom_write_symbol(w, tx_size == quarter_txsize_lookup[bsize],
cm->fc->quarter_tx_size_cdf, 2); cm->fc->quarter_tx_size_cdf, 2);
......
...@@ -219,7 +219,7 @@ void av1_fill_mode_rates(AV1_COMMON *const cm, MACROBLOCK *x, ...@@ -219,7 +219,7 @@ void av1_fill_mode_rates(AV1_COMMON *const cm, MACROBLOCK *x,
} }
#endif // CONFIG_CFL #endif // CONFIG_CFL
for (i = 0; i < MAX_TX_DEPTH; ++i) for (i = 0; i < MAX_TX_CATS; ++i)
for (j = 0; j < TX_SIZE_CONTEXTS; ++j) for (j = 0; j < TX_SIZE_CONTEXTS; ++j)
av1_cost_tokens_from_cdf(x->tx_size_cost[i][j], fc->tx_size_cdf[i][j], av1_cost_tokens_from_cdf(x->tx_size_cost[i][j], fc->tx_size_cdf[i][j],
NULL); NULL);
......
...@@ -2357,7 +2357,7 @@ static int tx_size_cost(const AV1_COMMON *const cm, const MACROBLOCK *const x, ...@@ -2357,7 +2357,7 @@ static int tx_size_cost(const AV1_COMMON *const cm, const MACROBLOCK *const x,
const int32_t tx_size_cat = is_inter ? inter_tx_size_cat_lookup[bsize] const int32_t tx_size_cat = is_inter ? inter_tx_size_cat_lookup[bsize]
: intra_tx_size_cat_lookup[bsize]; : intra_tx_size_cat_lookup[bsize];
const TX_SIZE coded_tx_size = txsize_sqr_up_map[tx_size]; const TX_SIZE coded_tx_size = txsize_sqr_up_map[tx_size];
const int depth = tx_size_to_depth(coded_tx_size); const int depth = tx_size_to_depth(coded_tx_size, tx_size_cat);
const int tx_size_ctx = get_tx_size_context(xd); const int tx_size_ctx = get_tx_size_context(xd);
int r_tx_size = x->tx_size_cost[tx_size_cat][tx_size_ctx][depth]; int r_tx_size = x->tx_size_cost[tx_size_cat][tx_size_ctx][depth];
#if CONFIG_RECT_TX_EXT #if CONFIG_RECT_TX_EXT
...@@ -2739,7 +2739,7 @@ static void choose_tx_size_type_from_rd(const AV1_COMP *const cpi, ...@@ -2739,7 +2739,7 @@ static void choose_tx_size_type_from_rd(const AV1_COMP *const cpi,
if (tx_select) { if (tx_select) {
start_tx = max_tx_size; start_tx = max_tx_size;
end_tx = (max_tx_size >= TX_32X32) ? TX_8X8 : TX_4X4; end_tx = AOMMAX((int)TX_4X4, start_tx - MAX_TX_DEPTH + evaluate_rect_tx);
} else { } else {
const TX_SIZE chosen_tx_size = const TX_SIZE chosen_tx_size =
tx_size_from_tx_mode(bs, cm->tx_mode, is_inter); tx_size_from_tx_mode(bs, cm->tx_mode, is_inter);
......
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