av1_highbd_dr_prediction_z2_c: Add an assertion.
We add an assertion to make sure that we are not reading beyond the valid range
of the 'above' or 'left' buffers.
Valid minimum index is:
-1 when upsampling is NOT used, and
-2 when upsampling is used.
And this minimum index corresponds to the top-left pixel.
Also,
- A similar assertion was already present in lowbd function
av1_dr_prediction_z2_c. But I made the function structure same as hbd
version.
- Related code cleanup for variable names, and moving declarations
closer to use.
Change-Id: If477013843edcf408332b107e58a2238ca30dfb7
diff --git a/av1/common/reconintra.c b/av1/common/reconintra.c
index 71a52e7..df69d6b 100644
--- a/av1/common/reconintra.c
+++ b/av1/common/reconintra.c
@@ -556,33 +556,37 @@
const uint8_t *above, const uint8_t *left,
int upsample_above, int upsample_left, int dx,
int dy) {
- int r, c, x, y, shift1, shift2, val, base1, base2;
-
assert(dx > 0);
assert(dy > 0);
const int min_base_x = -(1 << upsample_above);
+ const int min_base_y = -(1 << upsample_left);
+ (void)min_base_y;
const int frac_bits_x = 6 - upsample_above;
const int frac_bits_y = 6 - upsample_left;
- const int base_inc_x = 1 << upsample_above;
- x = -dx;
- for (r = 0; r < bh; ++r, x -= dx, dst += stride) {
- base1 = x >> frac_bits_x;
- y = (r << 6) - dy;
- for (c = 0; c < bw; ++c, base1 += base_inc_x, y -= dy) {
- if (base1 >= min_base_x) {
- shift1 = ((x * (1 << upsample_above)) & 0x3F) >> 1;
- val = above[base1] * (32 - shift1) + above[base1 + 1] * shift1;
+
+ for (int r = 0; r < bh; ++r) {
+ for (int c = 0; c < bw; ++c) {
+ int val;
+ int y = r + 1;
+ int x = (c << 6) - y * dx;
+ const int base_x = x >> frac_bits_x;
+ if (base_x >= min_base_x) {
+ const int shift = ((x * (1 << upsample_above)) & 0x3F) >> 1;
+ val = above[base_x] * (32 - shift) + above[base_x + 1] * shift;
val = ROUND_POWER_OF_TWO(val, 5);
} else {
- base2 = y >> frac_bits_y;
- assert(base2 >= -(1 << upsample_left));
- shift2 = ((y * (1 << upsample_left)) & 0x3F) >> 1;
- val = left[base2] * (32 - shift2) + left[base2 + 1] * shift2;
+ x = c + 1;
+ y = (r << 6) - x * dy;
+ const int base_y = y >> frac_bits_y;
+ assert(base_y >= min_base_y);
+ const int shift = ((y * (1 << upsample_left)) & 0x3F) >> 1;
+ val = left[base_y] * (32 - shift) + left[base_y + 1] * shift;
val = ROUND_POWER_OF_TWO(val, 5);
}
dst[c] = val;
}
+ dst += stride;
}
}
@@ -688,30 +692,33 @@
int bh, const uint16_t *above,
const uint16_t *left, int upsample_above,
int upsample_left, int dx, int dy, int bd) {
- int r, c, x, y, shift, val, base;
-
(void)bd;
assert(dx > 0);
assert(dy > 0);
const int min_base_x = -(1 << upsample_above);
+ const int min_base_y = -(1 << upsample_left);
+ (void)min_base_y;
const int frac_bits_x = 6 - upsample_above;
const int frac_bits_y = 6 - upsample_left;
- for (r = 0; r < bh; ++r) {
- for (c = 0; c < bw; ++c) {
- y = r + 1;
- x = (c << 6) - y * dx;
- base = x >> frac_bits_x;
- if (base >= min_base_x) {
- shift = ((x * (1 << upsample_above)) & 0x3F) >> 1;
- val = above[base] * (32 - shift) + above[base + 1] * shift;
+
+ for (int r = 0; r < bh; ++r) {
+ for (int c = 0; c < bw; ++c) {
+ int val;
+ int y = r + 1;
+ int x = (c << 6) - y * dx;
+ const int base_x = x >> frac_bits_x;
+ if (base_x >= min_base_x) {
+ const int shift = ((x * (1 << upsample_above)) & 0x3F) >> 1;
+ val = above[base_x] * (32 - shift) + above[base_x + 1] * shift;
val = ROUND_POWER_OF_TWO(val, 5);
} else {
x = c + 1;
y = (r << 6) - x * dy;
- base = y >> frac_bits_y;
- shift = ((y * (1 << upsample_left)) & 0x3F) >> 1;
- val = left[base] * (32 - shift) + left[base + 1] * shift;
+ const int base_y = y >> frac_bits_y;
+ assert(base_y >= min_base_y);
+ const int shift = ((y * (1 << upsample_left)) & 0x3F) >> 1;
+ val = left[base_y] * (32 - shift) + left[base_y + 1] * shift;
val = ROUND_POWER_OF_TWO(val, 5);
}
dst[c] = val;