Commit 2e70b2de authored by Aneesh Dogra's avatar Aneesh Dogra Committed by Diego Biurrun

dct: K&R formatting cosmetics

Signed-off-by: 's avatarDiego Biurrun <diego@biurrun.de>
parent 212fd3a1
...@@ -28,15 +28,16 @@ ...@@ -28,15 +28,16 @@
*/ */
#include <math.h> #include <math.h>
#include "libavutil/mathematics.h" #include "libavutil/mathematics.h"
#include "dct.h" #include "dct.h"
#include "dct32.h" #include "dct32.h"
/* sin((M_PI * x / (2*n)) */ /* sin((M_PI * x / (2 * n)) */
#define SIN(s,n,x) (s->costab[(n) - (x)]) #define SIN(s, n, x) (s->costab[(n) - (x)])
/* cos((M_PI * x / (2*n)) */ /* cos((M_PI * x / (2 * n)) */
#define COS(s,n,x) (s->costab[x]) #define COS(s, n, x) (s->costab[x])
static void ff_dst_calc_I_c(DCTContext *ctx, FFTSample *data) static void ff_dst_calc_I_c(DCTContext *ctx, FFTSample *data)
{ {
...@@ -44,28 +45,28 @@ static void ff_dst_calc_I_c(DCTContext *ctx, FFTSample *data) ...@@ -44,28 +45,28 @@ static void ff_dst_calc_I_c(DCTContext *ctx, FFTSample *data)
int i; int i;
data[0] = 0; data[0] = 0;
for(i = 1; i < n/2; i++) { for (i = 1; i < n / 2; i++) {
float tmp1 = data[i ]; float tmp1 = data[i ];
float tmp2 = data[n - i]; float tmp2 = data[n - i];
float s = SIN(ctx, n, 2*i); float s = SIN(ctx, n, 2 * i);
s *= tmp1 + tmp2; s *= tmp1 + tmp2;
tmp1 = (tmp1 - tmp2) * 0.5f; tmp1 = (tmp1 - tmp2) * 0.5f;
data[i ] = s + tmp1; data[i] = s + tmp1;
data[n - i] = s - tmp1; data[n - i] = s - tmp1;
} }
data[n/2] *= 2; data[n / 2] *= 2;
ctx->rdft.rdft_calc(&ctx->rdft, data); ctx->rdft.rdft_calc(&ctx->rdft, data);
data[0] *= 0.5f; data[0] *= 0.5f;
for(i = 1; i < n-2; i += 2) { for (i = 1; i < n - 2; i += 2) {
data[i + 1] += data[i - 1]; data[i + 1] += data[i - 1];
data[i ] = -data[i + 2]; data[i] = -data[i + 2];
} }
data[n-1] = 0; data[n - 1] = 0;
} }
static void ff_dct_calc_I_c(DCTContext *ctx, FFTSample *data) static void ff_dct_calc_I_c(DCTContext *ctx, FFTSample *data)
...@@ -74,11 +75,11 @@ static void ff_dct_calc_I_c(DCTContext *ctx, FFTSample *data) ...@@ -74,11 +75,11 @@ static void ff_dct_calc_I_c(DCTContext *ctx, FFTSample *data)
int i; int i;
float next = -0.5f * (data[0] - data[n]); float next = -0.5f * (data[0] - data[n]);
for(i = 0; i < n/2; i++) { for (i = 0; i < n / 2; i++) {
float tmp1 = data[i ]; float tmp1 = data[i];
float tmp2 = data[n - i]; float tmp2 = data[n - i];
float s = SIN(ctx, n, 2*i); float s = SIN(ctx, n, 2 * i);
float c = COS(ctx, n, 2*i); float c = COS(ctx, n, 2 * i);
c *= tmp1 - tmp2; c *= tmp1 - tmp2;
s *= tmp1 - tmp2; s *= tmp1 - tmp2;
...@@ -86,7 +87,7 @@ static void ff_dct_calc_I_c(DCTContext *ctx, FFTSample *data) ...@@ -86,7 +87,7 @@ static void ff_dct_calc_I_c(DCTContext *ctx, FFTSample *data)
next += c; next += c;
tmp1 = (tmp1 + tmp2) * 0.5f; tmp1 = (tmp1 + tmp2) * 0.5f;
data[i ] = tmp1 - s; data[i] = tmp1 - s;
data[n - i] = tmp1 + s; data[n - i] = tmp1 + s;
} }
...@@ -94,7 +95,7 @@ static void ff_dct_calc_I_c(DCTContext *ctx, FFTSample *data) ...@@ -94,7 +95,7 @@ static void ff_dct_calc_I_c(DCTContext *ctx, FFTSample *data)
data[n] = data[1]; data[n] = data[1];
data[1] = next; data[1] = next;
for(i = 3; i <= n; i += 2) for (i = 3; i <= n; i += 2)
data[i] = data[i - 2] - data[i]; data[i] = data[i - 2] - data[i];
} }
...@@ -107,12 +108,12 @@ static void ff_dct_calc_III_c(DCTContext *ctx, FFTSample *data) ...@@ -107,12 +108,12 @@ static void ff_dct_calc_III_c(DCTContext *ctx, FFTSample *data)
float inv_n = 1.0f / n; float inv_n = 1.0f / n;
for (i = n - 2; i >= 2; i -= 2) { for (i = n - 2; i >= 2; i -= 2) {
float val1 = data[i ]; float val1 = data[i];
float val2 = data[i - 1] - data[i + 1]; float val2 = data[i - 1] - data[i + 1];
float c = COS(ctx, n, i); float c = COS(ctx, n, i);
float s = SIN(ctx, n, i); float s = SIN(ctx, n, i);
data[i ] = c * val1 + s * val2; data[i] = c * val1 + s * val2;
data[i + 1] = s * val1 - c * val2; data[i + 1] = s * val1 - c * val2;
} }
...@@ -121,12 +122,12 @@ static void ff_dct_calc_III_c(DCTContext *ctx, FFTSample *data) ...@@ -121,12 +122,12 @@ static void ff_dct_calc_III_c(DCTContext *ctx, FFTSample *data)
ctx->rdft.rdft_calc(&ctx->rdft, data); ctx->rdft.rdft_calc(&ctx->rdft, data);
for (i = 0; i < n / 2; i++) { for (i = 0; i < n / 2; i++) {
float tmp1 = data[i ] * inv_n; float tmp1 = data[i] * inv_n;
float tmp2 = data[n - i - 1] * inv_n; float tmp2 = data[n - i - 1] * inv_n;
float csc = ctx->csc2[i] * (tmp1 - tmp2); float csc = ctx->csc2[i] * (tmp1 - tmp2);
tmp1 += tmp2; tmp1 += tmp2;
data[i ] = tmp1 + csc; data[i] = tmp1 + csc;
data[n - i - 1] = tmp1 - csc; data[n - i - 1] = tmp1 - csc;
} }
} }
...@@ -137,15 +138,15 @@ static void ff_dct_calc_II_c(DCTContext *ctx, FFTSample *data) ...@@ -137,15 +138,15 @@ static void ff_dct_calc_II_c(DCTContext *ctx, FFTSample *data)
int i; int i;
float next; float next;
for (i=0; i < n/2; i++) { for (i = 0; i < n / 2; i++) {
float tmp1 = data[i ]; float tmp1 = data[i];
float tmp2 = data[n - i - 1]; float tmp2 = data[n - i - 1];
float s = SIN(ctx, n, 2*i + 1); float s = SIN(ctx, n, 2 * i + 1);
s *= tmp1 - tmp2; s *= tmp1 - tmp2;
tmp1 = (tmp1 + tmp2) * 0.5f; tmp1 = (tmp1 + tmp2) * 0.5f;
data[i ] = tmp1 + s; data[i] = tmp1 + s;
data[n-i-1] = tmp1 - s; data[n-i-1] = tmp1 - s;
} }
...@@ -160,9 +161,8 @@ static void ff_dct_calc_II_c(DCTContext *ctx, FFTSample *data) ...@@ -160,9 +161,8 @@ static void ff_dct_calc_II_c(DCTContext *ctx, FFTSample *data)
float c = COS(ctx, n, i); float c = COS(ctx, n, i);
float s = SIN(ctx, n, i); float s = SIN(ctx, n, i);
data[i ] = c * inr + s * ini; data[i] = c * inr + s * ini;
data[i + 1] = next;
data[i+1] = next;
next += s * inr - c * ini; next += s * inr - c * ini;
} }
...@@ -186,30 +186,30 @@ av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse) ...@@ -186,30 +186,30 @@ av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse)
if (inverse == DCT_II && nbits == 5) { if (inverse == DCT_II && nbits == 5) {
s->dct_calc = dct32_func; s->dct_calc = dct32_func;
} else { } else {
ff_init_ff_cos_tabs(nbits+2); ff_init_ff_cos_tabs(nbits + 2);
s->costab = ff_cos_tabs[nbits+2];
s->csc2 = av_malloc(n/2 * sizeof(FFTSample)); s->costab = ff_cos_tabs[nbits + 2];
s->csc2 = av_malloc(n / 2 * sizeof(FFTSample));
if (ff_rdft_init(&s->rdft, nbits, inverse == DCT_III) < 0) { if (ff_rdft_init(&s->rdft, nbits, inverse == DCT_III) < 0) {
av_free(s->csc2); av_free(s->csc2);
return -1; return -1;
} }
for (i = 0; i < n/2; i++) for (i = 0; i < n / 2; i++)
s->csc2[i] = 0.5 / sin((M_PI / (2*n) * (2*i + 1))); s->csc2[i] = 0.5 / sin((M_PI / (2 * n) * (2 * i + 1)));
switch(inverse) { switch (inverse) {
case DCT_I : s->dct_calc = ff_dct_calc_I_c; break; case DCT_I : s->dct_calc = ff_dct_calc_I_c; break;
case DCT_II : s->dct_calc = ff_dct_calc_II_c ; break; case DCT_II : s->dct_calc = ff_dct_calc_II_c; break;
case DCT_III: s->dct_calc = ff_dct_calc_III_c; break; case DCT_III: s->dct_calc = ff_dct_calc_III_c; break;
case DST_I : s->dct_calc = ff_dst_calc_I_c; break; case DST_I : s->dct_calc = ff_dst_calc_I_c; break;
} }
} }
s->dct32 = ff_dct32_float; s->dct32 = ff_dct32_float;
if (HAVE_MMX) ff_dct_init_mmx(s); if (HAVE_MMX)
ff_dct_init_mmx(s);
return 0; return 0;
} }
......
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