annotate Fotopoulos/cast-pv.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 be303a3f5ea8
children cbecc570129d
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 - Fast Cosine 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 : 21/7/1999 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
5 /* Revision : 2.01a */
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 /* (without Visual Masking) */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 /*------------------------------------------------------*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
13 /* pseudorandom noise generator's code is */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
14 /* taken from "Numerical Recipes in C" */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15 /* FCT implementation from the University of Bath */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 /*------------------------------------------------------*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17 #include <stdio.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 #include <stdlib.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19 #include <string.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 #include <math.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21 #include <float.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22 #include <getopt.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23 #include "common.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25 double cu[1024];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26 double cv[1024];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27 int height, width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30 void add_watermark(double *in, int N, int coeff_start, int wm_length, int wm_key, double wm_alpha)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32 int row, col, count;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 long int elem, L, M, temp, seed;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34 double a;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 count = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36 elem = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37 row = 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 col = -1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 M = coeff_start;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 L = wm_length;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 seed = wm_key;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42 a = wm_alpha;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43 do {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 do {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45 row--;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46 col++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 elem++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48 if (col < N) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49 if (elem > M) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50 temp = row * N + col;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 in[temp] += a * fabs(in[temp]) * gasdev(&seed);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 count++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55 } while (row > 0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 row = 2 + col;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 col = -1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 } while (count < L);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 void initialize_constants(void)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 cu[0] = cv[0] = 0.7071068;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 for (i = 1; i < 1024; i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 cu[i] = cv[i] = 1.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69 //--------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 int main(int argc, char* argv[])
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72 FILE *in, *out;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 int **image_i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74 double *image_f = NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 int N;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 int c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77 int coeff_start = 5000, wm_length = 10000, wm_key = 123;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78 double wm_alpha = 0.2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 pgm_init(&argc, argv); wm_init();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82 while ((c = getopt(argc, argv, "a:s:l:k:")) != EOF) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83 switch (c) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84 case 'a':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85 wm_alpha = atof(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 case 's':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 coeff_start = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 case 'l':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91 wm_length = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93 case 'k':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 wm_key = atoi(optarg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
96 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 argc -= optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 argv += optind;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101 in = stdin;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102 out = stdout;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 open_image(in, &width, &height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 image_i = imatrix(height, width);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 load_image(image_i, in, width, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108 if (height == width)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109 N = height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
111 fprintf(stderr, "Cannot Proccess non-square images!\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 exit( -11);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 initialize_constants();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
116 image_f = (double *)calloc(N * N, sizeof(double));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 if (image_f == NULL) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 printf("Unable to allocate the float array\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 exit(1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 put_image_from_int_2_double(image_i, image_f, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
123 fct2d(image_f, N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
124 add_watermark(image_f, N, coeff_start, wm_length, wm_key, wm_alpha);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
125 ifct2d(image_f, N, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
126 put_image_from_double_2_int(image_f, image_i, N);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127 save_image(image_i, out, width, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128 freematrix(image_i, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 free(image_f);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 fclose(in);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 fclose(out);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132 }

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