Mercurial > hg > wm
comparison Meerwald/wavelet.h @ 0:be303a3f5ea8
import
| author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
|---|---|
| date | Sun, 12 Aug 2007 13:14:34 +0200 |
| parents | |
| children | f83ef905a63d |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:be303a3f5ea8 |
|---|---|
| 1 #ifndef WAVELET_H | |
| 2 | |
| 3 #include <stdio.h> | |
| 4 | |
| 5 extern char dbgstr[1000]; | |
| 6 | |
| 7 /* this are internal functions - don't use 'em! */ | |
| 8 extern void out_dbg_str(const char *str); | |
| 9 extern void start_trace(void); | |
| 10 extern void stop_trace(void); | |
| 11 extern void flush_trace_file(void); | |
| 12 | |
| 13 /* public functions / macros */ | |
| 14 #define StartTrace | |
| 15 #define StopTrace | |
| 16 | |
| 17 #define Trace(str) | |
| 18 #define TraceVar(str,var) | |
| 19 | |
| 20 #define Entering | |
| 21 #define Leaving | |
| 22 #define LeavingErr | |
| 23 #define FlushTrace | |
| 24 | |
| 25 #define Warning(str) | |
| 26 | |
| 27 #define PreCondition(exp,str) | |
| 28 #define PostCondition(exp,str) | |
| 29 | |
| 30 /* Note that if an error is added, an errormessage for this specific | |
| 31 error must also be added. Otherwise no appropriate message can | |
| 32 be displayed in an error window. ( Then "Unknown error ocurred" | |
| 33 will be displayed.) | |
| 34 The errormessage must be added to the case-construct in the | |
| 35 procedure err_GetErrorMessage | |
| 36 */ | |
| 37 | |
| 38 typedef enum | |
| 39 { | |
| 40 Error_NoError, /* No Error has happened. */ | |
| 41 Error_NotImplemented, /* A needed part has not (yet) been | |
| 42 implemented */ | |
| 43 Error_AssertionFailed, /* An assertion, pre- or postcondition failed. | |
| 44 Occurs only in buggy programs. */ | |
| 45 Error_NotEnoughMemory, /* We can't allocate the memory we need. */ | |
| 46 | |
| 47 Error_Limitation, /* Some limitation exceeded, e.g. a string | |
| 48 variable is too short */ | |
| 49 | |
| 50 | |
| 51 Error_CantOpenFile, /* The file cannot be opened */ | |
| 52 Error_CantCreateFile, | |
| 53 Error_CantWriteIntoFile, | |
| 54 Error_CantCloseFile, | |
| 55 Error_WrongFileFormat, | |
| 56 | |
| 57 Error_WidthOrHeightZero, | |
| 58 Error_CompressedZeroContent, | |
| 59 Error_OriginalZeroContent, | |
| 60 | |
| 61 Error_InternalError | |
| 62 | |
| 63 }Error; | |
| 64 | |
| 65 | |
| 66 /************************************************************************/ | |
| 67 /* Functionname: err_simple_message */ | |
| 68 /* -------------------------------------------------------------------- */ | |
| 69 /* Parameter: */ | |
| 70 /* char *: string that contains information about an */ | |
| 71 /* error the user should know. */ | |
| 72 /* -------------------------------------------------------------------- */ | |
| 73 /* Description: */ | |
| 74 /* Prints error messages for the user. */ | |
| 75 /************************************************************************/ | |
| 76 void err_SimpleMessage(char *message); | |
| 77 | |
| 78 /************************************************************************/ | |
| 79 /* Functionname: err_get_message */ | |
| 80 /* -------------------------------------------------------------------- */ | |
| 81 /* Return value: Errormessage for this specific error. */ | |
| 82 /* Parameter: */ | |
| 83 /* Error err: Error whose errormessage should be returned */ | |
| 84 /* -------------------------------------------------------------------- */ | |
| 85 /* Description: */ | |
| 86 /************************************************************************/ | |
| 87 char * err_GetErrorMessage(Error err); | |
| 88 | |
| 89 #include <stddef.h> | |
| 90 | |
| 91 typedef double Pixel; | |
| 92 | |
| 93 typedef struct Image_struct { | |
| 94 Pixel *data; | |
| 95 int width,height; | |
| 96 | |
| 97 /* redundant, for our fun only :-) */ | |
| 98 Pixel min_val,max_val; /* range of pixel-values in data */ | |
| 99 /* [min_val..max_val] */ | |
| 100 int size; /* = width * height */ | |
| 101 int bpp; /* bits per pixel of original image */ | |
| 102 } *Image; | |
| 103 | |
| 104 typedef unsigned int IntPixel; | |
| 105 | |
| 106 typedef struct IntImage_struct { | |
| 107 IntPixel *data; | |
| 108 int width, height; | |
| 109 | |
| 110 /* redundant, for our fun only :-) */ | |
| 111 IntPixel min_val,max_val; /* range of values in data */ | |
| 112 /* [min_val..max_val] */ | |
| 113 int size; /* = width * height */ | |
| 114 int bpp; /* bits per pixel of original image */ | |
| 115 } *IntImage; | |
| 116 | |
| 117 typedef struct Image_tree_struct { | |
| 118 double entropy; | |
| 119 struct Image_tree_struct *coarse,*horizontal,*vertical,*diagonal,*doubletree; | |
| 120 Image image; | |
| 121 int level; | |
| 122 int flag; | |
| 123 | |
| 124 void *codec_data; | |
| 125 IntImage significance_map; | |
| 126 } *Image_tree; | |
| 127 | |
| 128 typedef struct Image_info_struct { | |
| 129 Pixel min,max,mean,var,rms; | |
| 130 } *Image_info; | |
| 131 | |
| 132 enum zigzag_direction {zigzag_up,zigzag_down,zigzag_right,zigzag_left}; | |
| 133 | |
| 134 typedef struct Zigzag_data_struct { | |
| 135 int x,y,w,h; | |
| 136 enum zigzag_direction dir; | |
| 137 } *Zigzag_data; | |
| 138 | |
| 139 #define get_intpixel(image,x,y) ( ((image)==NULL || \ | |
| 140 (x)<0 || (x)>=(image)->width || (y)<0 || (y)>=(image)->height) \ | |
| 141 ? (IntPixel) 0 : (image)->data[(x)+(y)*(image)->width]) | |
| 142 | |
| 143 #define set_intpixel(image,x,y,val) if (!((image)==NULL || \ | |
| 144 (x)<0 || (x)>=(image)->width || (y)<0 || (y)>=(image)->height)) \ | |
| 145 (image)->data[(x)+(y)*(image)->width]=(IntPixel) (val) | |
| 146 | |
| 147 #define get_pixel(image,x,y) ( ((image)==NULL || \ | |
| 148 (x)<0 || (x)>=(image)->width || (y)<0 || (y)>=(image)->height) \ | |
| 149 ? (Pixel) 0 : (image)->data[(x)+(y)*(image)->width]) | |
| 150 | |
| 151 #define set_pixel(image,x,y,val) if (!((image)==NULL || \ | |
| 152 (x)<0 || (x)>=(image)->width || (y)<0 || (y)>=(image)->height)) \ | |
| 153 (image)->data[(x)+(y)*(image)->width]=(Pixel) (val) | |
| 154 | |
| 155 #define get_pixel_adr(image,x,y) ( ((image)==NULL || \ | |
| 156 (x)<0 || (x)>=(image)->width || (y)<0 || (y)>=(image)->height) \ | |
| 157 ? (Pixel*) NULL : (image)->data+((x)+(y)*(image)->width)) | |
| 158 | |
| 159 /* functions: */ | |
| 160 | |
| 161 extern IntImage new_intimage(int width, int height); | |
| 162 extern IntImage load_intimage(char *file, int max_val); | |
| 163 extern void free_intimage(IntImage img); | |
| 164 | |
| 165 extern void clear_intimage(IntImage img); | |
| 166 extern void copy_into_intimage(IntImage img1,IntImage img2,int x,int y); | |
| 167 extern void copy_part_of_intimage(IntImage img1,IntImage img2,int x,int y); | |
| 168 | |
| 169 extern Image new_image(int width, int height); | |
| 170 extern void free_image(Image img); | |
| 171 extern void clear_image(Image img); | |
| 172 extern void copy_into_image(Image img1,Image img2,int x,int y); | |
| 173 extern void scale_image(Image img,int maximum); | |
| 174 extern void copy_part_of_image(Image img1,Image img2,int x,int y); | |
| 175 | |
| 176 extern void copy_part_of_image_into_image( | |
| 177 Image dest_img, int dest_x, int dest_y, | |
| 178 Image src_img, int src_x, int src_y, | |
| 179 int width, int height); | |
| 180 | |
| 181 | |
| 182 extern int string_to_pixel(char *str, Pixel *p); | |
| 183 | |
| 184 extern Image load_image(char *file, int max_val); | |
| 185 extern int save_image_P5(char *file, Image img); | |
| 186 | |
| 187 extern Image intimage_to_image(IntImage i); | |
| 188 extern IntImage image_to_intimage(Image i); | |
| 189 | |
| 190 extern Image_tree new_image_tree(); | |
| 191 extern void free_image_tree(Image_tree t); | |
| 192 | |
| 193 extern Image get_difference_image(Image image1, Image image2); | |
| 194 | |
| 195 extern void get_image_infos(Image image, Image_info info); | |
| 196 | |
| 197 extern void get_intimage_infos(IntImage image, IntPixel *min, IntPixel *max, Pixel *avg, Pixel *var); | |
| 198 | |
| 199 extern void init_zigzag(Zigzag_data zz, int width, int height); | |
| 200 extern void next_zigzag(Zigzag_data zz); | |
| 201 extern Image get_absolute_image_scaled(Image img); | |
| 202 | |
| 203 /* common macros */ | |
| 204 | |
| 205 #ifndef MIN | |
| 206 #define MIN(a,b) ((a)<(b)?(a):(b)) | |
| 207 #endif | |
| 208 | |
| 209 #ifndef MAX | |
| 210 #define MAX(a,b) ((a)>(b)?(a):(b)) | |
| 211 #endif | |
| 212 | |
| 213 enum FilterType { FTNoSymm, FTSymm, FTAntiSymm}; | |
| 214 | |
| 215 typedef struct FilterStruct { | |
| 216 enum FilterType type; | |
| 217 int hipass; | |
| 218 Pixel * data; | |
| 219 int start,end; | |
| 220 | |
| 221 int len; | |
| 222 } *Filter; | |
| 223 | |
| 224 extern Filter new_filter(int size); | |
| 225 | |
| 226 extern int filter_cutoff(Image in, int in_start, int in_len, int in_step, | |
| 227 Image out, int out_start, int out_len, int out_step, | |
| 228 Filter f); | |
| 229 | |
| 230 extern int filter_inv_cutoff(Image in, int in_start, int in_len, int in_step, | |
| 231 Image out, int out_start, int out_len, int out_step, | |
| 232 Filter f); | |
| 233 | |
| 234 extern int filter_periodical(Image in, int in_start, int in_len, int in_step, | |
| 235 Image out, int out_start, int out_len, int out_step, | |
| 236 Filter f); | |
| 237 | |
| 238 extern int filter_inv_periodical(Image in, int in_start, int in_len, int in_step, | |
| 239 Image out, int out_start, int out_len, int out_step, | |
| 240 Filter f); | |
| 241 | |
| 242 extern int filter_mirror(Image in, int in_start, int in_len, int in_step, | |
| 243 Image out, int out_start, int out_len, int out_step, | |
| 244 Filter f); | |
| 245 | |
| 246 extern int filter_inv_mirror(Image in, int in_start, int in_len, int in_step, | |
| 247 Image out, int out_start, int out_len, int out_step, | |
| 248 Filter f); | |
| 249 | |
| 250 extern Pixel get_filter_center(Filter f); | |
| 251 | |
| 252 enum FilterGHType { FTOrtho, FTBiOrtho, FTOther}; | |
| 253 | |
| 254 typedef struct FilterGHStruct { | |
| 255 enum FilterGHType type; | |
| 256 Filter g, h, gi, hi; | |
| 257 char *name; | |
| 258 } *FilterGH; | |
| 259 | |
| 260 typedef struct AllFilterStruct { | |
| 261 FilterGH *filter; | |
| 262 int count; | |
| 263 } *AllFilters; | |
| 264 | |
| 265 | |
| 266 extern AllFilters load_filters(char *name); | |
| 267 | |
| 268 typedef struct SegmentsStruct { | |
| 269 int width,height; /* segment width & height*/ | |
| 270 int *data; | |
| 271 } *Segments; | |
| 272 | |
| 273 enum FilterMethod{cutoff,inv_cutoff,periodical,inv_periodical,mirror,inv_mirror}; | |
| 274 | |
| 275 enum Information_Cost{threshold,log_energy,entropy,norml,norml2,gauss_markov, | |
| 276 shanon,weak_l,weak_lq,compression_number,compression_numberq, | |
| 277 compression_area,compression_areaq,sdiscrepancy,discrepancy,concentration}; | |
| 278 | |
| 279 extern Image_tree wavelettransform(Image original,int level,FilterGH *flt,enum FilterMethod method); | |
| 280 extern Image_tree wavelettransform_wp(Image original,int level,FilterGH *flt,enum FilterMethod method); | |
| 281 | |
| 282 extern Image_tree best_basis(Image original,int level,FilterGH *flt, | |
| 283 enum FilterMethod method,enum Information_Cost cost,double epsilon); | |
| 284 | |
| 285 extern Image_tree best_level(Image original,int maxlevel,int *bestlevel,FilterGH *flt,enum FilterMethod method, | |
| 286 enum Information_Cost cost,double epsilon); | |
| 287 | |
| 288 extern Image build_image(Image_tree quadtree,int width,int height); | |
| 289 | |
| 290 extern Image inv_transform(Image_tree quadtree,FilterGH *flt, | |
| 291 enum FilterMethod method); | |
| 292 | |
| 293 extern Image inv_transform_wp(Image_tree quadtree,FilterGH *flt, | |
| 294 enum FilterMethod method); | |
| 295 | |
| 296 extern int rec_double(Image_tree dtree,int level,FilterGH *flt,enum FilterMethod method,enum Information_Cost cost,double epsilon); | |
| 297 | |
| 298 extern Image_tree decompose_to_level(Image original,int level,FilterGH *flt,enum FilterMethod method); | |
| 299 | |
| 300 extern decompose_all(Image_tree tree,int maxlevel,FilterGH *flt,enum FilterMethod method, | |
| 301 enum Information_Cost cost,double epsilon); | |
| 302 | |
| 303 extern int find_deepest_level(int width,int height); | |
| 304 | |
| 305 /*Selective methods*/ | |
| 306 extern int selectiv_tiling1(Image img,Segments seg,int filternumber,char *file, | |
| 307 enum Information_Cost cost,double epsilon); | |
| 308 extern Image inv_selectiv_tiling1(char *file); | |
| 309 | |
| 310 extern int selectiv_tiling2(Image img,Segments seg,int filternumber,char *file, | |
| 311 enum Information_Cost cost,double epsilon); | |
| 312 extern Image inv_selectiv_tiling2(char *file); | |
| 313 | |
| 314 extern int selectiv_quant1(Image img,IntImage area,int filternumber,char *file, | |
| 315 enum Information_Cost cost,double epsilon); | |
| 316 extern Image inv_selectiv_quant1(char *file); | |
| 317 | |
| 318 extern int selectiv_quant2(Image img,IntImage area,int filternumber,char *file, | |
| 319 enum Information_Cost cost,double epsilon); | |
| 320 extern Image inv_selectiv_quant2(char *file); | |
| 321 | |
| 322 extern int selectiv_quant3(Image img,IntImage area,int filternumber,char *file, | |
| 323 enum Information_Cost cost,double epsilon); | |
| 324 extern Image inv_selectiv_quant3(char *file); | |
| 325 | |
| 326 extern smooth_block(Image img,int x,int y, int width,int height); | |
| 327 | |
| 328 extern compute_map(Image_tree tree,IntImage map); | |
| 329 | |
| 330 extern int *pixelarray_to_intarray(Pixel *pdata,int size); | |
| 331 extern Pixel *intarray_to_pixelarray(int *idata,int size); | |
| 332 | |
| 333 #define WAVELET_H | |
| 334 #endif |
