summaryrefslogtreecommitdiff
path: root/third_party/aom/av1/common/cfl.c
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/aom/av1/common/cfl.c')
-rw-r--r--third_party/aom/av1/common/cfl.c642
1 files changed, 264 insertions, 378 deletions
diff --git a/third_party/aom/av1/common/cfl.c b/third_party/aom/av1/common/cfl.c
index f9acfcbc90..ee19f0bcfb 100644
--- a/third_party/aom/av1/common/cfl.c
+++ b/third_party/aom/av1/common/cfl.c
@@ -13,20 +13,77 @@
#include "av1/common/common_data.h"
#include "av1/common/onyxc_int.h"
+#include "config/av1_rtcd.h"
+
void cfl_init(CFL_CTX *cfl, AV1_COMMON *cm) {
- if (!((cm->subsampling_x == 0 && cm->subsampling_y == 0) ||
- (cm->subsampling_x == 1 && cm->subsampling_y == 1))) {
+ assert(block_size_wide[CFL_MAX_BLOCK_SIZE] == CFL_BUF_LINE);
+ assert(block_size_high[CFL_MAX_BLOCK_SIZE] == CFL_BUF_LINE);
+ if (!(cm->subsampling_x == 0 && cm->subsampling_y == 0) &&
+ !(cm->subsampling_x == 1 && cm->subsampling_y == 1) &&
+ !(cm->subsampling_x == 1 && cm->subsampling_y == 0)) {
aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM,
- "Only 4:4:4 and 4:2:0 are currently supported by CfL");
+ "Only 4:4:4, 4:2:2 and 4:2:0 are currently supported by "
+ "CfL, %d %d subsampling is not supported.\n",
+ cm->subsampling_x, cm->subsampling_y);
}
- memset(&cfl->pred_buf_q3, 0, sizeof(cfl->pred_buf_q3));
+ memset(&cfl->recon_buf_q3, 0, sizeof(cfl->recon_buf_q3));
+ memset(&cfl->ac_buf_q3, 0, sizeof(cfl->ac_buf_q3));
cfl->subsampling_x = cm->subsampling_x;
cfl->subsampling_y = cm->subsampling_y;
cfl->are_parameters_computed = 0;
cfl->store_y = 0;
-#if CONFIG_CHROMA_SUB8X8 && CONFIG_DEBUG
- cfl_clear_sub8x8_val(cfl);
-#endif // CONFIG_CHROMA_SUB8X8 && CONFIG_DEBUG
+ // The DC_PRED cache is disabled by default and is only enabled in
+ // cfl_rd_pick_alpha
+ cfl->use_dc_pred_cache = 0;
+ cfl->dc_pred_is_cached[CFL_PRED_U] = 0;
+ cfl->dc_pred_is_cached[CFL_PRED_V] = 0;
+}
+
+void cfl_store_dc_pred(MACROBLOCKD *const xd, const uint8_t *input,
+ CFL_PRED_TYPE pred_plane, int width) {
+ assert(pred_plane < CFL_PRED_PLANES);
+ assert(width <= CFL_BUF_LINE);
+
+ if (get_bitdepth_data_path_index(xd)) {
+ uint16_t *const input_16 = CONVERT_TO_SHORTPTR(input);
+ memcpy(xd->cfl.dc_pred_cache[pred_plane], input_16, width << 1);
+ return;
+ }
+
+ memcpy(xd->cfl.dc_pred_cache[pred_plane], input, width);
+}
+
+static void cfl_load_dc_pred_lbd(const int16_t *dc_pred_cache, uint8_t *dst,
+ int dst_stride, int width, int height) {
+ for (int j = 0; j < height; j++) {
+ memcpy(dst, dc_pred_cache, width);
+ dst += dst_stride;
+ }
+}
+
+static void cfl_load_dc_pred_hbd(const int16_t *dc_pred_cache, uint16_t *dst,
+ int dst_stride, int width, int height) {
+ const size_t num_bytes = width << 1;
+ for (int j = 0; j < height; j++) {
+ memcpy(dst, dc_pred_cache, num_bytes);
+ dst += dst_stride;
+ }
+}
+void cfl_load_dc_pred(MACROBLOCKD *const xd, uint8_t *dst, int dst_stride,
+ TX_SIZE tx_size, CFL_PRED_TYPE pred_plane) {
+ const int width = tx_size_wide[tx_size];
+ const int height = tx_size_high[tx_size];
+ assert(pred_plane < CFL_PRED_PLANES);
+ assert(width <= CFL_BUF_LINE);
+ assert(height <= CFL_BUF_LINE);
+ if (get_bitdepth_data_path_index(xd)) {
+ uint16_t *dst_16 = CONVERT_TO_SHORTPTR(dst);
+ cfl_load_dc_pred_hbd(xd->cfl.dc_pred_cache[pred_plane], dst_16, dst_stride,
+ width, height);
+ return;
+ }
+ cfl_load_dc_pred_lbd(xd->cfl.dc_pred_cache[pred_plane], dst, dst_stride,
+ width, height);
}
// Due to frame boundary issues, it is possible that the total area covered by
@@ -38,217 +95,54 @@ static INLINE void cfl_pad(CFL_CTX *cfl, int width, int height) {
if (diff_width > 0) {
const int min_height = height - diff_height;
- int16_t *pred_buf_q3 = cfl->pred_buf_q3 + (width - diff_width);
+ uint16_t *recon_buf_q3 = cfl->recon_buf_q3 + (width - diff_width);
for (int j = 0; j < min_height; j++) {
- const int last_pixel = pred_buf_q3[-1];
+ const uint16_t last_pixel = recon_buf_q3[-1];
+ assert(recon_buf_q3 + diff_width <= cfl->recon_buf_q3 + CFL_BUF_SQUARE);
for (int i = 0; i < diff_width; i++) {
- pred_buf_q3[i] = last_pixel;
+ recon_buf_q3[i] = last_pixel;
}
- pred_buf_q3 += MAX_SB_SIZE;
+ recon_buf_q3 += CFL_BUF_LINE;
}
cfl->buf_width = width;
}
if (diff_height > 0) {
- int16_t *pred_buf_q3 =
- cfl->pred_buf_q3 + ((height - diff_height) * MAX_SB_SIZE);
+ uint16_t *recon_buf_q3 =
+ cfl->recon_buf_q3 + ((height - diff_height) * CFL_BUF_LINE);
for (int j = 0; j < diff_height; j++) {
- const int16_t *last_row_q3 = pred_buf_q3 - MAX_SB_SIZE;
+ const uint16_t *last_row_q3 = recon_buf_q3 - CFL_BUF_LINE;
+ assert(recon_buf_q3 + width <= cfl->recon_buf_q3 + CFL_BUF_SQUARE);
for (int i = 0; i < width; i++) {
- pred_buf_q3[i] = last_row_q3[i];
+ recon_buf_q3[i] = last_row_q3[i];
}
- pred_buf_q3 += MAX_SB_SIZE;
+ recon_buf_q3 += CFL_BUF_LINE;
}
cfl->buf_height = height;
}
}
-static void sum_above_row_lbd(const uint8_t *above_u, const uint8_t *above_v,
- int width, int *out_sum_u, int *out_sum_v) {
- int sum_u = 0;
- int sum_v = 0;
- for (int i = 0; i < width; i++) {
- sum_u += above_u[i];
- sum_v += above_v[i];
- }
- *out_sum_u += sum_u;
- *out_sum_v += sum_v;
-}
-#if CONFIG_HIGHBITDEPTH
-static void sum_above_row_hbd(const uint16_t *above_u, const uint16_t *above_v,
- int width, int *out_sum_u, int *out_sum_v) {
- int sum_u = 0;
- int sum_v = 0;
- for (int i = 0; i < width; i++) {
- sum_u += above_u[i];
- sum_v += above_v[i];
- }
- *out_sum_u += sum_u;
- *out_sum_v += sum_v;
-}
-#endif // CONFIG_HIGHBITDEPTH
-
-static void sum_above_row(const MACROBLOCKD *xd, int width, int *out_sum_u,
- int *out_sum_v) {
- const struct macroblockd_plane *const pd_u = &xd->plane[AOM_PLANE_U];
- const struct macroblockd_plane *const pd_v = &xd->plane[AOM_PLANE_V];
-#if CONFIG_HIGHBITDEPTH
- if (get_bitdepth_data_path_index(xd)) {
- const uint16_t *above_u_16 =
- CONVERT_TO_SHORTPTR(pd_u->dst.buf) - pd_u->dst.stride;
- const uint16_t *above_v_16 =
- CONVERT_TO_SHORTPTR(pd_v->dst.buf) - pd_v->dst.stride;
- sum_above_row_hbd(above_u_16, above_v_16, width, out_sum_u, out_sum_v);
- return;
- }
-#endif // CONFIG_HIGHBITDEPTH
- const uint8_t *above_u = pd_u->dst.buf - pd_u->dst.stride;
- const uint8_t *above_v = pd_v->dst.buf - pd_v->dst.stride;
- sum_above_row_lbd(above_u, above_v, width, out_sum_u, out_sum_v);
-}
-
-static void sum_left_col_lbd(const uint8_t *left_u, int u_stride,
- const uint8_t *left_v, int v_stride, int height,
- int *out_sum_u, int *out_sum_v) {
- int sum_u = 0;
- int sum_v = 0;
- for (int i = 0; i < height; i++) {
- sum_u += left_u[i * u_stride];
- sum_v += left_v[i * v_stride];
- }
- *out_sum_u += sum_u;
- *out_sum_v += sum_v;
-}
-#if CONFIG_HIGHBITDEPTH
-static void sum_left_col_hbd(const uint16_t *left_u, int u_stride,
- const uint16_t *left_v, int v_stride, int height,
- int *out_sum_u, int *out_sum_v) {
- int sum_u = 0;
- int sum_v = 0;
- for (int i = 0; i < height; i++) {
- sum_u += left_u[i * u_stride];
- sum_v += left_v[i * v_stride];
- }
- *out_sum_u += sum_u;
- *out_sum_v += sum_v;
-}
-#endif // CONFIG_HIGHBITDEPTH
-static void sum_left_col(const MACROBLOCKD *xd, int height, int *out_sum_u,
- int *out_sum_v) {
- const struct macroblockd_plane *const pd_u = &xd->plane[AOM_PLANE_U];
- const struct macroblockd_plane *const pd_v = &xd->plane[AOM_PLANE_V];
-
-#if CONFIG_HIGHBITDEPTH
- if (get_bitdepth_data_path_index(xd)) {
- const uint16_t *left_u_16 = CONVERT_TO_SHORTPTR(pd_u->dst.buf) - 1;
- const uint16_t *left_v_16 = CONVERT_TO_SHORTPTR(pd_v->dst.buf) - 1;
- sum_left_col_hbd(left_u_16, pd_u->dst.stride, left_v_16, pd_v->dst.stride,
- height, out_sum_u, out_sum_v);
- return;
- }
-#endif // CONFIG_HIGHBITDEPTH
- const uint8_t *left_u = pd_u->dst.buf - 1;
- const uint8_t *left_v = pd_v->dst.buf - 1;
- sum_left_col_lbd(left_u, pd_u->dst.stride, left_v, pd_v->dst.stride, height,
- out_sum_u, out_sum_v);
-}
-
-// CfL computes its own block-level DC_PRED. This is required to compute both
-// alpha_cb and alpha_cr before the prediction are computed.
-static void cfl_dc_pred(MACROBLOCKD *xd, BLOCK_SIZE plane_bsize) {
- CFL_CTX *const cfl = xd->cfl;
-
- // Compute DC_PRED until block boundary. We can't assume the neighbor will use
- // the same transform size.
- const int width = max_block_wide(xd, plane_bsize, AOM_PLANE_U)
- << tx_size_wide_log2[0];
- const int height = max_block_high(xd, plane_bsize, AOM_PLANE_U)
- << tx_size_high_log2[0];
- // Number of pixel on the top and left borders.
- const int num_pel = width + height;
-
- int sum_u = 0;
- int sum_v = 0;
-
-// Match behavior of build_intra_predictors_high (reconintra.c) at superblock
-// boundaries:
-// base-1 base-1 base-1 .. base-1 base-1 base-1 base-1 base-1 base-1
-// base+1 A B .. Y Z
-// base+1 C D .. W X
-// base+1 E F .. U V
-// base+1 G H .. S T T T T T
-// ..
-
-#if CONFIG_CHROMA_SUB8X8
- if (xd->chroma_up_available && xd->mb_to_right_edge >= 0) {
-#else
- if (xd->up_available && xd->mb_to_right_edge >= 0) {
-#endif
- sum_above_row(xd, width, &sum_u, &sum_v);
- } else {
- const int base = 128 << (xd->bd - 8);
- sum_u = width * (base - 1);
- sum_v = width * (base - 1);
- }
-
-#if CONFIG_CHROMA_SUB8X8
- if (xd->chroma_left_available && xd->mb_to_bottom_edge >= 0) {
-#else
- if (xd->left_available && xd->mb_to_bottom_edge >= 0) {
-#endif
- sum_left_col(xd, height, &sum_u, &sum_v);
- } else {
- const int base = 128 << (xd->bd - 8);
- sum_u += height * (base + 1);
- sum_v += height * (base + 1);
+static void subtract_average_c(const uint16_t *src, int16_t *dst, int width,
+ int height, int round_offset, int num_pel_log2) {
+ int sum = round_offset;
+ const uint16_t *recon = src;
+ for (int j = 0; j < height; j++) {
+ for (int i = 0; i < width; i++) {
+ sum += recon[i];
+ }
+ recon += CFL_BUF_LINE;
}
-
- // TODO(ltrudeau) Because of max_block_wide and max_block_high, num_pel will
- // not be a power of two. So these divisions will have to use a lookup table.
- cfl->dc_pred[CFL_PRED_U] = (sum_u + (num_pel >> 1)) / num_pel;
- cfl->dc_pred[CFL_PRED_V] = (sum_v + (num_pel >> 1)) / num_pel;
-}
-
-static void cfl_subtract_averages(CFL_CTX *cfl, TX_SIZE tx_size) {
- const int width = cfl->uv_width;
- const int height = cfl->uv_height;
- const int tx_height = tx_size_high[tx_size];
- const int tx_width = tx_size_wide[tx_size];
- const int block_row_stride = MAX_SB_SIZE << tx_size_high_log2[tx_size];
- const int num_pel_log2 =
- (tx_size_high_log2[tx_size] + tx_size_wide_log2[tx_size]);
-
- int16_t *pred_buf_q3 = cfl->pred_buf_q3;
-
- cfl_pad(cfl, width, height);
-
- for (int b_j = 0; b_j < height; b_j += tx_height) {
- for (int b_i = 0; b_i < width; b_i += tx_width) {
- int sum_q3 = 0;
- int16_t *tx_pred_buf_q3 = pred_buf_q3;
- for (int t_j = 0; t_j < tx_height; t_j++) {
- for (int t_i = b_i; t_i < b_i + tx_width; t_i++) {
- sum_q3 += tx_pred_buf_q3[t_i];
- }
- tx_pred_buf_q3 += MAX_SB_SIZE;
- }
- int avg_q3 = (sum_q3 + (1 << (num_pel_log2 - 1))) >> num_pel_log2;
- // Loss is never more than 1/2 (in Q3)
- assert(fabs((double)avg_q3 - (sum_q3 / ((double)(1 << num_pel_log2)))) <=
- 0.5);
-
- tx_pred_buf_q3 = pred_buf_q3;
- for (int t_j = 0; t_j < tx_height; t_j++) {
- for (int t_i = b_i; t_i < b_i + tx_width; t_i++) {
- tx_pred_buf_q3[t_i] -= avg_q3;
- }
-
- tx_pred_buf_q3 += MAX_SB_SIZE;
- }
+ const int avg = sum >> num_pel_log2;
+ for (int j = 0; j < height; j++) {
+ for (int i = 0; i < width; i++) {
+ dst[i] = src[i] - avg;
}
- pred_buf_q3 += block_row_stride;
+ src += CFL_BUF_LINE;
+ dst += CFL_BUF_LINE;
}
}
+CFL_SUB_AVG_FN(c)
+
static INLINE int cfl_idx_to_alpha(int alpha_idx, int joint_sign,
CFL_PRED_TYPE pred_type) {
const int alpha_sign = (pred_type == CFL_PRED_U) ? CFL_SIGN_U(joint_sign)
@@ -259,159 +153,218 @@ static INLINE int cfl_idx_to_alpha(int alpha_idx, int joint_sign,
return (alpha_sign == CFL_SIGN_POS) ? abs_alpha_q3 + 1 : -abs_alpha_q3 - 1;
}
-static void cfl_build_prediction_lbd(const int16_t *pred_buf_q3, uint8_t *dst,
- int dst_stride, int width, int height,
- int alpha_q3, int dc_pred) {
+static INLINE void cfl_predict_lbd_c(const int16_t *ac_buf_q3, uint8_t *dst,
+ int dst_stride, int alpha_q3, int width,
+ int height) {
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
- dst[i] =
- clip_pixel(get_scaled_luma_q0(alpha_q3, pred_buf_q3[i]) + dc_pred);
+ dst[i] = clip_pixel(get_scaled_luma_q0(alpha_q3, ac_buf_q3[i]) + dst[i]);
}
dst += dst_stride;
- pred_buf_q3 += MAX_SB_SIZE;
+ ac_buf_q3 += CFL_BUF_LINE;
}
}
-#if CONFIG_HIGHBITDEPTH
-static void cfl_build_prediction_hbd(const int16_t *pred_buf_q3, uint16_t *dst,
- int dst_stride, int width, int height,
- int alpha_q3, int dc_pred, int bit_depth) {
+// Null function used for invalid tx_sizes
+void cfl_predict_lbd_null(const int16_t *ac_buf_q3, uint8_t *dst,
+ int dst_stride, int alpha_q3) {
+ (void)ac_buf_q3;
+ (void)dst;
+ (void)dst_stride;
+ (void)alpha_q3;
+ assert(0);
+}
+
+CFL_PREDICT_FN(c, lbd)
+
+void cfl_predict_hbd_c(const int16_t *ac_buf_q3, uint16_t *dst, int dst_stride,
+ int alpha_q3, int bit_depth, int width, int height) {
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
dst[i] = clip_pixel_highbd(
- get_scaled_luma_q0(alpha_q3, pred_buf_q3[i]) + dc_pred, bit_depth);
+ get_scaled_luma_q0(alpha_q3, ac_buf_q3[i]) + dst[i], bit_depth);
}
dst += dst_stride;
- pred_buf_q3 += MAX_SB_SIZE;
+ ac_buf_q3 += CFL_BUF_LINE;
}
}
-#endif // CONFIG_HIGHBITDEPTH
-static void cfl_build_prediction(const int16_t *pred_buf_q3, uint8_t *dst,
- int dst_stride, int width, int height,
- int alpha_q3, int dc_pred, int use_hbd,
- int bit_depth) {
-#if CONFIG_HIGHBITDEPTH
- if (use_hbd) {
- uint16_t *dst_16 = CONVERT_TO_SHORTPTR(dst);
- cfl_build_prediction_hbd(pred_buf_q3, dst_16, dst_stride, width, height,
- alpha_q3, dc_pred, bit_depth);
- return;
- }
-#endif // CONFIG_HIGHBITDEPTH
- (void)use_hbd;
- (void)bit_depth;
- cfl_build_prediction_lbd(pred_buf_q3, dst, dst_stride, width, height,
- alpha_q3, dc_pred);
+// Null function used for invalid tx_sizes
+void cfl_predict_hbd_null(const int16_t *ac_buf_q3, uint16_t *dst,
+ int dst_stride, int alpha_q3, int bd) {
+ (void)ac_buf_q3;
+ (void)dst;
+ (void)dst_stride;
+ (void)alpha_q3;
+ (void)bd;
+ assert(0);
+}
+
+CFL_PREDICT_FN(c, hbd)
+
+static void cfl_compute_parameters(MACROBLOCKD *const xd, TX_SIZE tx_size) {
+ CFL_CTX *const cfl = &xd->cfl;
+ // Do not call cfl_compute_parameters multiple time on the same values.
+ assert(cfl->are_parameters_computed == 0);
+
+ cfl_pad(cfl, tx_size_wide[tx_size], tx_size_high[tx_size]);
+ get_subtract_average_fn(tx_size)(cfl->recon_buf_q3, cfl->ac_buf_q3);
+ cfl->are_parameters_computed = 1;
}
void cfl_predict_block(MACROBLOCKD *const xd, uint8_t *dst, int dst_stride,
- int row, int col, TX_SIZE tx_size, int plane) {
- CFL_CTX *const cfl = xd->cfl;
- MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
+ TX_SIZE tx_size, int plane) {
+ CFL_CTX *const cfl = &xd->cfl;
+ MB_MODE_INFO *mbmi = xd->mi[0];
+ assert(is_cfl_allowed(xd));
- // CfL parameters must be computed before prediction can be done.
- assert(cfl->are_parameters_computed == 1);
+ if (!cfl->are_parameters_computed) cfl_compute_parameters(xd, tx_size);
- const int16_t *pred_buf_q3 =
- cfl->pred_buf_q3 + ((row * MAX_SB_SIZE + col) << tx_size_wide_log2[0]);
const int alpha_q3 =
cfl_idx_to_alpha(mbmi->cfl_alpha_idx, mbmi->cfl_alpha_signs, plane - 1);
+ assert((tx_size_high[tx_size] - 1) * CFL_BUF_LINE + tx_size_wide[tx_size] <=
+ CFL_BUF_SQUARE);
+ if (get_bitdepth_data_path_index(xd)) {
+ uint16_t *dst_16 = CONVERT_TO_SHORTPTR(dst);
+ get_predict_hbd_fn(tx_size)(cfl->ac_buf_q3, dst_16, dst_stride, alpha_q3,
+ xd->bd);
+ return;
+ }
+ get_predict_lbd_fn(tx_size)(cfl->ac_buf_q3, dst, dst_stride, alpha_q3);
+}
- cfl_build_prediction(pred_buf_q3, dst, dst_stride, tx_size_wide[tx_size],
- tx_size_high[tx_size], alpha_q3, cfl->dc_pred[plane - 1],
- get_bitdepth_data_path_index(xd), xd->bd);
+// Null function used for invalid tx_sizes
+void cfl_subsample_lbd_null(const uint8_t *input, int input_stride,
+ uint16_t *output_q3) {
+ (void)input;
+ (void)input_stride;
+ (void)output_q3;
+ assert(0);
}
-static void cfl_luma_subsampling_420_lbd(const uint8_t *input, int input_stride,
- int16_t *output_q3, int width,
- int height) {
- for (int j = 0; j < height; j++) {
- for (int i = 0; i < width; i++) {
- int top = i << 1;
- int bot = top + input_stride;
- output_q3[i] = (input[top] + input[top + 1] + input[bot] + input[bot + 1])
- << 1;
+// Null function used for invalid tx_sizes
+void cfl_subsample_hbd_null(const uint16_t *input, int input_stride,
+ uint16_t *output_q3) {
+ (void)input;
+ (void)input_stride;
+ (void)output_q3;
+ assert(0);
+}
+
+static void cfl_luma_subsampling_420_lbd_c(const uint8_t *input,
+ int input_stride,
+ uint16_t *output_q3, int width,
+ int height) {
+ for (int j = 0; j < height; j += 2) {
+ for (int i = 0; i < width; i += 2) {
+ const int bot = i + input_stride;
+ output_q3[i >> 1] =
+ (input[i] + input[i + 1] + input[bot] + input[bot + 1]) << 1;
}
input += input_stride << 1;
- output_q3 += MAX_SB_SIZE;
+ output_q3 += CFL_BUF_LINE;
}
}
-static void cfl_luma_subsampling_444_lbd(const uint8_t *input, int input_stride,
- int16_t *output_q3, int width,
- int height) {
+static void cfl_luma_subsampling_422_lbd_c(const uint8_t *input,
+ int input_stride,
+ uint16_t *output_q3, int width,
+ int height) {
+ assert((height - 1) * CFL_BUF_LINE + width <= CFL_BUF_SQUARE);
for (int j = 0; j < height; j++) {
- for (int i = 0; i < width; i++) {
- output_q3[i] = input[i] << 3;
+ for (int i = 0; i < width; i += 2) {
+ output_q3[i >> 1] = (input[i] + input[i + 1]) << 2;
}
input += input_stride;
- output_q3 += MAX_SB_SIZE;
+ output_q3 += CFL_BUF_LINE;
}
}
-#if CONFIG_HIGHBITDEPTH
-static void cfl_luma_subsampling_420_hbd(const uint16_t *input,
- int input_stride, int16_t *output_q3,
- int width, int height) {
+static void cfl_luma_subsampling_444_lbd_c(const uint8_t *input,
+ int input_stride,
+ uint16_t *output_q3, int width,
+ int height) {
+ assert((height - 1) * CFL_BUF_LINE + width <= CFL_BUF_SQUARE);
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
- int top = i << 1;
- int bot = top + input_stride;
- output_q3[i] = (input[top] + input[top + 1] + input[bot] + input[bot + 1])
- << 1;
+ output_q3[i] = input[i] << 3;
+ }
+ input += input_stride;
+ output_q3 += CFL_BUF_LINE;
+ }
+}
+
+static void cfl_luma_subsampling_420_hbd_c(const uint16_t *input,
+ int input_stride,
+ uint16_t *output_q3, int width,
+ int height) {
+ for (int j = 0; j < height; j += 2) {
+ for (int i = 0; i < width; i += 2) {
+ const int bot = i + input_stride;
+ output_q3[i >> 1] =
+ (input[i] + input[i + 1] + input[bot] + input[bot + 1]) << 1;
}
input += input_stride << 1;
- output_q3 += MAX_SB_SIZE;
+ output_q3 += CFL_BUF_LINE;
}
}
-static void cfl_luma_subsampling_444_hbd(const uint16_t *input,
- int input_stride, int16_t *output_q3,
- int width, int height) {
+static void cfl_luma_subsampling_422_hbd_c(const uint16_t *input,
+ int input_stride,
+ uint16_t *output_q3, int width,
+ int height) {
+ assert((height - 1) * CFL_BUF_LINE + width <= CFL_BUF_SQUARE);
+ for (int j = 0; j < height; j++) {
+ for (int i = 0; i < width; i += 2) {
+ output_q3[i >> 1] = (input[i] + input[i + 1]) << 2;
+ }
+ input += input_stride;
+ output_q3 += CFL_BUF_LINE;
+ }
+}
+
+static void cfl_luma_subsampling_444_hbd_c(const uint16_t *input,
+ int input_stride,
+ uint16_t *output_q3, int width,
+ int height) {
+ assert((height - 1) * CFL_BUF_LINE + width <= CFL_BUF_SQUARE);
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
output_q3[i] = input[i] << 3;
}
input += input_stride;
- output_q3 += MAX_SB_SIZE;
+ output_q3 += CFL_BUF_LINE;
}
}
-#endif // CONFIG_HIGHBITDEPTH
-static void cfl_luma_subsampling_420(const uint8_t *input, int input_stride,
- int16_t *output_q3, int width, int height,
- int use_hbd) {
-#if CONFIG_HIGHBITDEPTH
- if (use_hbd) {
- const uint16_t *input_16 = CONVERT_TO_SHORTPTR(input);
- cfl_luma_subsampling_420_hbd(input_16, input_stride, output_q3, width,
- height);
- return;
+CFL_GET_SUBSAMPLE_FUNCTION(c)
+
+static INLINE cfl_subsample_hbd_fn cfl_subsampling_hbd(TX_SIZE tx_size,
+ int sub_x, int sub_y) {
+ if (sub_x == 1) {
+ if (sub_y == 1) {
+ return cfl_get_luma_subsampling_420_hbd(tx_size);
+ }
+ return cfl_get_luma_subsampling_422_hbd(tx_size);
}
-#endif // CONFIG_HIGHBITDEPTH
- (void)use_hbd;
- cfl_luma_subsampling_420_lbd(input, input_stride, output_q3, width, height);
+ return cfl_get_luma_subsampling_444_hbd(tx_size);
}
-static void cfl_luma_subsampling_444(const uint8_t *input, int input_stride,
- int16_t *output_q3, int width, int height,
- int use_hbd) {
-#if CONFIG_HIGHBITDEPTH
- if (use_hbd) {
- uint16_t *input_16 = CONVERT_TO_SHORTPTR(input);
- cfl_luma_subsampling_444_hbd(input_16, input_stride, output_q3, width,
- height);
- return;
+static INLINE cfl_subsample_lbd_fn cfl_subsampling_lbd(TX_SIZE tx_size,
+ int sub_x, int sub_y) {
+ if (sub_x == 1) {
+ if (sub_y == 1) {
+ return cfl_get_luma_subsampling_420_lbd(tx_size);
+ }
+ return cfl_get_luma_subsampling_422_lbd(tx_size);
}
-#endif // CONFIG_HIGHBITDEPTH
- (void)use_hbd;
- cfl_luma_subsampling_444_lbd(input, input_stride, output_q3, width, height);
+ return cfl_get_luma_subsampling_444_lbd(tx_size);
}
-static INLINE void cfl_store(CFL_CTX *cfl, const uint8_t *input,
- int input_stride, int row, int col, int width,
- int height, int use_hbd) {
+static void cfl_store(CFL_CTX *cfl, const uint8_t *input, int input_stride,
+ int row, int col, TX_SIZE tx_size, int use_hbd) {
+ const int width = tx_size_wide[tx_size];
+ const int height = tx_size_high[tx_size];
const int tx_off_log2 = tx_size_wide_log2[0];
const int sub_x = cfl->subsampling_x;
const int sub_y = cfl->subsampling_y;
@@ -435,26 +388,22 @@ static INLINE void cfl_store(CFL_CTX *cfl, const uint8_t *input,
}
// Check that we will remain inside the pixel buffer.
- assert(store_row + store_height <= MAX_SB_SIZE);
- assert(store_col + store_width <= MAX_SB_SIZE);
+ assert(store_row + store_height <= CFL_BUF_LINE);
+ assert(store_col + store_width <= CFL_BUF_LINE);
// Store the input into the CfL pixel buffer
- int16_t *pred_buf_q3 =
- cfl->pred_buf_q3 + (store_row * MAX_SB_SIZE + store_col);
-
- if (sub_y == 0 && sub_x == 0) {
- cfl_luma_subsampling_444(input, input_stride, pred_buf_q3, store_width,
- store_height, use_hbd);
- } else if (sub_y == 1 && sub_x == 1) {
- cfl_luma_subsampling_420(input, input_stride, pred_buf_q3, store_width,
- store_height, use_hbd);
+ uint16_t *recon_buf_q3 =
+ cfl->recon_buf_q3 + (store_row * CFL_BUF_LINE + store_col);
+
+ if (use_hbd) {
+ cfl_subsampling_hbd(tx_size, sub_x, sub_y)(CONVERT_TO_SHORTPTR(input),
+ input_stride, recon_buf_q3);
} else {
- // TODO(ltrudeau) add support for 4:2:2
- assert(0); // Unsupported chroma subsampling
+ cfl_subsampling_lbd(tx_size, sub_x, sub_y)(input, input_stride,
+ recon_buf_q3);
}
}
-#if CONFIG_CHROMA_SUB8X8
// Adjust the row and column of blocks smaller than 8X8, as chroma-referenced
// and non-chroma-referenced blocks are stored together in the CfL buffer.
static INLINE void sub8x8_adjust_offset(const CFL_CTX *cfl, int *row_out,
@@ -471,99 +420,36 @@ static INLINE void sub8x8_adjust_offset(const CFL_CTX *cfl, int *row_out,
(*col_out)++;
}
}
-#if CONFIG_DEBUG
-static INLINE void sub8x8_set_val(CFL_CTX *cfl, int row, int col, int val_high,
- int val_wide) {
- for (int val_r = 0; val_r < val_high; val_r++) {
- assert(row + val_r < CFL_SUB8X8_VAL_MI_SIZE);
- int row_off = (row + val_r) * CFL_SUB8X8_VAL_MI_SIZE;
- for (int val_c = 0; val_c < val_wide; val_c++) {
- assert(col + val_c < CFL_SUB8X8_VAL_MI_SIZE);
- assert(cfl->sub8x8_val[row_off + col + val_c] == 0);
- cfl->sub8x8_val[row_off + col + val_c]++;
- }
- }
-}
-#endif // CONFIG_DEBUG
-#endif // CONFIG_CHROMA_SUB8X8
void cfl_store_tx(MACROBLOCKD *const xd, int row, int col, TX_SIZE tx_size,
BLOCK_SIZE bsize) {
- CFL_CTX *const cfl = xd->cfl;
+ CFL_CTX *const cfl = &xd->cfl;
struct macroblockd_plane *const pd = &xd->plane[AOM_PLANE_Y];
uint8_t *dst =
&pd->dst.buf[(row * pd->dst.stride + col) << tx_size_wide_log2[0]];
- (void)bsize;
-#if CONFIG_CHROMA_SUB8X8
if (block_size_high[bsize] == 4 || block_size_wide[bsize] == 4) {
// Only dimensions of size 4 can have an odd offset.
assert(!((col & 1) && tx_size_wide[tx_size] != 4));
assert(!((row & 1) && tx_size_high[tx_size] != 4));
sub8x8_adjust_offset(cfl, &row, &col);
-#if CONFIG_DEBUG
- sub8x8_set_val(cfl, row, col, tx_size_high_unit[tx_size],
- tx_size_wide_unit[tx_size]);
-#endif // CONFIG_DEBUG
}
-#endif
- cfl_store(cfl, dst, pd->dst.stride, row, col, tx_size_wide[tx_size],
- tx_size_high[tx_size], get_bitdepth_data_path_index(xd));
+ cfl_store(cfl, dst, pd->dst.stride, row, col, tx_size,
+ get_bitdepth_data_path_index(xd));
}
void cfl_store_block(MACROBLOCKD *const xd, BLOCK_SIZE bsize, TX_SIZE tx_size) {
- CFL_CTX *const cfl = xd->cfl;
+ CFL_CTX *const cfl = &xd->cfl;
struct macroblockd_plane *const pd = &xd->plane[AOM_PLANE_Y];
int row = 0;
int col = 0;
-#if CONFIG_CHROMA_SUB8X8
- bsize = AOMMAX(BLOCK_4X4, bsize);
+
if (block_size_high[bsize] == 4 || block_size_wide[bsize] == 4) {
sub8x8_adjust_offset(cfl, &row, &col);
-#if CONFIG_DEBUG
- sub8x8_set_val(cfl, row, col, mi_size_high[bsize], mi_size_wide[bsize]);
-#endif // CONFIG_DEBUG
}
-#endif // CONFIG_CHROMA_SUB8X8
const int width = max_intra_block_width(xd, bsize, AOM_PLANE_Y, tx_size);
const int height = max_intra_block_height(xd, bsize, AOM_PLANE_Y, tx_size);
- cfl_store(cfl, pd->dst.buf, pd->dst.stride, row, col, width, height,
+ tx_size = get_tx_size(width, height);
+ cfl_store(cfl, pd->dst.buf, pd->dst.stride, row, col, tx_size,
get_bitdepth_data_path_index(xd));
}
-
-void cfl_compute_parameters(MACROBLOCKD *const xd, TX_SIZE tx_size) {
- CFL_CTX *const cfl = xd->cfl;
- MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
-
- // Do not call cfl_compute_parameters multiple time on the same values.
- assert(cfl->are_parameters_computed == 0);
-
-#if CONFIG_CHROMA_SUB8X8
- const BLOCK_SIZE plane_bsize = AOMMAX(
- BLOCK_4X4, get_plane_block_size(mbmi->sb_type, &xd->plane[AOM_PLANE_U]));
-#if CONFIG_DEBUG
- if (mbmi->sb_type < BLOCK_8X8) {
- for (int val_r = 0; val_r < mi_size_high[mbmi->sb_type]; val_r++) {
- for (int val_c = 0; val_c < mi_size_wide[mbmi->sb_type]; val_c++) {
- assert(cfl->sub8x8_val[val_r * CFL_SUB8X8_VAL_MI_SIZE + val_c] == 1);
- }
- }
- cfl_clear_sub8x8_val(cfl);
- }
-#endif // CONFIG_DEBUG
-#else
- const BLOCK_SIZE plane_bsize =
- get_plane_block_size(mbmi->sb_type, &xd->plane[AOM_PLANE_U]);
-#endif
- // AOM_PLANE_U is used, but both planes will have the same sizes.
- cfl->uv_width = max_intra_block_width(xd, plane_bsize, AOM_PLANE_U, tx_size);
- cfl->uv_height =
- max_intra_block_height(xd, plane_bsize, AOM_PLANE_U, tx_size);
-
- assert(cfl->buf_width <= cfl->uv_width);
- assert(cfl->buf_height <= cfl->uv_height);
-
- cfl_dc_pred(xd, plane_bsize);
- cfl_subtract_averages(cfl, tx_size);
- cfl->are_parameters_computed = 1;
-}