Mercurial > hg > wm
annotate Meerwald/wm_kund_e.c @ 23:71dd4b96221b
fix some compiler warning
author | Peter Meerwald-Stadler <pmeerw@pmeerw.net> |
---|---|
date | Fri, 20 Dec 2024 12:53:41 +0100 |
parents | 4987db85cfae |
children |
rev | line source |
---|---|
3 | 1 #include "wm.h" |
2 #include "signature.h" | |
3 #include "wm_dwt.h" | |
4 #include "pgm.h" | |
5 | |
6 char *progname; | |
7 | |
8 void usage(void) { | |
9 fprintf(stderr, "usage: %s [-e n] [-f n] [-F n] [-h] [-o file] [-q n] [-v n] -s file file\n\n", progname); | |
10 fprintf(stderr, "\t-e n\t\twavelet filtering method\n"); | |
11 fprintf(stderr, "\t-f n\t\tfilter number\n"); | |
12 fprintf(stderr, "\t-F file\t\tfilter definition file\n"); | |
13 fprintf(stderr, "\t-h\t\tprint usage\n"); | |
14 fprintf(stderr, "\t-o file\t\toutput (watermarked) file\n"); | |
15 fprintf(stderr, "\t-q n\t\tquantization/quality factor\n"); | |
16 fprintf(stderr, "\t-s file\t\tsignature to embed in input image\n"); | |
17 fprintf(stderr, "\t-v n\t\tverbosity level\n"); | |
18 exit(0); | |
19 } | |
20 | |
21 int main(int argc, char *argv[]) { | |
22 | |
23 FILE *in = stdin; | |
24 FILE *out = stdout; | |
25 FILE *sig = NULL; | |
26 | |
27 char output_name[MAXPATHLEN] = "(stdout)"; | |
28 char input_name[MAXPATHLEN] = "(stdin)"; | |
29 char signature_name[MAXPATHLEN]; | |
30 | |
31 int c; | |
32 int row, col; | |
33 | |
34 int n; | |
35 | |
36 double quality = 0.0; | |
37 | |
38 int filter = 0; | |
39 int method = -1; | |
40 int level = 0; | |
41 char filter_name[MAXPATHLEN] = ""; | |
42 | |
43 int seed; | |
44 int verbose = 0; | |
45 | |
46 gray **image; | |
47 Image_tree dwts; | |
48 | |
49 gray maxval; | |
50 int rows, cols, colors, format; | |
51 | |
52 progname = argv[0]; | |
53 | |
54 pgm_init(&argc, argv); | |
55 | |
56 #ifdef __EMX__ | |
57 _fsetmode(in, "b"); | |
58 _fsetmode(out, "b"); | |
59 #endif | |
60 | |
61 while ((c = getopt(argc, argv, "e:f:F:h?l:o:q:s:v:")) != EOF) { | |
62 switch (c) { | |
63 case 'e': | |
64 method = atoi(optarg); | |
65 if (method < 0) { | |
66 fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, method); | |
67 exit(1); | |
68 } | |
69 break; | |
70 case 'f': | |
71 filter = atoi(optarg); | |
72 if (filter <= 0) { | |
73 fprintf(stderr, "%s: filter number %d out of range\n", progname, filter); | |
74 exit(1); | |
75 } | |
76 break; | |
77 case 'F': | |
78 strcpy(filter_name, optarg); | |
79 break; | |
80 case 'h': | |
81 case '?': | |
82 usage(); | |
83 break; | |
84 case 'l': | |
85 level = atoi(optarg); | |
86 if (level < 1) { | |
87 fprintf(stderr, "%s: embedding level out of range\n", progname); | |
88 exit(1); | |
89 } | |
90 break; | |
91 case 'o': | |
92 if ((out = fopen(optarg, "wb")) == NULL) { | |
93 fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg); | |
94 exit(1); | |
95 } | |
96 strcpy(output_name, optarg); | |
97 break; | |
98 case 'q': | |
99 quality = atoi(optarg); | |
100 if (quality <= 0) { | |
101 fprintf(stderr, "%s: quality factor %d out of range\n", progname, quality); | |
102 exit(1); | |
103 } | |
104 break; | |
105 case 's': | |
106 if ((sig = fopen(optarg, "r")) == NULL) { | |
107 fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg); | |
108 exit(1); | |
109 } | |
110 strcpy(signature_name, optarg); | |
111 break; | |
112 case 'v': | |
113 verbose = atoi(optarg); | |
114 if (verbose < 0) { | |
115 fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose); | |
116 exit(1); | |
117 } | |
118 break; | |
119 } | |
120 } | |
121 | |
122 argc -= optind; | |
123 argv += optind; | |
124 | |
125 if (argc > 1) { | |
126 usage(); | |
127 exit(1); | |
128 } | |
129 | |
130 if (argc == 1 && *argv[0] != '-') | |
131 if ((in = fopen(argv[0], "rb")) == NULL) { | |
132 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]); | |
133 exit(1); | |
134 } | |
135 else | |
136 strcpy(input_name, argv[0]); | |
137 | |
138 if (sig) { | |
139 char line[32]; | |
140 fgets(line, sizeof(line), sig); | |
141 if (strspn(line, "KDSG") >= 4) { | |
142 fscanf(sig, "%d\n", &n); | |
143 if (quality == 0.0) | |
144 fscanf(sig, "%lf\n", &quality); | |
145 else | |
16
4987db85cfae
fix another scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
15
diff
changeset
|
146 fscanf(sig, "%*f\n"); |
3 | 147 if (method < 0) |
148 fscanf(sig, "%d\n", &method); | |
149 else | |
150 fscanf(sig, "%*d\n"); | |
151 if (filter == 0) | |
152 fscanf(sig, "%d\n", &filter); | |
153 else | |
154 fscanf(sig, "%*d\n"); | |
155 if (!strcmp(filter_name, "")) | |
15 | 156 fscanf(sig, "%[^\n\r]\n", filter_name); |
3 | 157 else |
158 fscanf(sig, "%*[^\n\r]\n"); | |
159 if (level == 0) | |
160 fscanf(sig, "%d\n", &level); | |
161 else | |
162 fscanf(sig, "%*d\n"); | |
163 fscanf(sig, "%d\n", &seed); | |
164 srandom(seed); | |
165 n_signature = NBITSTOBYTES(nbit_signature); | |
166 fread(signature, sizeof(char), n_signature, sig); | |
167 fscanf(sig, "\n"); | |
168 } | |
169 else { | |
170 fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name); | |
171 exit(1); | |
172 } | |
173 fclose(sig); | |
174 } | |
175 else { | |
176 fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname); | |
177 exit(1); | |
178 } | |
179 | |
180 pgm_readpgminit(in, &cols, &rows, &maxval, &format); | |
181 | |
182 image = pgm_allocarray(cols, rows); | |
183 | |
184 for (row = 0; row < rows; row++) | |
185 pgm_readpgmrow(in, image[row], cols, maxval, format); | |
186 | |
187 fclose(in); | |
188 | |
189 // check watermark dimensions and decomposition level | |
190 | |
191 | |
192 // decomposition of image | |
193 init_dwt(cols, rows, filter_name, filter, level, method); | |
194 #ifdef POLLEN_STUFF | |
195 { | |
196 double alpha, beta; | |
197 char *alpha_str = getenv("POLLEN_ALPHA"), *beta_str = getenv("POLLEN_BETA"); | |
198 | |
199 if (alpha_str && beta_str) { | |
200 alpha = atof(alpha_str); | |
201 beta = atof(beta_str); | |
202 | |
203 if (alpha < -M_PI || alpha >= M_PI) { | |
204 fprintf(stderr, "%s: pollen - alpha %f out of range\n", progname, alpha); | |
205 exit(1); | |
206 } | |
207 | |
208 if (beta < -M_PI || beta >= M_PI) { | |
209 fprintf(stderr, "%s: pollen - beta %f out of range\n", progname, beta); | |
210 exit(1); | |
211 } | |
212 | |
213 if (verbose > 7) | |
214 fprintf(stderr, "%s: pollen - alpha %f, beta %f\n", progname, alpha, beta); | |
215 | |
216 dwt_pollen_filter(alpha, beta); | |
217 } | |
218 } | |
219 #endif | |
220 | |
221 dwts = fdwt(image); | |
222 | |
223 // create 'image' from binary watermark | |
224 | |
225 // decomposition of watermark | |
226 init_dwt(cols, rows, filter_name, filter, 1, method); | |
227 // dwts = fdwt(watermark); | |
228 | |
229 // calculate mean value of image and set alpha | |
230 | |
231 // setup of contrast sensitivity matrix | |
232 | |
233 // segment detail images at each level | |
234 | |
235 // calculate DFT of each segment | |
236 | |
237 // compute salience for each segment | |
238 | |
239 // calculate gamma or each detail image | |
240 | |
241 // embed watermark | |
242 | |
243 // reconstruction of watermarked image | |
244 | |
245 idwt(dwts, image); | |
246 | |
247 pgm_writepgminit(out, cols, rows, maxval, 0); | |
248 | |
249 for (row = 0; row < rows; row++) | |
250 pgm_writepgmrow(out, image[row], cols, maxval, 0); | |
251 | |
252 fclose(out); | |
253 | |
254 pgm_freearray(image, rows); | |
255 | |
256 exit(0); | |
257 } |