Mercurial > hg > wm
annotate Meerwald/gen_xie2_sig.c @ 18:3bdb67e76858
mse opt.
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 30 Jan 2009 12:46:49 +0100 |
parents | 4987db85cfae |
children |
rev | line source |
---|---|
3 | 1 #include "wm.h" |
2 #include "signature.h" | |
3 | |
4 char *progname; | |
5 | |
6 void usage(void) { | |
7 fprintf(stderr, "usage: %s [-a n] [-e n] [-f n] [-F file] [-l n] [-n n] [-o file] [-s file] [-S n] [-v n] file\n\n", progname); | |
8 fprintf(stderr, "\t-a n\t\tembedding strength (default 0.5)\n"); | |
9 fprintf(stderr, "\t-e n\t\twavelet filtering method (default 2)\n"); | |
10 fprintf(stderr, "\t-f n\t\tfilter number (default 1)\n"); | |
11 fprintf(stderr, "\t-F file\t\tfilter definition file (default 'filter.dat')\n"); | |
12 fprintf(stderr, "\t-h\t\tprint usage\n"); | |
13 fprintf(stderr, "\t-l n\t\tembedding level (default 5)\n"); | |
14 fprintf(stderr, "\t-n n\t\twatermark bit length\n"); | |
15 fprintf(stderr, "\t-o file\t\toutput file\n"); | |
16 fprintf(stderr, "\t-q n\t\tquantization level\n"); | |
17 fprintf(stderr, "\t-s file\t\tuse signature file's embedding information\n"); | |
18 fprintf(stderr, "\t-S n\t\tseed\n"); | |
19 fprintf(stderr, "\t-v n\t\tverbosity level\n"); | |
20 exit(0); | |
21 } | |
22 | |
23 int main(int argc, char *argv[]) { | |
24 FILE *in = stdin; | |
25 FILE *out = stdout; | |
26 FILE *sig = NULL; | |
27 | |
28 char output_name[MAXPATHLEN] = "(stdout)"; | |
29 char input_name[MAXPATHLEN] = "(stdin)"; | |
30 char signature_name[MAXPATHLEN]; | |
31 | |
32 int verbose = 0; | |
33 int c; | |
34 int i; | |
35 double a = 0.5; | |
36 int q = 4; | |
37 int l = 5; | |
38 int n = 0, nb; | |
39 int s = 0; | |
40 int e = 2; | |
41 int f = 1; | |
42 char F[MAXPATHLEN] = "filter.dat"; | |
43 | |
44 progname = argv[0]; | |
45 wm_init(); | |
46 | |
47 while ((c = getopt(argc, argv, "a:e:f:F:h?l:n:o:s:S:v:q:")) != EOF) { | |
48 switch (c) { | |
49 case 'a': | |
50 a = atof(optarg); | |
51 if (a <= 0.0) { | |
52 fprintf(stderr, "%s: embedding strength %f out of range\n", progname, a); | |
53 exit(1); | |
54 } | |
55 break; | |
56 case 'e': | |
57 e = atoi(optarg); | |
58 if (e < 0) { | |
59 fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, e); | |
60 } | |
61 break; | |
62 case 'q': | |
63 q = atoi(optarg); | |
64 break; | |
65 case 'f': | |
66 f = atoi(optarg); | |
67 if (f <= 0) { | |
68 fprintf(stderr, "%s: filter number %d out of range\n", progname, f); | |
69 exit(1); | |
70 } | |
71 break; | |
72 case 'F': | |
73 strcpy(F, optarg); | |
74 break; | |
75 case 'h': | |
76 case '?': | |
77 usage(); | |
78 break; | |
79 case 'l': | |
80 l = atoi(optarg); | |
81 if (l < 1) { | |
82 fprintf(stderr, "%s: embedding level out of range\n", progname); | |
83 exit(1); | |
84 } | |
85 break; | |
86 case 'n': | |
87 n = atoi(optarg); | |
88 if (n < 1 || n > 1000) { | |
89 fprintf(stderr, "%s: watermark length %d out of range\n", progname, n); | |
90 exit(1); | |
91 } | |
92 break; | |
93 case 'o': | |
94 if ((out = fopen(optarg, "wb")) == NULL) { | |
95 fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg); | |
96 exit(1); | |
97 } | |
98 strcpy(output_name, optarg); | |
99 break; | |
100 case 's': | |
101 if ((sig = fopen(optarg, "r")) == NULL) { | |
102 fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg); | |
103 exit(1); | |
104 } | |
105 strcpy(signature_name, optarg); | |
106 break; | |
107 case 'S': | |
108 s = atoi(optarg); | |
109 break; | |
110 case 'v': | |
111 verbose = atoi(optarg); | |
112 if (verbose < 0) { | |
113 fprintf(stderr, "%s: verbosity level %d out of range", progname, verbose); | |
114 exit(1); | |
115 } | |
116 break; | |
117 } | |
118 } | |
119 | |
120 argc -= optind; | |
121 argv += optind; | |
122 | |
123 if (argc > 1) { | |
124 usage(); | |
125 exit(1); | |
126 } | |
127 | |
8 | 128 if (argc == 1 && *argv[0] != '-') { |
3 | 129 if ((in = fopen(argv[0], "rb")) == NULL) { |
130 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]); | |
131 exit(1); | |
132 } | |
133 else | |
134 strcpy(input_name, argv[0]); | |
8 | 135 } |
136 | |
3 | 137 if (sig) { |
138 char line[32]; | |
139 fgets(line, sizeof(line), sig); | |
140 if (strspn(line, "XE2SG") >= 5) { | |
141 if (n == 0) | |
142 fscanf(sig, "%d\n", &n); | |
143 else | |
144 fscanf(sig, "%*d\n"); | |
145 if (a == 0.0) | |
146 fscanf(sig, "%lf\n", &a); | |
147 else | |
16
4987db85cfae
fix another scanf() warning
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
15
diff
changeset
|
148 fscanf(sig, "%*f\n"); |
3 | 149 if (e < 0) |
150 fscanf(sig, "%d\n", &e); | |
151 else | |
152 fscanf(sig, "%*d\n"); | |
153 if (f == 0) | |
154 fscanf(sig, "%d\n", &f); | |
155 else | |
156 fscanf(sig, "%*d\n"); | |
157 if (!strcmp(F, "")) | |
15 | 158 fscanf(sig, "%[^\n\r]\n", F); |
3 | 159 else |
160 fscanf(sig, "%*[^\n\r]\n"); | |
161 if (q == 0) | |
162 fscanf(sig, "%d\n", &q); | |
163 else | |
164 fscanf(sig, "%*d\n"); | |
165 if (l == 0) | |
166 fscanf(sig, "%d\n", &l); | |
167 else | |
168 fscanf(sig, "%*d\n"); | |
169 } | |
170 else { | |
171 fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name); | |
172 exit(1); | |
173 } | |
8 | 174 fclose(sig); |
3 | 175 } |
176 | |
177 if (s) | |
178 srandom(s); | |
179 else | |
180 srandom(time(NULL) * getpid()); | |
181 | |
182 if (n > 0) { | |
183 nb = fread(signature, sizeof(char), i = NBITSTOBYTES(n), in); | |
184 if (nb < i) { | |
185 fprintf(stderr, "%s: failed to read all %d signature bits from %s\n", progname, n, input_name); | |
186 exit(1); | |
187 } | |
188 } | |
189 else { | |
190 if (fscanf(in, "%128[^\n\r]", signature) == EOF) { | |
191 fprintf(stderr, "%s: failed to read signature bits from %s\n", progname, input_name); | |
192 exit(1); | |
193 } | |
194 nb = strlen(signature); | |
195 n = NBYTESTOBITS(nb); | |
196 fprintf(stderr, "%s: got %d signature bits\n", progname, n); | |
197 } | |
198 | |
199 fprintf(out, "XE2SG\n"); | |
200 fprintf(out, "%d\n", n); | |
201 fprintf(out, "%f\n", a); | |
202 fprintf(out, "%d\n", e); | |
203 fprintf(out, "%d\n", f); | |
204 fprintf(out, "%s\n", F); | |
205 fprintf(out, "%d\n", q); | |
206 fprintf(out, "%d\n", l); | |
8 | 207 fprintf(out, "%ld\n", random()); |
3 | 208 fwrite(signature, sizeof(char), nb, out); |
209 fprintf(out, "\n"); | |
210 | |
211 fclose(out); | |
212 | |
213 exit(0); | |
214 } |