comparison Meerwald/wavelet.c @ 8:f83ef905a63d

fixing many warnings increase capacity for coordinates in bruyn fix some uninit. variables
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Tue, 22 Apr 2008 13:36:05 +0200
parents be303a3f5ea8
children bd669312f068
comparison
equal deleted inserted replaced
7:2b350281f8b0 8:f83ef905a63d
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <string.h> 3 #include <string.h>
4 #include <math.h> 4 #include <math.h>
5 #include "wavelet.h" 5 #include "wavelet.h"
6 #include <ctype.h> 6 #include <ctype.h>
7 #include <values.h>
7 8
8 static int read_char(FILE *fp); 9 static int read_char(FILE *fp);
9 static int read_int(FILE *fp); 10 static int read_int(FILE *fp);
10 11
11 IntImage new_intimage(int width, int height) 12 IntImage new_intimage(int width, int height)
138 * -------------------------------------------------------------------- 139 * --------------------------------------------------------------------
139 * DESCRIPTION: 140 * DESCRIPTION:
140 * This function loads an IntImage with load_intimage 141 * This function loads an IntImage with load_intimage
141 * and then converts to Image. 142 * and then converts to Image.
142 ************************************************************************/ 143 ************************************************************************/
143 extern Image load_image(char *file, int max_val) 144 Image load_image(char *file, int max_val)
144 { 145 {
145 Image img; 146 Image img;
146 IntImage intimg; 147 IntImage intimg;
147 148
148 intimg = load_intimage(file, max_val); 149 intimg = load_intimage(file, max_val);
162 /* -------------------------------------------------------------------- */ 163 /* -------------------------------------------------------------------- */
163 /* Description: save an image as PGM (P5 binary decoded) file */ 164 /* Description: save an image as PGM (P5 binary decoded) file */
164 /* */ 165 /* */
165 /************************************************************************/ 166 /************************************************************************/
166 167
167 extern int save_image_P5(char *file, Image img) 168 int save_image_P5(char *file, Image img)
168 { FILE *fp; 169 { FILE *fp;
169 Pixel *data; 170 Pixel *data;
170 long i; 171 long i;
171 int p; 172 int p;
172 173
200 201
201 for (i=0;i<img->size;i++) 202 for (i=0;i<img->size;i++)
202 (img->data)[i]=(Pixel) 0; 203 (img->data)[i]=(Pixel) 0;
203 } 204 }
204 205
205 extern void copy_into_image(Image img1,Image img2,int x,int y) 206 void copy_into_image(Image img1,Image img2,int x,int y)
206 /* copy img2 into img1 at position (x,y)*/ 207 /* copy img2 into img1 at position (x,y)*/
207 { 208 {
208 int start,i,j,aim; 209 int start,i,j,aim;
209 Pixel *temp; 210 Pixel *temp;
210 211
217 temp++; 218 temp++;
218 } 219 }
219 } 220 }
220 } 221 }
221 222
222 extern void copy_into_intimage(IntImage img1,IntImage img2,int x,int y) 223 void copy_into_intimage(IntImage img1,IntImage img2,int x,int y)
223 {/* copy img2 into img1 at position (x,y)*/ 224 {/* copy img2 into img1 at position (x,y)*/
224 225
225 int start,i,j,aim; 226 int start,i,j,aim;
226 IntPixel *temp; 227 IntPixel *temp;
227 228
256 sp+=src_img->width; 257 sp+=src_img->width;
257 dp+=dest_img->width; 258 dp+=dest_img->width;
258 } 259 }
259 } 260 }
260 261
261 extern void copy_part_of_image(Image img1,Image img2,int x,int y) 262 void copy_part_of_image(Image img1,Image img2,int x,int y)
262 /* copy part of img2 begining at position (x,y) into img1 */ 263 /* copy part of img2 begining at position (x,y) into img1 */
263 { int i,j,width,height,start,step; 264 { int i,j,width,height,start,step;
264 Pixel *data; 265 Pixel *data;
265 266
266 width=img1->width; 267 width=img1->width;
275 } 276 }
276 } 277 }
277 } 278 }
278 279
279 280
280 extern void scale_image(Image img,int maximum) 281 void scale_image(Image img, int maximum)
281 /* scale image to [0..maximum]*/ 282 /* scale image to [0..maximum]*/
282 { int i; 283 { int i;
283 Pixel max,min,multi; 284 Pixel max = MINDOUBLE, min = MAXDOUBLE, multi;
284 285
285 for (i=0;i<img->size;i++) { 286 for (i=0;i<img->size;i++) {
286 if (img->data[i]<min) min=img->data[i]; 287 if (img->data[i]<min) min=img->data[i];
287 else if (img->data[i]>max) max=img->data[i]; 288 else if (img->data[i]>max) max=img->data[i];
288 } 289 }
949 int i,i2,j; 950 int i,i2,j;
950 Pixel *out_pix, *in_pix, *f_data; 951 Pixel *out_pix, *in_pix, *f_data;
951 int fstart,fend; 952 int fstart,fend;
952 int in_pos; 953 int in_pos;
953 954
954 int in_dir,in_div,in_mod;
955
956 Entering; 955 Entering;
957 PreCondition(out_len == in_len/2,"out_len != in_len/2 !!!"); 956 PreCondition(out_len == in_len/2,"out_len != in_len/2 !!!");
958 957
959 /* convolution: out[i]=sum_{j=start}^{end} (in[2*i-j]*f[j]) 958 /* convolution: out[i]=sum_{j=start}^{end} (in[2*i-j]*f[j])
960 959
1000 int filter_inv_mirror(Image in, int in_start, int in_len, int in_step, 999 int filter_inv_mirror(Image in, int in_start, int in_len, int in_step,
1001 Image out, int out_start, int out_len, int out_step, 1000 Image out, int out_start, int out_len, int out_step,
1002 Filter f) 1001 Filter f)
1003 { 1002 {
1004 int i,j; 1003 int i,j;
1005 Pixel *out_pix, *in_pix, *f_data; 1004 Pixel *out_pix, *in_pix;
1006 int fstart,fend; /* Source interval */ 1005 int fstart,fend; /* Source interval */
1007 int in_pos,in_dir,in_div,in_mod; 1006 int in_pos;
1008 1007
1009 Entering; 1008 Entering;
1010 PreCondition(out_len == in_len*2,"out_len != in_len*2 !!!"); 1009 PreCondition(out_len == in_len*2,"out_len != in_len*2 !!!");
1011 1010
1012 /* convolution: out[i]=sum_{j=start}^{end} (f[2*j-i]*in[j]) 1011 /* convolution: out[i]=sum_{j=start}^{end} (f[2*j-i]*in[j])
1351 static int decomposition(Image t_img,Image coarse,Image horizontal,Image vertical, 1350 static int decomposition(Image t_img,Image coarse,Image horizontal,Image vertical,
1352 Image diagonal,Filter g,Filter h,enum FilterMethod method); 1351 Image diagonal,Filter g,Filter h,enum FilterMethod method);
1353 static int compute_best(Image_tree tree,int level,int max_level,FilterGH *flt, 1352 static int compute_best(Image_tree tree,int level,int max_level,FilterGH *flt,
1354 enum FilterMethod method,enum Information_Cost cost,double epsilon); 1353 enum FilterMethod method,enum Information_Cost cost,double epsilon);
1355 static double compute_entropy(Image img,enum Information_Cost cost,double epsilon); 1354 static double compute_entropy(Image img,enum Information_Cost cost,double epsilon);
1356 static compute_levels(Image_tree tree,double *entropies,enum Information_Cost cost,double epsilon); 1355 static void compute_levels(Image_tree tree,double *entropies,enum Information_Cost cost,double epsilon);
1357 static free_levels(Image_tree tree,int best); 1356 static void free_levels(Image_tree tree,int best);
1358 1357
1359 static Pixel sumationq(Image img); 1358 static Pixel sumationq(Image img);
1360 static Pixel normq(Image_tree tree); 1359 static Pixel normq(Image_tree tree);
1361 static Pixel sumation_down(Image_tree tree, Pixel normq); 1360 static Pixel sumation_down(Image_tree tree, Pixel normq);
1362 static Pixel compute_non_additive(Image_tree tree,int size,enum Information_Cost cost,double 1361 static Pixel compute_non_additive(Image_tree tree,int size,enum Information_Cost cost,double
1372 /* method: method of filtering */ 1371 /* method: method of filtering */
1373 /* -------------------------------------------------------------------- */ 1372 /* -------------------------------------------------------------------- */
1374 /* Description: Carries out the wavelettransform */ 1373 /* Description: Carries out the wavelettransform */
1375 /* */ 1374 /* */
1376 /************************************************************************/ 1375 /************************************************************************/
1377 extern Image_tree wavelettransform(Image original,int level,FilterGH *flt,enum FilterMethod method) 1376 Image_tree wavelettransform(Image original,int level,FilterGH *flt,enum FilterMethod method)
1378 { int i,width,height,min,max_level,e; 1377 { int i,width,height,min,max_level,e;
1379 Image coarsei,horizontali,verticali,diagonali,tempi; 1378 Image coarsei,horizontali,verticali,diagonali,tempi;
1380 Image_tree ret_tree,temp_tree; 1379 Image_tree ret_tree,temp_tree;
1381 1380
1382 width=original->width; 1381 width=original->width;
1530 error: 1529 error:
1531 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory)); 1530 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
1532 return NULL; 1531 return NULL;
1533 } 1532 }
1534 1533
1535 extern Image_tree wavelettransform_wp(Image original, int level, FilterGH *flt, enum FilterMethod method) { 1534 Image_tree wavelettransform_wp(Image original, int level, FilterGH *flt, enum FilterMethod method) {
1536 wavelettransform__wp(original, 0, level, flt, method); 1535 return wavelettransform__wp(original, 0, level, flt, method);
1537 } 1536 }
1538 1537
1539 1538
1540 /************************************************************************/ 1539 /************************************************************************/
1541 /* Functionname: best_basis */ 1540 /* Functionname: best_basis */
1549 /* epsilon: limit for threshold method */ 1548 /* epsilon: limit for threshold method */
1550 /* -------------------------------------------------------------------- */ 1549 /* -------------------------------------------------------------------- */
1551 /* Description: carries best basis and near best basis selection */ 1550 /* Description: carries best basis and near best basis selection */
1552 /* out */ 1551 /* out */
1553 /************************************************************************/ 1552 /************************************************************************/
1554 extern Image_tree best_basis(Image original,int level,FilterGH *flt, 1553 Image_tree best_basis(Image original,int level,FilterGH *flt,
1555 enum FilterMethod method,enum Information_Cost cost,double epsilon) 1554 enum FilterMethod method,enum Information_Cost cost,double epsilon)
1556 1555
1557 { Image_tree tree; 1556 { Image_tree tree;
1558 Image img; 1557 Image img;
1559 int min,max_level,e; 1558 int min,max_level,e;
1596 /* epsilon: limit for threshold method */ 1595 /* epsilon: limit for threshold method */
1597 /* -------------------------------------------------------------------- */ 1596 /* -------------------------------------------------------------------- */
1598 /* Description: Carries out the best level selection */ 1597 /* Description: Carries out the best level selection */
1599 /* */ 1598 /* */
1600 /************************************************************************/ 1599 /************************************************************************/
1601 extern Image_tree best_level(Image original,int maxlevel,int *bestlevel,FilterGH *flt,enum FilterMethod method, 1600 Image_tree best_level(Image original,int maxlevel,int *bestlevel,FilterGH *flt,enum FilterMethod method,
1602 enum Information_Cost cost,double epsilon) 1601 enum Information_Cost cost,double epsilon)
1603 { Image_tree tree; 1602 { Image_tree tree;
1604 Image img; 1603 Image img;
1605 double *entropies,min; 1604 double *entropies,min;
1606 int best=0,i,e; 1605 int best=0,i,e;
1750 /* epsilon: limit for threshold method */ 1749 /* epsilon: limit for threshold method */
1751 /* -------------------------------------------------------------------- */ 1750 /* -------------------------------------------------------------------- */
1752 /* Description: whole decompositing down to maxlevel */ 1751 /* Description: whole decompositing down to maxlevel */
1753 /* The original image must be in tree->image */ 1752 /* The original image must be in tree->image */
1754 /************************************************************************/ 1753 /************************************************************************/
1755 extern int decompose_all(Image_tree tree,int maxlevel,FilterGH *flt,enum FilterMethod method, 1754 int decompose_all(Image_tree tree,int maxlevel,FilterGH *flt,enum FilterMethod method,
1756 enum Information_Cost cost,double epsilon) 1755 enum Information_Cost cost,double epsilon)
1757 { 1756 {
1758 Image original,coarse,horizontal,vertical,diagonal; 1757 Image original,coarse,horizontal,vertical,diagonal;
1759 int e,width,height,level; 1758 int e,width,height,level;
1760 1759
1817 /* cost: carry best basis selection out with this costfunc */ 1816 /* cost: carry best basis selection out with this costfunc */
1818 /* epsilon: limit for threshold method */ 1817 /* epsilon: limit for threshold method */
1819 /* -------------------------------------------------------------------- */ 1818 /* -------------------------------------------------------------------- */
1820 /* Description: Compute the entropies of all decomposition levels */ 1819 /* Description: Compute the entropies of all decomposition levels */
1821 /************************************************************************/ 1820 /************************************************************************/
1822 static compute_levels(Image_tree tree,double *entropies,enum Information_Cost cost,double epsilon) 1821 static void compute_levels(Image_tree tree,double *entropies,enum Information_Cost cost,double epsilon)
1823 { 1822 {
1824 if (tree->image){ 1823 if (tree->image){
1825 entropies[tree->level]+=compute_entropy(tree->image,cost,epsilon); 1824 entropies[tree->level]+=compute_entropy(tree->image,cost,epsilon);
1826 } 1825 }
1827 if (tree->coarse) compute_levels(tree->coarse,entropies,cost,epsilon); 1826 if (tree->coarse) compute_levels(tree->coarse,entropies,cost,epsilon);
1838 /* tree: Image tree which should be cleaned */ 1837 /* tree: Image tree which should be cleaned */
1839 /* best: best level */ 1838 /* best: best level */
1840 /* -------------------------------------------------------------------- */ 1839 /* -------------------------------------------------------------------- */
1841 /* Description: clean the image tree except the best level */ 1840 /* Description: clean the image tree except the best level */
1842 /************************************************************************/ 1841 /************************************************************************/
1843 static free_levels(Image_tree tree,int best) 1842 static void free_levels(Image_tree tree,int best)
1844 { 1843 {
1845 if (tree->level<best) 1844 if (tree->level<best)
1846 { 1845 {
1847 free_image(tree->image); 1846 free_image(tree->image);
1848 tree->image=NULL; 1847 tree->image=NULL;
1874 /* method: transform with filter method */ 1873 /* method: transform with filter method */
1875 /* -------------------------------------------------------------------- */ 1874 /* -------------------------------------------------------------------- */
1876 /* Description: Decomposes an image to an certain level and stores */ 1875 /* Description: Decomposes an image to an certain level and stores */
1877 /* only this level in the returned quadtree */ 1876 /* only this level in the returned quadtree */
1878 /************************************************************************/ 1877 /************************************************************************/
1879 extern Image_tree decompose_to_level(Image original,int level,FilterGH *flt,enum FilterMethod method) 1878 Image_tree decompose_to_level(Image original,int level,FilterGH *flt,enum FilterMethod method)
1880 { Image_tree tree; 1879 { Image_tree tree;
1881 int e; 1880 int e;
1882 1881
1883 tree=new_image_tree(); 1882 tree=new_image_tree();
1884 tree->image=original; 1883 tree->image=original;
2002 /* RETURN: returns the build up image */ 2001 /* RETURN: returns the build up image */
2003 /* -------------------------------------------------------------------- */ 2002 /* -------------------------------------------------------------------- */
2004 /* Description: builds up an image out of an Image_tree */ 2003 /* Description: builds up an image out of an Image_tree */
2005 /* */ 2004 /* */
2006 /************************************************************************/ 2005 /************************************************************************/
2007 extern Image build_image(Image_tree quadtree,int width,int height) 2006 Image build_image(Image_tree quadtree,int width,int height)
2008 { Image ret_img,coarse,horizontal,vertical,diagonal; 2007 { Image ret_img,coarse,horizontal,vertical,diagonal;
2009 2008
2010 2009
2011 ret_img=new_image(width,height); 2010 ret_img=new_image(width,height);
2012 if(!ret_img) goto error; 2011 if(!ret_img) goto error;
2049 /* method: transform with filter method */ 2048 /* method: transform with filter method */
2050 /* -------------------------------------------------------------------- */ 2049 /* -------------------------------------------------------------------- */
2051 /* Description: Inverts the wavelettransform,best_basis,best_level */ 2050 /* Description: Inverts the wavelettransform,best_basis,best_level */
2052 /* */ 2051 /* */
2053 /************************************************************************/ 2052 /************************************************************************/
2054 extern Image inv_transform(Image_tree tree,FilterGH *flt, 2053 Image inv_transform(Image_tree tree,FilterGH *flt,
2055 enum FilterMethod method) 2054 enum FilterMethod method)
2056 2055
2057 { int er,width,height; 2056 { int er,width,height;
2058 Image ret_img,coarse,vertical,horizontal,diagonal; 2057 Image ret_img,coarse,vertical,horizontal,diagonal;
2059 2058
2107 /* Parameter: */ 2106 /* Parameter: */
2108 /* -------------------------------------------------------------------- */ 2107 /* -------------------------------------------------------------------- */
2109 /* Description: Finds the deepest possible level where width and */ 2108 /* Description: Finds the deepest possible level where width and */
2110 /* height can divided by two exactly. */ 2109 /* height can divided by two exactly. */
2111 /************************************************************************/ 2110 /************************************************************************/
2112 extern int find_deepest_level(int width,int height) 2111 int find_deepest_level(int width,int height)
2113 { 2112 {
2114 int level=0,w=width,h=height; 2113 int level=0,w=width,h=height;
2115 2114
2116 while ( !((w%2)||(h%2))) 2115 while ( !((w%2)||(h%2)))
2117 { 2116 {
2386 if (!list) goto error; 2385 if (!list) goto error;
2387 2386
2388 recarea(tree,list,list_size); 2387 recarea(tree,list,list_size);
2389 abs_list(list,*list_size); 2388 abs_list(list,*list_size);
2390 2389
2391 qsort(list,*list_size, sizeof(Pixel), &comp); 2390 qsort(list,*list_size, sizeof(Pixel), (int (*)(const void*, const void*)) comp);
2392 2391
2393 for (k=0;k<size;k++) 2392 for (k=0;k<size;k++)
2394 { 2393 {
2395 if (k!=0) wlp=pow(k,1/p)*list[k]; 2394 if (k!=0) wlp=pow(k,1/p)*list[k];
2396 else wlp=0; 2395 else wlp=0;
2405 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory)); 2404 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
2406 return 0; 2405 return 0;
2407 } 2406 }
2408 2407
2409 static Pixel comp_number(Image_tree tree,int size,int p,double f) 2408 static Pixel comp_number(Image_tree tree,int size,int p,double f)
2410 { Pixel sum=0,*list,min,norm,npf,normf; 2409 { Pixel sum=0,*list,min=MAXDOUBLE,norm,npf,normf;
2411 int *list_size=0,k; 2410 int *list_size=0,k;
2412 2411
2413 list_size=(int *)malloc(sizeof(int)); 2412 list_size=(int *)malloc(sizeof(int));
2414 if (!list_size) goto error; 2413 if (!list_size) goto error;
2415 *list_size=0; 2414 *list_size=0;
2417 list=(Pixel *)calloc(size,sizeof(Pixel)); 2416 list=(Pixel *)calloc(size,sizeof(Pixel));
2418 if (!list) goto error; 2417 if (!list) goto error;
2419 recarea(tree,list,list_size); 2418 recarea(tree,list,list_size);
2420 abs_list(list,*list_size); 2419 abs_list(list,*list_size);
2421 2420
2422 qsort(list,*list_size, sizeof(Pixel), &comp); 2421 qsort(list,*list_size, sizeof(Pixel), (int (*)(const void*, const void*)) comp);
2423 2422
2424 norm=sum_list(list,p,size); 2423 norm=sum_list(list,p,size);
2425 normf=norm*f; 2424 normf=norm*f;
2426 2425
2427 for (k=0;k<size;k++) 2426 for (k=0;k<size;k++)
2456 if (!list) goto error; 2455 if (!list) goto error;
2457 2456
2458 recarea(tree,list,list_size); 2457 recarea(tree,list,list_size);
2459 abs_list(list,*list_size); 2458 abs_list(list,*list_size);
2460 2459
2461 qsort(list,*list_size, sizeof(Pixel), &comp); 2460 qsort(list,*list_size, sizeof(Pixel), (int (*)(const void*, const void*)) comp);
2462 2461
2463 norm=sum_list(list,p,size); 2462 norm=sum_list(list,p,size);
2464 2463
2465 for (k=0;k<size;k++) 2464 for (k=0;k<size;k++)
2466 { 2465 {
2492 list=(Pixel *)calloc(size,sizeof(Pixel)); 2491 list=(Pixel *)calloc(size,sizeof(Pixel));
2493 if (!list) goto error; 2492 if (!list) goto error;
2494 2493
2495 recarea(tree,list,list_size); 2494 recarea(tree,list,list_size);
2496 2495
2497 qsort(list,*list_size, sizeof(Pixel), &comp); 2496 qsort(list,*list_size, sizeof(Pixel), (int (*)(const void*, const void*)) comp);
2498 2497
2499 min=list[0]; 2498 min=list[0];
2500 max=list[size-1]; 2499 max=list[size-1];
2501 factor=1/(max-min); 2500 factor=1/(max-min);
2502 2501
2532 list=(Pixel *)calloc(size,sizeof(Pixel)); 2531 list=(Pixel *)calloc(size,sizeof(Pixel));
2533 if (!list) goto error; 2532 if (!list) goto error;
2534 2533
2535 recarea(tree,list,list_size); 2534 recarea(tree,list,list_size);
2536 2535
2537 qsort(list,*list_size, sizeof(Pixel), &comp); 2536 qsort(list,*list_size, sizeof(Pixel), (int (*)(const void*, const void*)) comp);
2538 2537
2539 min=list[0]; 2538 min=list[0];
2540 max=list[size-1]; 2539 max=list[size-1];
2541 factor=1/(max-min); 2540 factor=1/(max-min);
2542 2541
2574 list=(Pixel *)calloc(size+1,sizeof(Pixel)); 2573 list=(Pixel *)calloc(size+1,sizeof(Pixel));
2575 if (!list) goto error; 2574 if (!list) goto error;
2576 2575
2577 recarea(tree,list,list_size); 2576 recarea(tree,list,list_size);
2578 2577
2579 qsort(list,*list_size, sizeof(Pixel), &comp); 2578 qsort(list,*list_size, sizeof(Pixel), (int (*)(const void*, const void*)) comp);
2580 2579
2581 min=list[0]; 2580 min=list[0];
2582 max=list[size-1]; 2581 max=list[size-1];
2583 length=(max-min)/100; 2582 length=(max-min)/100;
2584 2583
2692 /* -------------------------------------------------------------------- */ 2691 /* -------------------------------------------------------------------- */
2693 /* Description: computes entropy of an image */ 2692 /* Description: computes entropy of an image */
2694 /************************************************************************/ 2693 /************************************************************************/
2695 static Pixel compute_non_additive(Image_tree tree,int size,enum Information_Cost cost,double epsilon,int down) 2694 static Pixel compute_non_additive(Image_tree tree,int size,enum Information_Cost cost,double epsilon,int down)
2696 { Pixel sum=0,normx; 2695 { Pixel sum=0,normx;
2697 Image img; 2696 Image img=NULL;
2698 2697
2699 if (down) 2698 if (down)
2700 { 2699 {
2701 img=tree->image; 2700 img=tree->image;
2702 tree->image=NULL; 2701 tree->image=NULL;
2742 if (down) tree->image=img; 2741 if (down) tree->image=img;
2743 2742
2744 return sum; 2743 return sum;
2745 } 2744 }
2746 2745
2747 extern int rec_double(Image_tree dtree,int level,FilterGH *flt,enum FilterMethod method,enum Information_Cost cost,double epsilon) 2746 int rec_double(Image_tree dtree,int level,FilterGH *flt,enum FilterMethod method,enum Information_Cost cost,double epsilon)
2748 2747
2749 { int min,width,height; 2748 { int min,width,height;
2750 double sum=0; 2749 double sum=0;
2751 Image c,h,v,d; 2750 Image c,h,v,d;
2752 2751
2852 error: 2851 error:
2853 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory)); 2852 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
2854 return 0; 2853 return 0;
2855 } 2854 }
2856 2855
2857 static save_structur(Image_tree tree,FILE *fp,int pos) 2856 static void save_structur(Image_tree tree,FILE *fp,int pos)
2858 { 2857 {
2859 int shift,next_pos,max; 2858 int shift,next_pos,max;
2860 2859
2861 if (tree->flag) 2860 if (tree->flag)
2862 { 2861 {
2868 if (tree->coarse) save_structur(tree->coarse,fp,next_pos); 2867 if (tree->coarse) save_structur(tree->coarse,fp,next_pos);
2869 if (tree->horizontal) save_structur(tree->horizontal,fp,next_pos+1); 2868 if (tree->horizontal) save_structur(tree->horizontal,fp,next_pos+1);
2870 if (tree->vertical) save_structur(tree->vertical,fp,next_pos+2); 2869 if (tree->vertical) save_structur(tree->vertical,fp,next_pos+2);
2871 if (tree->diagonal) save_structur(tree->diagonal,fp,next_pos+3); 2870 if (tree->diagonal) save_structur(tree->diagonal,fp,next_pos+3);
2872 } 2871 }
2873
2874 } 2872 }
2875 2873
2876 static int is_in_list(int *list,int len, int x) 2874 static int is_in_list(int *list,int len, int x)
2877 { 2875 {
2878 int i,found=0; 2876 int i,found=0;
2887 } 2885 }
2888 2886
2889 return found; 2887 return found;
2890 } 2888 }
2891 2889
2892 static write_flags(Image_tree tree,int *list,int len,int pos) 2890 static void write_flags(Image_tree tree,int *list,int len,int pos)
2893 { 2891 {
2894 int shift,next_pos,max; 2892 int shift,next_pos,max;
2895 2893
2896 if (is_in_list(list,len,pos)) 2894 if (is_in_list(list,len,pos))
2897 { 2895 {
2906 write_flags(tree->vertical,list,len,next_pos+2); 2904 write_flags(tree->vertical,list,len,next_pos+2);
2907 write_flags(tree->diagonal,list,len,next_pos+3); 2905 write_flags(tree->diagonal,list,len,next_pos+3);
2908 } 2906 }
2909 } 2907 }
2910 2908
2911 static read_structur(Image_tree tree,FILE *fp)
2912 {
2913 int e, flags[1000],len=0,i=0;
2914
2915 do
2916 {
2917 e=fscanf(fp,"%d ",&flags[i++]);
2918 if (e!=-1) len++;
2919 }
2920 while (e!=-1);
2921
2922 write_flags(tree,flags,len,0);
2923
2924 }
2925
2926 /************************************************************************/ 2909 /************************************************************************/
2927 /* Functionname: err_simple_message */ 2910 /* Functionname: err_simple_message */
2928 /* -------------------------------------------------------------------- */ 2911 /* -------------------------------------------------------------------- */
2929 /* Parameter: */ 2912 /* Parameter: */
2930 /* char *: string that contains information about an */ 2913 /* char *: string that contains information about an */

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.