2 * Sun mediaLib optimized DSP utils
3 * Copyright (c) 2001 Fabrice Bellard.
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavcodec/dsputil.h"
23 #include "libavcodec/mpegvideo.h"
25 #include <mlib_types.h>
26 #include <mlib_status.h>
28 #include <mlib_algebra.h>
29 #include <mlib_video.h>
33 static void get_pixels_mlib(DCTELEM
*restrict block
, const uint8_t *pixels
, int line_size
)
38 mlib_VectorConvert_S16_U8_Mod((mlib_s16
*)block
, (mlib_u8
*)pixels
, 8);
45 static void diff_pixels_mlib(DCTELEM
*restrict block
, const uint8_t *s1
, const uint8_t *s2
, int line_size
)
50 mlib_VectorSub_S16_U8_Mod((mlib_s16
*)block
, (mlib_u8
*)s1
, (mlib_u8
*)s2
, 8);
58 static void add_pixels_clamped_mlib(const DCTELEM
*block
, uint8_t *pixels
, int line_size
)
60 mlib_VideoAddBlock_U8_S16(pixels
, (mlib_s16
*)block
, line_size
);
63 /* put block, width 16 pixel, height 8/16 */
65 static void put_pixels16_mlib (uint8_t * dest
, const uint8_t * ref
,
66 int stride
, int height
)
70 mlib_VideoCopyRef_U8_U8_16x8(dest
, (uint8_t *)ref
, stride
);
74 mlib_VideoCopyRef_U8_U8_16x16(dest
, (uint8_t *)ref
, stride
);
82 static void put_pixels16_x2_mlib (uint8_t * dest
, const uint8_t * ref
,
83 int stride
, int height
)
87 mlib_VideoInterpX_U8_U8_16x8(dest
, (uint8_t *)ref
, stride
, stride
);
91 mlib_VideoInterpX_U8_U8_16x16(dest
, (uint8_t *)ref
, stride
, stride
);
99 static void put_pixels16_y2_mlib (uint8_t * dest
, const uint8_t * ref
,
100 int stride
, int height
)
104 mlib_VideoInterpY_U8_U8_16x8(dest
, (uint8_t *)ref
, stride
, stride
);
108 mlib_VideoInterpY_U8_U8_16x16(dest
, (uint8_t *)ref
, stride
, stride
);
116 static void put_pixels16_xy2_mlib(uint8_t * dest
, const uint8_t * ref
,
117 int stride
, int height
)
121 mlib_VideoInterpXY_U8_U8_16x8(dest
, (uint8_t *)ref
, stride
, stride
);
125 mlib_VideoInterpXY_U8_U8_16x16(dest
, (uint8_t *)ref
, stride
, stride
);
133 /* put block, width 8 pixel, height 4/8/16 */
135 static void put_pixels8_mlib (uint8_t * dest
, const uint8_t * ref
,
136 int stride
, int height
)
140 mlib_VideoCopyRef_U8_U8_8x4(dest
, (uint8_t *)ref
, stride
);
144 mlib_VideoCopyRef_U8_U8_8x8(dest
, (uint8_t *)ref
, stride
);
148 mlib_VideoCopyRef_U8_U8_8x16(dest
, (uint8_t *)ref
, stride
);
156 static void put_pixels8_x2_mlib (uint8_t * dest
, const uint8_t * ref
,
157 int stride
, int height
)
161 mlib_VideoInterpX_U8_U8_8x4(dest
, (uint8_t *)ref
, stride
, stride
);
165 mlib_VideoInterpX_U8_U8_8x8(dest
, (uint8_t *)ref
, stride
, stride
);
169 mlib_VideoInterpX_U8_U8_8x16(dest
, (uint8_t *)ref
, stride
, stride
);
177 static void put_pixels8_y2_mlib (uint8_t * dest
, const uint8_t * ref
,
178 int stride
, int height
)
182 mlib_VideoInterpY_U8_U8_8x4(dest
, (uint8_t *)ref
, stride
, stride
);
186 mlib_VideoInterpY_U8_U8_8x8(dest
, (uint8_t *)ref
, stride
, stride
);
190 mlib_VideoInterpY_U8_U8_8x16(dest
, (uint8_t *)ref
, stride
, stride
);
198 static void put_pixels8_xy2_mlib(uint8_t * dest
, const uint8_t * ref
,
199 int stride
, int height
)
203 mlib_VideoInterpXY_U8_U8_8x4(dest
, (uint8_t *)ref
, stride
, stride
);
207 mlib_VideoInterpXY_U8_U8_8x8(dest
, (uint8_t *)ref
, stride
, stride
);
211 mlib_VideoInterpXY_U8_U8_8x16(dest
, (uint8_t *)ref
, stride
, stride
);
219 /* average block, width 16 pixel, height 8/16 */
221 static void avg_pixels16_mlib (uint8_t * dest
, const uint8_t * ref
,
222 int stride
, int height
)
226 mlib_VideoCopyRefAve_U8_U8_16x8(dest
, (uint8_t *)ref
, stride
);
230 mlib_VideoCopyRefAve_U8_U8_16x16(dest
, (uint8_t *)ref
, stride
);
238 static void avg_pixels16_x2_mlib (uint8_t * dest
, const uint8_t * ref
,
239 int stride
, int height
)
243 mlib_VideoInterpAveX_U8_U8_16x8(dest
, (uint8_t *)ref
, stride
, stride
);
247 mlib_VideoInterpAveX_U8_U8_16x16(dest
, (uint8_t *)ref
, stride
, stride
);
255 static void avg_pixels16_y2_mlib (uint8_t * dest
, const uint8_t * ref
,
256 int stride
, int height
)
260 mlib_VideoInterpAveY_U8_U8_16x8(dest
, (uint8_t *)ref
, stride
, stride
);
264 mlib_VideoInterpAveY_U8_U8_16x16(dest
, (uint8_t *)ref
, stride
, stride
);
272 static void avg_pixels16_xy2_mlib(uint8_t * dest
, const uint8_t * ref
,
273 int stride
, int height
)
277 mlib_VideoInterpAveXY_U8_U8_16x8(dest
, (uint8_t *)ref
, stride
, stride
);
281 mlib_VideoInterpAveXY_U8_U8_16x16(dest
, (uint8_t *)ref
, stride
, stride
);
289 /* average block, width 8 pixel, height 4/8/16 */
291 static void avg_pixels8_mlib (uint8_t * dest
, const uint8_t * ref
,
292 int stride
, int height
)
296 mlib_VideoCopyRefAve_U8_U8_8x4(dest
, (uint8_t *)ref
, stride
);
300 mlib_VideoCopyRefAve_U8_U8_8x8(dest
, (uint8_t *)ref
, stride
);
304 mlib_VideoCopyRefAve_U8_U8_8x16(dest
, (uint8_t *)ref
, stride
);
312 static void avg_pixels8_x2_mlib (uint8_t * dest
, const uint8_t * ref
,
313 int stride
, int height
)
317 mlib_VideoInterpAveX_U8_U8_8x4(dest
, (uint8_t *)ref
, stride
, stride
);
321 mlib_VideoInterpAveX_U8_U8_8x8(dest
, (uint8_t *)ref
, stride
, stride
);
325 mlib_VideoInterpAveX_U8_U8_8x16(dest
, (uint8_t *)ref
, stride
, stride
);
333 static void avg_pixels8_y2_mlib (uint8_t * dest
, const uint8_t * ref
,
334 int stride
, int height
)
338 mlib_VideoInterpAveY_U8_U8_8x4(dest
, (uint8_t *)ref
, stride
, stride
);
342 mlib_VideoInterpAveY_U8_U8_8x8(dest
, (uint8_t *)ref
, stride
, stride
);
346 mlib_VideoInterpAveY_U8_U8_8x16(dest
, (uint8_t *)ref
, stride
, stride
);
354 static void avg_pixels8_xy2_mlib(uint8_t * dest
, const uint8_t * ref
,
355 int stride
, int height
)
359 mlib_VideoInterpAveXY_U8_U8_8x4(dest
, (uint8_t *)ref
, stride
, stride
);
363 mlib_VideoInterpAveXY_U8_U8_8x8(dest
, (uint8_t *)ref
, stride
, stride
);
367 mlib_VideoInterpAveXY_U8_U8_8x16(dest
, (uint8_t *)ref
, stride
, stride
);
375 /* swap byte order of a buffer */
377 static void bswap_buf_mlib(uint32_t *dst
, const uint32_t *src
, int w
)
379 mlib_VectorReverseByteOrder_U32_U32(dst
, src
, w
);
382 /* transformations */
384 static void ff_idct_put_mlib(uint8_t *dest
, int line_size
, DCTELEM
*data
)
387 uint8_t *cm
= ff_cropTbl
+ MAX_NEG_CROP
;
389 mlib_VideoIDCT8x8_S16_S16 (data
, data
);
392 dest
[0] = cm
[data
[0]];
393 dest
[1] = cm
[data
[1]];
394 dest
[2] = cm
[data
[2]];
395 dest
[3] = cm
[data
[3]];
396 dest
[4] = cm
[data
[4]];
397 dest
[5] = cm
[data
[5]];
398 dest
[6] = cm
[data
[6]];
399 dest
[7] = cm
[data
[7]];
406 static void ff_idct_add_mlib(uint8_t *dest
, int line_size
, DCTELEM
*data
)
408 mlib_VideoIDCT8x8_S16_S16 (data
, data
);
409 mlib_VideoAddBlock_U8_S16(dest
, (mlib_s16
*)data
, line_size
);
412 static void ff_idct_mlib(DCTELEM
*data
)
414 mlib_VideoIDCT8x8_S16_S16 (data
, data
);
417 static void ff_fdct_mlib(DCTELEM
*data
)
419 mlib_VideoDCT8x8_S16_S16 (data
, data
);
422 void dsputil_init_mlib(DSPContext
* c
, AVCodecContext
*avctx
)
424 c
->get_pixels
= get_pixels_mlib
;
425 c
->diff_pixels
= diff_pixels_mlib
;
426 c
->add_pixels_clamped
= add_pixels_clamped_mlib
;
428 c
->put_pixels_tab
[0][0] = put_pixels16_mlib
;
429 c
->put_pixels_tab
[0][1] = put_pixels16_x2_mlib
;
430 c
->put_pixels_tab
[0][2] = put_pixels16_y2_mlib
;
431 c
->put_pixels_tab
[0][3] = put_pixels16_xy2_mlib
;
432 c
->put_pixels_tab
[1][0] = put_pixels8_mlib
;
433 c
->put_pixels_tab
[1][1] = put_pixels8_x2_mlib
;
434 c
->put_pixels_tab
[1][2] = put_pixels8_y2_mlib
;
435 c
->put_pixels_tab
[1][3] = put_pixels8_xy2_mlib
;
437 c
->avg_pixels_tab
[0][0] = avg_pixels16_mlib
;
438 c
->avg_pixels_tab
[0][1] = avg_pixels16_x2_mlib
;
439 c
->avg_pixels_tab
[0][2] = avg_pixels16_y2_mlib
;
440 c
->avg_pixels_tab
[0][3] = avg_pixels16_xy2_mlib
;
441 c
->avg_pixels_tab
[1][0] = avg_pixels8_mlib
;
442 c
->avg_pixels_tab
[1][1] = avg_pixels8_x2_mlib
;
443 c
->avg_pixels_tab
[1][2] = avg_pixels8_y2_mlib
;
444 c
->avg_pixels_tab
[1][3] = avg_pixels8_xy2_mlib
;
446 c
->put_no_rnd_pixels_tab
[0][0] = put_pixels16_mlib
;
447 c
->put_no_rnd_pixels_tab
[1][0] = put_pixels8_mlib
;
449 c
->bswap_buf
= bswap_buf_mlib
;
452 void MPV_common_init_mlib(MpegEncContext
*s
)
454 if(s
->avctx
->dct_algo
==FF_DCT_AUTO
|| s
->avctx
->dct_algo
==FF_DCT_MLIB
){
455 s
->dsp
.fdct
= ff_fdct_mlib
;
458 if(s
->avctx
->idct_algo
==FF_IDCT_MLIB
){
459 s
->dsp
.idct_put
= ff_idct_put_mlib
;
460 s
->dsp
.idct_add
= ff_idct_add_mlib
;
461 s
->dsp
.idct
= ff_idct_mlib
;
462 s
->dsp
.idct_permutation_type
= FF_NO_IDCT_PERM
;