Commit 7dcd7f5e authored by David Barker's avatar David Barker Committed by Debargha Mukherjee

Remove double rounding in selfguided filter

In av1_selfguided_restoration, the values stored into 'dgd' are
unnecessarily rounded twice. This patch replaces this by a single
rounding operation.

Change-Id: I188d283137b74823f5d5447d441250520d6ee294
parent b83e64ba
...@@ -678,9 +678,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride, ...@@ -678,9 +678,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride,
3 * A[k] + 2 * A[k + 1] + 2 * A[k + width] + A[k + width + 1]; 3 * A[k] + 2 * A[k + 1] + 2 * A[k + width] + A[k + width + 1];
const int32_t b = const int32_t b =
3 * B[k] + 2 * B[k + 1] + 2 * B[k + width] + B[k + width + 1]; 3 * B[k] + 2 * B[k + 1] + 2 * B[k + width] + B[k + width + 1];
const int32_t v = const int32_t v = a * dgd[l] + b;
(((a * dgd[l] + b) << SGRPROJ_RST_BITS) + (1 << nb) / 2) >> nb; dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS + nb - SGRPROJ_RST_BITS);
dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS);
} }
i = 0; i = 0;
j = width - 1; j = width - 1;
...@@ -692,9 +691,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride, ...@@ -692,9 +691,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride,
3 * A[k] + 2 * A[k - 1] + 2 * A[k + width] + A[k + width - 1]; 3 * A[k] + 2 * A[k - 1] + 2 * A[k + width] + A[k + width - 1];
const int32_t b = const int32_t b =
3 * B[k] + 2 * B[k - 1] + 2 * B[k + width] + B[k + width - 1]; 3 * B[k] + 2 * B[k - 1] + 2 * B[k + width] + B[k + width - 1];
const int32_t v = const int32_t v = a * dgd[l] + b;
(((a * dgd[l] + b) << SGRPROJ_RST_BITS) + (1 << nb) / 2) >> nb; dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS + nb - SGRPROJ_RST_BITS);
dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS);
} }
i = height - 1; i = height - 1;
j = 0; j = 0;
...@@ -706,9 +704,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride, ...@@ -706,9 +704,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride,
3 * A[k] + 2 * A[k + 1] + 2 * A[k - width] + A[k - width + 1]; 3 * A[k] + 2 * A[k + 1] + 2 * A[k - width] + A[k - width + 1];
const int32_t b = const int32_t b =
3 * B[k] + 2 * B[k + 1] + 2 * B[k - width] + B[k - width + 1]; 3 * B[k] + 2 * B[k + 1] + 2 * B[k - width] + B[k - width + 1];
const int32_t v = const int32_t v = a * dgd[l] + b;
(((a * dgd[l] + b) << SGRPROJ_RST_BITS) + (1 << nb) / 2) >> nb; dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS + nb - SGRPROJ_RST_BITS);
dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS);
} }
i = height - 1; i = height - 1;
j = width - 1; j = width - 1;
...@@ -720,9 +717,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride, ...@@ -720,9 +717,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride,
3 * A[k] + 2 * A[k - 1] + 2 * A[k - width] + A[k - width - 1]; 3 * A[k] + 2 * A[k - 1] + 2 * A[k - width] + A[k - width - 1];
const int32_t b = const int32_t b =
3 * B[k] + 2 * B[k - 1] + 2 * B[k - width] + B[k - width - 1]; 3 * B[k] + 2 * B[k - 1] + 2 * B[k - width] + B[k - width - 1];
const int32_t v = const int32_t v = a * dgd[l] + b;
(((a * dgd[l] + b) << SGRPROJ_RST_BITS) + (1 << nb) / 2) >> nb; dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS + nb - SGRPROJ_RST_BITS);
dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS);
} }
i = 0; i = 0;
for (j = 1; j < width - 1; ++j) { for (j = 1; j < width - 1; ++j) {
...@@ -733,9 +729,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride, ...@@ -733,9 +729,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride,
A[k + width - 1] + A[k + width + 1]; A[k + width - 1] + A[k + width + 1];
const int32_t b = B[k] + 2 * (B[k - 1] + B[k + 1]) + B[k + width] + const int32_t b = B[k] + 2 * (B[k - 1] + B[k + 1]) + B[k + width] +
B[k + width - 1] + B[k + width + 1]; B[k + width - 1] + B[k + width + 1];
const int32_t v = const int32_t v = a * dgd[l] + b;
(((a * dgd[l] + b) << SGRPROJ_RST_BITS) + (1 << nb) / 2) >> nb; dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS + nb - SGRPROJ_RST_BITS);
dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS);
} }
i = height - 1; i = height - 1;
for (j = 1; j < width - 1; ++j) { for (j = 1; j < width - 1; ++j) {
...@@ -746,9 +741,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride, ...@@ -746,9 +741,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride,
A[k - width - 1] + A[k - width + 1]; A[k - width - 1] + A[k - width + 1];
const int32_t b = B[k] + 2 * (B[k - 1] + B[k + 1]) + B[k - width] + const int32_t b = B[k] + 2 * (B[k - 1] + B[k + 1]) + B[k - width] +
B[k - width - 1] + B[k - width + 1]; B[k - width - 1] + B[k - width + 1];
const int32_t v = const int32_t v = a * dgd[l] + b;
(((a * dgd[l] + b) << SGRPROJ_RST_BITS) + (1 << nb) / 2) >> nb; dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS + nb - SGRPROJ_RST_BITS);
dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS);
} }
j = 0; j = 0;
for (i = 1; i < height - 1; ++i) { for (i = 1; i < height - 1; ++i) {
...@@ -759,9 +753,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride, ...@@ -759,9 +753,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride,
A[k - width + 1] + A[k + width + 1]; A[k - width + 1] + A[k + width + 1];
const int32_t b = B[k] + 2 * (B[k - width] + B[k + width]) + B[k + 1] + const int32_t b = B[k] + 2 * (B[k - width] + B[k + width]) + B[k + 1] +
B[k - width + 1] + B[k + width + 1]; B[k - width + 1] + B[k + width + 1];
const int32_t v = const int32_t v = a * dgd[l] + b;
(((a * dgd[l] + b) << SGRPROJ_RST_BITS) + (1 << nb) / 2) >> nb; dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS + nb - SGRPROJ_RST_BITS);
dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS);
} }
j = width - 1; j = width - 1;
for (i = 1; i < height - 1; ++i) { for (i = 1; i < height - 1; ++i) {
...@@ -772,9 +765,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride, ...@@ -772,9 +765,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride,
A[k - width - 1] + A[k + width - 1]; A[k - width - 1] + A[k + width - 1];
const int32_t b = B[k] + 2 * (B[k - width] + B[k + width]) + B[k - 1] + const int32_t b = B[k] + 2 * (B[k - width] + B[k + width]) + B[k - 1] +
B[k - width - 1] + B[k + width - 1]; B[k - width - 1] + B[k + width - 1];
const int32_t v = const int32_t v = a * dgd[l] + b;
(((a * dgd[l] + b) << SGRPROJ_RST_BITS) + (1 << nb) / 2) >> nb; dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS + nb - SGRPROJ_RST_BITS);
dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS);
} }
for (i = 1; i < height - 1; ++i) { for (i = 1; i < height - 1; ++i) {
for (j = 1; j < width - 1; ++j) { for (j = 1; j < width - 1; ++j) {
...@@ -791,9 +783,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride, ...@@ -791,9 +783,8 @@ void av1_selfguided_restoration(int32_t *dgd, int width, int height, int stride,
(B[k - 1 - width] + B[k - 1 + width] + B[k + 1 - width] + (B[k - 1 - width] + B[k - 1 + width] + B[k + 1 - width] +
B[k + 1 + width]) * B[k + 1 + width]) *
3; 3;
const int32_t v = const int32_t v = a * dgd[l] + b;
(((a * dgd[l] + b) << SGRPROJ_RST_BITS) + (1 << nb) / 2) >> nb; dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS + nb - SGRPROJ_RST_BITS);
dgd[l] = ROUND_POWER_OF_TWO(v, SGRPROJ_SGR_BITS);
} }
} }
#else #else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment