VirtualBox

source: vbox/trunk/src/libs/ffmpeg-20060710/libavcodec/mlib/dsputil_mlib.c@ 9441

Last change on this file since 9441 was 5776, checked in by vboxsync, 17 years ago

ffmpeg: exported to OSE

File size: 11.2 KB
Line 
1/*
2 * Sun mediaLib optimized DSP utils
3 * Copyright (c) 2001 Fabrice Bellard.
4 *
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.
9 *
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.
14 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include "../dsputil.h"
21#include "../mpegvideo.h"
22
23#include <mlib_types.h>
24#include <mlib_status.h>
25#include <mlib_sys.h>
26#include <mlib_algebra.h>
27#include <mlib_video.h>
28
29/* misc */
30
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 */
62
63static void put_pixels16_mlib (uint8_t * dest, const uint8_t * ref,
64 int stride, int height)
65{
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 }
78}
79
80static void put_pixels16_x2_mlib (uint8_t * dest, const uint8_t * ref,
81 int stride, int height)
82{
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 }
95}
96
97static void put_pixels16_y2_mlib (uint8_t * dest, const uint8_t * ref,
98 int stride, int height)
99{
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 }
112}
113
114static void put_pixels16_xy2_mlib(uint8_t * dest, const uint8_t * ref,
115 int stride, int height)
116{
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 }
129}
130
131/* put block, width 8 pixel, height 4/8/16 */
132
133static void put_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
134 int stride, int height)
135{
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 }
152}
153
154static void put_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
155 int stride, int height)
156{
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 }
173}
174
175static void put_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
176 int stride, int height)
177{
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 }
194}
195
196static void put_pixels8_xy2_mlib(uint8_t * dest, const uint8_t * ref,
197 int stride, int height)
198{
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 }
215}
216
217/* average block, width 16 pixel, height 8/16 */
218
219static void avg_pixels16_mlib (uint8_t * dest, const uint8_t * ref,
220 int stride, int height)
221{
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 }
234}
235
236static void avg_pixels16_x2_mlib (uint8_t * dest, const uint8_t * ref,
237 int stride, int height)
238{
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 }
251}
252
253static void avg_pixels16_y2_mlib (uint8_t * dest, const uint8_t * ref,
254 int stride, int height)
255{
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 }
268}
269
270static void avg_pixels16_xy2_mlib(uint8_t * dest, const uint8_t * ref,
271 int stride, int height)
272{
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 }
285}
286
287/* average block, width 8 pixel, height 4/8/16 */
288
289static void avg_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
290 int stride, int height)
291{
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 }
308}
309
310static void avg_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
311 int stride, int height)
312{
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 }
329}
330
331static void avg_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
332 int stride, int height)
333{
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 }
350}
351
352static void avg_pixels8_xy2_mlib(uint8_t * dest, const uint8_t * ref,
353 int stride, int height)
354{
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 }
371}
372
373/* swap byte order of a buffer */
374
375static void bswap_buf_mlib(uint32_t *dst, uint32_t *src, int w)
376{
377 mlib_VectorReverseByteOrder_U32_U32(dst, src, w);
378}
379
380/* transformations */
381
382static void ff_idct_put_mlib(uint8_t *dest, int line_size, DCTELEM *data)
383{
384 int i;
385 uint8_t *cm = cropTbl + MAX_NEG_CROP;
386
387 mlib_VideoIDCT8x8_S16_S16 (data, data);
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 }
402}
403
404static void ff_idct_add_mlib(uint8_t *dest, int line_size, DCTELEM *data)
405{
406 mlib_VideoIDCT8x8_S16_S16 (data, data);
407 mlib_VideoAddBlock_U8_S16(dest, (mlib_s16 *)data, line_size);
408}
409
410static void ff_idct_mlib(DCTELEM *data)
411{
412 mlib_VideoIDCT8x8_S16_S16 (data, data);
413}
414
415static void ff_fdct_mlib(DCTELEM *data)
416{
417 mlib_VideoDCT8x8_S16_S16 (data, data);
418}
419
420void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx)
421{
422 c->get_pixels = get_pixels_mlib;
423 c->diff_pixels = diff_pixels_mlib;
424 c->add_pixels_clamped = add_pixels_clamped_mlib;
425
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
447 c->bswap_buf = bswap_buf_mlib;
448}
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){
453 s->dsp.fdct = ff_fdct_mlib;
454 }
455
456 if(s->avctx->idct_algo==FF_IDCT_AUTO || s->avctx->idct_algo==FF_IDCT_MLIB){
457 s->dsp.idct_put= ff_idct_put_mlib;
458 s->dsp.idct_add= ff_idct_add_mlib;
459 s->dsp.idct = ff_idct_mlib;
460 s->dsp.idct_permutation_type= FF_NO_IDCT_PERM;
461 }
462}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette