2 * Sun mediaLib optimized DSP utils
3 * Copyright (c) 2001 Fabrice Bellard.
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.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
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
20 #include "../dsputil.h"
21 #include "../mpegvideo.h"
23 #include <mlib_types.h>
24 #include <mlib_status.h>
26 #include <mlib_video.h>
29 /* copy block, width 16 pixel, height 8/16 */
31 static void put_pixels16_mlib (uint8_t * dest
, const uint8_t * ref
,
32 int stride
, int height
)
34 assert(height
== 16 || height
== 8);
36 mlib_VideoCopyRef_U8_U8_16x16(dest
, (uint8_t *)ref
, stride
);
38 mlib_VideoCopyRef_U8_U8_16x8 (dest
, (uint8_t *)ref
, stride
);
41 static void put_pixels16_x2_mlib (uint8_t * dest
, const uint8_t * ref
,
42 int stride
, int height
)
44 assert(height
== 16 || height
== 8);
46 mlib_VideoInterpX_U8_U8_16x16(dest
, (uint8_t *)ref
, stride
, stride
);
48 mlib_VideoInterpX_U8_U8_16x8 (dest
, (uint8_t *)ref
, stride
, stride
);
51 static void put_pixels16_y2_mlib (uint8_t * dest
, const uint8_t * ref
,
52 int stride
, int height
)
54 assert(height
== 16 || height
== 8);
56 mlib_VideoInterpY_U8_U8_16x16(dest
, (uint8_t *)ref
, stride
, stride
);
58 mlib_VideoInterpY_U8_U8_16x8 (dest
, (uint8_t *)ref
, stride
, stride
);
61 static void put_pixels16_xy2_mlib(uint8_t * dest
, const uint8_t * ref
,
62 int stride
, int height
)
64 assert(height
== 16 || height
== 8);
66 mlib_VideoInterpXY_U8_U8_16x16(dest
, (uint8_t *)ref
, stride
, stride
);
68 mlib_VideoInterpXY_U8_U8_16x8 (dest
, (uint8_t *)ref
, stride
, stride
);
72 /* copy block, width 8 pixel, height 8/16 */
74 static void put_pixels8_mlib (uint8_t * dest
, const uint8_t * ref
,
75 int stride
, int height
)
77 assert(height
== 16 || height
== 8);
79 mlib_VideoCopyRef_U8_U8_8x16(dest
, (uint8_t *)ref
, stride
);
81 mlib_VideoCopyRef_U8_U8_8x8 (dest
, (uint8_t *)ref
, stride
);
84 static void put_pixels8_x2_mlib (uint8_t * dest
, const uint8_t * ref
,
85 int stride
, int height
)
87 assert(height
== 16 || height
== 8);
89 mlib_VideoInterpX_U8_U8_8x16(dest
, (uint8_t *)ref
, stride
, stride
);
91 mlib_VideoInterpX_U8_U8_8x8 (dest
, (uint8_t *)ref
, stride
, stride
);
94 static void put_pixels8_y2_mlib (uint8_t * dest
, const uint8_t * ref
,
95 int stride
, int height
)
97 assert(height
== 16 || height
== 8);
99 mlib_VideoInterpY_U8_U8_8x16(dest
, (uint8_t *)ref
, stride
, stride
);
101 mlib_VideoInterpY_U8_U8_8x8 (dest
, (uint8_t *)ref
, stride
, stride
);
104 static void put_pixels8_xy2_mlib(uint8_t * dest
, const uint8_t * ref
,
105 int stride
, int height
)
107 assert(height
== 16 || height
== 8);
109 mlib_VideoInterpXY_U8_U8_8x16(dest
, (uint8_t *)ref
, stride
, stride
);
111 mlib_VideoInterpXY_U8_U8_8x8 (dest
, (uint8_t *)ref
, stride
, stride
);
115 /* average/merge dest+source block, width 16 pixel, height 8/16 */
117 static void avg_pixels16_mlib (uint8_t * dest
, const uint8_t * ref
,
118 int stride
, int height
)
120 assert(height
== 16 || height
== 8);
122 mlib_VideoCopyRefAve_U8_U8_16x16(dest
, (uint8_t *)ref
, stride
);
124 mlib_VideoCopyRefAve_U8_U8_16x8 (dest
, (uint8_t *)ref
, stride
);
127 static void avg_pixels16_x2_mlib (uint8_t * dest
, const uint8_t * ref
,
128 int stride
, int height
)
130 assert(height
== 16 || height
== 8);
132 mlib_VideoInterpAveX_U8_U8_16x16(dest
, (uint8_t *)ref
, stride
, stride
);
134 mlib_VideoInterpAveX_U8_U8_16x8 (dest
, (uint8_t *)ref
, stride
, stride
);
137 static void avg_pixels16_y2_mlib (uint8_t * dest
, const uint8_t * ref
,
138 int stride
, int height
)
140 assert(height
== 16 || height
== 8);
142 mlib_VideoInterpAveY_U8_U8_16x16(dest
, (uint8_t *)ref
, stride
, stride
);
144 mlib_VideoInterpAveY_U8_U8_16x8 (dest
, (uint8_t *)ref
, stride
, stride
);
147 static void avg_pixels16_xy2_mlib (uint8_t * dest
, const uint8_t * ref
,
148 int stride
, int height
)
150 assert(height
== 16 || height
== 8);
152 mlib_VideoInterpAveXY_U8_U8_16x16(dest
, (uint8_t *)ref
, stride
, stride
);
154 mlib_VideoInterpAveXY_U8_U8_16x8 (dest
, (uint8_t *)ref
, stride
, stride
);
158 /* average/merge dest+source block, width 8 pixel, height 8/16 */
160 static void avg_pixels8_mlib (uint8_t * dest
, const uint8_t * ref
,
161 int stride
, int height
)
163 assert(height
== 16 || height
== 8);
165 mlib_VideoCopyRefAve_U8_U8_8x16(dest
, (uint8_t *)ref
, stride
);
167 mlib_VideoCopyRefAve_U8_U8_8x8 (dest
, (uint8_t *)ref
, stride
);
170 static void avg_pixels8_x2_mlib (uint8_t * dest
, const uint8_t * ref
,
171 int stride
, int height
)
173 assert(height
== 16 || height
== 8);
175 mlib_VideoInterpAveX_U8_U8_8x16(dest
, (uint8_t *)ref
, stride
, stride
);
177 mlib_VideoInterpAveX_U8_U8_8x8 (dest
, (uint8_t *)ref
, stride
, stride
);
180 static void avg_pixels8_y2_mlib (uint8_t * dest
, const uint8_t * ref
,
181 int stride
, int height
)
183 assert(height
== 16 || height
== 8);
185 mlib_VideoInterpAveY_U8_U8_8x16(dest
, (uint8_t *)ref
, stride
, stride
);
187 mlib_VideoInterpAveY_U8_U8_8x8 (dest
, (uint8_t *)ref
, stride
, stride
);
190 static void avg_pixels8_xy2_mlib (uint8_t * dest
, const uint8_t * ref
,
191 int stride
, int height
)
193 assert(height
== 16 || height
== 8);
195 mlib_VideoInterpAveXY_U8_U8_8x16(dest
, (uint8_t *)ref
, stride
, stride
);
197 mlib_VideoInterpAveXY_U8_U8_8x8 (dest
, (uint8_t *)ref
, stride
, stride
);
201 static void (*put_pixels_clamped
)(const DCTELEM
*block
, UINT8
*pixels
, int line_size
);
204 static void add_pixels_clamped_mlib(const DCTELEM
*block
, UINT8
*pixels
, int line_size
)
206 mlib_VideoAddBlock_U8_S16(pixels
, (mlib_s16
*)block
, line_size
);
210 /* XXX: those functions should be suppressed ASAP when all IDCTs are
212 static void ff_idct_put_mlib(UINT8
*dest
, int line_size
, DCTELEM
*data
)
214 mlib_VideoIDCT8x8_S16_S16 (data
, data
);
215 put_pixels_clamped(data
, dest
, line_size
);
218 static void ff_idct_add_mlib(UINT8
*dest
, int line_size
, DCTELEM
*data
)
220 mlib_VideoIDCT8x8_S16_S16 (data
, data
);
221 mlib_VideoAddBlock_U8_S16(dest
, (mlib_s16
*)data
, line_size
);
224 static void ff_fdct_mlib(DCTELEM
*data
)
226 mlib_VideoDCT8x8_S16_S16 (data
, data
);
229 void dsputil_init_mlib(DSPContext
* c
, unsigned mask
)
231 c
->put_pixels_tab
[0][0] = put_pixels16_mlib
;
232 c
->put_pixels_tab
[0][1] = put_pixels16_x2_mlib
;
233 c
->put_pixels_tab
[0][2] = put_pixels16_y2_mlib
;
234 c
->put_pixels_tab
[0][3] = put_pixels16_xy2_mlib
;
235 c
->put_pixels_tab
[1][0] = put_pixels8_mlib
;
236 c
->put_pixels_tab
[1][1] = put_pixels8_x2_mlib
;
237 c
->put_pixels_tab
[1][2] = put_pixels8_y2_mlib
;
238 c
->put_pixels_tab
[1][3] = put_pixels8_xy2_mlib
;
240 c
->avg_pixels_tab
[0][0] = avg_pixels16_mlib
;
241 c
->avg_pixels_tab
[0][1] = avg_pixels16_x2_mlib
;
242 c
->avg_pixels_tab
[0][2] = avg_pixels16_y2_mlib
;
243 c
->avg_pixels_tab
[0][3] = avg_pixels16_xy2_mlib
;
244 c
->avg_pixels_tab
[1][0] = avg_pixels8_mlib
;
245 c
->avg_pixels_tab
[1][1] = avg_pixels8_x2_mlib
;
246 c
->avg_pixels_tab
[1][2] = avg_pixels8_y2_mlib
;
247 c
->avg_pixels_tab
[1][3] = avg_pixels8_xy2_mlib
;
249 c
->put_no_rnd_pixels_tab
[0][0] = put_pixels16_mlib
;
250 c
->put_no_rnd_pixels_tab
[1][0] = put_pixels8_mlib
;
252 c
->add_pixels_clamped
= add_pixels_clamped_mlib
;
253 put_pixels_clamped
= c
->put_pixels_clamped
;
256 void MPV_common_init_mlib(MpegEncContext
*s
)
260 if(s
->avctx
->dct_algo
==FF_DCT_AUTO
|| s
->avctx
->dct_algo
==FF_DCT_MLIB
){
261 s
->fdct
= ff_fdct_mlib
;
264 if(s
->avctx
->idct_algo
==FF_IDCT_AUTO
|| s
->avctx
->idct_algo
==FF_IDCT_MLIB
){
265 s
->idct_put
= ff_idct_put_mlib
;
266 s
->idct_add
= ff_idct_add_mlib
;
267 s
->idct_permutation_type
= FF_NO_IDCT_PERM
;