comparison Fotopoulos-dir/cast-pv.c @ 24:9f20bce6184e v0.7

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

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