| 
0
 | 
     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
 | 
     8 void out_dbg_str(const char *str);
 | 
| 
 | 
     9 void start_trace(void);
 | 
| 
 | 
    10 void stop_trace(void);
 | 
| 
 | 
    11 void flush_trace_file(void);
 | 
| 
0
 | 
    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 
 | 
| 
8
 | 
   161 IntImage new_intimage(int width, int height);
 | 
| 
 | 
   162 IntImage load_intimage(char *file, int max_val);
 | 
| 
 | 
   163 void free_intimage(IntImage img);
 | 
| 
0
 | 
   164 
 | 
| 
8
 | 
   165 void clear_intimage(IntImage img);
 | 
| 
 | 
   166 void copy_into_intimage(IntImage img1,IntImage img2,int x,int y);
 | 
| 
 | 
   167 void copy_part_of_intimage(IntImage img1,IntImage img2,int x,int y);
 | 
| 
0
 | 
   168 
 | 
| 
8
 | 
   169 Image new_image(int width, int height);
 | 
| 
 | 
   170 void free_image(Image img);
 | 
| 
 | 
   171 void clear_image(Image img);
 | 
| 
 | 
   172 void copy_into_image(Image img1,Image img2,int x,int y);
 | 
| 
 | 
   173 void scale_image(Image img,int maximum);
 | 
| 
 | 
   174 void copy_part_of_image(Image img1,Image img2,int x,int y);
 | 
| 
0
 | 
   175 
 | 
| 
8
 | 
   176 void copy_part_of_image_into_image(
 | 
| 
0
 | 
   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 
 | 
| 
8
 | 
   182 int string_to_pixel(char *str, Pixel *p);
 | 
| 
0
 | 
   183 
 | 
| 
8
 | 
   184 Image load_image(char *file, int max_val);
 | 
| 
 | 
   185 int save_image_P5(char *file, Image img);
 | 
| 
0
 | 
   186 
 | 
| 
8
 | 
   187 Image intimage_to_image(IntImage i);
 | 
| 
 | 
   188 IntImage image_to_intimage(Image i);
 | 
| 
0
 | 
   189 
 | 
| 
8
 | 
   190 Image_tree new_image_tree();
 | 
| 
 | 
   191 void free_image_tree(Image_tree t);
 | 
| 
0
 | 
   192 
 | 
| 
8
 | 
   193 Image get_difference_image(Image image1, Image image2);
 | 
| 
0
 | 
   194 
 | 
| 
8
 | 
   195 void get_image_infos(Image image, Image_info info);
 | 
| 
0
 | 
   196 
 | 
| 
8
 | 
   197 void get_intimage_infos(IntImage image, IntPixel *min, IntPixel *max, Pixel *avg, Pixel *var);
 | 
| 
0
 | 
   198 
 | 
| 
8
 | 
   199 void init_zigzag(Zigzag_data zz, int width, int height);
 | 
| 
 | 
   200 void next_zigzag(Zigzag_data zz);
 | 
| 
 | 
   201 Image get_absolute_image_scaled(Image img);
 | 
| 
0
 | 
   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 
 | 
| 
8
 | 
   224 Filter new_filter(int size);
 | 
| 
0
 | 
   225 
 | 
| 
8
 | 
   226 int filter_cutoff(Image in, int in_start, int in_len, int in_step,
 | 
| 
0
 | 
   227 		Image out, int out_start, int out_len, int out_step,
 | 
| 
 | 
   228 		Filter f);
 | 
| 
 | 
   229 
 | 
| 
8
 | 
   230 int filter_inv_cutoff(Image in, int in_start, int in_len, int in_step,
 | 
| 
0
 | 
   231 		Image out, int out_start, int out_len, int out_step,
 | 
| 
 | 
   232 		Filter f);
 | 
| 
 | 
   233 
 | 
| 
8
 | 
   234 int filter_periodical(Image in, int in_start, int in_len, int in_step,
 | 
| 
0
 | 
   235 		Image out, int out_start, int out_len, int out_step,
 | 
| 
 | 
   236 		Filter f);
 | 
| 
 | 
   237 
 | 
| 
8
 | 
   238 int filter_inv_periodical(Image in, int in_start, int in_len, int in_step,
 | 
| 
0
 | 
   239 		Image out, int out_start, int out_len, int out_step,
 | 
| 
 | 
   240 		Filter f);
 | 
| 
 | 
   241 
 | 
| 
8
 | 
   242 int filter_mirror(Image in, int in_start, int in_len, int in_step,
 | 
| 
0
 | 
   243 		Image out, int out_start, int out_len, int out_step,
 | 
| 
 | 
   244 		Filter f);
 | 
| 
 | 
   245 
 | 
| 
8
 | 
   246 int filter_inv_mirror(Image in, int in_start, int in_len, int in_step,
 | 
| 
0
 | 
   247 		Image out, int out_start, int out_len, int out_step,
 | 
| 
 | 
   248 		Filter f);
 | 
| 
 | 
   249 
 | 
| 
8
 | 
   250 Pixel get_filter_center(Filter f);
 | 
| 
0
 | 
   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 
 | 
| 
8
 | 
   266 AllFilters load_filters(char *name);
 | 
| 
0
 | 
   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 
 | 
| 
8
 | 
   279 Image_tree wavelettransform(Image original,int level,FilterGH *flt,enum FilterMethod method);
 | 
| 
 | 
   280 Image_tree wavelettransform_wp(Image original,int level,FilterGH *flt,enum FilterMethod method);
 | 
| 
0
 | 
   281                             
 | 
| 
8
 | 
   282 Image_tree best_basis(Image original,int level,FilterGH *flt,
 | 
| 
0
 | 
   283 				enum FilterMethod method,enum Information_Cost cost,double epsilon);
 | 
| 
 | 
   284 				                             
 | 
| 
8
 | 
   285 Image_tree best_level(Image original,int maxlevel,int *bestlevel,FilterGH *flt,enum FilterMethod method,
 | 
| 
0
 | 
   286 				enum Information_Cost cost,double epsilon);
 | 
| 
 | 
   287 
 | 
| 
8
 | 
   288 Image build_image(Image_tree quadtree,int width,int height);
 | 
| 
0
 | 
   289 
 | 
| 
8
 | 
   290 Image inv_transform(Image_tree quadtree,FilterGH *flt,
 | 
| 
 | 
   291                                  enum FilterMethod method);
 | 
| 
0
 | 
   292 
 | 
| 
8
 | 
   293 Image inv_transform_wp(Image_tree quadtree,FilterGH *flt,
 | 
| 
 | 
   294                                  enum FilterMethod method);
 | 
| 
0
 | 
   295 
 | 
| 
8
 | 
   296 int rec_double(Image_tree dtree,int level,FilterGH *flt,enum FilterMethod method,enum Information_Cost cost,double epsilon);
 | 
| 
 | 
   297 
 | 
| 
 | 
   298 Image_tree decompose_to_level(Image original,int level,FilterGH *flt,enum FilterMethod method);
 | 
| 
0
 | 
   299 
 | 
| 
8
 | 
   300 int decompose_all(Image_tree tree,int maxlevel,FilterGH *flt,enum FilterMethod method,
 | 
| 
 | 
   301 				enum Information_Cost cost,double epsilon);
 | 
| 
0
 | 
   302 
 | 
| 
8
 | 
   303 int find_deepest_level(int width,int height);
 | 
| 
0
 | 
   304 
 | 
| 
 | 
   305 
 | 
| 
 | 
   306 #define WAVELET_H
 | 
| 
 | 
   307 #endif
 |