Mercurial > hg > wm
comparison Meerwald/gen_xie2_sig.c @ 3:acb6967ee76d
update to 0.5
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Tue, 14 Aug 2007 21:11:21 +0200 |
parents | |
children | f83ef905a63d |
comparison
equal
deleted
inserted
replaced
2:b92f06d9a967 | 3:acb6967ee76d |
---|---|
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 | |
128 if (argc == 1 && *argv[0] != '-') | |
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]); | |
135 | |
136 if (sig) { | |
137 char line[32]; | |
138 fgets(line, sizeof(line), sig); | |
139 if (strspn(line, "XE2SG") >= 5) { | |
140 if (n == 0) | |
141 fscanf(sig, "%d\n", &n); | |
142 else | |
143 fscanf(sig, "%*d\n"); | |
144 if (a == 0.0) | |
145 fscanf(sig, "%lf\n", &a); | |
146 else | |
147 fscanf(sig, "%*lf\n"); | |
148 if (e < 0) | |
149 fscanf(sig, "%d\n", &e); | |
150 else | |
151 fscanf(sig, "%*d\n"); | |
152 if (f == 0) | |
153 fscanf(sig, "%d\n", &f); | |
154 else | |
155 fscanf(sig, "%*d\n"); | |
156 if (!strcmp(F, "")) | |
157 fscanf(sig, "%[^\n\r]\n", &F); | |
158 else | |
159 fscanf(sig, "%*[^\n\r]\n"); | |
160 if (q == 0) | |
161 fscanf(sig, "%d\n", &q); | |
162 else | |
163 fscanf(sig, "%*d\n"); | |
164 if (l == 0) | |
165 fscanf(sig, "%d\n", &l); | |
166 else | |
167 fscanf(sig, "%*d\n"); | |
168 } | |
169 else { | |
170 fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name); | |
171 exit(1); | |
172 } | |
173 close(sig); | |
174 } | |
175 | |
176 if (s) | |
177 srandom(s); | |
178 else | |
179 srandom(time(NULL) * getpid()); | |
180 | |
181 if (n > 0) { | |
182 nb = fread(signature, sizeof(char), i = NBITSTOBYTES(n), in); | |
183 if (nb < i) { | |
184 fprintf(stderr, "%s: failed to read all %d signature bits from %s\n", progname, n, input_name); | |
185 exit(1); | |
186 } | |
187 } | |
188 else { | |
189 if (fscanf(in, "%128[^\n\r]", signature) == EOF) { | |
190 fprintf(stderr, "%s: failed to read signature bits from %s\n", progname, input_name); | |
191 exit(1); | |
192 } | |
193 nb = strlen(signature); | |
194 n = NBYTESTOBITS(nb); | |
195 fprintf(stderr, "%s: got %d signature bits\n", progname, n); | |
196 } | |
197 | |
198 fprintf(out, "XE2SG\n"); | |
199 fprintf(out, "%d\n", n); | |
200 fprintf(out, "%f\n", a); | |
201 fprintf(out, "%d\n", e); | |
202 fprintf(out, "%d\n", f); | |
203 fprintf(out, "%s\n", F); | |
204 fprintf(out, "%d\n", q); | |
205 fprintf(out, "%d\n", l); | |
206 fprintf(out, "%d\n", random()); | |
207 fwrite(signature, sizeof(char), nb, out); | |
208 fprintf(out, "\n"); | |
209 | |
210 fclose(out); | |
211 | |
212 exit(0); | |
213 } |