Add EOB threshold calculation for ADAPT_SCAN
Change-Id: I0c58fb5ee2a77ae15f6243b1c645dbe601171e67
diff --git a/av1/common/common_data.h b/av1/common/common_data.h
index 6369386..415d5cf 100644
--- a/av1/common/common_data.h
+++ b/av1/common/common_data.h
@@ -1394,6 +1394,10 @@
#endif // CONFIG_EXT_PARTITION_TYPES
#endif // CONFIG_SUPERTX
+#if CONFIG_ADAPT_SCAN
+#define EOB_THRESHOLD_NUM 2
+#endif
+
#ifdef __cplusplus
} // extern "C"
#endif
diff --git a/av1/common/entropymode.h b/av1/common/entropymode.h
index 6ec269e..9cdd2b7 100644
--- a/av1/common/entropymode.h
+++ b/av1/common/entropymode.h
@@ -164,6 +164,8 @@
int16_t nb_32X16[TX_TYPES][(512 + 1) * 2];
SCAN_ORDER sc[TX_SIZES_ALL][TX_TYPES];
+
+ int16_t eob_threshold[TX_SIZES][TX_TYPES][EOB_THRESHOLD_NUM];
#endif // CONFIG_ADAPT_SCAN
#if CONFIG_LV_MAP
diff --git a/av1/common/scan.c b/av1/common/scan.c
index 6d0d15e..41ed284 100644
--- a/av1/common/scan.c
+++ b/av1/common/scan.c
@@ -6801,6 +6801,40 @@
}
}
+static void update_eob_threshold(AV1_COMMON *cm, TX_SIZE tx_size,
+ TX_TYPE tx_type) {
+ int i, row, col, row_limit, col_limit, cal_idx = 0;
+ const int tx_width = tx_size_wide[tx_size];
+ const int tx_height = tx_size_high[tx_size];
+
+ row_limit = tx_width >> 1;
+ col_limit = tx_height >> 1;
+
+ if (tx_width >= 8 && tx_height >= 8) {
+ SCAN_ORDER *sc = &cm->fc->sc[tx_size][tx_type];
+ int16_t *threshold = &cm->fc->eob_threshold[tx_size][tx_type][0];
+ const int tx2d_size = tx_size_2d[tx_size];
+
+ while (cal_idx < EOB_THRESHOLD_NUM) {
+ for (i = 0; i < tx2d_size; ++i) {
+ row = sc->scan[i] / tx_height;
+ col = sc->scan[i] % tx_width;
+ if (row >= row_limit || col >= col_limit) break;
+ }
+ row_limit >>= 1;
+ col_limit >>= 1;
+ threshold[cal_idx] = i;
+ cal_idx++;
+ }
+ }
+}
+
+const EobThreshold *av1_get_eob_threshold(const AV1_COMMON *cm,
+ const TX_SIZE tx_size,
+ const TX_TYPE tx_type) {
+ return (const EobThreshold *)&cm->fc->eob_threshold[tx_size][tx_type];
+}
+
void av1_adapt_scan_order(AV1_COMMON *cm) {
TX_SIZE tx_size;
for (tx_size = 0; tx_size < TX_SIZES_ALL; ++tx_size) {
@@ -6813,6 +6847,7 @@
for (tx_type = DCT_DCT; tx_type < TX_TYPES; ++tx_type) {
update_scan_prob(cm, tx_size, tx_type, ADAPT_SCAN_UPDATE_RATE_16);
update_scan_order_facade(cm, tx_size, tx_type);
+ update_eob_threshold(cm, tx_size, tx_type);
}
}
}
diff --git a/av1/common/scan.h b/av1/common/scan.h
index e1bf7d4..0f5ffdc 100644
--- a/av1/common/scan.h
+++ b/av1/common/scan.h
@@ -55,6 +55,11 @@
const int16_t *iscan, int16_t *neighbors);
void av1_init_scan_order(AV1_COMMON *cm);
void av1_adapt_scan_order(AV1_COMMON *cm);
+
+typedef int16_t EobThreshold[EOB_THRESHOLD_NUM];
+const EobThreshold *av1_get_eob_threshold(const AV1_COMMON *cm,
+ const TX_SIZE tx_size,
+ const TX_TYPE tx_type);
#endif
static INLINE int get_coef_context(const int16_t *neighbors,