[encoder] Added 1/8th pel MV refinement
[schroedinger/research-port.git] / testsuite / downsample.c
blob66a0ef26e74519374dd187d451bd091b6364b78a
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 <schroedinger/schrooil.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <math.h>
16 #define OIL_ENABLE_UNSTABLE_API
17 #include <liboil/liboilrandom.h>
18 #include <liboil/liboil.h>
20 #include "common.h"
22 void ref_frame_downsample (SchroFrame *dest, SchroFrame *src);
24 void frame_create_test_pattern(SchroFrame *frame, int type);
26 int failed = FALSE;
28 void
29 test (int width, int height)
31 SchroFrame *frame;
32 SchroFrame *frame_ref;
33 SchroFrame *frame_test;
34 char name[TEST_PATTERN_NAME_SIZE];
35 int i;
37 printf("size %dx%d\n", width, height);
39 frame = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_U8_420, width, height);
40 frame_ref = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_U8_420,
41 ROUND_UP_SHIFT(width, 1), ROUND_UP_SHIFT(height, 1));
42 frame_test = schro_frame_new_and_alloc (NULL, SCHRO_FRAME_FORMAT_U8_420,
43 ROUND_UP_SHIFT(width, 1), ROUND_UP_SHIFT(height, 1));
45 for(i=0;i<test_pattern_get_n_generators();i++){
46 test_pattern_generate (frame->components + 0, name, i);
48 ref_frame_downsample (frame_ref, frame);
49 schro_frame_downsample (frame_test, frame);
51 if (frame_compare (frame_ref, frame_test)) {
52 printf(" pattern %s: OK\n", name);
53 } else {
54 printf(" pattern %s: broken\n", name);
55 frame_data_dump_full (frame_test->components + 0,
56 frame_ref->components + 0, frame->components + 0);
57 failed = TRUE;
61 schro_frame_unref (frame_ref);
62 schro_frame_unref (frame_test);
63 schro_frame_unref (frame);
66 int
67 main (int argc, char *argv[])
69 int width;
70 int height;
72 schro_init();
74 for(width=10;width<40;width++){
75 for(height=10;height<40;height++){
76 test (width, height);
80 if (failed) {
81 printf("FAILED\n");
82 } else {
83 printf("SUCCESS\n");
86 return failed;
90 int
91 component_get (SchroFrameData *src, int i, int j)
93 uint8_t *data;
95 i = CLAMP(i,0,src->width-1);
96 j = CLAMP(j,0,src->height-1);
97 data = OFFSET(src->data, j*src->stride);
99 return data[i];
102 void
103 ref_frame_component_downsample (SchroFrameData *dest,
104 SchroFrameData *src)
106 static const int taps[4] = { 6, 26, 26, 6 };
107 int i,j;
108 int k,l;
109 uint8_t *ddata;
111 for(j=0;j<dest->height;j++){
112 ddata = OFFSET(dest->data, dest->stride * j);
113 for(i=0;i<dest->width;i++){
114 int x = 0;
115 for(l=0;l<4;l++){
116 int y = 0;
117 for(k=0;k<4;k++){
118 y += component_get (src, (i*2-1) + l, (j*2-1) + k) * taps[k];
120 x += CLAMP((y + 32) >> 6,0,255) * taps[l];
122 ddata[i] = CLAMP((x + 32) >> 6,0,255);
127 void
128 ref_frame_downsample (SchroFrame *dest, SchroFrame *src)
130 ref_frame_component_downsample (dest->components+0, src->components+0);
131 ref_frame_component_downsample (dest->components+1, src->components+1);
132 ref_frame_component_downsample (dest->components+2, src->components+2);
135 void
136 frame_create_test_pattern(SchroFrame *frame, int type)
138 int i,j,k;
139 uint8_t *data;
141 for(k=0;k<3;k++){
142 for(j=0;j<frame->components[k].height;j++){
143 data = OFFSET(frame->components[k].data,j*frame->components[k].stride);
144 for(i=0;i<frame->components[k].width;i++) {
145 //data[i] = 100;
146 //data[i] = i*10;
147 //data[i] = j*10;
148 data[i] = oil_rand_u8();