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