Statistics
| Branch: | Revision:

ffmpeg / libavcodec / mlib / dsputil_mlib.c @ 5509bffa

History | View | Annotate | Download (11.2 KB)

1 c34270f5 Fabrice Bellard
/*
2
 * Sun mediaLib optimized DSP utils
3 ff4ec49e Fabrice Bellard
 * Copyright (c) 2001 Fabrice Bellard.
4 c34270f5 Fabrice Bellard
 *
5 ff4ec49e Fabrice Bellard
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2 of the License, or (at your option) any later version.
9 c34270f5 Fabrice Bellard
 *
10 ff4ec49e Fabrice Bellard
 * This library is distributed in the hope that it will be useful,
11 c34270f5 Fabrice Bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ff4ec49e Fabrice Bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14 c34270f5 Fabrice Bellard
 *
15 ff4ec49e Fabrice Bellard
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 c34270f5 Fabrice Bellard
 */
19
20
#include "../dsputil.h"
21 c7e07931 Martin Olschewski
#include "../mpegvideo.h"
22 c34270f5 Fabrice Bellard
23
#include <mlib_types.h>
24
#include <mlib_status.h>
25
#include <mlib_sys.h>
26 a62a7323 Mike Melanson
#include <mlib_algebra.h>
27 c34270f5 Fabrice Bellard
#include <mlib_video.h>
28
29 a62a7323 Mike Melanson
/* misc */
30 c34270f5 Fabrice Bellard
31 a62a7323 Mike Melanson
static void get_pixels_mlib(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
32
{
33
  int i;
34
35
  for (i=0;i<8;i++) {
36
    mlib_VectorConvert_S16_U8_Mod((mlib_s16 *)block, (mlib_u8 *)pixels, 8);
37
38
    pixels += line_size;
39
    block += 8;
40
  }
41
}
42
43
static void diff_pixels_mlib(DCTELEM *restrict block, const uint8_t *s1, const uint8_t *s2, int line_size)
44
{
45
  int i;
46
47
  for (i=0;i<8;i++) {
48
    mlib_VectorSub_S16_U8_Mod((mlib_s16 *)block, (mlib_u8 *)s1, (mlib_u8 *)s2, 8);
49
50
    s1 += line_size;
51
    s2 += line_size;
52
    block += 8;
53
  }
54
}
55
56
static void add_pixels_clamped_mlib(const DCTELEM *block, uint8_t *pixels, int line_size)
57
{
58
    mlib_VideoAddBlock_U8_S16(pixels, (mlib_s16 *)block, line_size);
59
}
60
61
/* put block, width 16 pixel, height 8/16 */
62 47fa9c20 Jürgen Keil
63
static void put_pixels16_mlib (uint8_t * dest, const uint8_t * ref,
64 bb270c08 Diego Biurrun
                               int stride, int height)
65 47fa9c20 Jürgen Keil
{
66 a62a7323 Mike Melanson
  switch (height) {
67
    case 8:
68
      mlib_VideoCopyRef_U8_U8_16x8(dest, (uint8_t *)ref, stride);
69
    break;
70
71
    case 16:
72
      mlib_VideoCopyRef_U8_U8_16x16(dest, (uint8_t *)ref, stride);
73
    break;
74
75
    default:
76
      assert(0);
77
  }
78 47fa9c20 Jürgen Keil
}
79
80
static void put_pixels16_x2_mlib (uint8_t * dest, const uint8_t * ref,
81 bb270c08 Diego Biurrun
                                  int stride, int height)
82 47fa9c20 Jürgen Keil
{
83 a62a7323 Mike Melanson
  switch (height) {
84
    case 8:
85
      mlib_VideoInterpX_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
86
    break;
87
88
    case 16:
89
      mlib_VideoInterpX_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
90
    break;
91
92
    default:
93
      assert(0);
94
  }
95 47fa9c20 Jürgen Keil
}
96
97
static void put_pixels16_y2_mlib (uint8_t * dest, const uint8_t * ref,
98 bb270c08 Diego Biurrun
                                  int stride, int height)
99 47fa9c20 Jürgen Keil
{
100 a62a7323 Mike Melanson
  switch (height) {
101
    case 8:
102
      mlib_VideoInterpY_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
103
    break;
104
105
    case 16:
106
      mlib_VideoInterpY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
107
    break;
108
109
    default:
110
      assert(0);
111
  }
112 47fa9c20 Jürgen Keil
}
113
114
static void put_pixels16_xy2_mlib(uint8_t * dest, const uint8_t * ref,
115 bb270c08 Diego Biurrun
                                  int stride, int height)
116 47fa9c20 Jürgen Keil
{
117 a62a7323 Mike Melanson
  switch (height) {
118
    case 8:
119
      mlib_VideoInterpXY_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
120
    break;
121
122
    case 16:
123
      mlib_VideoInterpXY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
124
    break;
125
126
    default:
127
      assert(0);
128
  }
129 47fa9c20 Jürgen Keil
}
130
131 a62a7323 Mike Melanson
/* put block, width 8 pixel, height 4/8/16 */
132 47fa9c20 Jürgen Keil
133
static void put_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
134 bb270c08 Diego Biurrun
                               int stride, int height)
135 c34270f5 Fabrice Bellard
{
136 a62a7323 Mike Melanson
  switch (height) {
137
    case 4:
138
      mlib_VideoCopyRef_U8_U8_8x4(dest, (uint8_t *)ref, stride);
139
    break;
140
141
    case 8:
142
      mlib_VideoCopyRef_U8_U8_8x8(dest, (uint8_t *)ref, stride);
143
    break;
144
145
    case 16:
146
      mlib_VideoCopyRef_U8_U8_8x16(dest, (uint8_t *)ref, stride);
147
    break;
148
149
    default:
150
      assert(0);
151
  }
152 c34270f5 Fabrice Bellard
}
153
154 47fa9c20 Jürgen Keil
static void put_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
155 bb270c08 Diego Biurrun
                                  int stride, int height)
156 c34270f5 Fabrice Bellard
{
157 a62a7323 Mike Melanson
  switch (height) {
158
    case 4:
159
      mlib_VideoInterpX_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
160
    break;
161
162
    case 8:
163
      mlib_VideoInterpX_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
164
    break;
165
166
    case 16:
167
      mlib_VideoInterpX_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
168
    break;
169
170
    default:
171
      assert(0);
172
  }
173 c34270f5 Fabrice Bellard
}
174
175 47fa9c20 Jürgen Keil
static void put_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
176 bb270c08 Diego Biurrun
                                  int stride, int height)
177 c34270f5 Fabrice Bellard
{
178 a62a7323 Mike Melanson
  switch (height) {
179
    case 4:
180
      mlib_VideoInterpY_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
181
    break;
182
183
    case 8:
184
      mlib_VideoInterpY_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
185
    break;
186
187
    case 16:
188
      mlib_VideoInterpY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
189
    break;
190
191
    default:
192
      assert(0);
193
  }
194 c34270f5 Fabrice Bellard
}
195
196 47fa9c20 Jürgen Keil
static void put_pixels8_xy2_mlib(uint8_t * dest, const uint8_t * ref,
197 bb270c08 Diego Biurrun
                                  int stride, int height)
198 c34270f5 Fabrice Bellard
{
199 a62a7323 Mike Melanson
  switch (height) {
200
    case 4:
201
      mlib_VideoInterpXY_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
202
    break;
203
204
    case 8:
205
      mlib_VideoInterpXY_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
206
    break;
207
208
    case 16:
209
      mlib_VideoInterpXY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
210
    break;
211
212
    default:
213
      assert(0);
214
  }
215 c34270f5 Fabrice Bellard
}
216
217 a62a7323 Mike Melanson
/* average block, width 16 pixel, height 8/16 */
218 47fa9c20 Jürgen Keil
219
static void avg_pixels16_mlib (uint8_t * dest, const uint8_t * ref,
220 bb270c08 Diego Biurrun
                               int stride, int height)
221 47fa9c20 Jürgen Keil
{
222 a62a7323 Mike Melanson
  switch (height) {
223
    case 8:
224
      mlib_VideoCopyRefAve_U8_U8_16x8(dest, (uint8_t *)ref, stride);
225
    break;
226
227
    case 16:
228
      mlib_VideoCopyRefAve_U8_U8_16x16(dest, (uint8_t *)ref, stride);
229
    break;
230
231
    default:
232
      assert(0);
233
  }
234 47fa9c20 Jürgen Keil
}
235
236
static void avg_pixels16_x2_mlib (uint8_t * dest, const uint8_t * ref,
237 bb270c08 Diego Biurrun
                                  int stride, int height)
238 47fa9c20 Jürgen Keil
{
239 a62a7323 Mike Melanson
  switch (height) {
240
    case 8:
241
      mlib_VideoInterpAveX_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
242
    break;
243
244
    case 16:
245
      mlib_VideoInterpAveX_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
246
    break;
247
248
    default:
249
      assert(0);
250
  }
251 47fa9c20 Jürgen Keil
}
252
253
static void avg_pixels16_y2_mlib (uint8_t * dest, const uint8_t * ref,
254 bb270c08 Diego Biurrun
                                  int stride, int height)
