forgot to commit, i hope its correct
[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>
26#include <mlib_video.h>
27
28
47fa9c20
JK
29/* copy block, width 16 pixel, height 8/16 */
30
31static void put_pixels16_mlib (uint8_t * dest, const uint8_t * ref,
32 int stride, int height)
33{
34 assert(height == 16 || height == 8);
35 if (height == 16)
36 mlib_VideoCopyRef_U8_U8_16x16(dest, (uint8_t *)ref, stride);
37 else
38 mlib_VideoCopyRef_U8_U8_16x8 (dest, (uint8_t *)ref, stride);
39}
40
41static void put_pixels16_x2_mlib (uint8_t * dest, const uint8_t * ref,
42 int stride, int height)
43{
44 assert(height == 16 || height == 8);
45 if (height == 16)
46 mlib_VideoInterpX_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
47 else
48 mlib_VideoInterpX_U8_U8_16x8 (dest, (uint8_t *)ref, stride, stride);
49}
50
51static void put_pixels16_y2_mlib (uint8_t * dest, const uint8_t * ref,
52 int stride, int height)
53{
54 assert(height == 16 || height == 8);
55 if (height == 16)
56 mlib_VideoInterpY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
57 else
58 mlib_VideoInterpY_U8_U8_16x8 (dest, (uint8_t *)ref, stride, stride);
59}
60
61static void put_pixels16_xy2_mlib(uint8_t * dest, const uint8_t * ref,
62 int stride, int height)
63{
64 assert(height == 16 || height == 8);
65 if (height == 16)
66 mlib_VideoInterpXY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
67 else
68 mlib_VideoInterpXY_U8_U8_16x8 (dest, (uint8_t *)ref, stride, stride);
69}
70
71
72/* copy block, width 8 pixel, height 8/16 */
73
74static void put_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
75 int stride, int height)
c34270f5
FB
76{
77 assert(height == 16 || height == 8);
78 if (height == 16)
79 mlib_VideoCopyRef_U8_U8_8x16(dest, (uint8_t *)ref, stride);
80 else
81 mlib_VideoCopyRef_U8_U8_8x8 (dest, (uint8_t *)ref, stride);
82}
83
47fa9c20
JK
84static void put_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
85 int stride, int height)
c34270f5
FB
86{
87 assert(height == 16 || height == 8);
88 if (height == 16)
89 mlib_VideoInterpX_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
90 else
91 mlib_VideoInterpX_U8_U8_8x8 (dest, (uint8_t *)ref, stride, stride);
92}
93
47fa9c20
JK
94static void put_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
95 int stride, int height)
c34270f5
FB
96{
97 assert(height == 16 || height == 8);
98 if (height == 16)
99 mlib_VideoInterpY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
100 else
101 mlib_VideoInterpY_U8_U8_8x8 (dest, (uint8_t *)ref, stride, stride);
102}
103
47fa9c20
JK
104static void put_pixels8_xy2_mlib(uint8_t * dest, const uint8_t * ref,
105 int stride, int height)
c34270f5
FB
106{
107 assert(height == 16 || height == 8);
108 if (height == 16)
109 mlib_VideoInterpXY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
110 else
111 mlib_VideoInterpXY_U8_U8_8x8 (dest, (uint8_t *)ref, stride, stride);
112}
113
47fa9c20
JK
114
115/* average/merge dest+source block, width 16 pixel, height 8/16 */
116
117static void avg_pixels16_mlib (uint8_t * dest, const uint8_t * ref,
118 int stride, int height)
119{
120 assert(height == 16 || height == 8);
121 if (height == 16)
122 mlib_VideoCopyRefAve_U8_U8_16x16(dest, (uint8_t *)ref, stride);
123 else
124 mlib_VideoCopyRefAve_U8_U8_16x8 (dest, (uint8_t *)ref, stride);
125}
126
127static void avg_pixels16_x2_mlib (uint8_t * dest, const uint8_t * ref,
128 int stride, int height)
129{
130 assert(height == 16 || height == 8);
131 if (height == 16)
132 mlib_VideoInterpAveX_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
133 else
134 mlib_VideoInterpAveX_U8_U8_16x8 (dest, (uint8_t *)ref, stride, stride);
135}
136
137static void avg_pixels16_y2_mlib (uint8_t * dest, const uint8_t * ref,
138 int stride, int height)
139{
140 assert(height == 16 || height == 8);
141 if (height == 16)
142 mlib_VideoInterpAveY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
143 else
144 mlib_VideoInterpAveY_U8_U8_16x8 (dest, (uint8_t *)ref, stride, stride);
145}
146
147static void avg_pixels16_xy2_mlib (uint8_t * dest, const uint8_t * ref,
148 int stride, int height)
149{
150 assert(height == 16 || height == 8);
151 if (height == 16)
152 mlib_VideoInterpAveXY_U8_U8_16x16(dest, (uint8_t *)ref, stride, stride);
153 else
154 mlib_VideoInterpAveXY_U8_U8_16x8 (dest, (uint8_t *)ref, stride, stride);
155}
156
157
158/* average/merge dest+source block, width 8 pixel, height 8/16 */
159
160static void avg_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
161 int stride, int height)
c34270f5
FB
162{
163 assert(height == 16 || height == 8);
164 if (height == 16)
165 mlib_VideoCopyRefAve_U8_U8_8x16(dest, (uint8_t *)ref, stride);
166 else
167 mlib_VideoCopyRefAve_U8_U8_8x8 (dest, (uint8_t *)ref, stride);
168}
169
47fa9c20
JK
170static void avg_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
171 int stride, int height)
c34270f5
FB
172{
173 assert(height == 16 || height == 8);
174 if (height == 16)
175 mlib_VideoInterpAveX_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
176 else
177 mlib_VideoInterpAveX_U8_U8_8x8 (dest, (uint8_t *)ref, stride, stride);
178}
179
47fa9c20
JK
180static void avg_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
181 int stride, int height)
c34270f5
FB
182{
183 assert(height == 16 || height == 8);
184 if (height == 16)
185 mlib_VideoInterpAveY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
186 else
187 mlib_VideoInterpAveY_U8_U8_8x8 (dest, (uint8_t *)ref, stride, stride);
188}
189
47fa9c20
JK
190static void avg_pixels8_xy2_mlib (uint8_t * dest, const uint8_t * ref,
191 int stride, int height)
c34270f5
FB
192{
193 assert(height == 16 || height == 8);
194 if (height == 16)
195 mlib_VideoInterpAveXY_U8_U8_8x16(dest, (uint8_t *)ref, stride, stride);
196 else
197 mlib_VideoInterpAveXY_U8_U8_8x8 (dest, (uint8_t *)ref, stride, stride);
198}
199
200
0c1a9eda 201static void (*put_pixels_clamped)(const DCTELEM *block, uint8_t *pixels, int line_size);
a8140ad5
JK
202
203
0c1a9eda 204static void add_pixels_clamped_mlib(const DCTELEM *block, uint8_t *pixels, int line_size)
c34270f5
FB
205{
206 mlib_VideoAddBlock_U8_S16(pixels, (mlib_s16 *)block, line_size);
207}
208
47fa9c20 209
676e200c
MN
210/* XXX: those functions should be suppressed ASAP when all IDCTs are
211 converted */
0c1a9eda 212static void ff_idct_put_mlib(uint8_t *dest, int line_size, DCTELEM *data)
c34270f5
FB
213{
214 mlib_VideoIDCT8x8_S16_S16 (data, data);
47fa9c20 215 put_pixels_clamped(data, dest, line_size);
676e200c 216}
47fa9c20 217
0c1a9eda 218static void ff_idct_add_mlib(uint8_t *dest, int line_size, DCTELEM *data)
676e200c
MN
219{
220 mlib_VideoIDCT8x8_S16_S16 (data, data);
a8140ad5 221 mlib_VideoAddBlock_U8_S16(dest, (mlib_s16 *)data, line_size);
c34270f5 222}
c34270f5 223
4fb518c3
MN
224static void ff_idct_mlib(uint8_t *dest, int line_size, DCTELEM *data)
225{
226 mlib_VideoIDCT8x8_S16_S16 (data, data);
227}
228
47fa9c20 229static void ff_fdct_mlib(DCTELEM *data)
c34270f5
FB
230{
231 mlib_VideoDCT8x8_S16_S16 (data, data);
232}
233
31d8cb13 234void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx)
c34270f5 235{
af19f78f
ZK
236 c->put_pixels_tab[0][0] = put_pixels16_mlib;
237 c->put_pixels_tab[0][1] = put_pixels16_x2_mlib;
238 c->put_pixels_tab[0][2] = put_pixels16_y2_mlib;
239 c->put_pixels_tab[0][3] = put_pixels16_xy2_mlib;
240 c->put_pixels_tab[1][0] = put_pixels8_mlib;
241 c->put_pixels_tab[1][1] = put_pixels8_x2_mlib;
242 c->put_pixels_tab[1][2] = put_pixels8_y2_mlib;
243 c->put_pixels_tab[1][3] = put_pixels8_xy2_mlib;
244
245 c->avg_pixels_tab[0][0] = avg_pixels16_mlib;
246 c->avg_pixels_tab[0][1] = avg_pixels16_x2_mlib;
247 c->avg_pixels_tab[0][2] = avg_pixels16_y2_mlib;
248 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mlib;
249 c->avg_pixels_tab[1][0] = avg_pixels8_mlib;
250 c->avg_pixels_tab[1][1] = avg_pixels8_x2_mlib;
251 c->avg_pixels_tab[1][2] = avg_pixels8_y2_mlib;
252 c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mlib;
253
254 c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mlib;
255 c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mlib;
256
257 c->add_pixels_clamped = add_pixels_clamped_mlib;
a8140ad5 258 put_pixels_clamped = c->put_pixels_clamped;
c34270f5 259}
c7e07931
MO
260
261void MPV_common_init_mlib(MpegEncContext *s)
262{
676e200c 263 int i;
676e200c 264
c7e07931 265 if(s->avctx->dct_algo==FF_DCT_AUTO || s->avctx->dct_algo==FF_DCT_MLIB){
31d8cb13 266 s->dsp.fdct = ff_fdct_mlib;
c7e07931 267 }
676e200c 268
47fa9c20 269 if(s->avctx->idct_algo==FF_IDCT_AUTO || s->avctx->idct_algo==FF_IDCT_MLIB){
31d8cb13
ZK
270 s->dsp.idct_put= ff_idct_put_mlib;
271 s->dsp.idct_add= ff_idct_add_mlib;
4fb518c3 272 s->dsp.idct = ff_idct_mlib;
31d8cb13 273 s->dsp.idct_permutation_type= FF_NO_IDCT_PERM;
676e200c 274 }
c7e07931 275}