Skip to content

Commit 3c54935

Browse files
committed
[intra] Extend the reference inside the reference building
1 parent a1413a4 commit 3c54935

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

src/intra.c

+34-19
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ static void intra_filter_reference(
198198
refs->filtered_initialized = true;
199199
}
200200

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

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

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

218218
// Left to right
219-
for (int_fast8_t x = 1; x < ref_width - 1; ++x) {
219+
for (int_fast16_t x = 1; x < ref_width - 1; ++x) {
220220
uvg_pixel *p = &ref->top[x];
221221
filtered_ref->top[x] = (p[-1] + 2 * p[0] + p[1] + 2) >> 2;
222222
}
@@ -712,7 +712,16 @@ static void intra_predict_regular(
712712
}
713713

714714
if (used_ref == &refs->filtered_ref && !refs->filtered_initialized) {
715-
intra_filter_reference(log2_width, log2_height, refs);
715+
int temp_log2_width = log2_width;
716+
int temp_log2_height = log2_height;
717+
if (color == COLOR_Y && isp_mode == ISP_MODE_NO_ISP) {
718+
temp_log2_width = cur_cu->log2_width;
719+
temp_log2_height = cur_cu->log2_height;
720+
} else if (color != COLOR_Y) {
721+
temp_log2_width = cur_cu->log2_chroma_width;
722+
temp_log2_height = cur_cu->log2_chroma_height;
723+
}
724+
intra_filter_reference(temp_log2_width, temp_log2_height, refs);
716725
}
717726

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

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

871880
// If first isp split, take samples as if it were normal square block
872881
int tmp_h = is_first_isp_block ? cu_height * 2 : (isp_mode ? cu_height + height : height * 2);
873-
for (int i = px_available_left; i < tmp_h + mrl_extension; ++i) {
882+
int total_height = MIN(tmp_h + mrl_extension, INTRA_REF_LENGTH);
883+
for (int i = px_available_left; i < total_height; ++i) {
874884
out_left_ref[i + 1 + multi_ref_index] = nearest_pixel;
875885
}
876886
} else {
877887
// If we are on the left edge, extend the first pixel of the top row.
878888
uvg_pixel nearest_pixel = luma_px->y > 0 ? top_border[0] : dc_val;
879889
// If first isp split, take samples as if it were normal square block
880890
int tmp_h = is_first_isp_block ? cu_height * 2 : (isp_mode ? cu_height + height : height * 2);
881-
for (int i = 0; i < tmp_h + mrl_extension; i++) {
891+
int total_height = MIN(tmp_h + mrl_extension, INTRA_REF_LENGTH);
892+
for (int i = 0; i < total_height; i++) {
882893
// Reserve space for top left reference
883894
out_left_ref[i + 1 + multi_ref_index] = nearest_pixel;
884895
}
@@ -901,11 +912,11 @@ void uvg_intra_build_reference_any(
901912
// LCU left border case
902913
uvg_pixel *top_left_corner = &extra_ref_lines[multi_ref_index * 128];
903914
switch (multi_ref_index) {
904-
case 0:
915+
case 0:
905916
out_left_ref[0] = left_border[(-1) * left_stride];
906917
out_top_ref[0] = top_left_corner[MAX_REF_LINE_IDX - 1];
907918
break;
908-
case 1:
919+
case 1:
909920
for (int i = 0; i <= 1; ++i) {
910921
out_left_ref[i] = left_border[(i - 1 - 1) * left_stride];
911922
out_top_ref[i] = top_left_corner[(128 * -i) + MAX_REF_LINE_IDX - 1 - 1];
@@ -1002,7 +1013,7 @@ void uvg_intra_build_reference_any(
10021013
// Generate top reference.
10031014
int px_available_top;
10041015
s = MAX(0, log2_ratio);
1005-
mrl_extension = (multi_ref_index << s) + 3;
1016+
mrl_extension = (multi_ref_index << s) + (width << s) + 2;
10061017
if (luma_px->y > 0) {
10071018
// Get the number of reference pixels based on the PU coordinate within the LCU.
10081019
if (isp_mode && !is_first_isp_block && !is_chroma) {
@@ -1018,7 +1029,7 @@ void uvg_intra_build_reference_any(
10181029
const int num_cus = uvg_count_available_edge_cus(cu_loc, lcu, false);
10191030
px_available_top = !is_chroma ? num_cus * 4 : num_cus * 2;
10201031
}
1021-
1032+
10221033
// Limit the number of available pixels based on block size and dimensions
10231034
// of the picture.
10241035
px_available_top = MIN(px_available_top, cu_width + pu_loc->width);
@@ -1033,7 +1044,8 @@ void uvg_intra_build_reference_any(
10331044

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

10431055
// If first isp split, take samples as if it were normal square block
10441056
int tmp_w = is_first_isp_block ? cu_width * 2 : (isp_mode ? cu_width + width : width * 2);
1045-
for (int i = 0; i < tmp_w + mrl_extension; i++) {
1057+
int total_width = MIN(tmp_w + mrl_extension, INTRA_REF_LENGTH);
1058+
for (int i = 0; i < total_width; i++) {
10461059
out_top_ref[i + 1] = nearest_pixel;
10471060
}
10481061
}
@@ -1266,9 +1279,10 @@ void uvg_intra_build_reference_inner(
12661279
// If first isp split, take samples as if it were normal square block
12671280
const int log2_ratio = log2_width - log2_height;
12681281
int s = MAX(0, -log2_ratio);
1269-
int mrl_extension = (multi_ref_index << s) + 3;
1282+
int mrl_extension = ((multi_ref_index + 0) << s) + (height << s) + 2;
12701283
int tmp_h = is_first_isp_block ? cu_height * 2 : (isp_mode ? cu_height + height : height * 2);
1271-
for (; i < tmp_h + mrl_extension; i += 4) {
1284+
int total_height = MIN(tmp_h + mrl_extension, INTRA_REF_LENGTH - 2);
1285+
for (; i < total_height; i += 4) {
12721286
out_left_ref[i + 1] = nearest_pixel;
12731287
out_left_ref[i + 2] = nearest_pixel;
12741288
out_left_ref[i + 3] = nearest_pixel;
@@ -1314,9 +1328,10 @@ void uvg_intra_build_reference_inner(
13141328

13151329
// If first isp split, take samples as if it were normal square block
13161330
s = MAX(0, -log2_ratio);
1317-
mrl_extension = (multi_ref_index << s) + 3;
1331+
mrl_extension = ((multi_ref_index + 0) << s) + (width << s) + 2;
13181332
int tmp_w = is_first_isp_block ? cu_width * 2 : (isp_mode ? cu_width + width : width * 2);
1319-
for (; i < tmp_w + mrl_extension; i += 4) {
1333+
int total_width = MIN(tmp_w+ mrl_extension, INTRA_REF_LENGTH - 2);
1334+
for (; i < total_width; i += 4) {
13201335
out_top_ref[i + 1 + multi_ref_index] = nearest_pixel;
13211336
out_top_ref[i + 2 + multi_ref_index] = nearest_pixel;
13221337
out_top_ref[i + 3 + multi_ref_index] = nearest_pixel;

0 commit comments

Comments
 (0)