255 47fa9c20 Jürgen Keil
{
256 a62a7323 Mike Melanson
  switch (height) {
257
    case 8:
258
      mlib_VideoInterpAveY_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
259
    break;
260
261
    case 16:
262
      mlib_VideoInterpAveY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
263
    break;
264
265
    default:
266
      assert(0);
267
  }
268 47fa9c20 Jürgen Keil
}
269
270 a62a7323 Mike Melanson
static void avg_pixels16_xy2_mlib(uint8_t * dest, const uint8_t * ref,
271 bb270c08 Diego Biurrun
                                  int stride, int height)
272 47fa9c20 Jürgen Keil
{
273 a62a7323 Mike Melanson
  switch (height) {
274
    case 8:
275
      mlib_VideoInterpAveXY_U8_U8_16x8(dest, (uint8_t *)ref, stride, stride);
276
    break;
277
278
    case 16:
279
      mlib_VideoInterpAveXY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
280
    break;
281
282
    default:
283
      assert(0);
284
  }
285 47fa9c20 Jürgen Keil
}
286
287 a62a7323 Mike Melanson
/* average block, width 8 pixel, height 4/8/16 */
288 47fa9c20 Jürgen Keil
289
static void avg_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
290 bb270c08 Diego Biurrun
                               int stride, int height)
291 c34270f5 Fabrice Bellard
{
292 a62a7323 Mike Melanson
  switch (height) {
293
    case 4:
294
      mlib_VideoCopyRefAve_U8_U8_8x4(dest, (uint8_t *)ref, stride);
295
    break;
296
297
    case 8:
298
      mlib_VideoCopyRefAve_U8_U8_8x8(dest, (uint8_t *)ref, stride);
299
    break;
300
301
    case 16:
302
      mlib_VideoCopyRefAve_U8_U8_8x16(dest, (uint8_t *)ref, stride);
303
    break;
304
305
    default:
306
      assert(0);
307
  }
308 c34270f5 Fabrice Bellard
}
309
310 47fa9c20 Jürgen Keil
static void avg_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
311 bb270c08 Diego Biurrun
                                  int stride, int height)
312 c34270f5 Fabrice Bellard
{
313 a62a7323 Mike Melanson
  switch (height) {
314
    case 4:
315
      mlib_VideoInterpAveX_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
316
    break;
317
318
    case 8:
319
      mlib_VideoInterpAveX_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
320
    break;
321
322
    case 16:
323
      mlib_VideoInterpAveX_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
324
    break;
325
326
    default:
327
      assert(0);
328
  }
329 c34270f5 Fabrice Bellard
}
330
331 47fa9c20 Jürgen Keil
static void avg_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
332 bb270c08 Diego Biurrun
                                  int stride, int height)
333 c34270f5 Fabrice Bellard
{
334 a62a7323 Mike Melanson
  switch (height) {
335
    case 4:
336
      mlib_VideoInterpAveY_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
337
    break;
338
339
    case 8:
340
      mlib_VideoInterpAveY_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
341
    break;
342
343
    case 16:
344
      mlib_VideoInterpAveY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
345
    break;
346
347
    default:
348
      assert(0);
349
  }
350 c34270f5 Fabrice Bellard
}
351
352 a62a7323 Mike Melanson
static void avg_pixels8_xy2_mlib(uint8_t * dest, const uint8_t * ref,
353 bb270c08 Diego Biurrun
                                  int stride, int height)
