**************************************************************************/
#include <assert.h>
#include <math.h>
+
#include "./vpx_config.h"
#include "vp9/common/vp9_systemdependent.h"
#include "vp9/common/vp9_blockd.h"
#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;
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;
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;
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;
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);
}
}
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;
}
}
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;
}
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);
}
}
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);
}
}
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;
}
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);
}
}
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);
}
}
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) {
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);
}
}
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);
}
}
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) {
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);
}
}
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);
}