1 /* hf_filters.h - headers for managing filters
2  *
3  * Copyright (C) 2001 Patrice St-Gelais
4  *         patrstg@users.sourceforge.net
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20 
21 #ifndef _FILTERS
22 #define _FILTERS 1
23 
24 #include "hf.h"
25 #include "hf_calc.h"
26 
27 //	Filter merge operations
28 
29 //	MULTIPLY: transform the multiplier as a ratio between 0.0 and 1.0
30 #ifndef MULTIPLY
31 	#define MULTIPLY 1
32 #endif
33 
34 //	MULTIPLY2: transform the multiplier as a ratio between 1.0 and 2.0
35 #ifndef MULTIPLY2
36 	#define MULTIPLY2 2
37 #endif
38 
39 #ifndef ADD
40 	#define ADD 3
41 #endif
42 #ifndef SUBTRACT
43 	#define SUBTRACT 4
44 #endif
45 
46 //	Standard options for gaussian filter
47 typedef struct {
48 	gfloat base;	// From 1 to 20 (1st best guess!)
49 	gfloat exp;	// From 0 to 10
50 	gfloat scale;	// From 0 to 100 %
51 } gauss_opt;
52 
53 typedef struct {
54 //	A filter struct
55 	gint hf_size;	// HF size;  allows fast check of the presence of a big enough filter struct
56 	gint size;	// Vector size = square of the quadrant size
57 			// Example:  256 for a 16 pixels wide square for a 32 pixels wide HF
58 	gfloat *values;	// == NULL when the filter is an image
59 			// These values are read using dist_matrix_struct->distances as indices
60 			// ranges:  from 0 to 1
61 	gauss_opt *opt;
62 //	2 next variables can be seen as img_opt * (may be embedded in the future?)
63 	hf_struct_type *hf;	// When the filter is an image;  otherwise == NULL;
64 	hf_struct_type *hf_scaled;	// Scaled version of the preceding structure
65 			// Could be a scaled copy of *this->hf->hf_buf
66 			// or == this->hf->hf_buf, when no scaling is necessary
67 			// Before re-scaling this->hf, we free this->hf_scaled
68 			// only when this->if_scaled is TRUE
69 			// this->hf_size is the size of this->scaled
70 	gboolean if_scaled;
71 } filter_struct;
72 
73 filter_struct *wide_filter_new(gint hf_size, dist_matrix_struct *);
74 filter_struct *medium_filter1_new(gint hf_size, dist_matrix_struct *);
75 filter_struct *medium_filter2_new(gint hf_size, dist_matrix_struct *);
76 filter_struct *sharp_filter_new(gint hf_size, dist_matrix_struct *);
77 filter_struct *image_filter_new();
78 filter_struct *gauss_filter_new(gint hf_size, dist_matrix_struct *dist, gauss_opt *opt);
79 
80 void gauss_filter_init(filter_struct *, dist_matrix_struct *);
81 void gauss_filter_reinit (filter_struct *filter, gint hf_size, dist_matrix_struct *dist);
82 
83 gauss_opt *gauss_opt_new(gfloat base, gfloat exp, gfloat scale);
84 
85 void filter_free(filter_struct *);
86 void gauss_opt_free (gauss_opt *);
87 
88 void filter_apply(hf_struct_type *, filter_struct *, dist_matrix_struct *dist,
89 		gboolean revert, gfloat level, gint merge_oper);
90 void filter_apply_uns_char(unsigned char *, filter_struct *, gint hf_size,
91 		dist_matrix_struct *dist,
92 		gboolean revert, gfloat level, gint merge_oper);
93 
94 #endif
95 
96 
97 
98 
99 
100