354 c34270f5 Fabrice Bellard
{
355 a62a7323 Mike Melanson
  switch (height) {
356
    case 4:
357
      mlib_VideoInterpAveXY_U8_U8_8x4(dest, (uint8_t *)ref, stride, stride);
358
    break;
359
360
    case 8:
361
      mlib_VideoInterpAveXY_U8_U8_8x8(dest, (uint8_t *)ref, stride, stride);
362
    break;
363
364
    case 16:
365
      mlib_VideoInterpAveXY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
366
    break;
367
368
    default:
369
      assert(0);
370
  }
371 c34270f5 Fabrice Bellard
}
372
373 a62a7323 Mike Melanson
/* swap byte order of a buffer */
374 c34270f5 Fabrice Bellard
375 a62a7323 Mike Melanson
static void bswap_buf_mlib(uint32_t *dst, uint32_t *src, int w)
376 c34270f5 Fabrice Bellard
{
377 a62a7323 Mike Melanson
  mlib_VectorReverseByteOrder_U32_U32(dst, src, w);
378 c34270f5 Fabrice Bellard
}
379
380 a62a7323 Mike Melanson
/* transformations */
381 47fa9c20 Jürgen Keil
382 0c1a9eda Zdenek Kabelac
static void ff_idct_put_mlib(uint8_t *dest, int line_size, DCTELEM *data)
383 c34270f5 Fabrice Bellard
{
384 a62a7323 Mike Melanson
    int i;
385
    uint8_t *cm = cropTbl + MAX_NEG_CROP;
386
387 c34270f5 Fabrice Bellard
    mlib_VideoIDCT8x8_S16_S16 (data, data);
388 115329f1 Diego Biurrun
389 a62a7323 Mike Melanson
    for(i=0;i<8;i++) {
390
        dest[0] = cm[data[0]];
391
        dest[1] = cm[data[1]];
392
        dest[2] = cm[data[2]];
393
        dest[3] = cm[data[3]];
394
        dest[4] = cm[data[4]];
395
        dest[5] = cm[data[5]];
396
        dest[6] = cm[data[6]];
397
        dest[7] = cm[data[7]];
398
399
        dest += line_size;
400
        data += 8;
401
    }
402 676e200c Michael Niedermayer
}
403 47fa9c20 Jürgen Keil
404 0c1a9eda Zdenek Kabelac
static void ff_idct_add_mlib(uint8_t *dest, int line_size, DCTELEM *data)
405 676e200c Michael Niedermayer
{
406
    mlib_VideoIDCT8x8_S16_S16 (data, data);
407 a8140ad5 Jürgen Keil
    mlib_VideoAddBlock_U8_S16(dest, (mlib_s16 *)data, line_size);
408 c34270f5 Fabrice Bellard
}
409
410 6cc270c2 Mike Melanson
static void ff_idct_mlib(DCTELEM *data)
411 4fb518c3 Michael Niedermayer
{
412
    mlib_VideoIDCT8x8_S16_S16 (data, data);
413
}
414
415 47fa9c20 Jürgen Keil
static void ff_fdct_mlib(DCTELEM *data)
416 c34270f5 Fabrice Bellard
{
417
    mlib_VideoDCT8x8_S16_S16 (data, data);
418
}
419
420 31d8cb13 Zdenek Kabelac
void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx)
421 c34270f5 Fabrice Bellard
{
422 a62a7323 Mike Melanson
    c->get_pixels  = get_pixels_mlib;
423
    c->diff_pixels = diff_pixels_mlib;
424
    c->add_pixels_clamped = add_pixels_clamped_mlib;
425
426 af19f78f Zdenek Kabelac
    c->put_pixels_tab[0][0] = put_pixels16_mlib;
427
    c->put_pixels_tab[0][1] = put_pixels16_x2_mlib;
428
    c->put_pixels_tab[0][2] = put_pixels16_y2_mlib;
429
    c->put_pixels_tab[0][3] = put_pixels16_xy2_mlib;
430
    c->put_pixels_tab[1][0] = put_pixels8_mlib;
431
    c->put_pixels_tab[1][1] = put_pixels8_x2_mlib;
432
    c->put_pixels_tab[1][2] = put_pixels8_y2_mlib;
433
    c->put_pixels_tab[1][3] = put_pixels8_xy2_mlib;
434
435
    c->avg_pixels_tab[0][0] = avg_pixels16_mlib;
436
    c->avg_pixels_tab[0][1] = avg_pixels16_x2_mlib;
437
    c->avg_pixels_tab[0][2] = avg_pixels16_y2_mlib;
438
    c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mlib;
439
    c->avg_pixels_tab[1][0] = avg_pixels8_mlib;
440
    c->avg_pixels_tab[1][1] = avg_pixels8_x2_mlib;
441
    c->avg_pixels_tab[1][2] = avg_pixels8_y2_mlib;
442
    c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mlib;
443
444
    c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mlib;
445
    c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mlib;
446
447 a62a7323 Mike Melanson
    c->bswap_buf = bswap_buf_mlib;
448 c34270f5 Fabrice Bellard
}
449 c7e07931 Martin Olschewski
450
void MPV_common_init_mlib(MpegEncContext *s)
451
{
452
    if(s->avctx->dct_algo==FF_DCT_AUTO || s->avctx->dct_algo==FF_DCT_MLIB){
453 bb270c08 Diego Biurrun
        s->dsp.fdct = ff_fdct_mlib;
454 c7e07931 Martin Olschewski
    }
455 676e200c Michael Niedermayer
456 47fa9c20 Jürgen Keil
    if(s->avctx->idct_algo==FF_IDCT_AUTO || s->avctx->idct_algo==FF_IDCT_MLIB){
457 31d8cb13 Zdenek Kabelac
        s->dsp.idct_put= ff_idct_put_mlib;
458
        s->dsp.idct_add= ff_idct_add_mlib;
459 4fb518c3 Michael Niedermayer
        s->dsp.idct    = ff_idct_mlib;
460 31d8cb13 Zdenek Kabelac
        s->dsp.idct_permutation_type= FF_NO_IDCT_PERM;
461 676e200c Michael Niedermayer
    }
462 c7e07931 Martin Olschewski
}