Bug fixing in chroma block matching
[schroedinger/research-port.git] / testsuite / wavelet2.c
blob7746243c4e36fd0bfb770798f29157e2819e2c27
2 #ifdef HAVE_CONFIG_H
3 #include "config.h"
4 #endif
6 #include <schroedinger/schro.h>
7 #include <schroedinger/schrowavelet.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdlib.h>
14 int
15 check_output (int type, int split)
17 int16_t *src;
18 int16_t *dest;
19 int i;
20 int n;
21 int ret = 1;
23 src = malloc (256 * 2);
24 dest = malloc (256 * 2);
26 for(n=2;n<16;n+=2) {
27 for(i=0;i<256;i++){
28 dest[i] = 100;
29 src[i] = 0;
32 if (split) {
33 schro_lift_split (type, dest + 10, src + 10, n);
34 } else {
35 schro_lift_synth (type, dest + 10, src + 10, n);
38 for(i=10;i<10+n;i++){
39 if (dest[i] != 0) {
40 printf("check_output failed type=%d, split=%d, n=%d, offset=%d\n",
41 type, split, n, i - 10);
42 ret = 0;
43 break;
48 free(src);
49 free(dest);
50 return ret;
53 int
54 check_endpoints (int type, int split)
56 int16_t *src;
57 int16_t *dest;
58 int i;
59 int n;
60 int x;
61 int ret = 1;
63 src = malloc (256 * 2);
64 dest = malloc (256 * 2);
66 for(n=2;n<16;n+=2) {
67 for(x=-5;x<5;x++){
68 for(i=0;i<256;i++){
69 dest[i] = 100;
70 src[i] = 0;
72 if (x<0) {
73 src[10+x] = 100;
74 } else {
75 src[10+n+x] = 100;
78 if (split) {
79 schro_lift_split (type, dest + 10, src + 10, n);
80 } else {
81 schro_lift_synth (type, dest + 10, src + 10, n);
84 for(i=10;i<10+n;i++){
85 if (dest[i] != 0) {
86 printf("check_endpoints failed type=%d, split=%d, n=%d, x=%d\n",
87 type, split, n, x);
88 ret = 0;
89 break;
95 free(src);
96 free(dest);
97 return ret;
101 check_constant (int type)
103 int16_t *src;
104 int16_t *dest;
105 int i;
106 int n;
107 int ret = 1;
109 src = malloc (256 * 2);
110 dest = malloc (256 * 2);
112 for(n=2;n<16;n+=2) {
113 for(i=0;i<n;i++){
114 src[i] = 100;
117 schro_lift_split (type, dest, src, n);
119 for(i=0;i<n;i+=2){
120 if (dest[i] != dest[0]) {
121 printf("check_constant failed type=%d, n=%d, i=%d\n",
122 type, n, i);
123 ret = 0;
124 break;
127 for(i=0;i<n;i+=2){
128 if (dest[i+1] != 0) {
129 printf("check_constant failed type=%d, n=%d, i=%d\n",
130 type, n, i);
131 ret = 0;
132 break;
137 free(src);
138 free(dest);
139 return ret;
143 check_random (int type)
145 int16_t *src;
146 int16_t *tmp;
147 int16_t *dest;
148 int i;
149 int n;
150 int ret = 1;
152 src = malloc (256 * 2);
153 tmp = malloc (256 * 2);
154 dest = malloc (256 * 2);
156 for(n=2;n<16;n+=2) {
157 for(i=0;i<n;i++){
158 src[i] = rand()&0xff;
161 schro_lift_split (type, tmp, src, n);
162 schro_lift_synth (type, dest, tmp, n);
164 for(i=0;i<n;i++){
165 if (dest[i] != src[i]) {
166 printf("check_random failed type=%d, n=%d, i=%d\n", type, n, i);
167 ret = 0;
168 break;
173 free(src);
174 free(tmp);
175 free(dest);
176 return ret;
180 main (int argc, char *argv[])
182 schro_init();
184 check_output (SCHRO_WAVELET_DAUBECHIES_9_7, 1);
185 check_output (SCHRO_WAVELET_DAUBECHIES_9_7, 0);
187 check_output (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7, 1);
188 check_output (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7, 0);
190 check_output (SCHRO_WAVELET_LE_GALL_5_3, 1);
191 check_output (SCHRO_WAVELET_LE_GALL_5_3, 0);
193 check_output (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7, 1);
194 check_output (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7, 0);
196 check_endpoints (SCHRO_WAVELET_DAUBECHIES_9_7, 1);
197 check_endpoints (SCHRO_WAVELET_DAUBECHIES_9_7, 0);
199 check_endpoints (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7, 1);
200 check_endpoints (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7, 0);
202 check_endpoints (SCHRO_WAVELET_LE_GALL_5_3, 1);
203 check_endpoints (SCHRO_WAVELET_LE_GALL_5_3, 0);
205 check_endpoints (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7, 1);
206 check_endpoints (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7, 0);
209 check_constant (SCHRO_WAVELET_DAUBECHIES_9_7);
210 check_constant (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7);
211 check_constant (SCHRO_WAVELET_LE_GALL_5_3);
212 check_constant (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7);
215 check_random (SCHRO_WAVELET_DAUBECHIES_9_7);
216 check_random (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7);
217 check_random (SCHRO_WAVELET_LE_GALL_5_3);
218 check_random (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7);
221 return 0;