annotate Fotopoulos/cast-sub.c @ 14:1906e659edd0

fix undef. behaviour
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Mon, 30 Jun 2008 15:46:32 +0200
parents cbecc570129d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1 /* Watermarking program - Subband DCT Transform based */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2 /* Module : Casting */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
3 /* Author : Vassilis Fotopoulos */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
4 /* Date : 25/4/2000 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
5 /* Revision : 7.0 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
6 /* Developed at : ELLAB */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
7 /* Electronics Laboratory */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
8 /* Department of Physics */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
9 /* University of Patras - GREECE */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
10 /* Copyleft (c) 1999 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
11 /*------------------------------------------------------*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 /* pseudorandom noise generator's code is */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
13 /* taken from "Numerical Recipes in C" */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
14 /* FCT implementation from University of Bath */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15 /*------------------------------------------------------*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 #include <stdio.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17 #include <stdlib.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 #include <string.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19 #include <math.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 #include <float.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21 #include <getopt.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22 #include "common.h"
13
cbecc570129d cleanup warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
23 #include "pgm.h"
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25 void add_hor_add_ver(double **in, int N, double **out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26 void add_hor_sub_ver(double **in, int N, double **out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27 void sub_hor_add_ver(double **in, int N, double **out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28 void sub_hor_sub_ver(double **in, int N, double **out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29 void band_synthesis(double **ll, double **lh, double **hl, double **hh, int N, double **s);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30 void watermark(double **i, int N, long key, long int L, long int M, double a);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32 double cu[1024];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 double cv[1024];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34 int height, width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37 void add_hor_add_ver(double **in, int N, double **out)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 double **temp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 int r, c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 temp = dmatrix(N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42 for (r = 0; r < N; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43 for (c = 0; c < N / 2; c++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 temp[r][c] = (in[r][2 * c] + in[r][2 * c + 1]) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45 for (c = 0; c < N / 2; c++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46 for (r = 0; r < N / 2; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 out[r][c] = (temp[2 * r][c] + temp[2 * r + 1][c]) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48 freematrix_d(temp, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 void add_hor_sub_ver(double **in, int N, double **out)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 double **temp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 int r, c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55 temp = dmatrix(N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 for (r = 0; r < N; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 for (c = 0; c < N / 2; c++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 temp[r][c] = (in[r][2 * c] + in[r][2 * c + 1]) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 for (c = 0; c < N / 2; c++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 for (r = 0; r < N / 2; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 out[r][c] = (temp[2 * r][c] - temp[2 * r + 1][c]) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 freematrix_d(temp, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 void sub_hor_add_ver(double **in, int N, double **out)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67 double **temp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68 int r, c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69 temp = dmatrix(N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 for (r = 0; r < N; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 for (c = 0; c < N / 2; c++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72 temp[r][c] = (in[r][2 * c] - in[r][2 * c + 1]) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 for (c = 0; c < N / 2; c++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74 for (r = 0; r < N / 2; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 out[r][c] = (temp[2 * r][c] + temp[2 * r + 1][c]) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 freematrix_d(temp, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 void sub_hor_sub_ver(double **in, int N, double **out)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 double **temp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82 int r, c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83 temp = dmatrix(N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84 for (r = 0; r < N; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85 for (c = 0; c < N / 2; c++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86 temp[r][c] = (in[r][2 * c] - in[r][2 * c + 1]) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 for (c = 0; c < N / 2; c++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 for (r = 0; r < N / 2; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89 out[r][c] = (temp[2 * r][c] - temp[2 * r + 1][c]) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 freematrix_d(temp, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93 void band_synthesis(double **ll, double **lh, double **hl, double **hh, int N, double **s)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95 int r, c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
96 double b1, b2, b3, b4;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 for (r = 0; r < N; r++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 for (c = 0; c < N; c++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 b1 = ll[r][c] + lh[r][c] + hl[r][c] + hh[r][c]; //Reconstruct each
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100 b2 = ll[r][c] + lh[r][c] - hl[r][c] - hh[r][c]; //of the pixels
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101 b3 = ll[r][c] - lh[r][c] + hl[r][c] - hh[r][c];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102 b4 = ll[r][c] - lh[r][c] - hl[r][c] + hh[r][c];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 b1 = (b1 > 255.0) ? 255.0 : b1; //Check for positive...
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 b1 = (b1 < 0.0) ? 0.0 : b1; //or negative core!
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 b2 = (b2 > 255.0) ? 255.0 : b2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 b2 = (b2 < 0.0) ? 0.0 : b2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107 b3 = (b3 > 255.0) ? 255.0 : b3;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108 b3 = (b3 < 0.0) ? 0.0 : b3;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109 b4 = (b4 > 255.0) ? 255.0 : b4;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110 b4 = (b4 < 0.0) ? 0.0 : b4;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
111 s[2*r][2*c] = b1; //Put them back in
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 s[2*r][2*c + 1] = b2; //the right position
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113 s[2*r + 1][2*c] = b3;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114 s[2*r + 1][2*c + 1] = b4;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
116 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 void watermark(double **i, int N, long key, long int L, long int M, double a)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 int row, col, count;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 long int elem, temp, seed;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 double *v;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
123 v = dvector(N * N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
124 put_matrix_2_vector(i, v, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
125 fct2d(v, N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
126 seed = key;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127 count = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128 elem = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 row = 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 col = -1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 do {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132 do {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
133 row--;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134 col++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 elem++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
136 if (col < N) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137 if (elem > M) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
138 temp = row * N + col;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
139 v[temp] += a * fabs(v[temp]) * gasdev(&seed);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
140 count++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
141 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143 } while (row > 0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144 row = 2 + col;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
145 col = -1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
146 } while (count < L);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
147 ifct2d(v, N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
148 put_vector_2_matrix(v, i, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 free(v);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
150 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
151
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
152 int main(int argc, char* argv[])
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
153 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
154 double **i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
155 double **o;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
156 FILE *in;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
157 FILE *out;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
158 int N;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
159 int c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
160 long int M1, L1, M2, L2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
161 int **image_i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
162 double **ll, **lh, **hl, **hh;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
163 double a_ll = 0.1, a_other = 0.2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
164 int wm_length_1 = 10000, wm_length_ll = 10000, coeff_start_1 = 3000,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
165 coeff_start_ll = 3000, wm_key = 123;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
166
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
167 pgm_init(&argc, argv); wm_init();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
168
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
169 while ((c = getopt(argc, argv, "a:b:t:m:s:l:k:")) != EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
170 switch (c) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
171 case 'a':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
172 a_ll = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
173 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
174 case 'b':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
175 a_other = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
176 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
177 case 't':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
178 coeff_start_1 = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
179 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
180 case 'm':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
181 wm_length_1 = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
182 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
183 case 's':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
184 coeff_start_ll = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
185 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
186 case 'l':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
187 wm_length_ll = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
188 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
189 case 'k':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
190 wm_key = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
191 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
192 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
193 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
194 argc -= optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
195 argv += optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
196
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
197 in = stdin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
198 out = stdout;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
199 open_image(in, &width, &height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
200 image_i = imatrix(height, width);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
201 load_image(image_i, in, width, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
202 if (height == width)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
203 N = height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
204 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
205 fprintf(stderr, "Cannot Proccess non-square images!\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
206 exit( -11);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
207 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
208 // starting coeff. for 1st level decomp.
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
209 M1 = coeff_start_1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
210 // number of coeffs to alter
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
211 L1 = wm_length_1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
212
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
213 // now the LL band
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
214 M2 = coeff_start_ll;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
215 L2 = wm_length_ll;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
216
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
217 i = dmatrix(N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
218 o = dmatrix(N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
219 ll = dmatrix(N / 2, N / 2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
220 lh = dmatrix(N / 2, N / 2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
221 hl = dmatrix(N / 2, N / 2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
222 hh = dmatrix(N / 2, N / 2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
223
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
224 matrix_i2d(image_i, i, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
225
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
226 //---------------------1o decomposition-------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
227 add_hor_add_ver(i, N, ll);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
228 add_hor_sub_ver(i, N, lh);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
229 sub_hor_add_ver(i, N, hl);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
230 sub_hor_sub_ver(i, N, hh);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
231 //---------------------Watermark medium frequency bands---
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
232 watermark(lh, N / 2, wm_key, L1, M1, a_other);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
233 watermark(hl, N / 2, wm_key, L1, M1, a_other);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
234 watermark(hh, N / 2, wm_key, L1, M1, a_other);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
235 watermark(ll, N / 2, wm_key, L2, M2, a_ll);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
236 //---------------------Synthesis stage--------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
237 band_synthesis(ll, lh, hl, hh, N / 2, o);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
238 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
239 matrix_d2i(o, image_i, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
240 save_image(image_i, out, width, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
241
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
242 fclose(in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
243 fclose(out);
13
cbecc570129d cleanup warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
244
cbecc570129d cleanup warnings
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents: 0
diff changeset
245 exit(EXIT_SUCCESS);
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
246 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
247
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
248
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
249
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
250

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