Mercurial > libavcodec.hg
comparison dct.c @ 11519:c091ab3b4135 libavcodec
Split DCT-II and DCT-III in different functions, they do not share any code.
author | vitor |
---|---|
date | Sun, 21 Mar 2010 11:35:05 +0000 |
parents | c4d18d452f82 |
children | a791382fd782 |
comparison
equal
deleted
inserted
replaced
11518:c4d18d452f82 | 11519:c091ab3b4135 |
---|---|
35 #define SIN(s,n,x) (s->costab[(n) - (x)]) | 35 #define SIN(s,n,x) (s->costab[(n) - (x)]) |
36 | 36 |
37 /* cos((M_PI * x / (2*n)) */ | 37 /* cos((M_PI * x / (2*n)) */ |
38 #define COS(s,n,x) (s->costab[x]) | 38 #define COS(s,n,x) (s->costab[x]) |
39 | 39 |
40 static void ff_dct_calc_c(DCTContext *ctx, FFTSample *data) | 40 static void ff_dct_calc_III_c(DCTContext *ctx, FFTSample *data) |
41 { | 41 { |
42 int n = 1 << ctx->nbits; | 42 int n = 1 << ctx->nbits; |
43 int i; | 43 int i; |
44 | 44 |
45 if (ctx->inverse) { | |
46 float next = data[n - 1]; | 45 float next = data[n - 1]; |
47 float inv_n = 1.0f / n; | 46 float inv_n = 1.0f / n; |
48 | 47 |
49 for (i = n - 2; i >= 2; i -= 2) { | 48 for (i = n - 2; i >= 2; i -= 2) { |
50 float val1 = data[i ]; | 49 float val1 = data[i ]; |
67 | 66 |
68 tmp1 += tmp2; | 67 tmp1 += tmp2; |
69 data[i ] = tmp1 + csc; | 68 data[i ] = tmp1 + csc; |
70 data[n - i - 1] = tmp1 - csc; | 69 data[n - i - 1] = tmp1 - csc; |
71 } | 70 } |
72 } else { | 71 } |
72 | |
73 static void ff_dct_calc_II_c(DCTContext *ctx, FFTSample *data) | |
74 { | |
75 int n = 1 << ctx->nbits; | |
76 int i; | |
73 float next; | 77 float next; |
74 for (i=0; i < n/2; i++) { | 78 for (i=0; i < n/2; i++) { |
75 float tmp1 = data[i ]; | 79 float tmp1 = data[i ]; |
76 float tmp2 = data[n - i - 1]; | 80 float tmp2 = data[n - i - 1]; |
77 float s = SIN(ctx, n, 2*i + 1); | 81 float s = SIN(ctx, n, 2*i + 1); |
98 | 102 |
99 data[i+1] = next; | 103 data[i+1] = next; |
100 | 104 |
101 next += s * inr - c * ini; | 105 next += s * inr - c * ini; |
102 } | 106 } |
103 } | |
104 } | 107 } |
105 | 108 |
106 void ff_dct_calc(DCTContext *s, FFTSample *data) | 109 void ff_dct_calc(DCTContext *s, FFTSample *data) |
107 { | 110 { |
108 s->dct_calc(s, data); | 111 s->dct_calc(s, data); |
128 } | 131 } |
129 | 132 |
130 for (i = 0; i < n/2; i++) | 133 for (i = 0; i < n/2; i++) |
131 s->csc2[i] = 0.5 / sin((M_PI / (2*n) * (2*i + 1))); | 134 s->csc2[i] = 0.5 / sin((M_PI / (2*n) * (2*i + 1))); |
132 | 135 |
133 s->dct_calc = ff_dct_calc_c; | 136 if(inverse) { |
137 s->dct_calc = ff_dct_calc_III_c; | |
138 } else | |
139 s->dct_calc = ff_dct_calc_II_c; | |
134 | 140 |
135 return 0; | 141 return 0; |
136 } | 142 } |
137 | 143 |
138 av_cold void ff_dct_end(DCTContext *s) | 144 av_cold void ff_dct_end(DCTContext *s) |