summaryrefslogtreecommitdiff
path: root/apps/plugins/mpegplayer/idct.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/mpegplayer/idct.c')
-rw-r--r--apps/plugins/mpegplayer/idct.c109
1 files changed, 48 insertions, 61 deletions
diff --git a/apps/plugins/mpegplayer/idct.c b/apps/plugins/mpegplayer/idct.c
index 1cd1d91990..f9e3b7d664 100644
--- a/apps/plugins/mpegplayer/idct.c
+++ b/apps/plugins/mpegplayer/idct.c
@@ -29,26 +29,11 @@
29#include "attributes.h" 29#include "attributes.h"
30#include "mpeg2_internal.h" 30#include "mpeg2_internal.h"
31 31
32/* idct main entry point */ 32#if defined(CPU_COLDFIRE) || defined (CPU_ARM)
33void (* mpeg2_idct_copy) (int16_t * block, uint8_t * dest, int stride); 33#define IDCT_ASM
34void (* mpeg2_idct_add) (int last, int16_t * block, 34#endif
35 uint8_t * dest, int stride); 35
36 36#ifndef IDCT_ASM
37#ifdef CPU_COLDFIRE
38/* assembler functions */
39extern void mpeg2_idct_copy_coldfire(int16_t * block, uint8_t * dest,
40 const int stride);
41extern void mpeg2_idct_add_coldfire(const int last, int16_t * block,
42 uint8_t * dest, const int stride);
43
44#elif defined CPU_ARM
45/* assembler functions */
46extern void mpeg2_idct_copy_arm(int16_t * block, uint8_t * dest,
47 const int stride);
48extern void mpeg2_idct_add_arm(const int last, int16_t * block,
49 uint8_t * dest, const int stride);
50
51#else /* !CPU_COLDFIRE, !CPU_ARM */
52 37
53#define W1 2841 /* 2048 * sqrt (2) * cos (1 * pi / 16) */ 38#define W1 2841 /* 2048 * sqrt (2) * cos (1 * pi / 16) */
54#define W2 2676 /* 2048 * sqrt (2) * cos (2 * pi / 16) */ 39#define W2 2676 /* 2048 * sqrt (2) * cos (2 * pi / 16) */
@@ -63,8 +48,11 @@ extern void mpeg2_idct_add_arm(const int last, int16_t * block,
63 * to +-3826 - this is the worst case for a column IDCT where the 48 * to +-3826 - this is the worst case for a column IDCT where the
64 * column inputs are 16-bit values. 49 * column inputs are 16-bit values.
65 */ 50 */
66uint8_t mpeg2_clip[3840 * 2 + 256] IBSS_ATTR; 51#define CLIP(i) \
67#define CLIP(i) ((mpeg2_clip + 3840)[i]) 52 ({ typeof (i) _i = (i); \
53 if ((_i & 0xff) != _i) \
54 _i = ~(_i >> (8*sizeof(_i) - 1)); \
55 _i; })
68 56
69#if 0 57#if 0
70#define BUTTERFLY(t0,t1,W0,W1,d0,d1) \ 58#define BUTTERFLY(t0,t1,W0,W1,d0,d1) \
@@ -89,7 +77,8 @@ static inline void idct_row (int16_t * const block)
89 77
90 /* shortcut */ 78 /* shortcut */
91 if (likely (!(block[1] | ((int32_t *)block)[1] | ((int32_t *)block)[2] | 79 if (likely (!(block[1] | ((int32_t *)block)[1] | ((int32_t *)block)[2] |
92 ((int32_t *)block)[3]))) { 80 ((int32_t *)block)[3])))
81 {
93 uint32_t tmp = (uint16_t) (block[0] >> 1); 82 uint32_t tmp = (uint16_t) (block[0] >> 1);
94 tmp |= tmp << 16; 83 tmp |= tmp << 16;
95 ((int32_t *)block)[0] = tmp; 84 ((int32_t *)block)[0] = tmp;
@@ -175,16 +164,19 @@ static inline void idct_col (int16_t * const block)
175 block[8*7] = (a0 - b0) >> 17; 164 block[8*7] = (a0 - b0) >> 17;
176} 165}
177 166
178static void mpeg2_idct_copy_c (int16_t * block, uint8_t * dest, 167void mpeg2_idct_copy (int16_t * block, uint8_t * dest,
179 const int stride) 168 const int stride)
180{ 169{
181 int i; 170 int i;
182 171
183 for (i = 0; i < 8; i++) 172 for (i = 0; i < 8; i++)
184 idct_row (block + 8 * i); 173 idct_row (block + 8 * i);
174
185 for (i = 0; i < 8; i++) 175 for (i = 0; i < 8; i++)
186 idct_col (block + i); 176 idct_col (block + i);
187 do { 177
178 do
179 {
188 dest[0] = CLIP (block[0]); 180 dest[0] = CLIP (block[0]);
189 dest[1] = CLIP (block[1]); 181 dest[1] = CLIP (block[1]);
190 dest[2] = CLIP (block[2]); 182 dest[2] = CLIP (block[2]);
@@ -194,25 +186,32 @@ static void mpeg2_idct_copy_c (int16_t * block, uint8_t * dest,
194 dest[6] = CLIP (block[6]); 186 dest[6] = CLIP (block[6]);
195 dest[7] = CLIP (block[7]); 187 dest[7] = CLIP (block[7]);
196 188
197 ((int32_t *)block)[0] = 0; ((int32_t *)block)[1] = 0; 189 ((int32_t *)block)[0] = 0;
198 ((int32_t *)block)[2] = 0; ((int32_t *)block)[3] = 0; 190 ((int32_t *)block)[1] = 0;
191 ((int32_t *)block)[2] = 0;
192 ((int32_t *)block)[3] = 0;
199 193
200 dest += stride; 194 dest += stride;
201 block += 8; 195 block += 8;
202 } while (--i); 196 }
197 while (--i);
203} 198}
204 199
205static void mpeg2_idct_add_c (const int last, int16_t * block, 200void mpeg2_idct_add (const int last, int16_t * block,
206 uint8_t * dest, const int stride) 201 uint8_t * dest, const int stride)
207{ 202{
208 int i; 203 int i;
209 204
210 if (last != 129 || (block[0] & (7 << 4)) == (4 << 4)) { 205 if (last != 129 || (block[0] & (7 << 4)) == (4 << 4))
206 {
211 for (i = 0; i < 8; i++) 207 for (i = 0; i < 8; i++)
212 idct_row (block + 8 * i); 208 idct_row (block + 8 * i);
209
213 for (i = 0; i < 8; i++) 210 for (i = 0; i < 8; i++)
214 idct_col (block + i); 211 idct_col (block + i);
215 do { 212
213 do
214 {
216 dest[0] = CLIP (block[0] + dest[0]); 215 dest[0] = CLIP (block[0] + dest[0]);
217 dest[1] = CLIP (block[1] + dest[1]); 216 dest[1] = CLIP (block[1] + dest[1]);
218 dest[2] = CLIP (block[2] + dest[2]); 217 dest[2] = CLIP (block[2] + dest[2]);
@@ -222,19 +221,24 @@ static void mpeg2_idct_add_c (const int last, int16_t * block,
222 dest[6] = CLIP (block[6] + dest[6]); 221 dest[6] = CLIP (block[6] + dest[6]);
223 dest[7] = CLIP (block[7] + dest[7]); 222 dest[7] = CLIP (block[7] + dest[7]);
224 223
225 ((int32_t *)block)[0] = 0; ((int32_t *)block)[1] = 0; 224 ((int32_t *)block)[0] = 0;
226 ((int32_t *)block)[2] = 0; ((int32_t *)block)[3] = 0; 225 ((int32_t *)block)[1] = 0;
226 ((int32_t *)block)[2] = 0;
227 ((int32_t *)block)[3] = 0;
227 228
228 dest += stride; 229 dest += stride;
229 block += 8; 230 block += 8;
230 } while (--i); 231 }
231 } else { 232 while (--i);
232 int DC; 233 }
233 234 else
234 DC = (block[0] + 64) >> 7; 235 {
236 int DC = (block[0] + 64) >> 7;
235 block[0] = block[63] = 0; 237 block[0] = block[63] = 0;
236 i = 8; 238 i = 8;
237 do { 239
240 do
241 {
238 dest[0] = CLIP (DC + dest[0]); 242 dest[0] = CLIP (DC + dest[0]);
239 dest[1] = CLIP (DC + dest[1]); 243 dest[1] = CLIP (DC + dest[1]);
240 dest[2] = CLIP (DC + dest[2]); 244 dest[2] = CLIP (DC + dest[2]);
@@ -244,34 +248,17 @@ static void mpeg2_idct_add_c (const int last, int16_t * block,
244 dest[6] = CLIP (DC + dest[6]); 248 dest[6] = CLIP (DC + dest[6]);
245 dest[7] = CLIP (DC + dest[7]); 249 dest[7] = CLIP (DC + dest[7]);
246 dest += stride; 250 dest += stride;
247 } while (--i); 251 }
252 while (--i);
248 } 253 }
249} 254}
250 255
251#endif /* CPU selection */ 256#endif /* IDCT_ASM */
252 257
253void mpeg2_idct_init (void) 258void mpeg2_idct_init (void)
254{ 259{
255 extern uint8_t default_mpeg2_scan_norm[64];
256 extern uint8_t default_mpeg2_scan_alt[64];
257 extern uint8_t mpeg2_scan_norm[64];
258 extern uint8_t mpeg2_scan_alt[64];
259 int i, j; 260 int i, j;
260 261
261#ifdef CPU_COLDFIRE
262 mpeg2_idct_copy = mpeg2_idct_copy_coldfire;
263 mpeg2_idct_add = mpeg2_idct_add_coldfire;
264#elif defined CPU_ARM
265 mpeg2_idct_copy = mpeg2_idct_copy_arm;
266 mpeg2_idct_add = mpeg2_idct_add_arm;
267#else
268 mpeg2_idct_copy = mpeg2_idct_copy_c;
269 mpeg2_idct_add = mpeg2_idct_add_c;
270
271 for (i = -3840; i < 3840 + 256; i++)
272 CLIP(i) = (i < 0) ? 0 : ((i > 255) ? 255 : i);
273#endif
274
275 for (i = 0; i < 64; i++) 262 for (i = 0; i < 64; i++)
276 { 263 {
277 j = default_mpeg2_scan_norm[i]; 264 j = default_mpeg2_scan_norm[i];