[encoder] Added 1/8th pel MV refinement
[schroedinger/research-port.git] / testsuite / global_motion.c
blob3364f5340b6e8725e9ce3c22176d3c7af5b386ed
2 #ifdef HAVE_CONFIG_H
3 #include "config.h"
4 #endif
6 #include <schroedinger/schro.h>
7 #include <schroedinger/schromotion.h>
8 #include <schroedinger/schrodebug.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <math.h>
14 #define OIL_ENABLE_UNSTABLE_API
15 #include <liboil/liboilrandom.h>
18 int
19 test_full_field (int width, int height, double *a, double *b, int r, int hole)
21 SchroMotionField *mf;
22 SchroMotionVector *mv;
23 SchroGlobalMotion gm;
24 double mult;
25 int i,j;
27 mf = schro_motion_field_new (100, 80, 0);
29 printf("test_full_field: r=%d hole=%d\n"
30 "[%6.4f %6.4f %6.4f %6.4f] [%g %g]\n",
31 r, hole,
32 a[0], a[1], a[2], a[3], b[0], b[1]);
33 for(j=0;j<mf->y_num_blocks;j++){
34 for(i=0;i<mf->x_num_blocks;i++){
35 mv = mf->motion_vectors + j*mf->x_num_blocks + i;
37 mv->dx[0] = rint((a[0]-1)*8*i + a[1]*8*j + b[0] + r * oil_rand_f64());
38 mv->dy[0] = rint(a[2]*8*i + (a[3]-1)*8*j + b[1] + r * oil_rand_f64());
39 if (hole && abs(mf->y_num_blocks/2 - j) < 10 &&
40 abs(mf->x_num_blocks/2 - i) < 10) {
41 mv->dx[0] = 0;
42 mv->dy[0] = 0;
46 schro_motion_field_global_estimation (mf, &gm, 0);
48 mult = (1<<gm.a_exp);
49 printf("[%6.4f %6.4f %6.4f %6.4f] [%d %d]\n", gm.a00/mult, gm.a01/mult,
50 gm.a10/mult, gm.a11/mult, gm.b0, gm.b1);
52 if (fabs(gm.a00/mult - a[0]) > 0.01) return 0;
53 if (fabs(gm.a01/mult - a[1]) > 0.01) return 0;
54 if (fabs(gm.a10/mult - a[2]) > 0.01) return 0;
55 if (fabs(gm.a11/mult - a[3]) > 0.01) return 0;
56 if (fabs(gm.b0 - b[0]) > 1) return 0;
57 if (fabs(gm.b1 - b[1]) > 1) return 0;
59 return 1;
63 double matrices[][6] = {
64 { 1.0, 0.0, 0.0, 1.0, 1.0, 0.0 },
65 { 1.0, 0.0, 0.0, 1.0, 0.0, 1.0 },
66 { 1.1, 0.0, 0.0, 1.0, 0.0, 0.0 },
67 { 1.0, 0.1, 0.0, 1.0, 0.0, 0.0 },
68 { 1.0, 0.0, 0.1, 1.0, 0.0, 0.0 },
69 { 1.0, 0.0, 0.0, 1.1, 0.0, 0.0 }
72 int
73 main (int argc, char *argv[])
75 int i;
77 schro_init();
79 for(i=0;i<6;i++){
80 test_full_field(720/8, 576/8, matrices[i], matrices[i] + 4, 0, 0);
81 test_full_field(720/8, 576/8, matrices[i], matrices[i] + 4, 1, 0);
82 test_full_field(720/8, 576/8, matrices[i], matrices[i] + 4, 0, 1);
85 return 0;