From 91de92134fdce794b5256116503cc84d7c8cf1ae Mon Sep 17 00:00:00 2001 From: Laurent Fasnacht Date: Mon, 16 Jun 2014 14:27:56 +0200 Subject: [PATCH] Constrain the search not to go under the LCU below if OWF is enabled --- src/image.c | 7 ++++++- src/image.h | 2 +- src/search.c | 15 ++++++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/image.c b/src/image.c index b42fd9a2..8b8ca9b4 100644 --- a/src/image.c +++ b/src/image.c @@ -373,9 +373,14 @@ static unsigned image_interpolated_sad(const image *pic, const image *ref, unsigned image_calc_sad(const image *pic, const image *ref, int pic_x, int pic_y, int ref_x, int ref_y, - int block_width, int block_height) { + int block_width, int block_height, int max_lcu_below) { assert(pic_x >= 0 && pic_x <= pic->width - block_width); assert(pic_y >= 0 && pic_y <= pic->height - block_height); + + if ((((ref_y + block_height)/LCU_WIDTH) > (pic_y/LCU_WIDTH) + max_lcu_below) && max_lcu_below >= 0) { + //printf("OOB %d %d -> %d\n", ref_y + block_height, pic_y, ref_y + block_height - pic_y); + return INT_MAX; + } if (ref_x >= 0 && ref_x <= ref->width - block_width && ref_y >= 0 && ref_y <= ref->height - block_height) { diff --git a/src/image.h b/src/image.h index 5192b860..4c85be0f 100644 --- a/src/image.h +++ b/src/image.h @@ -72,7 +72,7 @@ void yuv_t_free(yuv_t * yuv); //Algorithms unsigned image_calc_sad(const image *pic, const image *ref, int pic_x, int pic_y, int ref_x, int ref_y, - int block_width, int block_height); + int block_width, int block_height, int max_lcu_below); typedef unsigned (*cost_16bit_nxn_func)(const pixel *block1, const pixel *block2); diff --git a/src/search.c b/src/search.c index 72363d4e..f47c0101 100644 --- a/src/search.c +++ b/src/search.c @@ -197,6 +197,11 @@ static unsigned hexagon_search(const encoder_state * const encoder_state, unsign uint32_t best_bitcost = 0, bitcost; unsigned i; unsigned best_index = 0; // Index of large_hexbs or finally small_hexbs. + int max_lcu_below = -1; + + if (encoder_state->encoder_control->owf) { + max_lcu_below = 1; + } // Search the initial 7 points of the hexagon. @@ -205,7 +210,7 @@ static unsigned hexagon_search(const encoder_state * const encoder_state, unsign unsigned cost = image_calc_sad(pic, ref, orig->x, orig->y, (encoder_state->tile->lcu_offset_x * LCU_WIDTH) + orig->x + mv.x + pattern->x, (encoder_state->tile->lcu_offset_y * LCU_WIDTH) + orig->y + mv.y + pattern->y, - block_width, block_width); + block_width, block_width, max_lcu_below); cost += calc_mvd_cost(encoder_state, mv.x + pattern->x, mv.y + pattern->y, mv_cand,merge_cand,num_cand,ref_idx, &bitcost); if (cost < best_cost) { @@ -220,7 +225,7 @@ static unsigned hexagon_search(const encoder_state * const encoder_state, unsign unsigned cost = image_calc_sad(pic, ref, orig->x, orig->y, (encoder_state->tile->lcu_offset_x * LCU_WIDTH) + orig->x, (encoder_state->tile->lcu_offset_y * LCU_WIDTH) + orig->y, - block_width, block_width); + block_width, block_width, max_lcu_below); cost += calc_mvd_cost(encoder_state, 0, 0, mv_cand,merge_cand,num_cand,ref_idx, &bitcost); // If the 0,0 is better, redo the hexagon around that point. @@ -236,7 +241,7 @@ static unsigned hexagon_search(const encoder_state * const encoder_state, unsign unsigned cost = image_calc_sad(pic, ref, orig->x, orig->y, (encoder_state->tile->lcu_offset_x * LCU_WIDTH) + orig->x + pattern->x, (encoder_state->tile->lcu_offset_y * LCU_WIDTH) + orig->y + pattern->y, - block_width, block_width); + block_width, block_width, max_lcu_below); cost += calc_mvd_cost(encoder_state, pattern->x, pattern->y, mv_cand,merge_cand,num_cand,ref_idx, &bitcost); if (cost < best_cost) { @@ -271,7 +276,7 @@ static unsigned hexagon_search(const encoder_state * const encoder_state, unsign unsigned cost = image_calc_sad(pic, ref, orig->x, orig->y, (encoder_state->tile->lcu_offset_x * LCU_WIDTH) + orig->x + mv.x + offset->x, (encoder_state->tile->lcu_offset_y * LCU_WIDTH) + orig->y + mv.y + offset->y, - block_width, block_width); + block_width, block_width, max_lcu_below); cost += calc_mvd_cost(encoder_state, mv.x + offset->x, mv.y + offset->y, mv_cand,merge_cand,num_cand,ref_idx, &bitcost); if (cost < best_cost) { @@ -294,7 +299,7 @@ static unsigned hexagon_search(const encoder_state * const encoder_state, unsign unsigned cost = image_calc_sad(pic, ref, orig->x, orig->y, (encoder_state->tile->lcu_offset_x * LCU_WIDTH) + orig->x + mv.x + offset->x, (encoder_state->tile->lcu_offset_y * LCU_WIDTH) + orig->y + mv.y + offset->y, - block_width, block_width); + block_width, block_width, max_lcu_below); cost += calc_mvd_cost(encoder_state, mv.x + offset->x, mv.y + offset->y, mv_cand,merge_cand,num_cand,ref_idx, &bitcost); if (cost > 0 && cost < best_cost) {