From 46e8122d27ea6c448f447973f6466c08232111a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arttu=20Yl=C3=A4-Outinen?= Date: Tue, 12 Jan 2016 09:21:00 +0200 Subject: [PATCH] Add functions for indexing cu_array_t structures. Replaces macro CU_ARRAY_AT with functions kvz_cu_array_at and kvz_cu_array_at_const. --- src/cu.c | 15 +++++++++++++++ src/cu.h | 6 ++---- src/encoderstate.c | 20 +++++++++----------- src/filter.c | 35 ++++++++++++++++++----------------- src/inter.c | 10 +++++----- src/search_inter.c | 2 +- src/videoframe.c | 18 ++++++++---------- 7 files changed, 58 insertions(+), 48 deletions(-) diff --git a/src/cu.c b/src/cu.c index 4c766804..575e1829 100644 --- a/src/cu.c +++ b/src/cu.c @@ -120,6 +120,21 @@ unsigned kvz_coefficients_calc_abs(const coeff_t *const buf, const int buf_strid return sum; } + +cu_info_t* kvz_cu_array_at(cu_array_t *cua, unsigned x_px, unsigned y_px) +{ + return (cu_info_t*) kvz_cu_array_at_const(cua, x_px, y_px); +} + + +const cu_info_t* kvz_cu_array_at_const(const cu_array_t *cua, unsigned x_px, unsigned y_px) +{ + assert(x_px < cua->width); + assert(y_px < cua->height); + return &(cua)->data[(x_px >> 2) + (y_px >> 2) * ((cua)->width >> 2)]; +} + + /** * \brief Allocate a CU array. * diff --git a/src/cu.h b/src/cu.h index 13ace41c..92fee074 100644 --- a/src/cu.h +++ b/src/cu.h @@ -186,15 +186,13 @@ typedef struct { cu_array_t * kvz_cu_array_alloc(int width, int height); int kvz_cu_array_free(cu_array_t *cua); +cu_info_t* kvz_cu_array_at(cu_array_t *cua, unsigned x_px, unsigned y_px); +const cu_info_t* kvz_cu_array_at_const(const cu_array_t *cua, unsigned x_px, unsigned y_px); void kvz_cu_array_copy(cu_array_t* dst, int dst_x, int dst_y, const cu_array_t* src, int src_x, int src_y, int width, int height); -#define CU_ARRAY_AT(cua, x_px, y_px) \ - (&(cua)->data[((x_px) >> 2) + ((y_px) >> 2) * ((cua)->width >> 2)]) - - /** * \brief Return the 7 lowest-order bits of the pixel coordinate. * diff --git a/src/encoderstate.c b/src/encoderstate.c index 25e08f4e..fa555b86 100644 --- a/src/encoderstate.c +++ b/src/encoderstate.c @@ -1093,8 +1093,7 @@ static void encode_part_mode(encoder_state_t * const state, static void encode_inter_prediction_unit(encoder_state_t * const state, cabac_data_t * const cabac, const cu_info_t * const cur_cu, - int x_ctb, int y_ctb, - int width_ctb, int height_ctb, + int x, int y, int width, int height, int depth) { // Mergeflag @@ -1182,8 +1181,7 @@ static void encode_inter_prediction_unit(encoder_state_t * const state, int16_t mv_cand[2][2]; kvz_inter_get_mv_cand_cua( state, - x_ctb << 3, y_ctb << 3, - width_ctb << 3, height_ctb << 3, + x, y, width, height, mv_cand, cur_cu, ref_list_idx); uint8_t cu_mv_cand = CU_GET_MV_CAND(cur_cu, ref_list_idx); @@ -1480,16 +1478,16 @@ void kvz_encode_coding_tree(encoder_state_t * const state, if (cur_cu->type == CU_INTER) { const int num_pu = kvz_part_mode_num_parts[cur_cu->part_size]; - const int cu_width_scu = LCU_CU_WIDTH >> depth; + const int cu_width = LCU_WIDTH >> depth; for (int i = 0; i < num_pu; ++i) { - const int pu_x_scu = PU_GET_X(cur_cu->part_size, cu_width_scu, x_ctb, i); - const int pu_y_scu = PU_GET_Y(cur_cu->part_size, cu_width_scu, y_ctb, i); - const int pu_w_scu = PU_GET_W(cur_cu->part_size, cu_width_scu, i); - const int pu_h_scu = PU_GET_H(cur_cu->part_size, cu_width_scu, i); - const cu_info_t *cur_pu = kvz_videoframe_get_cu_const(frame, pu_x_scu, pu_y_scu); + const int pu_x = PU_GET_X(cur_cu->part_size, cu_width, x_ctb << 3, i); + const int pu_y = PU_GET_Y(cur_cu->part_size, cu_width, y_ctb << 3, i); + const int pu_w = PU_GET_W(cur_cu->part_size, cu_width, i); + const int pu_h = PU_GET_H(cur_cu->part_size, cu_width, i); + const cu_info_t *cur_pu = kvz_cu_array_at_const(frame->cu_array, pu_x, pu_y); - encode_inter_prediction_unit(state, cabac, cur_pu, pu_x_scu, pu_y_scu, pu_w_scu, pu_h_scu, depth); + encode_inter_prediction_unit(state, cabac, cur_pu, pu_x, pu_y, pu_w, pu_h, depth); } { diff --git a/src/filter.c b/src/filter.c index a875f542..fd91df7f 100644 --- a/src/filter.c +++ b/src/filter.c @@ -179,9 +179,8 @@ static bool is_tu_boundary(const encoder_state_t *const state, int32_t y, edge_dir dir) { - const cu_info_t *const scu = kvz_videoframe_get_cu(state->tile->frame, - x >> MIN_SIZE, - y >> MIN_SIZE); + const cu_info_t *const scu = + kvz_cu_array_at_const(state->tile->frame->cu_array, x, y); const int tu_width = LCU_WIDTH >> scu->tr_depth; if (dir == EDGE_HOR) { @@ -206,16 +205,14 @@ static bool is_pu_boundary(const encoder_state_t *const state, int32_t y, edge_dir dir) { - const cu_info_t *const scu = kvz_videoframe_get_cu(state->tile->frame, - x >> MIN_SIZE, - y >> MIN_SIZE); + const cu_info_t *const scu = + kvz_cu_array_at_const(state->tile->frame->cu_array, x, y); // Get the containing CU. const int32_t cu_width = LCU_WIDTH >> scu->depth; const int32_t x_cu = x & ~(cu_width - 1); const int32_t y_cu = y & ~(cu_width - 1); - const cu_info_t *const cu = kvz_videoframe_get_cu(state->tile->frame, - x_cu >> MIN_SIZE, - y_cu >> MIN_SIZE); + const cu_info_t *const cu = + kvz_cu_array_at_const(state->tile->frame->cu_array, x_cu, y_cu); const int num_pu = kvz_part_mode_num_parts[cu->part_size]; for (int i = 0; i < num_pu; i++) { @@ -285,7 +282,7 @@ static void filter_deblock_edge_luma(encoder_state_t * const state, videoframe_t * const frame = state->tile->frame; const encoder_control_t * const encoder = state->encoder_control; - cu_info_t *cu_q = kvz_videoframe_get_cu(frame, x >> MIN_SIZE, y >> MIN_SIZE); + cu_info_t *cu_q = kvz_cu_array_at(frame->cu_array, x, y); { int32_t stride = frame->rec->stride; @@ -295,8 +292,6 @@ static void filter_deblock_edge_luma(encoder_state_t * const state, kvz_pixel *orig_src = &frame->rec->y[x + y*stride]; kvz_pixel *src = orig_src; cu_info_t *cu_p = NULL; - int16_t x_cu = x >> MIN_SIZE; - int16_t y_cu = y >> MIN_SIZE; int8_t strength = 0; int32_t qp = state->global->QP; @@ -321,7 +316,11 @@ static void filter_deblock_edge_luma(encoder_state_t * const state, { // CU in the side we are filtering, update every 8-pixels - cu_p = kvz_videoframe_get_cu(frame, x_cu - (dir == EDGE_VER) + (dir == EDGE_HOR ? block_idx>>1 : 0), y_cu - (dir == EDGE_HOR) + (dir == EDGE_VER ? block_idx>>1 : 0)); + if (dir == EDGE_VER) { + cu_p = kvz_cu_array_at(frame->cu_array, x - 1, y + 4 * block_idx); + } else { + cu_p = kvz_cu_array_at(frame->cu_array, x + 4 * block_idx, y - 1); + } bool nonzero_coeffs = cbf_is_set(cu_q->cbf.y, cu_q->tr_depth) || cbf_is_set(cu_p->cbf.y, cu_p->tr_depth); @@ -475,7 +474,7 @@ static void filter_deblock_edge_chroma(encoder_state_t * const state, { const encoder_control_t * const encoder = state->encoder_control; const videoframe_t * const frame = state->tile->frame; - const cu_info_t *cu_q = kvz_videoframe_get_cu_const(frame, x >> (MIN_SIZE - 1), y >> (MIN_SIZE - 1)); + const cu_info_t *cu_q = kvz_cu_array_at_const(frame->cu_array, x << 1, y << 1); // For each subpart { @@ -487,8 +486,6 @@ static void filter_deblock_edge_chroma(encoder_state_t * const state, &frame->rec->v[x + y*stride], }; const cu_info_t *cu_p = NULL; - int16_t x_cu = x >> (MIN_SIZE-1); - int16_t y_cu = y >> (MIN_SIZE-1); int8_t strength = 2; int32_t QP = kvz_g_chroma_scale[state->global->QP]; @@ -503,7 +500,11 @@ static void filter_deblock_edge_chroma(encoder_state_t * const state, for (uint32_t blk_idx = 0; blk_idx < num_4px_parts; ++blk_idx) { - cu_p = kvz_videoframe_get_cu_const(frame, x_cu - (dir == EDGE_VER) + (dir == EDGE_HOR ? blk_idx : 0), y_cu - (dir == EDGE_HOR) + (dir == EDGE_VER ? blk_idx : 0)); + if (dir == EDGE_VER) { + cu_p = kvz_cu_array_at(frame->cu_array, 2 * (x - 1), 2 * (y + 4 * blk_idx)); + } else { + cu_p = kvz_cu_array_at(frame->cu_array, 2 * (x + 4 * blk_idx), 2 * (y - 1)); + } // Only filter when strenght == 2 (one of the blocks is intra coded) if (cu_q->type == CU_INTRA || cu_p->type == CU_INTRA) { diff --git a/src/inter.c b/src/inter.c index 505c6b7c..156435c7 100644 --- a/src/inter.c +++ b/src/inter.c @@ -806,14 +806,14 @@ static void get_spatial_merge_candidates_cua(const cu_array_t *cua, int32_t y_local = SUB_SCU(y); // A0 and A1 availability testing if (x != 0) { - *a1 = CU_ARRAY_AT(cua, x - 1, y + height - 1); + *a1 = kvz_cu_array_at_const(cua, x - 1, y + height - 1); // The block above is always coded before the current one. if ((*a1)->type != CU_INTER) { *a1 = NULL; } if (y_local + height < LCU_WIDTH && y + height < picture_height) { - *a0 = CU_ARRAY_AT(cua, x - 1, y + height); + *a0 = kvz_cu_array_at_const(cua, x - 1, y + height); if ((*a0)->type != CU_INTER || !is_a0_cand_coded(x, y, width, height)) { *a0 = NULL; } @@ -823,20 +823,20 @@ static void get_spatial_merge_candidates_cua(const cu_array_t *cua, // B0, B1 and B2 availability testing if (y != 0) { if (x + width < picture_width && (x_local + width < LCU_WIDTH || y_local == 0)) { - *b0 = CU_ARRAY_AT(cua, x + width, y - 1); + *b0 = kvz_cu_array_at_const(cua, x + width, y - 1); if ((*b0)->type != CU_INTER || !is_b0_cand_coded(x, y, width, height)) { *b0 = NULL; } } - *b1 = CU_ARRAY_AT(cua, x + width - 1, y - 1); + *b1 = kvz_cu_array_at_const(cua, x + width - 1, y - 1); // The block to the left is always coded before the current one. if ((*b1)->type != CU_INTER) { *b1 = NULL; } if (x != 0) { - *b2 = CU_ARRAY_AT(cua, x - 1, y - 1); + *b2 = kvz_cu_array_at_const(cua, x - 1, y - 1); // The block above and to the left is always coded before the current // one. if ((*b2)->type != CU_INTER) { diff --git a/src/search_inter.c b/src/search_inter.c index 185f2743..0b036ec1 100644 --- a/src/search_inter.c +++ b/src/search_inter.c @@ -1195,7 +1195,7 @@ static void search_pu_inter_ref(encoder_state_t * const state, const int mid_x = tile_top_left_corner.x + x + (width >> 1); const int mid_y = tile_top_left_corner.y + y + (height >> 1); const cu_array_t* ref_array = state->global->ref->cu_arrays[ref_idx]; - const cu_info_t* ref_cu = CU_ARRAY_AT(ref_array, mid_x, mid_y); + const cu_info_t* ref_cu = kvz_cu_array_at_const(ref_array, mid_x, mid_y); if (ref_cu->type == CU_INTER) { if (ref_cu->inter.mv_dir & 1) { mv.x = ref_cu->inter.mv[0][0]; diff --git a/src/videoframe.c b/src/videoframe.c index 99e1c571..bdd36c0f 100644 --- a/src/videoframe.c +++ b/src/videoframe.c @@ -89,18 +89,16 @@ void kvz_videoframe_set_poc(videoframe_t * const frame, const int32_t poc) { frame->poc = poc; } -const cu_info_t* kvz_videoframe_get_cu_const(const videoframe_t * const frame, unsigned int x_in_scu, unsigned int y_in_scu) +const cu_info_t* kvz_videoframe_get_cu_const(const videoframe_t * const frame, + unsigned int x_in_scu, + unsigned int y_in_scu) { - assert(x_in_scu < (frame->width_in_lcu << MAX_DEPTH)); - assert(y_in_scu < (frame->height_in_lcu << MAX_DEPTH)); - - return CU_ARRAY_AT(frame->cu_array, x_in_scu << 3, y_in_scu << 3); + return kvz_cu_array_at_const(frame->cu_array, x_in_scu << 3, y_in_scu << 3); } -cu_info_t* kvz_videoframe_get_cu(videoframe_t * const frame, const unsigned int x_in_scu, const unsigned int y_in_scu) +cu_info_t* kvz_videoframe_get_cu(videoframe_t * const frame, + const unsigned int x_in_scu, + const unsigned int y_in_scu) { - assert(x_in_scu < (frame->width_in_lcu << MAX_DEPTH)); - assert(y_in_scu < (frame->height_in_lcu << MAX_DEPTH)); - - return CU_ARRAY_AT(frame->cu_array, x_in_scu << 3, y_in_scu << 3); + return kvz_cu_array_at(frame->cu_array, x_in_scu << 3, y_in_scu << 3); }