comparison Meerwald/frid2_common.c @ 20:bd669312f068

suppress warnings, fix link errors
author Peter Meerwald-Stadler <pmeerw@pmeerw.net>
date Sat, 28 Jan 2023 23:54:58 +0100
parents be303a3f5ea8
children
comparison
equal deleted inserted replaced
19:0fffb6f03ebf 20:bd669312f068
1 #include "frid2_common.h" 1 #include "frid2_common.h"
2 #include "signature.h" 2 #include "signature-utils.h"
3 #include "wm.h" 3 #include "wm.h"
4 4
5 extern char *progname; 5 extern char *progname;
6 6
7 void embed_low_freq(double **dcts, int cols, int rows, double alpha, int verbose) { 7 void embed_low_freq(double **dcts, int cols, int rows, double alpha, int verbose) {
41 41
42 if (out != embed) { 42 if (out != embed) {
43 if (fabs(d - x) < fabs(d - x * BACKWARD_STEP(alpha))) 43 if (fabs(d - x) < fabs(d - x * BACKWARD_STEP(alpha)))
44 x *= FORWARD_STEP(alpha); 44 x *= FORWARD_STEP(alpha);
45 else 45 else
46 x *= BACKWARD_STEP(alpha); 46 x *= BACKWARD_STEP(alpha);
47 } 47 }
48 48
49 d = (x + x * BACKWARD_STEP(alpha)) / 2.0; 49 d = (x + x * BACKWARD_STEP(alpha)) / 2.0;
50 50
51 if (verbose > 3) 51 if (verbose > 3)
52 fprintf(stderr, "%s: embedding bit #%d (= %d) at (%d/%d): %f -> %f\n", progname, n, get_signature_bit(n), col, row, dcts[row][col], d); 52 fprintf(stderr, "%s: embedding bit #%d (= %d) at (%d/%d): %f -> %f\n", progname, n, get_signature_bit(n), col, row, dcts[row][col], d);
53 53
54 dcts[row][col] = d; 54 dcts[row][col] = d;
55 55
56 n++; 56 n++;
57 } 57 }
58 } 58 }
59 59
60 void embed_med_freq(double **dcts, int cols, int rows, double gamma, int seed, int verbose) { 60 void embed_med_freq(double **dcts, int cols, int rows, double gamma, int seed, int verbose) {
61 // select mid-frequency (30%) coefficients 61 // select mid-frequency (30%) coefficients
62 int start = (int) (0.35 * rows * cols + 0.5); 62 int start = (int) (0.35 * rows * cols + 0.5);
63 int end = (int) (0.65 * rows * cols + 0.5); 63 int end = (int) (0.65 * rows * cols + 0.5);
64 64
65 double *vector; 65 double *vector;
66 int x = 0, y = 0, dir = 1; 66 int x = 0, y = 0, dir = 1;
67 int i, j; 67 int i, j;
68 68
69 vector = malloc((end - start) * sizeof(double)); 69 vector = malloc((end - start) * sizeof(double));
70 for (i = 0; i < (end - start); i++) 70 for (i = 0; i < (end - start); i++)
71 vector[i] = 0.0; 71 vector[i] = 0.0;
72 72
73 // create pseudo-random vector 73 // create pseudo-random vector
74 srandom(seed); 74 srandom(seed);
75 for (i = 0; i < nbit_signature; i++) { 75 for (i = 0; i < nbit_signature; i++) {
76 if (get_signature_bit(i)) 76 if (get_signature_bit(i))
77 random(); 77 random();
96 // embed vector 96 // embed vector
97 if ((i - start) >= 0) { 97 if ((i - start) >= 0) {
98 // fprintf(stderr, "%d/%d: %f -> %f\n", x, y, dcts[y][x], dcts[y][x] + gamma * vector[i - start]); 98 // fprintf(stderr, "%d/%d: %f -> %f\n", x, y, dcts[y][x], dcts[y][x] + gamma * vector[i - start]);
99 dcts[y][x] += gamma * vector[i - start]; 99 dcts[y][x] += gamma * vector[i - start];
100 } 100 }
101 } 101 }
102 102
103 free(vector); 103 free(vector);
104 } 104 }
105 105
106 double detect_low_freq(double **dcts, int cols, int rows, double alpha, double beta, int verbose) { 106 double detect_low_freq(double **dcts, int cols, int rows, double alpha, double beta, int verbose) {
146 set_signature2_bit(n, out > 0 ? 1 : 0); 146 set_signature2_bit(n, out > 0 ? 1 : 0);
147 sum1 += pow(fabs(d), beta) * out * detect; 147 sum1 += pow(fabs(d), beta) * out * detect;
148 sum2 += pow(fabs(d), beta); 148 sum2 += pow(fabs(d), beta);
149 149
150 n++; 150 n++;
151 } 151 }
152 152
153 return sum1 / sum2; 153 return sum1 / sum2;
154 } 154 }
155 155
156 double detect_med_freq(double **dcts, int cols, int rows, int seed, int verbose) { 156 double detect_med_freq(double **dcts, int cols, int rows, int seed, int verbose) {
163 double *vector; 163 double *vector;
164 int startx, starty, startdir; 164 int startx, starty, startdir;
165 double corr[2]; 165 double corr[2];
166 double correlation; 166 double correlation;
167 167
168 // locate start positions 168 // locate start positions
169 for (i = 0; i < start; i++) { 169 for (i = 0; i < start; i++) {
170 x -= dir; 170 x -= dir;
171 y += dir; 171 y += dir;
172 if (x < 0) { dir = -1; x = 0; } 172 if (x < 0) { dir = -1; x = 0; }
173 if (x >= cols) { dir = 1; x = cols - 1; y += 2; } 173 if (x >= cols) { dir = 1; x = cols - 1; y += 2; }
174 if (y < 0) { dir = 1; y = 0; } 174 if (y < 0) { dir = 1; y = 0; }
175 if (y >= rows) { dir = -1; y = rows - 1; x += 2; } 175 if (y >= rows) { dir = -1; y = rows - 1; x += 2; }
176 } 176 }
177 177
178 // save start positions 178 // save start positions
179 startx = x; 179 startx = x;
180 starty = y; 180 starty = y;
181 startdir = dir; 181 startdir = dir;
182 srandom(seed); 182 srandom(seed);
183 183
184 vector = malloc((end - start) * sizeof(double)); 184 vector = malloc((end - start) * sizeof(double));
185 185
186 for (i = 0; i < nbit_signature1; i++) { 186 for (i = 0; i < nbit_signature1; i++) {
187 187
188 for (j = 0; j <= (end - start); j++) 188 for (j = 0; j <= (end - start); j++)
189 vector[j] = (double) (random() & RAND_MAX) / (double) RAND_MAX - 0.5; 189 vector[j] = (double) (random() & RAND_MAX) / (double) RAND_MAX - 0.5;
190 190
191 for (j = 0; j <= 1; j++) { 191 for (j = 0; j <= 1; j++) {
192 x = startx; 192 x = startx;
193 y = starty; 193 y = starty;
194 dir = startdir; 194 dir = startdir;
195 corr[j] = 0; 195 corr[j] = 0;
196 196
197 for (k = 0; start + k < end; k++) { 197 for (k = 0; start + k < end; k++) {
198 x -= dir; 198 x -= dir;
199 y += dir; 199 y += dir;
200 if (x < 0) { dir = -1; x = 0; } 200 if (x < 0) { dir = -1; x = 0; }
201 if (x >= cols) { dir = 1; x = cols - 1; y += 2; } 201 if (x >= cols) { dir = 1; x = cols - 1; y += 2; }
202 if (y < 0) { dir = 1; y = 0; } 202 if (y < 0) { dir = 1; y = 0; }
203 if (y >= rows) { dir = -1; y = rows - 1; x += 2; } 203 if (y >= rows) { dir = -1; y = rows - 1; x += 2; }
204 corr[j] += dcts[y][x] * vector[k + j]; 204 corr[j] += dcts[y][x] * vector[k + j];
205 } 205 }
206 } 206 }
207 207
208 set_signature2_bit(i, (corr[0] >= corr[1]) ? 0 : 1); 208 set_signature2_bit(i, (corr[0] >= corr[1]) ? 0 : 1);
209 } 209 }
210 210
211 sum = 0; sum1 = 0; sum2 = 0; 211 sum = 0; sum1 = 0; sum2 = 0;
214 sum1 += get_signature1_bit(i) * get_signature1_bit(i); 214 sum1 += get_signature1_bit(i) * get_signature1_bit(i);
215 sum2 += get_signature2_bit(i) * get_signature2_bit(i); 215 sum2 += get_signature2_bit(i) * get_signature2_bit(i);
216 } 216 }
217 correlation = (double) sum / (sqrt(sum1) * sqrt(sum2)); 217 correlation = (double) sum / (sqrt(sum1) * sqrt(sum2));
218 218
219 return correlation; 219 return correlation;
220 } 220 }

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.