* compile fixes by Mitch at Bits.COM
[libav.git] / libavcodec / mlib / dsputil_mlib.c
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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_video.h>
27
28
29 /* copy block, width 16 pixel, height 8/16 */
30
31 static 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
41 static 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
51 static 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
61 static 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
74 static void put_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
75 int stride, int height)
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
84 static void put_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
85 int stride, int height)
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
94 static void put_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
95 int stride, int height)
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
104 static void put_pixels8_xy2_mlib(uint8_t * dest, const uint8_t * ref,
105 int stride, int height)
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
114
115 /* average/merge dest+source block, width 16 pixel, height 8/16 */
116
117 static 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
127 static 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
137 static 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
147 static 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
160 static void avg_pixels8_mlib (uint8_t * dest, const uint8_t * ref,
161 int stride, int height)
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
170 static void avg_pixels8_x2_mlib (uint8_t * dest, const uint8_t * ref,
171 int stride, int height)
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
180 static void avg_pixels8_y2_mlib (uint8_t * dest, const uint8_t * ref,
181 int stride, int height)
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
190 static void avg_pixels8_xy2_mlib (uint8_t * dest, const uint8_t * ref,
191 int stride, int height)
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
201 static void (*put_pixels_clamped)(const DCTELEM *block, uint8_t *pixels, int line_size);
202
203
204 static void add_pixels_clamped_mlib(const DCTELEM *block, uint8_t *pixels, int line_size)
205 {
206 mlib_VideoAddBlock_U8_S16(pixels, (mlib_s16 *)block, line_size);
207 }
208
209
210 /* XXX: those functions should be suppressed ASAP when all IDCTs are
211 converted */
212 static void ff_idct_put_mlib(uint8_t *dest, int line_size, DCTELEM *data)
213 {
214 mlib_VideoIDCT8x8_S16_S16 (data, data);
215 put_pixels_clamped(data, dest, line_size);
216 }
217
218 static void ff_idct_add_mlib(uint8_t *dest, int line_size, DCTELEM *data)
219 {
220 mlib_VideoIDCT8x8_S16_S16 (data, data);
221 mlib_VideoAddBlock_U8_S16(dest, (mlib_s16 *)data, line_size);
222 }
223
224 static void ff_fdct_mlib(DCTELEM *data)
225 {
226 mlib_VideoDCT8x8_S16_S16 (data, data);
227 }
228
229 void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx)
230 {
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;
239
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;
248
249 c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mlib;
250 c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mlib;
251
252 c->add_pixels_clamped = add_pixels_clamped_mlib;
253 put_pixels_clamped = c->put_pixels_clamped;
254 }
255
256 void MPV_common_init_mlib(MpegEncContext *s)
257 {
258 int i;
259
260 if(s->avctx->dct_algo==FF_DCT_AUTO || s->avctx->dct_algo==FF_DCT_MLIB){
261 s->dsp.fdct = ff_fdct_mlib;
262 }
263
264 if(s->avctx->idct_algo==FF_IDCT_AUTO || s->avctx->idct_algo==FF_IDCT_MLIB){
265 s->dsp.idct_put= ff_idct_put_mlib;
266 s->dsp.idct_add= ff_idct_add_mlib;
267 s->dsp.idct_permutation_type= FF_NO_IDCT_PERM;
268 }
269 }