update the API for the idct function
[libav.git] / libavcodec / mlib / dsputil_mlib.c
CommitLineData
c34270f5
FB
1/*
2 * Sun mediaLib optimized DSP utils
ff4ec49e 3 * Copyright (c) 2001 Fabrice Bellard.
c34270f5 4 *
ff4ec49e
FB
5 * 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.
c34270f5 9 *
ff4ec49e 10 * This library is distributed in the hope that it will be useful,
c34270f5 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ff4ec49e
FB
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
c34270f5 14 *
ff4ec49e
FB
15 * 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 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
c34270f5
FB
18 */
19
20#include "../dsputil.h"
c7e07931 21#include "../mpegvideo.h"
c34270f5
FB
22
23#include <mlib_types.h>
24#include <mlib_status.h>
25#include <mlib_sys.h>
a62a7323 26#include <mlib_algebra.h>
c34270f5
FB
27#include <mlib_video.h>
28
a62a7323 29/* misc */
c34270f5 30
a62a7323
MM
31static 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
43static 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
56static 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 */
47fa9c20
JK
62
63static void put_pixels16_mlib (uint8_t * dest, const uint8_t * ref,
64 int stride, int height)
65{
a62a7323
MM
66 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 }
47fa9c20
JK
78}
79
80static void put_pixels16_x2_mlib (uint8_t * dest, const uint8_t * ref,
81 int stride, int height)
82{
a62a7323
MM
83 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 }
47fa9c20
JK
95}
96
97static void put_pixels16_y2_mlib (uint8_t * dest, const uint8_t * ref,
98 int stride, int height)
99{
a62a7323
MM
100 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 }
47fa9c20
JK
112}
113
114static void put_pixels16_xy2_mlib(uint8_t * dest, const uint8_t * ref,
115 int stride, int height)
116{
a62a7323
MM
117 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 }
47fa9c20
JK
129}
130
a62a7323 131/* put block, width 8 pixel, height 4/8/16 */
47fa9c20
JK
132
133static void put_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
a62a7323 134 int stride, int height)
c34270f5 135{
a62a7323
MM
136 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 }
c34270f5
FB
152}
153
47fa9c20 154static void put_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
a62a7323 155 int stride, int height)
c34270f5 156{
a62a7323
MM
157 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 }
c34270f5
FB
173}
174
47fa9c20 175static void put_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
a62a7323 176 int stride, int height)
c34270f5 177{
a62a7323
MM
178 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 }
c34270f5
FB
194}
195
47fa9c20 196static void put_pixels8_xy2_mlib(uint8_t * dest, const uint8_t * ref,
a62a7323 197 int stride, int height)
c34270f5 198{
a62a7323
MM
199 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 }
c34270f5
FB
215}
216
a62a7323 217/* average block, width 16 pixel, height 8/16 */
47fa9c20
JK
218
219static void avg_pixels16_mlib (uint8_t * dest, const uint8_t * ref,
220 int stride, int height)
221{
a62a7323
MM
222 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 }
47fa9c20
JK
234}
235
236static void avg_pixels16_x2_mlib (uint8_t * dest, const uint8_t * ref,
237 int stride, int height)
238{
a62a7323
MM
239 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 }
47fa9c20
JK
251}
252
253static void avg_pixels16_y2_mlib (uint8_t * dest, const uint8_t * ref,
254 int stride, int height)
255{
a62a7323
MM
256 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 }
47fa9c20
JK
268}
269
a62a7323
MM
270static void avg_pixels16_xy2_mlib(uint8_t * dest, const uint8_t * ref,
271 int stride, int height)
47fa9c20 272{
a62a7323
MM
273 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 }
47fa9c20
JK
285}
286
a62a7323 287/* average block, width 8 pixel, height 4/8/16 */
47fa9c20
JK
288
289static void avg_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
a62a7323 290 int stride, int height)
c34270f5 291{
a62a7323
MM
292 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 }
c34270f5
FB
308}
309
47fa9c20 310static void avg_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
a62a7323 311 int stride, int height)
c34270f5 312{
a62a7323
MM
313 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 }
c34270f5
FB
329}
330
47fa9c20 331static void avg_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
a62a7323 332 int stride, int height)
c34270f5 333{
a62a7323
MM
334 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 }
c34270f5
FB
350}
351
a62a7323 352static void avg_pixels8_xy2_mlib(uint8_t * dest, const uint8_t * ref,
47fa9c20 353 int stride, int height)
c34270f5 354{
a62a7323
MM
355 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 }
c34270f5
FB
371}
372
a62a7323 373/* swap byte order of a buffer */
c34270f5 374
a62a7323 375static void bswap_buf_mlib(uint32_t *dst, uint32_t *src, int w)
c34270f5 376{
a62a7323 377 mlib_VectorReverseByteOrder_U32_U32(dst, src, w);
c34270f5
FB
378}
379
a62a7323 380/* transformations */
47fa9c20 381
0c1a9eda 382static void ff_idct_put_mlib(uint8_t *dest, int line_size, DCTELEM *data)
c34270f5 383{
a62a7323
MM
384 int i;
385 uint8_t *cm = cropTbl + MAX_NEG_CROP;
386
c34270f5 387 mlib_VideoIDCT8x8_S16_S16 (data, data);
a62a7323
MM
388
389 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 }
676e200c 402}
47fa9c20 403
0c1a9eda 404static void ff_idct_add_mlib(uint8_t *dest, int line_size, DCTELEM *data)
676e200c
MN
405{
406 mlib_VideoIDCT8x8_S16_S16 (data, data);
a8140ad5 407 mlib_VideoAddBlock_U8_S16(dest, (mlib_s16 *)data, line_size);
c34270f5 408}
c34270f5 409
6cc270c2 410static void ff_idct_mlib(DCTELEM *data)
4fb518c3
MN
411{
412 mlib_VideoIDCT8x8_S16_S16 (data, data);
413}
414
47fa9c20 415static void ff_fdct_mlib(DCTELEM *data)
c34270f5
FB
416{
417 mlib_VideoDCT8x8_S16_S16 (data, data);
418}
419
31d8cb13 420void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx)
c34270f5 421{
a62a7323
MM
422 c->get_pixels = get_pixels_mlib;
423 c->diff_pixels = diff_pixels_mlib;
424 c->add_pixels_clamped = add_pixels_clamped_mlib;
425
af19f78f
ZK
426 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
a62a7323 447 c->bswap_buf = bswap_buf_mlib;
c34270f5 448}
c7e07931
MO
449
450void MPV_common_init_mlib(MpegEncContext *s)
451{
452 if(s->avctx->dct_algo==FF_DCT_AUTO || s->avctx->dct_algo==FF_DCT_MLIB){
31d8cb13 453 s->dsp.fdct = ff_fdct_mlib;
c7e07931 454 }
676e200c 455
47fa9c20 456 if(s->avctx->idct_algo==FF_IDCT_AUTO || s->avctx->idct_algo==FF_IDCT_MLIB){
31d8cb13
ZK
457 s->dsp.idct_put= ff_idct_put_mlib;
458 s->dsp.idct_add= ff_idct_add_mlib;
4fb518c3 459 s->dsp.idct = ff_idct_mlib;
31d8cb13 460 s->dsp.idct_permutation_type= FF_NO_IDCT_PERM;
676e200c 461 }
c7e07931 462}