[cvs] / xvidcore / src / xvid.c Repository:
ViewVC logotype

Annotation of /xvidcore/src/xvid.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.45.2.14 - (view) (download)

1 : edgomez 1.16 /*****************************************************************************
2 : edgomez 1.17 *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * - Native API implementation -
5 :     *
6 : edgomez 1.45.2.6 * Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>
7 :     *
8 : edgomez 1.41 * This program is free software ; you can redistribute it and/or modify
9 :     * it under the terms of the GNU General Public License as published by
10 :     * the Free Software Foundation ; either version 2 of the License, or
11 : edgomez 1.17 * (at your option) any later version.
12 :     *
13 :     * This program is distributed in the hope that it will be useful,
14 : edgomez 1.41 * but WITHOUT ANY WARRANTY ; without even the implied warranty of
15 : edgomez 1.17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 :     * GNU General Public License for more details.
17 :     *
18 :     * You should have received a copy of the GNU General Public License
19 : edgomez 1.41 * along with this program ; if not, write to the Free Software
20 : edgomez 1.17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 :     *
22 : edgomez 1.45.2.14 * $Id$
23 : edgomez 1.36 *
24 : edgomez 1.17 ****************************************************************************/
25 : chenm001 1.29
26 : edgomez 1.41 #include <stdio.h>
27 :     #include <stdlib.h>
28 :     #include <string.h>
29 :     #include <time.h>
30 :    
31 : Isibaar 1.1 #include "xvid.h"
32 :     #include "decoder.h"
33 :     #include "encoder.h"
34 :     #include "bitstream/cbp.h"
35 :     #include "dct/idct.h"
36 :     #include "dct/fdct.h"
37 :     #include "image/colorspace.h"
38 :     #include "image/interpolate8x8.h"
39 : edgomez 1.41 #include "image/reduced.h"
40 : Isibaar 1.1 #include "utils/mem_transfer.h"
41 : edgomez 1.41 #include "utils/mbfunctions.h"
42 : Isibaar 1.1 #include "quant/quant_h263.h"
43 :     #include "quant/quant_mpeg4.h"
44 : ia64p 1.30 #include "motion/motion.h"
45 : Isibaar 1.1 #include "motion/sad.h"
46 :     #include "utils/emms.h"
47 :     #include "utils/timer.h"
48 : Isibaar 1.9 #include "bitstream/mbcoding.h"
49 : Isibaar 1.45.2.13 #include "image/qpel.h"
50 : Isibaar 1.1
51 : suxen_drol 1.45.2.4 #if defined(_DEBUG)
52 :     unsigned int xvid_debug = 0; /* xvid debug mask */
53 :     #endif
54 :    
55 : edgomez 1.41 #if defined(ARCH_IS_IA32)
56 : suxen_drol 1.31
57 : edgomez 1.41 #if defined(_MSC_VER)
58 :     # include <windows.h>
59 : suxen_drol 1.31 #else
60 : edgomez 1.41 # include <signal.h>
61 :     # include <setjmp.h>
62 : suxen_drol 1.31
63 : edgomez 1.41 static jmp_buf mark;
64 : suxen_drol 1.31
65 : edgomez 1.41 static void
66 :     sigill_handler(int signal)
67 :     {
68 :     longjmp(mark, 1);
69 :     }
70 : suxen_drol 1.31 #endif
71 :    
72 :    
73 :     /*
74 : edgomez 1.43 * Calls the funcptr, and returns whether SIGILL (illegal instruction) was
75 :     * signalled
76 :     *
77 :     * Return values:
78 :     * -1 : could not determine
79 :     * 0 : SIGILL was *not* signalled
80 :     * 1 : SIGILL was signalled
81 :     */
82 : suxen_drol 1.31
83 :     int
84 :     sigill_check(void (*func)())
85 :     {
86 : edgomez 1.41 #if defined(_MSC_VER)
87 : suxen_drol 1.31 _try {
88 :     func();
89 :     }
90 :     _except(EXCEPTION_EXECUTE_HANDLER) {
91 :    
92 :     if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
93 :     return 1;
94 :     }
95 :     return 0;
96 :     #else
97 :     void * old_handler;
98 :     int jmpret;
99 :    
100 :    
101 :     old_handler = signal(SIGILL, sigill_handler);
102 :     if (old_handler == SIG_ERR)
103 :     {
104 :     return -1;
105 :     }
106 :    
107 :     jmpret = setjmp(mark);
108 :     if (jmpret == 0)
109 :     {
110 :     func();
111 :     }
112 :    
113 :     signal(SIGILL, old_handler);
114 :    
115 :     return jmpret;
116 :     #endif
117 :     }
118 :     #endif
119 :    
120 : edgomez 1.41
121 :     /* detect cpu flags */
122 :     static unsigned int
123 :     detect_cpu_flags()
124 :     {
125 :     /* enable native assembly optimizations by default */
126 :     unsigned int cpu_flags = XVID_CPU_ASM;
127 :    
128 :     #if defined(ARCH_IS_IA32)
129 :     cpu_flags |= check_cpu_features();
130 :     if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger))
131 :     cpu_flags &= ~XVID_CPU_SSE;
132 :    
133 :     if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger))
134 :     cpu_flags &= ~XVID_CPU_SSE2;
135 :     #endif
136 :    
137 :     #if defined(ARCH_IS_PPC)
138 :     #if defined(ARCH_IS_PPC_ALTIVEC)
139 :     cpu_flags |= XVID_CPU_ALTIVEC;
140 :     #endif
141 :     #endif
142 :    
143 :     return cpu_flags;
144 :     }
145 :    
146 :    
147 : edgomez 1.16 /*****************************************************************************
148 :     * XviD Init Entry point
149 :     *
150 :     * Well this function initialize all internal function pointers according
151 :     * to the CPU features forced by the library client or autodetected (depending
152 :     * on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all
153 :     * image colorspace transformation tables.
154 :     *
155 :     * Returned value : XVID_ERR_OK
156 :     * + API_VERSION in the input XVID_INIT_PARAM structure
157 :     * + core build " " " " "
158 :     *
159 :     ****************************************************************************/
160 :    
161 : edgomez 1.41
162 :     static
163 : suxen_drol 1.45.2.1 int xvid_gbl_init(xvid_gbl_init_t * init)
164 : Isibaar 1.1 {
165 : suxen_drol 1.45.2.1 unsigned int cpu_flags;
166 : suxen_drol 1.31
167 : edgomez 1.45.2.12 if (XVID_VERSION_MAJOR(init->version) != 1) /* v1.x.x */
168 : suxen_drol 1.45.2.1 return XVID_ERR_VERSION;
169 : suxen_drol 1.31
170 : suxen_drol 1.45.2.1 cpu_flags = (init->cpu_flags & XVID_CPU_FORCE) ? init->cpu_flags : detect_cpu_flags();
171 : Isibaar 1.1
172 : edgomez 1.16 /* Initialize the function pointers */
173 : Isibaar 1.1 idct_int32_init();
174 : Isibaar 1.9 init_vlc_tables();
175 :    
176 : edgomez 1.16 /* Fixed Point Forward/Inverse DCT transformations */
177 : Isibaar 1.1 fdct = fdct_int32;
178 :     idct = idct_int32;
179 :    
180 : edgomez 1.16 /* Only needed on PPC Altivec archs */
181 : canard 1.10 sadInit = 0;
182 : edgomez 1.15
183 : edgomez 1.16 /* Restore FPU context : emms_c is a nop functions */
184 : Isibaar 1.1 emms = emms_c;
185 :    
186 : Isibaar 1.45.2.13 /* Qpel stuff */
187 :     xvid_QP_Funcs = &xvid_QP_Funcs_C;
188 :     xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_C;
189 : edgomez 1.45.2.14 xvid_Init_QP();
190 : Isibaar 1.45.2.13
191 : edgomez 1.16 /* Quantization functions */
192 :     quant_intra = quant_intra_c;
193 : Isibaar 1.1 dequant_intra = dequant_intra_c;
194 : edgomez 1.16 quant_inter = quant_inter_c;
195 : Isibaar 1.1 dequant_inter = dequant_inter_c;
196 :    
197 : edgomez 1.16 quant4_intra = quant4_intra_c;
198 : Isibaar 1.1 dequant4_intra = dequant4_intra_c;
199 : edgomez 1.16 quant4_inter = quant4_inter_c;
200 : Isibaar 1.1 dequant4_inter = dequant4_inter_c;
201 :    
202 : edgomez 1.16 /* Block transfer related functions */
203 : Isibaar 1.1 transfer_8to16copy = transfer_8to16copy_c;
204 :     transfer_16to8copy = transfer_16to8copy_c;
205 : edgomez 1.16 transfer_8to16sub = transfer_8to16sub_c;
206 : edgomez 1.41 transfer_8to16subro = transfer_8to16subro_c;
207 : suxen_drol 1.11 transfer_8to16sub2 = transfer_8to16sub2_c;
208 : edgomez 1.16 transfer_16to8add = transfer_16to8add_c;
209 :     transfer8x8_copy = transfer8x8_copy_c;
210 : Isibaar 1.1
211 : edgomez 1.41 /* Interlacing functions */
212 :     MBFieldTest = MBFieldTest_c;
213 :    
214 : edgomez 1.16 /* Image interpolation related functions */
215 :     interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c;
216 :     interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c;
217 : Isibaar 1.1 interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c;
218 :    
219 : edgomez 1.41 interpolate16x16_lowpass_h = interpolate16x16_lowpass_h_c;
220 :     interpolate16x16_lowpass_v = interpolate16x16_lowpass_v_c;
221 :     interpolate16x16_lowpass_hv = interpolate16x16_lowpass_hv_c;
222 :    
223 :     interpolate8x8_lowpass_h = interpolate8x8_lowpass_h_c;
224 :     interpolate8x8_lowpass_v = interpolate8x8_lowpass_v_c;
225 :     interpolate8x8_lowpass_hv = interpolate8x8_lowpass_hv_c;
226 :    
227 :     interpolate8x8_6tap_lowpass_h = interpolate8x8_6tap_lowpass_h_c;
228 :     interpolate8x8_6tap_lowpass_v = interpolate8x8_6tap_lowpass_v_c;
229 :    
230 :     interpolate8x8_avg2 = interpolate8x8_avg2_c;
231 :     interpolate8x8_avg4 = interpolate8x8_avg4_c;
232 :    
233 :     /* reduced resoltuion */
234 :     copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C;
235 :     add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C;
236 :     vfilter_31 = xvid_VFilter_31_C;
237 :     hfilter_31 = xvid_HFilter_31_C;
238 :     filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_C;
239 :     filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_C;
240 :    
241 : edgomez 1.16 /* Initialize internal colorspace transformation tables */
242 : Isibaar 1.1 colorspace_init();
243 :    
244 : edgomez 1.16 /* All colorspace transformation functions User Format->YV12 */
245 : edgomez 1.41 yv12_to_yv12 = yv12_to_yv12_c;
246 :     rgb555_to_yv12 = rgb555_to_yv12_c;
247 :     rgb565_to_yv12 = rgb565_to_yv12_c;
248 :     bgr_to_yv12 = bgr_to_yv12_c;
249 :     bgra_to_yv12 = bgra_to_yv12_c;
250 :     abgr_to_yv12 = abgr_to_yv12_c;
251 :     rgba_to_yv12 = rgba_to_yv12_c;
252 :     yuyv_to_yv12 = yuyv_to_yv12_c;
253 :     uyvy_to_yv12 = uyvy_to_yv12_c;
254 :    
255 :     rgb555i_to_yv12 = rgb555i_to_yv12_c;
256 :     rgb565i_to_yv12 = rgb565i_to_yv12_c;
257 :     bgri_to_yv12 = bgri_to_yv12_c;
258 :     bgrai_to_yv12 = bgrai_to_yv12_c;
259 :     abgri_to_yv12 = abgri_to_yv12_c;
260 :     rgbai_to_yv12 = rgbai_to_yv12_c;
261 :     yuyvi_to_yv12 = yuyvi_to_yv12_c;
262 :     uyvyi_to_yv12 = uyvyi_to_yv12_c;
263 :    
264 : Isibaar 1.1
265 : edgomez 1.16 /* All colorspace transformation functions YV12->User format */
266 : edgomez 1.41 yv12_to_rgb555 = yv12_to_rgb555_c;
267 :     yv12_to_rgb565 = yv12_to_rgb565_c;
268 :     yv12_to_bgr = yv12_to_bgr_c;
269 :     yv12_to_bgra = yv12_to_bgra_c;
270 :     yv12_to_abgr = yv12_to_abgr_c;
271 :     yv12_to_rgba = yv12_to_rgba_c;
272 :     yv12_to_yuyv = yv12_to_yuyv_c;
273 :     yv12_to_uyvy = yv12_to_uyvy_c;
274 :    
275 :     yv12_to_rgb555i = yv12_to_rgb555i_c;
276 :     yv12_to_rgb565i = yv12_to_rgb565i_c;
277 :     yv12_to_bgri = yv12_to_bgri_c;
278 :     yv12_to_bgrai = yv12_to_bgrai_c;
279 :     yv12_to_abgri = yv12_to_abgri_c;
280 :     yv12_to_rgbai = yv12_to_rgbai_c;
281 :     yv12_to_yuyvi = yv12_to_yuyvi_c;
282 :     yv12_to_uyvyi = yv12_to_uyvyi_c;
283 : Isibaar 1.1
284 : edgomez 1.16 /* Functions used in motion estimation algorithms */
285 : Isibaar 1.1 calc_cbp = calc_cbp_c;
286 : edgomez 1.16 sad16 = sad16_c;
287 : suxen_drol 1.33 sad8 = sad8_c;
288 : edgomez 1.16 sad16bi = sad16bi_c;
289 : suxen_drol 1.33 sad8bi = sad8bi_c;
290 : edgomez 1.16 dev16 = dev16_c;
291 : edgomez 1.41 sad16v = sad16v_c;
292 : suxen_drol 1.33
293 : edgomez 1.43 /* Halfpel8_Refine = Halfpel8_Refine_c; */
294 : Isibaar 1.1
295 : edgomez 1.41 #if defined(ARCH_IS_IA32)
296 :    
297 : edgomez 1.45.2.7 if ((cpu_flags & XVID_CPU_ASM)) {
298 : edgomez 1.41 vfilter_31 = xvid_VFilter_31_x86;
299 :     hfilter_31 = xvid_HFilter_31_x86;
300 :     }
301 :    
302 :     if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) ||
303 :     (cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) ||
304 :     (cpu_flags & XVID_CPU_SSE) || (cpu_flags & XVID_CPU_SSE2))
305 :     {
306 :     /* Restore FPU context : emms_c is a nop functions */
307 :     emms = emms_mmx;
308 :     }
309 :    
310 :     if ((cpu_flags & XVID_CPU_MMX)) {
311 : edgomez 1.16
312 :     /* Forward and Inverse Discrete Cosine Transformation functions */
313 : Isibaar 1.1 fdct = fdct_mmx;
314 : Isibaar 1.45.2.8 idct = idct_mmx;
315 : Isibaar 1.1
316 : Isibaar 1.45.2.13 /* Qpel stuff */
317 :     xvid_QP_Funcs = &xvid_QP_Funcs_mmx;
318 :     xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_mmx;
319 :    
320 : edgomez 1.16 /* Quantization related functions */
321 :     quant_intra = quant_intra_mmx;
322 : Isibaar 1.1 dequant_intra = dequant_intra_mmx;
323 : edgomez 1.16 quant_inter = quant_inter_mmx;
324 : Isibaar 1.1 dequant_inter = dequant_inter_mmx;
325 :    
326 : edgomez 1.16 quant4_intra = quant4_intra_mmx;
327 : Isibaar 1.1 dequant4_intra = dequant4_intra_mmx;
328 : edgomez 1.16 quant4_inter = quant4_inter_mmx;
329 : Isibaar 1.1 dequant4_inter = dequant4_inter_mmx;
330 :    
331 : edgomez 1.16 /* Block related functions */
332 : Isibaar 1.1 transfer_8to16copy = transfer_8to16copy_mmx;
333 :     transfer_16to8copy = transfer_16to8copy_mmx;
334 : edgomez 1.16 transfer_8to16sub = transfer_8to16sub_mmx;
335 : edgomez 1.41 transfer_8to16subro = transfer_8to16subro_mmx;
336 : edgomez 1.22 transfer_8to16sub2 = transfer_8to16sub2_mmx;
337 : edgomez 1.16 transfer_16to8add = transfer_16to8add_mmx;
338 :     transfer8x8_copy = transfer8x8_copy_mmx;
339 : edgomez 1.22
340 : edgomez 1.41 /* Interlacing Functions */
341 :     MBFieldTest = MBFieldTest_mmx;
342 : edgomez 1.16
343 :     /* Image Interpolation related functions */
344 :     interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx;
345 :     interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx;
346 : Isibaar 1.1 interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx;
347 :    
348 : edgomez 1.41 interpolate8x8_6tap_lowpass_h = interpolate8x8_6tap_lowpass_h_mmx;
349 :     interpolate8x8_6tap_lowpass_v = interpolate8x8_6tap_lowpass_v_mmx;
350 :    
351 :     interpolate8x8_avg2 = interpolate8x8_avg2_mmx;
352 :     interpolate8x8_avg4 = interpolate8x8_avg4_mmx;
353 :    
354 :     /* reduced resolution */
355 :     copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_mmx;
356 :     add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_mmx;
357 :     hfilter_31 = xvid_HFilter_31_mmx;
358 :     filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_mmx;
359 :     filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_mmx;
360 :    
361 :     /* image input xxx_to_yv12 related functions */
362 :     yv12_to_yv12 = yv12_to_yv12_mmx;
363 :     bgr_to_yv12 = bgr_to_yv12_mmx;
364 :     bgra_to_yv12 = bgra_to_yv12_mmx;
365 : edgomez 1.16 yuyv_to_yv12 = yuyv_to_yv12_mmx;
366 :     uyvy_to_yv12 = uyvy_to_yv12_mmx;
367 : Isibaar 1.1
368 : edgomez 1.41 /* image output yv12_to_xxx related functions */
369 :     yv12_to_bgr = yv12_to_bgr_mmx;
370 :     yv12_to_bgra = yv12_to_bgra_mmx;
371 : edgomez 1.16 yv12_to_yuyv = yv12_to_yuyv_mmx;
372 :     yv12_to_uyvy = yv12_to_uyvy_mmx;
373 : edgomez 1.41
374 :     yv12_to_yuyvi = yv12_to_yuyvi_mmx;
375 :     yv12_to_uyvyi = yv12_to_uyvyi_mmx;
376 : Isibaar 1.1
377 : edgomez 1.16 /* Motion estimation related functions */
378 : Isibaar 1.1 calc_cbp = calc_cbp_mmx;
379 : edgomez 1.16 sad16 = sad16_mmx;
380 :     sad8 = sad8_mmx;
381 : suxen_drol 1.33 sad16bi = sad16bi_mmx;
382 :     sad8bi = sad8bi_mmx;
383 : edgomez 1.16 dev16 = dev16_mmx;
384 : edgomez 1.41 sad16v = sad16v_mmx;
385 : Isibaar 1.1 }
386 :    
387 : suxen_drol 1.33 /* these 3dnow functions are faster than mmx, but slower than xmm. */
388 : edgomez 1.41 if ((cpu_flags & XVID_CPU_3DNOW)) {
389 :    
390 :     emms = emms_3dn;
391 : suxen_drol 1.33
392 :     /* ME functions */
393 :     sad16bi = sad16bi_3dn;
394 :     sad8bi = sad8bi_3dn;
395 : edgomez 1.41
396 :     yuyv_to_yv12 = yuyv_to_yv12_3dn;
397 :     uyvy_to_yv12 = uyvy_to_yv12_3dn;
398 : suxen_drol 1.33 }
399 :    
400 :    
401 : edgomez 1.41 if ((cpu_flags & XVID_CPU_MMXEXT)) {
402 : edgomez 1.16
403 :     /* Inverse DCT */
404 : Isibaar 1.1 idct = idct_xmm;
405 : edgomez 1.16
406 :     /* Interpolation */
407 :     interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm;
408 :     interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm;
409 : h 1.3 interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm;
410 : Isibaar 1.25
411 : edgomez 1.41 /* reduced resolution */
412 :     copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_xmm;
413 :     add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_xmm;
414 :    
415 : chenm001 1.29 /* Quantization */
416 : edgomez 1.45.2.11 quant4_intra = quant4_intra_xmm;
417 : edgomez 1.41 quant4_inter = quant4_inter_xmm;
418 :    
419 : chenm001 1.29 dequant_intra = dequant_intra_xmm;
420 :     dequant_inter = dequant_inter_xmm;
421 :    
422 : edgomez 1.19 /* Buffer transfer */
423 :     transfer_8to16sub2 = transfer_8to16sub2_xmm;
424 : edgomez 1.16
425 :     /* Colorspace transformation */
426 : edgomez 1.41 yv12_to_yv12 = yv12_to_yv12_xmm;
427 :     yuyv_to_yv12 = yuyv_to_yv12_xmm;
428 :     uyvy_to_yv12 = uyvy_to_yv12_xmm;
429 : Isibaar 1.1
430 : edgomez 1.16 /* ME functions */
431 : Isibaar 1.1 sad16 = sad16_xmm;
432 : suxen_drol 1.33 sad8 = sad8_xmm;
433 : chenm001 1.29 sad16bi = sad16bi_xmm;
434 : suxen_drol 1.33 sad8bi = sad8bi_xmm;
435 : Isibaar 1.1 dev16 = dev16_xmm;
436 : edgomez 1.41 sad16v = sad16v_xmm;
437 : Isibaar 1.1 }
438 :    
439 : edgomez 1.41 if ((cpu_flags & XVID_CPU_3DNOW)) {
440 : edgomez 1.16
441 :     /* Interpolation */
442 : Isibaar 1.1 interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn;
443 :     interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dn;
444 : h 1.4 interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn;
445 : Isibaar 1.1 }
446 :    
447 : edgomez 1.41 if ((cpu_flags & XVID_CPU_3DNOWEXT)) {
448 :    
449 :     /* Inverse DCT */
450 :     idct = idct_3dne;
451 :    
452 :     /* Buffer transfer */
453 :     transfer_8to16copy = transfer_8to16copy_3dne;
454 :     transfer_16to8copy = transfer_16to8copy_3dne;
455 :     transfer_8to16sub = transfer_8to16sub_3dne;
456 :     transfer_8to16subro = transfer_8to16subro_3dne;
457 :     transfer_8to16sub2 = transfer_8to16sub2_3dne;
458 :     transfer_16to8add = transfer_16to8add_3dne;
459 :     transfer8x8_copy = transfer8x8_copy_3dne;
460 :    
461 :     /* Quantization */
462 :     dequant4_intra = dequant4_intra_3dne;
463 :     dequant4_inter = dequant4_inter_3dne;
464 : edgomez 1.45.2.11 quant_intra = quant_intra_3dne;
465 : edgomez 1.41 quant_inter = quant_inter_3dne;
466 :     dequant_intra = dequant_intra_3dne;
467 :     dequant_inter = dequant_inter_3dne;
468 :    
469 :     /* ME functions */
470 :     calc_cbp = calc_cbp_3dne;
471 :     sad16 = sad16_3dne;
472 :     sad8 = sad8_3dne;
473 :     sad16bi = sad16bi_3dne;
474 :     sad8bi = sad8bi_3dne;
475 :     dev16 = dev16_3dne;
476 :    
477 :     /* Interpolation */
478 :     interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dne;
479 :     interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dne;
480 :     interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dne;
481 :     }
482 :    
483 : Isibaar 1.45.2.13 #if defined(EXPERIMENTAL_SSE2_CODE) /* mark the whole SSE2 stuff as experimental. At least on
484 :     my P4, it crashes... */
485 : edgomez 1.41 if ((cpu_flags & XVID_CPU_SSE2)) {
486 : edgomez 1.16
487 : chenm001 1.29 calc_cbp = calc_cbp_sse2;
488 :    
489 : edgomez 1.16 /* Quantization */
490 :     quant_intra = quant_intra_sse2;
491 : Isibaar 1.14 dequant_intra = dequant_intra_sse2;
492 : edgomez 1.16 quant_inter = quant_inter_sse2;
493 : Isibaar 1.14 dequant_inter = dequant_inter_sse2;
494 : h 1.13
495 : edgomez 1.41 /* ME; slower than xmm */
496 : edgomez 1.16 sad16 = sad16_sse2;
497 :     dev16 = dev16_sse2;
498 :     /* Forward and Inverse DCT */
499 : edgomez 1.45.2.7 #if 0 /* Both function are known to be unprecise, better keep them deactivated */
500 : edgomez 1.16 idct = idct_sse2;
501 : Isibaar 1.14 fdct = fdct_sse2;
502 : edgomez 1.45.2.7 #endif
503 : h 1.12 }
504 : Isibaar 1.45.2.13 #endif
505 : Isibaar 1.1 #endif
506 : Isibaar 1.18
507 : edgomez 1.41 #if defined(ARCH_IS_IA64)
508 : edgomez 1.43 if ((cpu_flags & XVID_CPU_ASM)) { /* use assembler routines? */
509 : Isibaar 1.18 idct_ia64_init();
510 :     fdct = fdct_ia64;
511 : edgomez 1.43 idct = idct_ia64; /*not yet working, crashes */
512 : Isibaar 1.18 interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64;
513 :     interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64;
514 :     interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64;
515 :     sad16 = sad16_ia64;
516 :     sad16bi = sad16bi_ia64;
517 :     sad8 = sad8_ia64;
518 :     dev16 = dev16_ia64;
519 : edgomez 1.43 /* Halfpel8_Refine = Halfpel8_Refine_ia64; */
520 : Isibaar 1.18 quant_intra = quant_intra_ia64;
521 :     dequant_intra = dequant_intra_ia64;
522 :     quant_inter = quant_inter_ia64;
523 :     dequant_inter = dequant_inter_ia64;
524 :     transfer_8to16copy = transfer_8to16copy_ia64;
525 :     transfer_16to8copy = transfer_16to8copy_ia64;
526 :     transfer_8to16sub = transfer_8to16sub_ia64;
527 :     transfer_8to16sub2 = transfer_8to16sub2_ia64;
528 :     transfer_16to8add = transfer_16to8add_ia64;
529 :     transfer8x8_copy = transfer8x8_copy_ia64;
530 :     }
531 :     #endif
532 : edgomez 1.16
533 : edgomez 1.41 #if defined(ARCH_IS_PPC)
534 :     if ((cpu_flags & XVID_CPU_ASM))
535 :     {
536 :     calc_cbp = calc_cbp_ppc;
537 :     }
538 :    
539 :     if ((cpu_flags & XVID_CPU_ALTIVEC))
540 :     {
541 :     calc_cbp = calc_cbp_altivec;
542 :     fdct = fdct_altivec;
543 :     idct = idct_altivec;
544 :     sadInit = sadInit_altivec;
545 :     sad16 = sad16_altivec;
546 :     sad8 = sad8_altivec;
547 :     dev16 = dev16_altivec;
548 :     }
549 : canard 1.6 #endif
550 : edgomez 1.41
551 : suxen_drol 1.45.2.4 #if defined(_DEBUG)
552 :     xvid_debug = init->debug;
553 :     #endif
554 :    
555 :     return 0;
556 : edgomez 1.41 }
557 :    
558 :    
559 : suxen_drol 1.45.2.1 static int
560 :     xvid_gbl_info(xvid_gbl_info_t * info)
561 :     {
562 : edgomez 1.45.2.12 if (XVID_VERSION_MAJOR(info->version) != 1) /* v1.x.x */
563 : suxen_drol 1.45.2.1 return XVID_ERR_VERSION;
564 :    
565 :     info->actual_version = XVID_VERSION;
566 :     info->build = "dev-api-4";
567 :     info->cpu_flags = detect_cpu_flags();
568 :    
569 :     #if defined(_SMP) && defined(WIN32)
570 :     info->num_threads = pthread_num_processors_np();;
571 :     #else
572 :     info->num_threads = 0;
573 :     #endif
574 :    
575 :     return 0;
576 :     }
577 :    
578 : edgomez 1.41
579 :     static int
580 : suxen_drol 1.45.2.1 xvid_gbl_convert(xvid_gbl_convert_t* convert)
581 : edgomez 1.41 {
582 : suxen_drol 1.45.2.1 int width;
583 :     int height;
584 :     int width2;
585 :     int height2;
586 : edgomez 1.41 IMAGE img;
587 :    
588 : edgomez 1.45.2.12 if (XVID_VERSION_MAJOR(convert->version) != 1) /* v1.x.x */
589 : suxen_drol 1.45.2.1 return XVID_ERR_VERSION;
590 :    
591 : edgomez 1.45.2.5 #if 0
592 :     const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP);
593 :     #endif
594 : suxen_drol 1.45.2.1 width = convert->width;
595 :     height = convert->height;
596 :     width2 = convert->width/2;
597 :     height2 = convert->height/2;
598 :    
599 :     switch (convert->input.csp & ~XVID_CSP_VFLIP)
600 : edgomez 1.41 {
601 :     case XVID_CSP_YV12 :
602 : suxen_drol 1.45.2.1 img.y = convert->input.plane[0];
603 :     img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height;
604 :     img.u = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height + (convert->input.stride[0]/2)*height2;
605 : edgomez 1.41 image_output(&img, width, height, width,
606 : suxen_drol 1.45.2.1 (uint8_t**)convert->output.plane, convert->output.stride,
607 :     convert->output.csp, convert->interlacing);
608 : edgomez 1.41 break;
609 :    
610 :     default :
611 :     return XVID_ERR_FORMAT;
612 :     }
613 :    
614 :    
615 :     emms();
616 : suxen_drol 1.45.2.1 return 0;
617 : edgomez 1.41 }
618 :    
619 :    
620 :    
621 :     void fill8(uint8_t * block, int size, int value)
622 :     {
623 :     int i;
624 :     for (i = 0; i < size; i++)
625 :     block[i] = value;
626 :     }
627 :    
628 :     void fill16(int16_t * block, int size, int value)
629 :     {
630 :     int i;
631 :     for (i = 0; i < size; i++)
632 :     block[i] = value;
633 :     }
634 :    
635 :     #define RANDOM(min,max) min + (rand() % (max-min))
636 :    
637 :     void random8(uint8_t * block, int size, int min, int max)
638 :     {
639 :     int i;
640 :     for (i = 0; i < size; i++)
641 :     block[i] = RANDOM(min,max);
642 :     }
643 :    
644 :     void random16(int16_t * block, int size, int min, int max)
645 :     {
646 :     int i;
647 :     for (i = 0; i < size; i++)
648 :     block[i] = RANDOM(min,max);
649 :     }
650 :    
651 :     int compare16(const int16_t * blockA, const int16_t * blockB, int size)
652 :     {
653 :     int i;
654 :     for (i = 0; i < size; i++)
655 :     if (blockA[i] != blockB[i])
656 :     return 1;
657 :    
658 :     return 0;
659 :     }
660 :    
661 :     int diff16(const int16_t * blockA, const int16_t * blockB, int size)
662 :     {
663 :     int i, diff = 0;
664 :     for (i = 0; i < size; i++)
665 : edgomez 1.45.2.3 diff += abs(blockA[i]-blockB[i]);
666 : edgomez 1.41 return diff;
667 :     }
668 :    
669 :    
670 :     #define XVID_TEST_RANDOM 0x00000001 /* random input data */
671 :     #define XVID_TEST_VERBOSE 0x00000002 /* verbose error output */
672 :    
673 :    
674 :     #define TEST_FORWARD 0x00000001 /* intra */
675 :     #define TEST_FDCT (TEST_FORWARD)
676 :     #define TEST_IDCT (0)
677 :    
678 : suxen_drol 1.42 static int test_transform(void * funcA, void * funcB, const char * nameB,
679 : edgomez 1.41 int test, int flags)
680 :     {
681 :     int i;
682 :     int64_t timeSTART;
683 :     int64_t timeA = 0;
684 :     int64_t timeB = 0;
685 :     DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);
686 :     DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);
687 :     int min, max;
688 :     int count = 0;
689 :    
690 :     int tmp;
691 :     int min_error = 0x10000*64;
692 :     int max_error = 0;
693 :    
694 :    
695 :     if ((test & TEST_FORWARD)) /* forward */
696 :     {
697 :     min = -256;
698 :     max = 255;
699 :     }else{ /* inverse */
700 :     min = -2048;
701 :     max = 2047;
702 :     }
703 :    
704 :     for (i = 0; i < 64*64; i++)
705 :     {
706 :     if ((flags & XVID_TEST_RANDOM))
707 :     {
708 :     random16(arrayA, 64, min, max);
709 :     }else{
710 :     fill16(arrayA, 64, i);
711 :     }
712 :     memcpy(arrayB, arrayA, 64*sizeof(int16_t));
713 :    
714 :     if ((test & TEST_FORWARD))
715 :     {
716 :     timeSTART = read_counter();
717 :     ((fdctFunc*)funcA)(arrayA);
718 :     timeA += read_counter() - timeSTART;
719 :    
720 :     timeSTART = read_counter();
721 :     ((fdctFunc*)funcB)(arrayB);
722 :     timeB += read_counter() - timeSTART;
723 :     }
724 :     else
725 :     {
726 :     timeSTART = read_counter();
727 :     ((idctFunc*)funcA)(arrayA);
728 :     timeA += read_counter() - timeSTART;
729 :    
730 :     timeSTART = read_counter();
731 :     ((idctFunc*)funcB)(arrayB);
732 :     timeB += read_counter() - timeSTART;
733 :     }
734 :    
735 :     tmp = diff16(arrayA, arrayB, 64) / 64;
736 :     if (tmp > max_error)
737 :     max_error = tmp;
738 :     if (tmp < min_error)
739 :     min_error = tmp;
740 :    
741 :     count++;
742 :     }
743 :    
744 :     /* print the "average difference" of best/worst transforms */
745 :     printf("%s:\t%i\t(min_error:%i, max_error:%i)\n", nameB, (int)(timeB / count), min_error, max_error);
746 :    
747 :     return 0;
748 :     }
749 :    
750 :    
751 :     #define TEST_QUANT 0x00000001 /* forward quantization */
752 :     #define TEST_INTRA 0x00000002 /* intra */
753 :     #define TEST_QUANT_INTRA (TEST_QUANT|TEST_INTRA)
754 :     #define TEST_QUANT_INTER (TEST_QUANT)
755 :     #define TEST_DEQUANT_INTRA (TEST_INTRA)
756 :     #define TEST_DEQUANT_INTER (0)
757 :    
758 : suxen_drol 1.42 static int test_quant(void * funcA, void * funcB, const char * nameB,
759 : edgomez 1.41 int test, int flags)
760 :     {
761 :     int q,i;
762 :     int64_t timeSTART;
763 :     int64_t timeA = 0;
764 :     int64_t timeB = 0;
765 : edgomez 1.43 int retA = 0, retB = 0;
766 : edgomez 1.41 DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE);
767 :     DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);
768 :     DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);
769 :     int min, max;
770 :     int count = 0;
771 :     int errors = 0;
772 :    
773 :     if ((test & TEST_QUANT)) /* quant */
774 :     {
775 :     min = -2048;
776 :     max = 2047;
777 :     }else{ /* dequant */
778 :     min = -256;
779 :     max = 255;
780 :     }
781 :    
782 :     for (q = 1; q <= 31; q++) /* quantizer */
783 :     {
784 :     for (i = min; i < max; i++) /* input coeff */
785 :     {
786 :     if ((flags & XVID_TEST_RANDOM))
787 :     {
788 :     random16(arrayX, 64, min, max);
789 :     }else{
790 :     fill16(arrayX, 64, i);
791 :     }
792 :    
793 :     if ((test & TEST_INTRA)) /* intra */
794 :     {
795 :     timeSTART = read_counter();
796 :     ((quanth263_intraFunc*)funcA)(arrayA, arrayX, q, q);
797 :     timeA += read_counter() - timeSTART;
798 :    
799 :     timeSTART = read_counter();
800 :     ((quanth263_intraFunc*)funcB)(arrayB, arrayX, q, q);
801 :     timeB += read_counter() - timeSTART;
802 :     }
803 :     else /* inter */
804 :     {
805 :     timeSTART = read_counter();
806 :     retA = ((quanth263_interFunc*)funcA)(arrayA, arrayX, q);
807 :     timeA += read_counter() - timeSTART;
808 :    
809 :     timeSTART = read_counter();
810 :     retB = ((quanth263_interFunc*)funcB)(arrayB, arrayX, q);
811 :     timeB += read_counter() - timeSTART;
812 :     }
813 :    
814 :     /* compare return value from quant_inter, and compare (de)quantiz'd arrays */
815 :     if ( ((test&TEST_QUANT) && !(test&TEST_INTRA) && retA != retB ) ||
816 :     compare16(arrayA, arrayB, 64))
817 :     {
818 :     errors++;
819 :     if ((flags & XVID_TEST_VERBOSE))
820 :     printf("%s error: q=%i, i=%i\n", nameB, q, i);
821 :     }
822 :    
823 :     count++;
824 :     }
825 :     }
826 :    
827 :     printf("%s:\t%i", nameB, (int)(timeB / count));
828 :     if (errors>0)
829 :     printf("\t(%i errors out of %i)", errors, count);
830 :     printf("\n");
831 :    
832 :     return 0;
833 :     }
834 :    
835 :    
836 :    
837 :     int xvid_init_test(int flags)
838 :     {
839 : edgomez 1.45 #if defined(ARCH_IS_IA32)
840 :     int cpu_flags;
841 :     #endif
842 : edgomez 1.41
843 : edgomez 1.44 printf("XviD tests\n\n");
844 : edgomez 1.41
845 : edgomez 1.44 #if defined(ARCH_IS_IA32)
846 : edgomez 1.41 cpu_flags = detect_cpu_flags();
847 : edgomez 1.44 #endif
848 :    
849 : edgomez 1.41 idct_int32_init();
850 : edgomez 1.44 emms();
851 : edgomez 1.45
852 :     srand(time(0));
853 : edgomez 1.41
854 : edgomez 1.44 /* fDCT test */
855 : edgomez 1.41 printf("--- fdct ---\n");
856 :     test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags);
857 : edgomez 1.44
858 :     #if defined(ARCH_IS_IA32)
859 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
860 :     test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags);
861 :     if (cpu_flags & XVID_CPU_SSE2)
862 :     test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags);
863 : edgomez 1.44 #endif
864 : edgomez 1.41
865 : edgomez 1.44 /* iDCT test */
866 : edgomez 1.41 printf("\n--- idct ---\n");
867 :     test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags);
868 : edgomez 1.44
869 :     #if defined(ARCH_IS_IA32)
870 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
871 :     test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags);
872 :     if (cpu_flags & XVID_CPU_MMXEXT)
873 :     test_transform(idct_int32, idct_xmm, "xmm", TEST_IDCT, flags);
874 :     if (cpu_flags & XVID_CPU_3DNOWEXT)
875 :     test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags);
876 :     if (cpu_flags & XVID_CPU_SSE2)
877 :     test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags);
878 : edgomez 1.44 #endif
879 : edgomez 1.41
880 : edgomez 1.44 /* Intra quantization test */
881 : edgomez 1.41 printf("\n--- quant intra ---\n");
882 :     test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags);
883 : edgomez 1.44
884 :     #if defined(ARCH_IS_IA32)
885 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
886 :     test_quant(quant_intra_c, quant_intra_mmx, "mmx", TEST_QUANT_INTRA, flags);
887 :     if (cpu_flags & XVID_CPU_3DNOWEXT)
888 :     test_quant(quant_intra_c, quant_intra_3dne, "3dne", TEST_QUANT_INTRA, flags);
889 :     if (cpu_flags & XVID_CPU_SSE2)
890 :     test_quant(quant_intra_c, quant_intra_sse2, "sse2", TEST_QUANT_INTRA, flags);
891 : edgomez 1.44 #endif
892 : edgomez 1.41
893 : edgomez 1.44 /* Inter quantization test */
894 : edgomez 1.41 printf("\n--- quant inter ---\n");
895 :     test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags);
896 : edgomez 1.44
897 :     #if defined(ARCH_IS_IA32)
898 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
899 :     test_quant(quant_inter_c, quant_inter_mmx, "mmx", TEST_QUANT_INTER, flags);
900 :     if (cpu_flags & XVID_CPU_3DNOWEXT)
901 :     test_quant(quant_inter_c, quant_inter_3dne, "3dne", TEST_QUANT_INTER, flags);
902 :     if (cpu_flags & XVID_CPU_SSE2)
903 :     test_quant(quant_inter_c, quant_inter_sse2, "sse2", TEST_QUANT_INTER, flags);
904 : edgomez 1.44 #endif
905 : edgomez 1.41
906 : edgomez 1.44 /* Intra dequantization test */
907 : edgomez 1.41 printf("\n--- dequant intra ---\n");
908 :     test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags);
909 : edgomez 1.44
910 :     #if defined(ARCH_IS_IA32)
911 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
912 :     test_quant(dequant_intra_c, dequant_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags);
913 :     if (cpu_flags & XVID_CPU_MMXEXT)
914 :     test_quant(dequant_intra_c, dequant_intra_xmm, "xmm", TEST_DEQUANT_INTRA, flags);
915 :     if (cpu_flags & XVID_CPU_3DNOWEXT)
916 :     test_quant(dequant_intra_c, dequant_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags);
917 :     if (cpu_flags & XVID_CPU_SSE2)
918 :     test_quant(dequant_intra_c, dequant_intra_sse2, "sse2", TEST_DEQUANT_INTRA, flags);
919 : edgomez 1.44 #endif
920 : edgomez 1.41
921 : edgomez 1.44 /* Inter dequantization test */
922 : edgomez 1.41 printf("\n--- dequant inter ---\n");
923 :     test_quant(dequant_inter_c, dequant_inter_c, "c", TEST_DEQUANT_INTER, flags);
924 : edgomez 1.44
925 :     #if defined(ARCH_IS_IA32)
926 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
927 :     test_quant(dequant_inter_c, dequant_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags);
928 :     if (cpu_flags & XVID_CPU_MMXEXT)
929 :     test_quant(dequant_inter_c, dequant_inter_xmm, "xmm", TEST_DEQUANT_INTER, flags);
930 :     if (cpu_flags & XVID_CPU_3DNOWEXT)
931 :     test_quant(dequant_inter_c, dequant_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags);
932 :     if (cpu_flags & XVID_CPU_SSE2)
933 :     test_quant(dequant_inter_c, dequant_inter_sse2, "sse2", TEST_DEQUANT_INTER, flags);
934 : edgomez 1.44 #endif
935 : edgomez 1.41
936 : edgomez 1.44 /* Intra quantization test */
937 :     printf("\n--- quant4 intra ---\n");
938 : edgomez 1.41 test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags);
939 : edgomez 1.44
940 :     #if defined(ARCH_IS_IA32)
941 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
942 :     test_quant(quant4_intra_c, quant4_intra_mmx, "mmx", TEST_QUANT_INTRA, flags);
943 :     if (cpu_flags & XVID_CPU_MMXEXT)
944 :     test_quant(quant4_intra_c, quant4_intra_xmm, "xmm", TEST_QUANT_INTRA, flags);
945 : edgomez 1.44 #endif
946 : edgomez 1.41
947 : edgomez 1.44 /* Inter quantization test */
948 :     printf("\n--- quant4 inter ---\n");
949 : edgomez 1.41 test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags);
950 : edgomez 1.44
951 :     #if defined(ARCH_IS_IA32)
952 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
953 :     test_quant(quant4_inter_c, quant4_inter_mmx, "mmx", TEST_QUANT_INTER, flags);
954 :     if (cpu_flags & XVID_CPU_MMXEXT)
955 :     test_quant(quant4_inter_c, quant4_inter_xmm, "xmm", TEST_QUANT_INTER, flags);
956 : edgomez 1.44 #endif
957 : edgomez 1.41
958 : edgomez 1.44 /* Intra dequantization test */
959 :     printf("\n--- dequant4 intra ---\n");
960 : edgomez 1.41 test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags);
961 : edgomez 1.44
962 :     #if defined(ARCH_IS_IA32)
963 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
964 :     test_quant(dequant4_intra_c, dequant4_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags);
965 :     if (cpu_flags & XVID_CPU_3DNOWEXT)
966 :     test_quant(dequant4_intra_c, dequant4_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags);
967 : edgomez 1.44 #endif
968 : edgomez 1.41
969 : edgomez 1.44 /* Inter dequantization test */
970 :     printf("\n--- dequant4 inter ---\n");
971 : edgomez 1.41 test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags);
972 : edgomez 1.44
973 :     #if defined(ARCH_IS_IA32)
974 : edgomez 1.41 if (cpu_flags & XVID_CPU_MMX)
975 :     test_quant(dequant4_inter_c, dequant4_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags);
976 :     if (cpu_flags & XVID_CPU_3DNOWEXT)
977 :     test_quant(dequant4_inter_c, dequant4_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags);
978 : edgomez 1.44 #endif
979 : edgomez 1.41
980 : edgomez 1.44 emms();
981 : Isibaar 1.1
982 : suxen_drol 1.45.2.1 return 0;
983 : Isibaar 1.1 }
984 :    
985 : edgomez 1.41
986 : suxen_drol 1.45.2.1 /*****************************************************************************
987 :     * XviD Global Entry point
988 :     *
989 :     * Well this function initialize all internal function pointers according
990 :     * to the CPU features forced by the library client or autodetected (depending
991 :     * on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all
992 :     * image colorspace transformation tables.
993 :     *
994 :     ****************************************************************************/
995 :    
996 :    
997 : edgomez 1.41 int
998 : suxen_drol 1.45.2.1 xvid_global(void *handle,
999 : edgomez 1.41 int opt,
1000 :     void *param1,
1001 :     void *param2)
1002 :     {
1003 :     switch(opt)
1004 :     {
1005 : suxen_drol 1.45.2.1 case XVID_GBL_INIT :
1006 :     return xvid_gbl_init((xvid_gbl_init_t*)param1);
1007 : edgomez 1.41
1008 : suxen_drol 1.45.2.1 case XVID_GBL_INFO :
1009 :     return xvid_gbl_info((xvid_gbl_info_t*)param1);
1010 : edgomez 1.41
1011 : suxen_drol 1.45.2.1 case XVID_GBL_CONVERT :
1012 :     return xvid_gbl_convert((xvid_gbl_convert_t*)param1);
1013 :    
1014 :     case XVID_GBL_TEST :
1015 : edgomez 1.44 {
1016 :     ptr_t flags = (ptr_t)param1;
1017 :     return xvid_init_test((int)flags);
1018 :     }
1019 : edgomez 1.41 default :
1020 :     return XVID_ERR_FAIL;
1021 :     }
1022 :     }
1023 :    
1024 : edgomez 1.16 /*****************************************************************************
1025 :     * XviD Native decoder entry point
1026 :     *
1027 :     * This function is just a wrapper to all the option cases.
1028 :     *
1029 :     * Returned values : XVID_ERR_FAIL when opt is invalid
1030 :     * else returns the wrapped function result
1031 :     *
1032 :     ****************************************************************************/
1033 :    
1034 : edgomez 1.15 int
1035 :     xvid_decore(void *handle,
1036 :     int opt,
1037 :     void *param1,
1038 :     void *param2)
1039 : Isibaar 1.1 {
1040 : edgomez 1.15 switch (opt) {
1041 :     case XVID_DEC_CREATE:
1042 : suxen_drol 1.45.2.1 return decoder_create((xvid_dec_create_t *) param1);
1043 : edgomez 1.15
1044 :     case XVID_DEC_DESTROY:
1045 :     return decoder_destroy((DECODER *) handle);
1046 : Isibaar 1.1
1047 : suxen_drol 1.45.2.1 case XVID_DEC_DECODE:
1048 :     return decoder_decode((DECODER *) handle, (xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2);
1049 :    
1050 : Isibaar 1.1 default:
1051 : edgomez 1.15 return XVID_ERR_FAIL;
1052 :     }
1053 : Isibaar 1.1 }
1054 :    
1055 : edgomez 1.16
1056 :     /*****************************************************************************
1057 :     * XviD Native encoder entry point
1058 :     *
1059 :     * This function is just a wrapper to all the option cases.
1060 :     *
1061 :     * Returned values : XVID_ERR_FAIL when opt is invalid
1062 :     * else returns the wrapped function result
1063 :     *
1064 :     ****************************************************************************/
1065 : Isibaar 1.1
1066 : edgomez 1.15 int
1067 :     xvid_encore(void *handle,
1068 :     int opt,
1069 :     void *param1,
1070 :     void *param2)
1071 : Isibaar 1.1 {
1072 : edgomez 1.15 switch (opt) {
1073 :     case XVID_ENC_ENCODE:
1074 : edgomez 1.41
1075 : suxen_drol 1.45.2.1 return enc_encode((Encoder *) handle,
1076 :     (xvid_enc_frame_t *) param1,
1077 :     (xvid_enc_stats_t *) param2);
1078 : edgomez 1.15
1079 :     case XVID_ENC_CREATE:
1080 : suxen_drol 1.45.2.2 return enc_create((xvid_enc_create_t *) param1);
1081 : edgomez 1.15
1082 :     case XVID_ENC_DESTROY:
1083 : suxen_drol 1.45.2.1 return enc_destroy((Encoder *) handle);
1084 : Isibaar 1.1
1085 :     default:
1086 : edgomez 1.15 return XVID_ERR_FAIL;
1087 :     }
1088 : Isibaar 1.1 }

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4