[encoder] Added 1/8th pel MV refinement
[schroedinger/research-port.git] / testsuite / motion2.c
blobe90ff70d226a41c9b1ce66dbdcc956b6e73e4c58
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 <schroedinger/schroutils.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
14 #define OIL_ENABLE_UNSTABLE_API
15 #include <liboil/liboilrandom.h>
17 void
18 schro_frame_clear (SchroFrame *frame)
20 memset(frame->components[0].data, 0, frame->components[0].length);
21 memset(frame->components[1].data, 0, frame->components[1].length);
22 memset(frame->components[2].data, 0, frame->components[2].length);
25 void
26 schro_frame_create_pattern (SchroFrame *frame, int type)
28 int i,j,k;
29 SchroFrameData *comp;
31 switch (type) {
32 case 0:
33 oil_random_u8 (frame->components[0].data, frame->components[0].length);
34 oil_random_u8 (frame->components[1].data, frame->components[1].length);
35 oil_random_u8 (frame->components[2].data, frame->components[2].length);
36 break;
37 case 1:
38 for(k=0;k<3;k++){
39 comp = &frame->components[k];
40 for(j=0;j<comp->height;j++){
41 for(i=0;i<comp->width;i++){
42 SCHRO_GET(comp->data, j*comp->stride + i, uint8_t) = i*4 + j*2;
47 break;
51 int
52 schro_frame_compare (SchroFrame *a, SchroFrame *b)
54 SchroFrameData *comp_a;
55 SchroFrameData *comp_b;
56 int k;
57 int i,j;
59 for(k=0;k<3;k++){
60 comp_a = &a->components[k];
61 comp_b = &b->components[k];
62 for(j=0;j<comp_a->height;j++){
63 for(i=0;i<comp_a->width;i++){
64 if (SCHRO_GET(comp_a->data, j*comp_a->stride + i, uint8_t) !=
65 SCHRO_GET(comp_b->data, j*comp_b->stride + i, uint8_t)) {
66 SCHRO_ERROR("difference comp=%d x=%d y=%d", k, i, j);
67 return FALSE;
73 return TRUE;
76 void
77 schro_frame_dump (SchroFrame *frame)
79 SchroFrameData *comp;
80 int i,j;
82 comp = &frame->components[0];
83 for(j=0;j<20;j++){
84 for(i=0;i<20;i++) {
85 printf("%-3d ", SCHRO_GET(comp->data, j*comp->stride + i, uint8_t));
87 printf("\n");
91 int
92 main (int argc, char *argv[])
94 SchroFrame *dest;
95 SchroFrame *dest_u8;
96 SchroFrame *ref;
97 SchroUpsampledFrame *uref;
98 SchroParams params;
99 SchroVideoFormat video_format;
100 SchroMotionVector *motion_vectors;
101 int i,j;
103 schro_init();
105 video_format.width = 720;
106 video_format.height = 480;
107 video_format.chroma_format = SCHRO_CHROMA_420;
108 schro_video_format_validate (&video_format);
110 params.video_format = &video_format;
111 params.xbsep_luma = 8;
112 params.ybsep_luma = 8;
113 params.xblen_luma = 12;
114 params.yblen_luma = 12;
116 schro_params_calculate_mc_sizes(&params);
118 dest = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_S16_420,
119 video_format.width, video_format.height);
120 ref = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_U8_420,
121 video_format.width, video_format.height);
122 dest_u8 = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_U8_420,
123 video_format.width, video_format.height);
125 schro_frame_clear(dest);
126 schro_frame_create_pattern(ref,1);
128 motion_vectors = malloc(sizeof(SchroMotionVector) *
129 params.x_num_blocks * params.y_num_blocks);
130 memset (motion_vectors, 0, sizeof(SchroMotionVector) *
131 params.x_num_blocks * params.y_num_blocks);
133 printf("sizeof(SchroMotionVector) = %lu\n",(unsigned long) sizeof(SchroMotionVector));
134 printf("num blocks %d x %d\n", params.x_num_blocks, params.y_num_blocks);
135 for(j=0;j<params.y_num_blocks;j++){
136 int jj;
137 jj = j * params.x_num_blocks;
138 for(i=0;i<params.x_num_blocks;i++){
139 #if 0
140 if (i == 0 || i == 2 || i == params.x_num_blocks*2) {
141 motion_vectors[jj+i].u.dc[0] = 100;
142 motion_vectors[jj+i].u.dc[1] = 100;
143 motion_vectors[jj+i].u.dc[2] = 0;
144 motion_vectors[jj+i].pred_mode = 0;
145 } else {
146 motion_vectors[jj+i].u.dc[0] = 0;
147 motion_vectors[jj+i].u.dc[1] = 0;
148 motion_vectors[jj+i].u.dc[2] = 0;
149 motion_vectors[jj+i].pred_mode = 0;
151 #endif
152 motion_vectors[jj+i].dx[0] = 0;
153 motion_vectors[jj+i].dy[0] = -8*i;
154 motion_vectors[jj+i].pred_mode = 1;
155 motion_vectors[jj+i].split = 2;
159 uref = schro_upsampled_frame_new (ref);
162 SchroMotion motion;
164 motion.src1 = uref;
165 motion.src2 = NULL;
166 motion.motion_vectors = motion_vectors;
167 motion.params = &params;
168 schro_motion_render (&motion, dest);
171 schro_frame_convert (dest_u8, dest);
172 schro_frame_dump (dest_u8);
173 //schro_frame_compare (ref, dest_u8);
175 schro_upsampled_frame_free (uref);
176 schro_frame_unref (dest);
177 schro_frame_unref (dest_u8);
178 free (motion_vectors);
180 return 0;