Skip to content

Commit

Permalink
[intra] Extend the reference inside the reference building
Browse files Browse the repository at this point in the history
  • Loading branch information
Jovasa committed Nov 27, 2024
1 parent a1413a4 commit 3c54935
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions src/intra.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ static void intra_filter_reference(
refs->filtered_initialized = true;
}

const int_fast8_t ref_width = 2 * (1 << log2_width) + 1;
const int_fast8_t ref_height = 2 * (1 << log2_height) + 1;
const int_fast16_t ref_width = 2 * (1 << (log2_width)) + 1;
const int_fast16_t ref_height = 2 * (1 << (log2_height)) + 1;
uvg_intra_ref *ref = &refs->ref;
uvg_intra_ref *filtered_ref = &refs->filtered_ref;

Expand All @@ -208,15 +208,15 @@ static void intra_filter_reference(
filtered_ref->top[0] = filtered_ref->left[0];

// Top to bottom
for (int_fast8_t y = 1; y < ref_height - 1; ++y) {
for (int_fast16_t y = 1; y < ref_height - 1; ++y) {
uvg_pixel *p = &ref->left[y];
filtered_ref->left[y] = (p[-1] + 2 * p[0] + p[1] + 2) >> 2;
}
// Bottom left (not filtered)
filtered_ref->left[ref_height - 1] = ref->left[ref_height - 1];

// Left to right
for (int_fast8_t x = 1; x < ref_width - 1; ++x) {
for (int_fast16_t x = 1; x < ref_width - 1; ++x) {
uvg_pixel *p = &ref->top[x];
filtered_ref->top[x] = (p[-1] + 2 * p[0] + p[1] + 2) >> 2;
}
Expand Down Expand Up @@ -712,7 +712,16 @@ static void intra_predict_regular(
}

if (used_ref == &refs->filtered_ref && !refs->filtered_initialized) {
intra_filter_reference(log2_width, log2_height, refs);
int temp_log2_width = log2_width;
int temp_log2_height = log2_height;
if (color == COLOR_Y && isp_mode == ISP_MODE_NO_ISP) {
temp_log2_width = cur_cu->log2_width;
temp_log2_height = cur_cu->log2_height;
} else if (color != COLOR_Y) {
temp_log2_width = cur_cu->log2_chroma_width;
temp_log2_height = cur_cu->log2_chroma_height;
}
intra_filter_reference(temp_log2_width, temp_log2_height, refs);
}

if (mode == 0) {
Expand Down Expand Up @@ -797,7 +806,7 @@ void uvg_intra_build_reference_any(
// Init pointers to LCUs reconstruction buffers, such that index 0 refers to block coordinate 0.
const uvg_pixel *left_ref;
bool extra_ref = false;
// On the left LCU edge, if left neighboring LCU is available,
// On the left LCU edge, if left neighboring LCU is available,
// left_ref needs to point to correct extra reference line if MRL is used.
if (luma_px->x > 0 && lcu_px.x == 0 && multi_ref_index != 0) {
left_ref = &extra_ref_lines[multi_ref_index * 128];
Expand Down Expand Up @@ -836,7 +845,7 @@ void uvg_intra_build_reference_any(

const int log2_ratio = log2_width - log2_height;
int s = MAX(0, -log2_ratio);
int mrl_extension = (multi_ref_index << s) + 3;
int mrl_extension = (multi_ref_index << s) + (height << s) + 2;
// Generate left reference.
if (luma_px->x > 0) {
// Get the number of reference pixels based on the PU coordinate within the LCU.
Expand Down Expand Up @@ -870,15 +879,17 @@ void uvg_intra_build_reference_any(

// If first isp split, take samples as if it were normal square block
int tmp_h = is_first_isp_block ? cu_height * 2 : (isp_mode ? cu_height + height : height * 2);
for (int i = px_available_left; i < tmp_h + mrl_extension; ++i) {
int total_height = MIN(tmp_h + mrl_extension, INTRA_REF_LENGTH);
for (int i = px_available_left; i < total_height; ++i) {
out_left_ref[i + 1 + multi_ref_index] = nearest_pixel;
}
} else {
// If we are on the left edge, extend the first pixel of the top row.
uvg_pixel nearest_pixel = luma_px->y > 0 ? top_border[0] : dc_val;
// If first isp split, take samples as if it were normal square block
int tmp_h = is_first_isp_block ? cu_height * 2 : (isp_mode ? cu_height + height : height * 2);
for (int i = 0; i < tmp_h + mrl_extension; i++) {
int total_height = MIN(tmp_h + mrl_extension, INTRA_REF_LENGTH);
for (int i = 0; i < total_height; i++) {
// Reserve space for top left reference
out_left_ref[i + 1 + multi_ref_index] = nearest_pixel;
}
Expand All @@ -901,11 +912,11 @@ void uvg_intra_build_reference_any(
// LCU left border case
uvg_pixel *top_left_corner = &extra_ref_lines[multi_ref_index * 128];
switch (multi_ref_index) {
case 0:
case 0:
out_left_ref[0] = left_border[(-1) * left_stride];
out_top_ref[0] = top_left_corner[MAX_REF_LINE_IDX - 1];
break;
case 1:
case 1:
for (int i = 0; i <= 1; ++i) {
out_left_ref[i] = left_border[(i - 1 - 1) * left_stride];
out_top_ref[i] = top_left_corner[(128 * -i) + MAX_REF_LINE_IDX - 1 - 1];
Expand Down Expand Up @@ -1002,7 +1013,7 @@ void uvg_intra_build_reference_any(
// Generate top reference.
int px_available_top;
s = MAX(0, log2_ratio);
mrl_extension = (multi_ref_index << s) + 3;
mrl_extension = (multi_ref_index << s) + (width << s) + 2;
if (luma_px->y > 0) {
// Get the number of reference pixels based on the PU coordinate within the LCU.
if (isp_mode && !is_first_isp_block && !is_chroma) {
Expand All @@ -1018,7 +1029,7 @@ void uvg_intra_build_reference_any(
const int num_cus = uvg_count_available_edge_cus(cu_loc, lcu, false);
px_available_top = !is_chroma ? num_cus * 4 : num_cus * 2;
}

// Limit the number of available pixels based on block size and dimensions
// of the picture.
px_available_top = MIN(px_available_top, cu_width + pu_loc->width);
Expand All @@ -1033,7 +1044,8 @@ void uvg_intra_build_reference_any(

// If first isp split, take samples as if it were normal square block
int tmp_w = is_first_isp_block ? cu_width * 2 : (isp_mode ? cu_width + width : width * 2);
for (int i = px_available_top; i < tmp_w + mrl_extension; ++i) {
int total_width = MIN(tmp_w + mrl_extension, INTRA_REF_LENGTH);
for (int i = px_available_top; i < total_width; ++i) {
out_top_ref[i + 1 + multi_ref_index] = nearest_pixel;
}
} else {
Expand All @@ -1042,7 +1054,8 @@ void uvg_intra_build_reference_any(

// If first isp split, take samples as if it were normal square block
int tmp_w = is_first_isp_block ? cu_width * 2 : (isp_mode ? cu_width + width : width * 2);
for (int i = 0; i < tmp_w + mrl_extension; i++) {
int total_width = MIN(tmp_w + mrl_extension, INTRA_REF_LENGTH);
for (int i = 0; i < total_width; i++) {
out_top_ref[i + 1] = nearest_pixel;
}
}
Expand Down Expand Up @@ -1266,9 +1279,10 @@ void uvg_intra_build_reference_inner(
// If first isp split, take samples as if it were normal square block
const int log2_ratio = log2_width - log2_height;
int s = MAX(0, -log2_ratio);
int mrl_extension = (multi_ref_index << s) + 3;
int mrl_extension = ((multi_ref_index + 0) << s) + (height << s) + 2;
int tmp_h = is_first_isp_block ? cu_height * 2 : (isp_mode ? cu_height + height : height * 2);
for (; i < tmp_h + mrl_extension; i += 4) {
int total_height = MIN(tmp_h + mrl_extension, INTRA_REF_LENGTH - 2);
for (; i < total_height; i += 4) {
out_left_ref[i + 1] = nearest_pixel;
out_left_ref[i + 2] = nearest_pixel;
out_left_ref[i + 3] = nearest_pixel;
Expand Down Expand Up @@ -1314,9 +1328,10 @@ void uvg_intra_build_reference_inner(

// If first isp split, take samples as if it were normal square block
s = MAX(0, -log2_ratio);
mrl_extension = (multi_ref_index << s) + 3;
mrl_extension = ((multi_ref_index + 0) << s) + (width << s) + 2;
int tmp_w = is_first_isp_block ? cu_width * 2 : (isp_mode ? cu_width + width : width * 2);
for (; i < tmp_w + mrl_extension; i += 4) {
int total_width = MIN(tmp_w+ mrl_extension, INTRA_REF_LENGTH - 2);
for (; i < total_width; i += 4) {
out_top_ref[i + 1 + multi_ref_index] = nearest_pixel;
out_top_ref[i + 2 + multi_ref_index] = nearest_pixel;
out_top_ref[i + 3 + multi_ref_index] = nearest_pixel;
Expand Down

0 comments on commit 3c54935

Please sign in to comment.