ref: 20b0cb599b379faafdaa1ab19ef3a28c6580e1ae
parent: 77a3becf92b6385ce7e2ffcf636c9cc373d8760c
author: Dmitry Kovalev <dkovalev@google.com>
date: Mon Feb 25 08:38:18 EST 2013
Code cleanup. Removing redundant parentheses, better code formatting, introducing ROUND_POWER_OF_TWO macro to replace repeated expression. Change-Id: I91aad7a53ed03482428b2419de4bb99fd92c6771
--- a/vp9/common/vp9_idctllm.c
+++ b/vp9/common/vp9_idctllm.c
@@ -24,6 +24,7 @@
**************************************************************************/
#include <assert.h>
#include <math.h>
+
#include "./vpx_config.h"
#include "vp9/common/vp9_systemdependent.h"
#include "vp9/common/vp9_blockd.h"
@@ -30,6 +31,13 @@
#include "vp9/common/vp9_common.h"
#include "vp9/common/vp9_idct.h"
+#define ROUND_POWER_OF_TWO(value, n) (((value) + (1 << ((n) - 1))) >> (n))
+
+/* If we don't want to use ROUND_POWER_OF_TWO macro
+static INLINE int16_t round_power_of_two(int16_t value, int n) {
+ return (value + (1 << (n - 1))) >> n;
+}*/
+
void vp9_short_inv_walsh4x4_x8_c(int16_t *input, int16_t *output, int pitch) {
int i;
int a1, b1, c1, d1;
@@ -38,10 +46,10 @@
int shortpitch = pitch >> 1;
for (i = 0; i < 4; i++) {
- a1 = ((ip[0] + ip[3])) >> WHT_UPSCALE_FACTOR;
- b1 = ((ip[1] + ip[2])) >> WHT_UPSCALE_FACTOR;
- c1 = ((ip[1] - ip[2])) >> WHT_UPSCALE_FACTOR;
- d1 = ((ip[0] - ip[3])) >> WHT_UPSCALE_FACTOR;
+ a1 = (ip[0] + ip[3]) >> WHT_UPSCALE_FACTOR;
+ b1 = (ip[1] + ip[2]) >> WHT_UPSCALE_FACTOR;
+ c1 = (ip[1] - ip[2]) >> WHT_UPSCALE_FACTOR;
+ d1 = (ip[0] - ip[3]) >> WHT_UPSCALE_FACTOR;
op[0] = (a1 + b1 + 1) >> 1;
op[1] = (c1 + d1) >> 1;
@@ -79,7 +87,7 @@
int shortpitch = pitch >> 1;
op[0] = ((ip[0] >> WHT_UPSCALE_FACTOR) + 1) >> 1;
- op[1] = op[2] = op[3] = ((ip[0] >> WHT_UPSCALE_FACTOR) >> 1);
+ op[1] = op[2] = op[3] = (ip[0] >> WHT_UPSCALE_FACTOR) >> 1;
ip = tmp;
@@ -101,9 +109,8 @@
vp9_short_inv_walsh4x4_1_x8_c(&dc, tmp, 4 << 1);
for (r = 0; r < 4; r++) {
- for (c = 0; c < 4; c++) {
+ for (c = 0; c < 4; c++)
dst_ptr[c] = clip_pixel(tmp[r * 4 + c] + pred_ptr[c]);
- }
dst_ptr += stride;
pred_ptr += pitch;
@@ -150,7 +157,7 @@
temp_in[j] = out[j * 4 + i];
idct4_1d(temp_in, temp_out);
for (j = 0; j < 4; ++j)
- output[j * short_pitch + i] = (temp_out[j] + 8) >> 4;
+ output[j * short_pitch + i] = ROUND_POWER_OF_TWO(temp_out[j], 4);
}
}
@@ -159,19 +166,12 @@
int a1;
int16_t *op = output;
int shortpitch = pitch >> 1;
- int tmp;
- int16_t out;
- tmp = input[0] * cospi_16_64;
- out = dct_const_round_shift(tmp);
- tmp = out * cospi_16_64;
- out = dct_const_round_shift(tmp);
- a1 = (out + 8) >> 4;
+ int16_t out = dct_const_round_shift(input[0] * cospi_16_64);
+ out = dct_const_round_shift(out * cospi_16_64);
+ a1 = ROUND_POWER_OF_TWO(out, 4);
for (i = 0; i < 4; i++) {
- op[0] = a1;
- op[1] = a1;
- op[2] = a1;
- op[3] = a1;
+ op[0] = op[1] = op[2] = op[3] = a1;
op += shortpitch;
}
}
@@ -180,18 +180,14 @@
uint8_t *dst_ptr, int pitch, int stride) {
int a1;
int r, c;
- int tmp;
- int16_t out;
- tmp = input_dc * cospi_16_64;
- out = dct_const_round_shift(tmp);
- tmp = out * cospi_16_64;
- out = dct_const_round_shift(tmp);
- a1 = (out + 8) >> 4;
+ int16_t out = dct_const_round_shift(input_dc * cospi_16_64);
+ out = dct_const_round_shift(out * cospi_16_64);
+ a1 = ROUND_POWER_OF_TWO(out, 4);
for (r = 0; r < 4; r++) {
- for (c = 0; c < 4; c++) {
+ for (c = 0; c < 4; c++)
dst_ptr[c] = clip_pixel(a1 + pred_ptr[c]);
- }
+
dst_ptr += stride;
pred_ptr += pitch;
}
@@ -262,7 +258,7 @@
temp_in[j] = out[j * 8 + i];
idct8_1d(temp_in, temp_out);
for (j = 0; j < 8; ++j)
- output[j * short_pitch + i] = (temp_out[j] + 16) >> 5;
+ output[j * short_pitch + i] = ROUND_POWER_OF_TWO(temp_out[j], 5);
}
}
@@ -354,7 +350,7 @@
temp_in[j] = out[j * 4 + i];
invc(temp_in, temp_out);
for (j = 0; j < 4; ++j)
- output[j * short_pitch + i] = (temp_out[j] + 8) >> 4;
+ output[j * short_pitch + i] = ROUND_POWER_OF_TWO(temp_out[j], 4);
}
}
@@ -373,7 +369,7 @@
if (!(x0 | x1 | x2 | x3 | x4 | x5 | x6 | x7)) {
output[0] = output[1] = output[2] = output[3] = output[4]
- = output[5] = output[6] = output[7] = 0;
+ = output[5] = output[6] = output[7] = 0;
return;
}
@@ -483,7 +479,7 @@
temp_in[j] = out[j * 8 + i];
invc(temp_in, temp_out);
for (j = 0; j < 8; ++j)
- output[j * short_pitch + i] = (temp_out[j] + 16) >> 5;
+ output[j * short_pitch + i] = ROUND_POWER_OF_TWO(temp_out[j], 5);
}
}
@@ -509,7 +505,7 @@
temp_in[j] = out[j * 8 + i];
idct8_1d(temp_in, temp_out);
for (j = 0; j < 8; ++j)
- output[j * short_pitch + i] = (temp_out[j] + 16) >> 5;
+ output[j * short_pitch + i] = ROUND_POWER_OF_TWO(temp_out[j], 5);
}
}
@@ -516,7 +512,7 @@
void vp9_short_idct1_8x8_c(int16_t *input, int16_t *output) {
int16_t out = dct_const_round_shift(input[0] * cospi_16_64);
out = dct_const_round_shift(out * cospi_16_64);
- output[0] = (out + 16) >> 5;
+ output[0] = ROUND_POWER_OF_TWO(out, 5);
}
void idct16_1d(int16_t *input, int16_t *output) {
@@ -703,7 +699,7 @@
temp_in[j] = out[j * 16 + i];
idct16_1d(temp_in, temp_out);
for (j = 0; j < 16; ++j)
- output[j * 16 + i] = (temp_out[j] + 32) >> 6;
+ output[j * 16 + i] = ROUND_POWER_OF_TWO(temp_out[j], 6);
}
}
@@ -924,7 +920,7 @@
temp_in[j] = out[j * 16 + i];
invc(temp_in, temp_out);
for (j = 0; j < 16; ++j)
- output[j * 16 + i] = (temp_out[j] + 32) >> 6;
+ output[j * 16 + i] = ROUND_POWER_OF_TWO(temp_out[j], 6);
}
}
@@ -951,19 +947,15 @@
temp_in[j] = out[j*16 + i];
idct16_1d(temp_in, temp_out);
for (j = 0; j < 16; ++j)
- output[j*16 + i] = (temp_out[j] + 32) >> 6;
+ output[j*16 + i] = ROUND_POWER_OF_TWO(temp_out[j], 6);
}
}
void vp9_short_idct1_16x16_c(int16_t *input, int16_t *output) {
- int tmp;
- int16_t out;
- tmp = input[0] * cospi_16_64;
- out = dct_const_round_shift(tmp);
- tmp = out * cospi_16_64;
- out = dct_const_round_shift(tmp);
- *output = (out + 32) >> 6;
+ int16_t out = dct_const_round_shift(input[0] * cospi_16_64);
+ out = dct_const_round_shift(out * cospi_16_64);
+ output[0] = ROUND_POWER_OF_TWO(out, 6);
}
void idct32_1d(int16_t *input, int16_t *output) {
@@ -1352,7 +1344,7 @@
temp_in[j] = out[j * 32 + i];
idct32_1d(temp_in, temp_out);
for (j = 0; j < 32; ++j)
- output[j * 32 + i] = (temp_out[j] + 32) >> 6;
+ output[j * 32 + i] = ROUND_POWER_OF_TWO(temp_out[j], 6);
}
}
@@ -1359,5 +1351,5 @@
void vp9_short_idct1_32x32_c(int16_t *input, int16_t *output) {
int16_t out = dct_const_round_shift(input[0] * cospi_16_64);
out = dct_const_round_shift(out * cospi_16_64);
- output[0] = (out + 32) >> 6;
+ output[0] = ROUND_POWER_OF_TWO(out, 6);
}
--
⑨