changeset 3:acb6967ee76d

update to 0.5
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Tue, 14 Aug 2007 21:11:21 +0200
parents b92f06d9a967
children 9cf6ec970448
files ANNOUNCEMENT Fotopoulos/Makefile Makefile Meerwald/Makefile Meerwald/bruyn_common.h Meerwald/cmp_kund2_sig.c Meerwald/cmp_kund3_sig.c Meerwald/cmp_kund_sig.c Meerwald/cmp_pgm.c Meerwald/cmp_xie2_sig.c Meerwald/coeff.c Meerwald/dct.c Meerwald/dct.h Meerwald/dwt.c Meerwald/dwt.h Meerwald/gen_kund2_sig.c Meerwald/gen_kund3_sig.c Meerwald/gen_kund_sig.c Meerwald/gen_xie2_sig.c Meerwald/param_stuff.c Meerwald/pollen_stuff.c Meerwald/signature.c Meerwald/signature.h Meerwald/wm.h Meerwald/wm_corvi_d.c Meerwald/wm_corvi_e.c Meerwald/wm_dugad_d.c Meerwald/wm_dugad_e.c Meerwald/wm_kim_a.c Meerwald/wm_kim_d.c Meerwald/wm_kim_e.c Meerwald/wm_kund2_d.c Meerwald/wm_kund2_e.c Meerwald/wm_kund3_d.c Meerwald/wm_kund3_e.c Meerwald/wm_kund_d.c Meerwald/wm_kund_e.c Meerwald/wm_wang_d.c Meerwald/wm_wang_e.c Meerwald/wm_xia_d.c Meerwald/wm_xia_e.c Meerwald/wm_xie2_d.c Meerwald/wm_xie2_e.c Meerwald/wm_xie_d.c Meerwald/wm_xie_e.c Meerwald/wm_zhu_d.c Meerwald/wm_zhu_e.c README make/make.linux manual.lyx manual.pdf
diffstat 51 files changed, 4529 insertions(+), 628 deletions(-) [+]
line wrap: on
line diff
--- a/ANNOUNCEMENT	Tue Aug 14 19:59:48 2007 +0200
+++ b/ANNOUNCEMENT	Tue Aug 14 21:11:21 2007 +0200
@@ -1,6 +1,6 @@
 Watermarking source
 
-version 0.4
+version 0.5
 
 
 This package provides source code for some watermarking algorithms in
@@ -59,6 +59,18 @@
         Conference on Image Processing ICIP '99, page 202,
         Kobe, Japan, October 1999.
 
+   Kund
+      refer to
+        Deepa Kundur and Dimitrios Hatzinakos.
+        Digital watermarking using multiresolution wavelet
+        decomposition. In Proceedings of IEEE ICASSP '98, volume 5, pages
+        2969-2972, Seattle, WA, USA, May 1998.
+      and
+        Deepa Kundur and D. Hatzinakos.
+        Diversity and attack characterization for improved robust
+        watermarking. IEEE Transactions on Signal Processing,
+        29(10):2383-2396, October 2001.
+
     Wang
       refer to
         Houng-Jyh Wang, Po-Chyi Su, and C.-C. Jay Kuo. 
@@ -118,7 +130,7 @@
 
 Peter Meerwald
 
-Dept. of Scientific Computing
+Dept. of Computer Sciences
 University of Salzburg
 Jakob-Haringer-Str. 2
 A-5020 Salzburg
@@ -127,6 +139,3 @@
 pmeerw@cosy.sbg.ac.at
 http://www.cosy.sbg.ac.at/~pmeerw/Watermarking
 
-+43-662-8044-6327
-
-
--- a/Fotopoulos/Makefile	Tue Aug 14 19:59:48 2007 +0200
+++ b/Fotopoulos/Makefile	Tue Aug 14 21:11:21 2007 +0200
@@ -10,22 +10,22 @@
 	$(CC) $(CFLAGS) $(INCLUDES) -o $@ -c $<
 
 cast-pv$(EXE):  cast-pv$(O) common$(O)
-	$(CC) $(LDFLAGS) -o $@ cast-pv$(O) common$(O) $(PGMLIBS)
+	$(CC) $(LDFLAGS) -o $@ cast-pv$(O) common$(O) $(PGMLIBS) $(LIBS)
 
 cast-hart$(EXE):  cast-hart$(O) common$(O)
-	$(CC) $(LDFLAGS) -o $@ cast-hart$(O) common$(O) $(PGMLIBS)
+	$(CC) $(LDFLAGS) -o $@ cast-hart$(O) common$(O) $(PGMLIBS) $(LIBS)
 
 cast-sub$(EXE):  cast-sub$(O) common$(O)
-	$(CC) $(LDFLAGS) -o $@ cast-sub$(O) common$(O) $(PGMLIBS)
+	$(CC) $(LDFLAGS) -o $@ cast-sub$(O) common$(O) $(PGMLIBS) $(LIBS)
 
 test-pv$(EXE):  test-pv$(O) common$(O)
-	$(CC) $(LDFLAGS) -o $@ test-pv$(O) common$(O) $(PGMLIBS)
+	$(CC) $(LDFLAGS) -o $@ test-pv$(O) common$(O) $(PGMLIBS) $(LIBS)
 
 test-hart$(EXE):  test-hart$(O) common$(O)
-	$(CC) $(LDFLAGS) -o $@ test-hart$(O) common$(O) $(PGMLIBS)
+	$(CC) $(LDFLAGS) -o $@ test-hart$(O) common$(O) $(PGMLIBS) $(LIBS)
 
 test-sub$(EXE):  test-sub$(O) common$(O)
-	$(CC) $(LDFLAGS) -o $@ test-sub$(O) common$(O) $(PGMLIBS)
+	$(CC) $(LDFLAGS) -o $@ test-sub$(O) common$(O) $(PGMLIBS) $(LIBS)
 
 test: cast-pv$(EXE) cast-hart$(EXE) cast-sub$(EXE) test-pv$(EXE) test-hart$(EXE) test-sub$(EXE)
 	cast-pv < ../images/lena.pgm > ../watermarked/foto-pv_lena.pgm
--- a/Makefile	Tue Aug 14 19:59:48 2007 +0200
+++ b/Makefile	Tue Aug 14 21:11:21 2007 +0200
@@ -20,7 +20,7 @@
 
 dist:
 	cp -v manual.pdf manual.ps $(WEBDIR)
-	cp -v ANNOUNCEMENT README $(WEBDIR)
+	cp -v ANNOUNCEMENT $(WEBDIR)
 	cd linux_bin ; tar -czf ../wm_linux_bin.tar.gz *
 	mv -v wm_linux_bin.tar.gz $(WEBDIR)
 	cd win32_bin ; zip -9 ../wm_win32_bin.zip *
--- a/Meerwald/Makefile	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/Makefile	Tue Aug 14 21:11:21 2007 +0200
@@ -1,25 +1,30 @@
 # Makefile
 
-# choose build platform
+# chose build plattform
 include ../make/make.config
 
+OPTIONS=-DPARAM_STUFF -DPOLLEN_STUFF
+
 all: 	tools \
 	bruyn \
 	koch \
 	corvi \
 	xia \
 	xie \
+	xie2 \
 	cox \
 	zhu \
 	dugad \
 	wang \
 	frid2 \
-	kim
+	kim \
+	kund2 \
+	kund3
 
 .SUFFIXES: .c .o .1 .ps
 
 .c$(O):
-	$(CC) $(CFLAGS) $(INCLUDES) -o $@ -c $<
+	$(CC) $(CFLAGS) $(INCLUDES) $(OPTIONS) -o $@ -c $<
 
 .1.ps:
 	$(GROFF) $< > $@ 
@@ -54,10 +59,10 @@
 toolsman: cmp_pgm.ps cmp_dct8x8.ps cmp_dct.ps
 
 toolsclean:
-	$(RM) cmp_pgm$(EXE) cmp_dct$(EXE) cmp_dct8x8$(EXE)
+	$(RM) cmp_pgm$(EXE) cmp_dct$(EXE) cmp_dct8x8$(EXE) cmp_dwt$(EXE)
 
 cmp_pgm$(EXE):  cmp_pgm$(O) $(LIBPREFIX)wm$(LIB)
-	$(CC) $(LDFLAGS) -o $@ cmp_pgm$(O) $(WMLIB) $(PGMLIBS)
+	$(CC) $(LDFLAGS) -o $@ cmp_pgm$(O) $(WMLIB) $(PGMLIBS) $(LIBS)
 
 cmp_dct$(EXE):  cmp_dct$(O) $(LIBPREFIX)wm$(LIB)
 	$(CC) $(LDFLAGS) -o $@ cmp_dct$(O) $(WMLIB) $(PGMLIBS)
@@ -373,6 +378,96 @@
 xieclean:
 	$(RM) gen_xie_sig$(EXE) wm_xie_e$(EXE) wm_xie_d$(EXE) cmp_xie_sig$(EXE)
 
+# Xie2's algorithm (DWT, blind, binary, quantization, approximation image)
+
+xie2: gen_xie2_sig$(EXE) wm_xie2_e$(EXE) wm_xie2_d$(EXE) cmp_xie2_sig$(EXE)
+
+xie2test: xie2
+	gen_xie2_sig$(EXE) -n 800 gen_xie2_sig.c > ../sigs/xie2.sig
+	wm_xie2_e$(EXE) -s ../sigs/xie2.sig -o ../watermarked/xie2_lena.pgm ../images/lena.pgm
+	wm_xie2_d$(EXE) -s ../sigs/xie2.sig -o ../wms/xie2.wm ../watermarked/xie2_lena.pgm 
+	cmp_xie2_sig$(EXE) -s ../sigs/xie2.sig ../wms/xie2.wm
+
+xie2install: xie2
+	$(CP) gen_xie2_sig$(EXE) wm_xie2_e$(EXE) wm_xie2_d$(EXE) cmp_xie2_sig$(EXE) $(INSTALLDIR)
+
+xie2man: gen_xie2_sig.ps wm_xie2_e.ps wm_xie2_d.ps
+
+wm_xie2_e$(EXE): wm_xie2_e$(O) $(LIBPREFIX)wm$(LIB) $(LIBPREFIX)wavelet$(LIB)
+	$(CC) $(LDFLAGS) -o $@ wm_xie2_e$(O) $(WMLIB) $(WAVELIB) $(LIBS) $(PGMLIBS)
+
+wm_xie2_d$(EXE): wm_xie2_d$(O) $(LIBPREFIX)wm$(LIB) $(LIBPREFIX)wavelet$(LIB)
+	$(CC) $(LDFLAGS) -o $@  wm_xie2_d$(O) $(WMLIB) $(WAVELIB) $(LIBS) $(PGMLIBS)
+
+gen_xie2_sig$(EXE): gen_xie2_sig$(O) wm$(O)
+	$(CC) $(LDFLAGS) -o $@ gen_xie2_sig$(O) wm$(O) $(LIBS)
+
+cmp_xie2_sig$(EXE): cmp_xie2_sig$(O) $(LIBPREFIX)wm$(LIB)
+	$(CC) $(LDFLAGS) -o $@ cmp_xie2_sig$(O) $(WMLIB) $(LIBS)
+
+xie2clean:
+	$(RM) gen_xie2_sig$(EXE) wm_xie2_e$(EXE) wm_xie2_d$(EXE) cmp_xie2_sig$(EXE)
+
+# Kundur's algorithm 2 (DWT, blind, binary, quantization, detail subbands, reference watermark)
+
+kund2: gen_kund2_sig$(EXE) wm_kund2_e$(EXE) wm_kund2_d$(EXE) cmp_kund2_sig$(EXE)
+
+kund2test: kund2
+	gen_kund2_sig$(EXE) -n 1000 -l 3 -q 2 gen_kund2_sig.c > ../sigs/kund2.sig
+	wm_kund2_e$(EXE) -s ../sigs/kund2.sig -o ../watermarked/kund2_lena.pgm ../images/lena.pgm
+	cjpeg -quality 70 ../watermarked/kund2_lena.pgm | djpeg | wm_kund2_d$(EXE) -s ../sigs/kund2.sig -o ../wms/kund2.wm
+	cmp_kund2_sig$(EXE) -s ../sigs/kund2.sig ../wms/kund2.wm
+
+kund2install: kund2
+	$(CP) gen_kund2_sig$(EXE) wm_kund2_e$(EXE) wm_kund2_d$(EXE) cmp_kund2_sig$(EXE) $(INSTALLDIR)
+
+kund2man: gen_kund2_sig.ps wm_kund2_e.ps wm_kund2_d.ps
+
+wm_kund2_e$(EXE): wm_kund2_e$(O) $(LIBPREFIX)wm$(LIB) $(LIBPREFIX)wavelet$(LIB)
+	$(CC) $(LDFLAGS) -o $@ wm_kund2_e$(O) $(WMLIB) $(WAVELIB) $(LIBS) $(PGMLIBS)
+
+wm_kund2_d$(EXE): wm_kund2_d$(O) $(LIBPREFIX)wm$(LIB) $(LIBPREFIX)wavelet$(LIB)
+	$(CC) $(LDFLAGS) -o $@  wm_kund2_d$(O) $(WMLIB) $(WAVELIB) $(LIBS) $(PGMLIBS)
+
+gen_kund2_sig$(EXE): gen_kund2_sig$(O) wm$(O) signature$(O)
+	$(CC) $(LDFLAGS) -o $@ gen_kund2_sig$(O) wm$(O) signature$(O) $(LIBS)
+
+cmp_kund2_sig$(EXE): cmp_kund2_sig$(O) $(LIBPREFIX)wm$(LIB)
+	$(CC) $(LDFLAGS) -o $@ cmp_kund2_sig$(O) $(WMLIB) $(LIBS)
+
+kund2clean:
+	$(RM) gen_kund2_sig$(EXE) wm_kund2_e$(EXE) wm_kund2_d$(EXE) cmp_kund2_sig$(EXE)
+
+# Kundur's algorithm 3 (DWT, blind, binary, quantization, detail subbands)
+
+kund3: gen_kund3_sig$(EXE) wm_kund3_e$(EXE) wm_kund3_d$(EXE) cmp_kund3_sig$(EXE)
+
+kund3test: kund3
+	gen_kund3_sig$(EXE) -n 1000 -l 2 -q 2 gen_kund3_sig.c > ../sigs/kund3.sig
+	wm_kund3_e$(EXE) -s ../sigs/kund3.sig -o ../watermarked/kund3_lena.pgm ../images/lena.pgm
+	wm_kund3_d$(EXE) -s ../sigs/kund3.sig -o ../wms/kund3.wm ../watermarked/kund3_lena.pgm 
+	cmp_kund3_sig$(EXE) -s ../sigs/kund3.sig ../wms/kund3.wm
+
+kund3install: kund3
+	$(CP) gen_kund3_sig$(EXE) wm_kund3_e$(EXE) wm_kund3_d$(EXE) cmp_kund3_sig$(EXE) $(INSTALLDIR)
+
+kund3man: gen_kund3_sig.ps wm_kund3_e.ps wm_kund3_d.ps
+
+wm_kund3_e$(EXE): wm_kund3_e$(O) $(LIBPREFIX)wm$(LIB) $(LIBPREFIX)wavelet$(LIB)
+	$(CC) $(LDFLAGS) -o $@ wm_kund3_e$(O) $(WMLIB) $(WAVELIB) $(LIBS) $(PGMLIBS)
+
+wm_kund3_d$(EXE): wm_kund3_d$(O) $(LIBPREFIX)wm$(LIB) $(LIBPREFIX)wavelet$(LIB)
+	$(CC) $(LDFLAGS) -o $@  wm_kund3_d$(O) $(WMLIB) $(WAVELIB) $(LIBS) $(PGMLIBS)
+
+gen_kund3_sig$(EXE): gen_kund3_sig$(O) wm$(O) signature$(O)
+	$(CC) $(LDFLAGS) -o $@ gen_kund3_sig$(O) wm$(O) signature$(O) $(LIBS)
+
+cmp_kund3_sig$(EXE): cmp_kund3_sig$(O) $(LIBPREFIX)wm$(LIB)
+	$(CC) $(LDFLAGS) -o $@ cmp_kund3_sig$(O) $(WMLIB) $(LIBS)
+
+kund3clean:
+	$(RM) gen_kund3_sig$(EXE) wm_kund3_e$(EXE) wm_kund3_d$(EXE) cmp_kund3_sig$(EXE)
+
 # Dugad's algorithm (DWT, blind)
 
 dugad: gen_dugad_sig$(EXE) wm_dugad_e$(EXE) wm_dugad_d$(EXE) cmp_dugad_sig$(EXE)
@@ -405,18 +500,18 @@
 
 
 
-clean:	coxclean bruynclean kochclean corviclean xiaclean zhuclean xieclean \
-	dugadclean kimclean wangclean frid2clean toolsclean libraryclean waveletclean
+clean:	coxclean bruynclean kochclean corviclean xiaclean zhuclean xieclean kund3clean kund2clean \
+	dugadclean kimclean wangclean frid2clean toolsclean libraryclean waveletclean xie2clean
 	$(RM) *$(O) *.ps ../sigs/* ../wms/* ../watermarked/* 
 	
 
 man:	coxman bruynman kochman corviman xiaman xieman toolsman
 
 test:	coxtest bruyntest kochtest corvitest xiatest xietest dugadtest zhutest \
-	wangtest frid2test kimtest toolstest
+	wangtest frid2test kimtest toolstest kund3test kund2test
 
 install: coxinstall bruyninstall kochinstall corviinstall xiainstall xieinstall \
-	dugadinstall zhuinstall wanginstall frid2install kiminstall toolsinstall
+	dugadinstall zhuinstall wanginstall frid2install kiminstall toolsinstall kund3install kund2install
 
 depend:
 	$(MAKEDEP) *.h *.c
--- a/Meerwald/bruyn_common.h	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/bruyn_common.h	Tue Aug 14 21:11:21 2007 +0200
@@ -38,4 +38,4 @@
 
 gray lookup_pattern(int pattern, int c, int r);
 
-#endif BRUYN_COMMON_H
+#endif /* BRUYN_COMMON_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/cmp_kund2_sig.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,215 @@
+#include "wm.h"
+#include "signature.h"
+
+char *progname;
+
+void usage(void) {
+  fprintf(stderr, "usage: %s [-h] [-C] [-o file] [-v n] -s file file\n\n", progname);
+  fprintf(stderr, "\t-C\t\toutput correlation only\n");
+  fprintf(stderr, "\t-h\t\tprint usage\n");
+  fprintf(stderr, "\t-o file\t\toutput file\n");
+  fprintf(stderr, "\t-s file\t\toriginal signature file\n");
+  fprintf(stderr, "\t-v n\t\tverbosity level\n");
+  exit(0);
+}
+
+int main(int argc, char *argv[]) {
+
+  FILE *in = stdin;
+  FILE *out = stdout;
+  FILE *sig = NULL;
+
+  char signature_name[MAXPATHLEN];
+  char output_name[MAXPATHLEN] = "(stdout)";
+  char input_name[MAXPATHLEN] = "(stdin)";
+
+  char *binstr;
+
+  int correlation_only = 0;
+
+  int c, i;
+  int quality = 0;
+  int blocksize = 0;
+  int corr = 0, match = 0;
+  int verbose = 0;
+  int filter = 0;
+  int method = 0;
+  int level = 0;
+  char filter_name[MAXPATHLEN] = "";
+  int k;
+
+  int seed;
+  char line[32];
+
+  progname = argv[0];
+
+  while ((c = getopt(argc, argv, "h?Co:s:v:")) != EOF) {
+    switch (c) {
+      case 'h':
+      case '?':
+        usage();
+        break; 
+      case 'C':
+        correlation_only = 1;
+        break;
+      case 'o':
+        if ((out = fopen(optarg, "w")) == NULL) {
+          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(output_name, optarg);
+        break;
+      case 's':
+        if ((sig = fopen(optarg, "r")) == NULL) {
+          fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(signature_name, optarg);
+        break;
+     case 'v':
+        verbose = atoi(optarg);
+        if (verbose < 0) {
+          fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
+          exit(1);
+        }
+        break;
+    }
+  }
+
+  argc -= optind;
+  argv += optind;
+
+  if (argc > 1) {
+    usage();
+    exit(1);
+  }
+
+  if (argc == 1 && *argv[0] != '-')
+    if ((in = fopen(argv[0], "r")) == NULL) {
+      fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
+      exit(1);
+    }
+    else
+      strcpy(input_name, argv[0]);
+
+  if (sig) {
+    fgets(line, sizeof(line), sig);
+    if (strspn(line, "KD2SG") >= 5) {
+      fscanf(sig, "%d\n", &nbit_signature1);
+      fscanf(sig, "%d\n", &quality);
+      fscanf(sig, "%d\n", &blocksize);
+      fscanf(sig, "%d\n", &method);
+      fscanf(sig, "%d\n", &filter);
+      fscanf(sig, "%[^\n\r]\n", &filter_name);
+      fscanf(sig, "%d\n", &level);
+      fscanf(sig, "%d\n", &seed);
+      srandom(seed);
+      n_signature1 = NBITSTOBYTES(nbit_signature1);
+
+      binstr = malloc((nbit_signature1 + 1) * sizeof(char));
+      fscanf(sig, "%[01]\n", binstr);
+      binstr_to_sig1(binstr);
+      free(binstr);
+    }
+    else {
+      fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
+      exit(1);
+    }
+    close(sig);
+  }
+  else {
+    fprintf(stderr, "%s: original signature file not specified, use -s file option\n", progname);
+    exit(1);
+  }
+
+  fgets(line, sizeof(line), in);
+  if (strspn(line, "KD2WM") >= 5) {
+    int max_nbit_signature;
+    int min_nbit_signature = -1;
+    double pe[100];
+    double pe_sum;
+    double alpha[100];
+    char *w[100];
+
+    fscanf(in, "%d\n", &max_nbit_signature);
+
+    k = 0;
+    while (!feof(in) && k < 100) {
+      int e;
+
+      fscanf(in, "%d\n", &nbit_signature2);
+      w[k] = binstr = malloc(sizeof(char) * (nbit_signature2 + 1));
+      fscanf(in, "%[01]\n", binstr);
+
+      binstr_to_sig2(binstr);
+
+      if (nbit_signature2 < min_nbit_signature || min_nbit_signature == -1)
+        min_nbit_signature = nbit_signature2;
+      e = 0;
+      for (i = 0; i < nbit_signature2; i += 2) {
+        if (get_signature1_bit(i % nbit_signature1) != get_signature2_bit(i))
+          e++;
+      }
+      if (e > 0)
+        pe[k++] = log( (1 - (e / (double) nbit_signature2)) / (e / (double) nbit_signature2));
+      else
+        pe[k++] = 0;
+    }
+
+    pe_sum = 0.0;
+    for (i = 0; i < k; i++) {
+// fprintf(stderr, "XXX pe[%d] = %f\n", i, pe[i]);
+      pe_sum += pe[i];
+    }
+
+    for (i = 0; i < k; i++) {
+      if (pe_sum != 0)
+        alpha[i] = pe[i] / pe_sum;
+      else
+        alpha[i] = 1.0;
+    }
+
+    nbit_signature = min_nbit_signature;
+    for (i = 0; i < min_nbit_signature; i++) {
+      double s = 0.0;
+      int j;
+
+      for (j = 0; j < k; j++) {
+        int bit;
+//fprintf(stderr, "XXX %d %d\n", i, j);
+        binstr_to_sig2(w[j]);
+        bit = get_signature2_bit(i) ? 1 : -1;
+        s += alpha[j] * bit;
+      }
+// fprintf(stderr, "YYY %d %f\n", i, s);
+      set_signature_bit(i, s > 0 ? 1 : 0);
+    }
+
+    free(binstr);
+  }
+  else {
+    fprintf(stderr, "%s: invalid watermark file %s\n", progname, input_name);
+    exit(1);
+  }
+
+  if (verbose > 0) {
+    fprintf(stderr, "signature length: %d\n", nbit_signature1);
+    fprintf(stderr, "watermark length: %d\n", nbit_signature);
+  }
+
+  for (i = 0; i < nbit_signature; i++)
+    if (get_signature1_bit(i % nbit_signature1) == get_signature2_bit(i))
+      corr++, match++;
+    else
+      corr--;
+
+  if (correlation_only)
+    fprintf(out, "%lf\n", (double) corr / nbit_signature2);
+  else {
+    fprintf(stderr, "redundant blocks: %d\n", k);
+    fprintf(out, "bit matches: %d/%d\n", match, nbit_signature2);
+    fprintf(out, "correlation: %lf\n", (double) corr / nbit_signature2);
+  }
+
+  exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/cmp_kund3_sig.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,156 @@
+#include "wm.h"
+#include "signature.h"
+
+char *progname;
+
+void usage(void) {
+  fprintf(stderr, "usage: %s [-h] [-C] [-o file] [-v n] -s file file\n\n", progname);
+  fprintf(stderr, "\t-C\t\toutput correlation only\n");
+  fprintf(stderr, "\t-h\t\tprint usage\n");
+  fprintf(stderr, "\t-o file\t\toutput file\n");
+  fprintf(stderr, "\t-s file\t\toriginal signature file\n");
+  fprintf(stderr, "\t-v n\t\tverbosity level\n");
+  exit(0);
+}
+
+int main(int argc, char *argv[]) {
+
+  FILE *in = stdin;
+  FILE *out = stdout;
+  FILE *sig = NULL;
+
+  char signature_name[MAXPATHLEN];
+  char output_name[MAXPATHLEN] = "(stdout)";
+  char input_name[MAXPATHLEN] = "(stdin)";
+
+  char *binstr1;
+  char *binstr2;
+
+  int correlation_only = 0;
+
+  int c, i;
+  int quality = 0;
+  int corr = 0, match = 0;
+  int verbose = 0;
+  int filter = 0;
+  int method = 0;
+  int level = 0;
+  char filter_name[MAXPATHLEN] = "";
+
+  int seed;
+  char line[32];
+
+  progname = argv[0];
+
+  while ((c = getopt(argc, argv, "h?Co:s:v:")) != EOF) {
+    switch (c) {
+      case 'h':
+      case '?':
+        usage();
+        break; 
+      case 'C':
+        correlation_only = 1;
+        break;
+      case 'o':
+        if ((out = fopen(optarg, "w")) == NULL) {
+          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(output_name, optarg);
+        break;
+      case 's':
+        if ((sig = fopen(optarg, "r")) == NULL) {
+          fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(signature_name, optarg);
+        break;
+     case 'v':
+        verbose = atoi(optarg);
+        if (verbose < 0) {
+          fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
+          exit(1);
+        }
+        break;
+    }
+  }
+
+  argc -= optind;
+  argv += optind;
+
+  if (argc > 1) {
+    usage();
+    exit(1);
+  }
+
+  if (argc == 1 && *argv[0] != '-')
+    if ((in = fopen(argv[0], "r")) == NULL) {
+      fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
+      exit(1);
+    }
+    else
+      strcpy(input_name, argv[0]);
+
+  if (sig) {
+    fgets(line, sizeof(line), sig);
+    if (strspn(line, "KD3SG") >= 5) {
+      fscanf(sig, "%d\n", &nbit_signature1);
+      fscanf(sig, "%d\n", &quality);
+      fscanf(sig, "%d\n", &method);
+      fscanf(sig, "%d\n", &filter);
+      fscanf(sig, "%[^\n\r]\n", &filter_name);
+      fscanf(sig, "%d\n", &level);
+      fscanf(sig, "%d\n", &seed);
+      srandom(seed);
+      n_signature1 = NBITSTOBYTES(nbit_signature1);
+
+      binstr1 = malloc((nbit_signature1 + 1) * sizeof(char));
+      fscanf(sig, "%[01]\n", binstr1);
+      binstr_to_sig1(binstr1);
+      free(binstr1);
+    }
+    else {
+      fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
+      exit(1);
+    }
+    close(sig);
+  }
+  else {
+    fprintf(stderr, "%s: original signature file not specified, use -s file option\n", progname);
+    exit(1);
+  }
+
+  fgets(line, sizeof(line), in);
+  if (strspn(line, "KD3WM") >= 5) {
+    fscanf(in, "%d\n", &nbit_signature2);
+    n_signature2 = NBITSTOBYTES(nbit_signature2);
+    binstr2 = malloc((nbit_signature2 + 1) * sizeof(char));
+    fscanf(in, "%[01]\n", binstr2);
+    binstr_to_sig2(binstr2);
+    free(binstr2);
+  }
+  else {
+    fprintf(stderr, "%s: invalid watermark file %s\n", progname, input_name);
+    exit(1);
+  }
+
+  if (verbose > 0) {
+    fprintf(stderr, "signature length: %d\n", nbit_signature1);
+    fprintf(stderr, "watermark length: %d\n", nbit_signature2);
+  }
+
+  for (i = 0; i < nbit_signature2; i++)
+    if (get_signature1_bit(i % nbit_signature1) == get_signature2_bit(i))
+      corr++, match++;
+    else
+      corr--;
+
+  if (correlation_only)
+    fprintf(out, "%lf\n", (double) corr / nbit_signature2);
+  else {
+    fprintf(out, "bit matches: %d/%d\n", match, nbit_signature2);
+    fprintf(out, "correlation: %lf\n", (double) corr / nbit_signature2);
+  }
+
+  exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/cmp_kund_sig.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,2 @@
+int main(int argc, char *argv[]) {
+}
--- a/Meerwald/cmp_pgm.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/cmp_pgm.c	Tue Aug 14 21:11:21 2007 +0200
@@ -4,7 +4,7 @@
 char *progname;
 
 void usage(void) {
-  fprintf(stderr, "usage: %s [-C] [-h] [-m n] [-o file] [-pP] [-r file] -i file file\n\n", progname);
+  fprintf(stderr, "usage: %s [-C] [-h] [-m n] [-o file] [-pP] -i file file\n\n", progname);
   fprintf(stderr, "\t-C\t\tprint PSNR value only\n");
   fprintf(stderr, "\t-h\t\tprint usage\n");
   fprintf(stderr, "\t-i file\t\toriginal image file\n");
@@ -12,7 +12,6 @@
   fprintf(stderr, "\t-o file\t\toutput file for difference image\n");
   fprintf(stderr, "\t-p\t\tprint PSNR, RMS and MSE\n");
   fprintf(stderr, "\t-P\t\tonly print PSNR, RMS and MSE, no difference image\n");
-  fprintf(stderr, "\t-r file\t\tROI (region-of-interest) mask (default none)\n");
   exit(0);
 }
 
@@ -21,29 +20,22 @@
   FILE *in = stdin;
   FILE *out = stdout;
   FILE *orig = NULL;
-  FILE *roi = NULL;
 
   gray **input_image;
   gray **orig_image;
-  gray **roi_image;
 
   char output_name[MAXPATHLEN] = "(stdout)";
   char input_name[MAXPATHLEN] = "(stdin)";
   char orig_name[MAXPATHLEN];
-  char roi_name[MAXPATHLEN];
 
   int in_cols, in_rows, in_format;
   gray in_maxval;
-  int roi_cols, roi_rows, roi_format;
-  gray roi_maxval;
   int orig_cols, orig_rows, orig_format;
   gray orig_maxval;
   int cols, rows, format;
   gray maxval;
   int col, row;
 
-  int roisize = 0;
-
   int i;
   int c;
 
@@ -59,7 +51,7 @@
 
   pgm_init(&argc, argv); wm_init();
 
-  while ((c = getopt(argc, argv, "h?i:m:o:r:pPC")) != EOF) {
+  while ((c = getopt(argc, argv, "h?i:m:o:pPC")) != EOF) {
     switch (c) {
       case 'h':
       case '?':
@@ -72,13 +64,6 @@
         }
         strcpy(orig_name, optarg);
         break;
-      case 'r':
-        if ((roi = fopen(optarg, "rb")) == NULL) {
-          fprintf(stderr, "%s: unable to open ROI image file %s\n", progname, optarg);
-          exit(1);
-        }
-        strcpy(roi_name, optarg);
-        break;
       case 'm':
         m = atoi(optarg);
         if (m <= 0) {
@@ -129,22 +114,11 @@
 
   pgm_readpgminit(in, &in_cols, &in_rows, &in_maxval, &in_format);
 
-  if (orig) {
-    pgm_readpgminit(orig, &orig_cols, &orig_rows, &orig_maxval, &orig_format);
+  pgm_readpgminit(orig, &orig_cols, &orig_rows, &orig_maxval, &orig_format);
 
-    if (in_cols != orig_cols || in_rows != orig_rows) {
-      fprintf(stderr, "%s: input image %s does not match dimensions of original image %s\n", progname, input_name, orig_name);
-      exit(1);
-    }
-  }
-
-  if (roi) {
-    pgm_readpgminit(roi, &roi_cols, &roi_rows, &roi_maxval, &roi_format);
-
-    if (in_cols != roi_cols || in_rows != roi_rows) {
-      fprintf(stderr, "%s: input image %s does not match dimensions of ROI image %s\n", progname, input_name, roi_name);
-      exit(1);
-    }
+  if (in_cols != orig_cols || in_rows != orig_rows) {
+    fprintf(stderr, "%s: input image %s does not match dimensions of original image %s\n", progname, input_name, orig_name);
+    exit(1);
   }
 
   cols = in_cols;
@@ -154,75 +128,45 @@
 
   input_image = pgm_allocarray(cols, rows);
   orig_image = pgm_allocarray(cols, rows);
-  roi_image = pgm_allocarray(cols, rows);
 
   for (row = 0; row < rows; row++) {
       pgm_readpgmrow(in, input_image[row], cols, in_maxval, in_format);
-      if (orig) 
-        pgm_readpgmrow(orig, orig_image[row], cols, orig_maxval, orig_format);
-      else
-        memset(orig_image[row], cols, 0);
-      if (roi) 
-        pgm_readpgmrow(roi, roi_image[row], cols, roi_maxval, roi_format);
-      else
-        memset(roi_image[row], cols, PGM_MAXMAXVAL);
+      pgm_readpgmrow(orig, orig_image[row], cols, orig_maxval, orig_format);
   }
 
   fclose(in);
-  if (orig) fclose(orig);
-  if (roi) fclose(roi);
+  fclose(orig);
 
-  max = 0;
-  min = PGM_MAXMAXVAL;
+  min = max = abs(input_image[0][0] - orig_image[0][0]);
 
   for (row = 0; row < rows; row++) {
     gray *pi = input_image[row];
     gray *po = orig_image[row];
-    gray *pr = roi_image[row];
 
     for (col = 0; col < cols; col++) {
       int diff = abs(*pi - *po);
-      int inroi = (!roi || *pr > 0);
-
-      pi++;
-      po++;
-      pr++;
-
-      if (roi && !inroi)
-        continue;
-
-      roisize++;
-
       error += sqr(diff);
       if (diff < min) min = diff;
       if (diff > max) max = diff;
 
+      pi++;
+      po++;
     }
   }
 
   for (row = 0; row < rows; row++) {
     gray *pi = input_image[row];
     gray *po = orig_image[row];
-    gray *pr = roi_image[row];
 
     for (col = 0; col < cols; col++) {
       int diff = abs(*pi - *po);
-      int inroi = (!roi || *pr > 0);
-      
-      if (!inroi) {
-        *pi = 0;
-      }
-      else {
-        if (m > 0)
-          *pi = PIXELRANGE(diff * m);
-        else
-          *pi = PIXELRANGE((double) (diff - min) / (double) (max - min) * maxval);
-      }
+      if (m > 0)
+        *pi = PIXELRANGE(diff * m);
+      else
+        *pi = PIXELRANGE((double) (diff - min) / (double) (max - min) * maxval);
 
       pi++;
       po++;
-      pr++;
-
     }
   }
 
@@ -236,16 +180,13 @@
 
   pgm_freearray(input_image, rows);
   pgm_freearray(orig_image, rows);
-  pgm_freearray(roi_image, rows);
 
   if (print_psnr || print_psnr_only) {
-    double mse = (roisize) ? error / (double) roisize : 0;
+    double mse = error / (double) (cols * rows);
     double rmse = sqrt(mse);
-    double psnr = (rmse) ? 20.0 * log(255.0 / rmse) / log(10.0) : 0;
+    double psnr = 20.0 * log(255.0 / rmse) / log(10.0);
     FILE *print = print_psnr_only ? out : stderr;
     if (!print_psnr_value_only) {
-      if (roi)
-        fprintf(print, "ROI size: %d\n", roisize);
       if (mse > 0.0) 
         fprintf(print, "PSNR: %lf dB\n", psnr);
       else 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/cmp_xie2_sig.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,152 @@
+#include "wm.h"
+#include "signature.h"
+
+char *progname;
+
+void usage(void) {
+  fprintf(stderr, "usage: %s [-h] [-C] [-o file] [-v n] -s file file\n\n", progname);
+  fprintf(stderr, "\t-C\t\toutput correlation only\n");
+  fprintf(stderr, "\t-h\t\tprint usage\n");
+  fprintf(stderr, "\t-o file\t\toutput file\n");
+  fprintf(stderr, "\t-s file\t\toriginal signature file\n");
+  fprintf(stderr, "\t-v n\t\tverbosity level\n");
+  exit(0);
+}
+
+int main(int argc, char *argv[]) {
+
+  FILE *in = stdin;
+  FILE *out = stdout;
+  FILE *sig = NULL;
+
+  char signature_name[MAXPATHLEN];
+  char output_name[MAXPATHLEN] = "(stdout)";
+  char input_name[MAXPATHLEN] = "(stdin)";
+
+  int correlation_only = 0;
+
+  int c, i;
+  int corr = 0, match = 0;
+  int verbose = 0;
+  int filter = 0;
+  int method = 0;
+  int level = 0;
+  int quant = 0;
+  double alpha = 0.0;
+  double intensity = 0.0;
+  int subband = 0;
+  char filter_name[MAXPATHLEN] = "";
+
+  int seed;
+  char line[32];
+
+  progname = argv[0];
+
+  while ((c = getopt(argc, argv, "h?Co:s:v:")) != EOF) {
+    switch (c) {
+      case 'h':
+      case '?':
+        usage();
+        break; 
+      case 'C':
+        correlation_only = 1;
+        break;
+      case 'o':
+        if ((out = fopen(optarg, "w")) == NULL) {
+          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(output_name, optarg);
+        break;
+      case 's':
+        if ((sig = fopen(optarg, "r")) == NULL) {
+          fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(signature_name, optarg);
+        break;
+     case 'v':
+        verbose = atoi(optarg);
+        if (verbose < 0) {
+          fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
+          exit(1);
+        }
+        break;
+    }
+  }
+
+  argc -= optind;
+  argv += optind;
+
+  if (argc > 1) {
+    usage();
+    exit(1);
+  }
+
+  if (argc == 1 && *argv[0] != '-')
+    if ((in = fopen(argv[0], "r")) == NULL) {
+      fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
+      exit(1);
+    }
+    else
+      strcpy(input_name, argv[0]);
+
+  if (sig) {
+    fgets(line, sizeof(line), sig);
+    if (strspn(line, "XE2SG") >= 5) {
+      fscanf(sig, "%d\n", &nbit_signature1);
+      fscanf(sig, "%lf\n", &alpha);
+      fscanf(sig, "%d\n", &method);
+      fscanf(sig, "%d\n", &filter);
+      fscanf(sig, "%[^\n\r]\n", &filter_name);
+      fscanf(sig, "%d\n", &quant);
+      fscanf(sig, "%d\n", &level);
+      fscanf(sig, "%d\n", &seed);
+      srandom(seed);
+      n_signature1 = NBITSTOBYTES(nbit_signature1);
+      fread(signature1, sizeof(char), n_signature1, sig);
+      fscanf(sig, "\n");
+    }
+    else {
+      fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
+      exit(1);
+    }
+    close(sig);
+  }
+  else {
+    fprintf(stderr, "%s: original signature file not specified, use -s file option\n", progname);
+    exit(1);
+  }
+
+  fgets(line, sizeof(line), in);
+  if (strspn(line, "XE2WM") >= 5) {
+    fscanf(in, "%d\n", &nbit_signature2);
+    n_signature2 = NBITSTOBYTES(nbit_signature2);
+    fread(signature2, sizeof(char), n_signature2, in);
+    fscanf(in, "\n");    
+  }
+  else {
+    fprintf(stderr, "%s: invalid watermark file %s\n", progname, input_name);
+    exit(1);
+  }
+
+  if (verbose > 0) {
+    fprintf(stderr, "signature length: %d\n", nbit_signature1);
+    fprintf(stderr, "watermark length: %d\n", nbit_signature2);
+  }
+
+  for (i = 0; i < nbit_signature2; i++)
+    if (get_signature1_bit(i % nbit_signature1) == get_signature2_bit(i))
+      corr++, match++;
+    else
+      corr--;
+
+  if (correlation_only)
+    fprintf(out, "%lf\n", (double) corr / nbit_signature2);
+  else {
+    fprintf(out, "bit matches: %d/%d\n", match, nbit_signature2);
+    fprintf(out, "correlation: %lf\n", (double) corr / nbit_signature2);
+  }
+
+  exit(0);
+}
--- a/Meerwald/coeff.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/coeff.c	Tue Aug 14 21:11:21 2007 +0200
@@ -14,7 +14,7 @@
    return NULL;
 #endif
   }
-  p[0] = (double *) malloc(rows * cols * sizeof(double));
+  p[0] = malloc(rows * cols * sizeof(double));
   if (!p[0]) {
 #ifdef DEBUG
     fprintf(stderr, "alloc_coeffs(): malloc() failed\n");
--- a/Meerwald/dct.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/dct.c	Tue Aug 14 21:11:21 2007 +0200
@@ -45,7 +45,7 @@
     }
   }while((1<<dct_NxN_log2N)<N);
   if (dct_NxN_costable) free(dct_NxN_costable);
-  dct_NxN_costable = (double*) malloc(N * sizeof(double));
+  dct_NxN_costable = malloc(N * sizeof(double));
 #ifdef DEBUG
   if(!dct_NxN_costable){
     fprintf(stderr, "Unable to allocate C array\n");
@@ -78,7 +78,7 @@
   N = width;
   M = height;
 
-  dct_NxN_tmp = (double *) malloc(height * sizeof(double));
+  dct_NxN_tmp = malloc(height * sizeof(double));
 #ifdef DEBUG
   if (!dct_NxN_tmp) {
     fprintf(stderr, "init_dct_NxN(): failed to allocate memory\n");
@@ -246,7 +246,7 @@
 
   for (u=0; u < N; u++)
     for (v=0; v < M; v++)
-      dcts[u][v] = ((int) pixels[u][v]-128);
+      dcts[u][v] = ((int) pixels[u][v] - 128);
 
   for (u=0; u<=M-1; u++){
     fct_noscale(dcts[u]);
@@ -539,7 +539,7 @@
         for ( j = 0 ; j < NJPEG ; j++ ) {
             temp[ i ][ j ] = 0.0;
             for ( k = 0 ; k < NJPEG ; k++ )
-                 temp[ i ][ j ] += ( (int) input[ i ][ k ]) *
+                 temp[ i ][ j ] += ( (int) input[ i ][ k ] - 128 ) *
                                    Ct[ k ][ j ];
         }
     }
@@ -593,6 +593,7 @@
             temp1 = 0.0;
             for ( k = 0 ; k < NJPEG ; k++ )
                 temp1 += Ct[ i ][ k ] * temp[ k ][ j ];
+            temp1 += 128.0;
             output[i][j] = PIXELRANGE(ROUND(temp1));
         }
     }
--- a/Meerwald/dct.h	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/dct.h	Tue Aug 14 21:11:21 2007 +0200
@@ -3,13 +3,7 @@
 
 #include "wm.h"
 #include "coeff.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
 #include "pgm.h"
-#ifdef __cplusplus
-}
-#endif
 
 extern int N;
 extern int M;
--- a/Meerwald/dwt.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/dwt.c	Tue Aug 14 21:11:21 2007 +0200
@@ -18,8 +18,10 @@
       strcpy(filter_file, filter_name);
     else
       strcpy(filter_file, "filter.dat");
+
     /* memory leak here - there is no function unload_filters() */
     dwt_allfilters = load_filters(filter_file);
+
     if (!dwt_allfilters) {
       fprintf(stderr, "init_dwt(): unable to open filter definition file %s\n", filter_file);
       return;
@@ -292,51 +294,66 @@
   return filterlength;
 }
 
-void dwt_param_filter(double alpha[], int n) {
+
+
+void dwt_param_filter(double alpha[], int param_len[]) {
   FilterGH filter;  
   int i;
-
-  filter = malloc(sizeof(struct FilterGHStruct));
-#ifdef DEBUG
-  if (!filter) {
-    fprintf(stderr, "dwt_param_filter(): malloc failed()\n");
-    return;
-  }
-#endif
-
-  filter->type = FTOrtho;
-  filter->name = "param";
-
-  filter->g = new_filter(2 * (n + 1));
-  filter->g->type = FTSymm;
-  filter->g->hipass = 1;
-  filter->g->len = gen_param_filter(filter->g->data, n, alpha,  FILTERG);
-  filter->g->start = -filter->g->len / 2;
-  filter->g->end = filter->g->len / 2 - 1;
-
-  filter->h = new_filter(2 * (n + 1));
-  filter->h->type = FTSymm;
-  filter->h->hipass = 0;
-  filter->h->len = gen_param_filter(filter->h->data, n, alpha,  FILTERH);
-  filter->h->start = -filter->h->len / 2;
-  filter->h->end = filter->h->len / 2 - 1;
+  int param_len_sum = 0;
 
 #ifdef DEBUG
   if (dwt_levels <= 0) {
-    fprintf(stderr, "dwt_pollen_filter(): level invalid - set to zero\n");
+    fprintf(stderr, "dwt_param_filter(): level invalid - set to zero\n");
     return;
   }
 #endif
 
 #ifdef DEBUG
   if (!dwt_filters) {
-    fprintf(stderr, "dwt_pollen_filter(): wm_dwt not initialized, call init_dwt() first\n");
+    fprintf(stderr, "dwt_param_filter(): wm_dwt not initialized, call init_dwt() first\n");
     return;
   }
 #endif
 
-  for (i = 0; i < dwt_levels + 1; i++)
+
+  for (i = 0; i < dwt_levels + 1; i++) {
+
+    filter = malloc(sizeof(struct FilterGHStruct));
+#ifdef DEBUG
+    if (!filter) {
+      fprintf(stderr, "dwt_param_filter(): malloc failed()\n");
+      return;
+    }
+#endif
+
+    filter->type = FTOrtho;
+    filter->name = "param";
+
+    filter->g = new_filter(2 * (param_len[i] + 1));
+    filter->g->type = FTSymm;
+    filter->g->hipass = 1;
+    filter->g->len = gen_param_filter(filter->g->data,
+				      param_len[i], &alpha[param_len_sum],
+				      FILTERG);
+    filter->g->start = -filter->g->len / 2;
+    filter->g->end = filter->g->len / 2 - 1;
+
+    filter->h = new_filter(2 * (param_len[i] + 1));
+    filter->h->type = FTSymm;
+    filter->h->hipass = 0;
+    filter->h->len = gen_param_filter(filter->h->data,
+				      param_len[i], &alpha[param_len_sum],
+				      FILTERH);
+    filter->h->start = -filter->h->len / 2;
+    filter->h->end = filter->h->len / 2 - 1;
+
+    filter->gi = 0;
+    filter->hi = 0;
+
     dwt_filters[i] = filter;
+
+    param_len_sum += param_len[i];
+  }
 }
 
 void done_dwt() {
--- a/Meerwald/dwt.h	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/dwt.h	Tue Aug 14 21:11:21 2007 +0200
@@ -18,7 +18,7 @@
 int gen_pollen_filter(double *filter, double alpha, double beta, int which);
 void dwt_pollen_filter(double alpha, double beta);
 int gen_param_filter(double *filter, int n, double alpha[], int which);
-void dwt_param_filter(double alpha[], int n);
+void dwt_param_filter(double alpha[], int param_len[]);
 void done_dwt();
 
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/gen_kund2_sig.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,220 @@
+#include "wm.h"
+#include "signature.h"
+
+char *progname;
+
+void usage(void) {
+  fprintf(stderr, "usage: %s [-b n] [-e n] [-f n] [-F file] [-l n] [-n n] [-o file] [-q n] [-s file] [-S n] [-v n] file\n\n", progname);
+  fprintf(stderr, "\t-h\t\tprint usage\n");
+  fprintf(stderr, "\t-b n\t\tblock size (default 64)\n");
+  fprintf(stderr, "\t-e n\t\twavelet filtering method (default 2)\n");
+  fprintf(stderr, "\t-f n\t\tfilter number (default 1)\n");
+  fprintf(stderr, "\t-F file\t\tfilter definition file (default 'filter.dat')\n");
+  fprintf(stderr, "\t-l n\t\tembedding level (default 1)\n");
+  fprintf(stderr, "\t-n n\t\twatermark bit length\n");
+  fprintf(stderr, "\t-o file\t\toutput file\n");
+  fprintf(stderr, "\t-q n\t\tsignature strength (default 4)\n");
+  fprintf(stderr, "\t-s file\t\tuse signature file's embedding information\n");
+  fprintf(stderr, "\t-S n\t\tseed\n");
+  fprintf(stderr, "\t-v n\t\tverbosity level\n");
+  exit(0);
+}
+
+int main(int argc, char *argv[]) {
+  FILE *in = stdin;
+  FILE *out = stdout;
+  FILE *sig = NULL;
+
+  char output_name[MAXPATHLEN] = "(stdout)";
+  char input_name[MAXPATHLEN] = "(stdin)";
+  char signature_name[MAXPATHLEN];
+  char *binstr;
+
+  int verbose = 0;
+  int c;
+  int i;
+  int l = 3;
+  int n = 0;
+  int s = 0;
+  int q = 4;
+  int e = 2;
+  int f = 1;
+  int blocksize = 64;
+  char F[MAXPATHLEN] = "filter.dat";
+
+  progname = argv[0];
+
+  wm_init();
+
+  while ((c = getopt(argc, argv, "b:e:f:F:h?l:n:o:q:s:S:v:")) != EOF) {
+    switch (c) {
+      case 'b':
+        blocksize = atoi(optarg);
+        if (blocksize < 0)
+          fprintf(stderr, "%s: block size %d out of range\n", progname, blocksize);
+        break;
+      case 'e':
+        e = atoi(optarg);
+        if (e < 0) {
+          fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, e);
+        }
+        break;
+      case 'f':
+        f = atoi(optarg);
+        if (f <= 0) {
+          fprintf(stderr, "%s: filter number %d out of range\n", progname, f);
+          exit(1);
+        }
+        break;
+      case 'F':
+        strcpy(F, optarg);
+        break;
+      case 'h':
+      case '?':
+        usage();
+        break;
+      case 'l':
+        l = atoi(optarg);
+        if (l < 1) {
+          fprintf(stderr, "%s: embedding level out of range\n", progname);
+          exit(1);
+        }
+        break;
+      case 'n':
+        n = atoi(optarg);
+        if (n < 1 || n > 1000) {
+          fprintf(stderr, "%s: watermark length %d out of range\n", progname, n);
+          exit(1);
+        }
+        break;
+      case 'o':
+        if ((out = fopen(optarg, "wb")) == NULL) {
+          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(output_name, optarg);
+        break;
+      case 'q':
+        q = atoi(optarg);
+        if (q < 1) {
+          fprintf(stderr, "%s: signature strength %d out of range\n", progname, q);
+          exit(1);
+        }
+        break;
+     case 's':
+        if ((sig = fopen(optarg, "r")) == NULL) {
+          fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(signature_name, optarg);
+        break;
+      case 'S':
+        s = atoi(optarg);
+        break;
+      case 'v':
+        verbose = atoi(optarg);
+        if (verbose < 0) {
+          fprintf(stderr, "%s: verbosity level %d out of range", progname, verbose);
+          exit(1);
+        }
+        break;
+    }
+  }
+
+  argc -= optind;
+  argv += optind;
+
+  if (argc > 1) {
+    usage();
+    exit(1);
+  }
+
+  if (argc == 1 && *argv[0] != '-')
+  if ((in = fopen(argv[0], "rb")) == NULL) {
+    fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
+    exit(1);
+  }
+  else
+    strcpy(input_name, argv[0]);
+
+  if (sig) {
+    char line[32];
+    fgets(line, sizeof(line), sig);
+    if (strspn(line, "KD2SG") >= 5) {
+      if (n == 0)
+        fscanf(sig, "%d\n", &n);
+      else
+        fscanf(sig, "%*d\n");
+      if (q == 0)
+        fscanf(sig, "%d\n", &q);
+      else
+        fscanf(sig, "%*d\n");
+      if (blocksize == 0)
+        fscanf(sig, "%d\n", &blocksize);
+      else
+        fscanf(sig, "%*d\n");
+      if (e < 0)
+        fscanf(sig, "%d\n", &e);
+      else
+        fscanf(sig, "%*d\n");
+      if (f == 0)
+        fscanf(sig, "%d\n", &f);
+      else
+        fscanf(sig, "%*d\n");
+      if (!strcmp(F, ""))
+        fscanf(sig, "%[^\n\r]\n", &F);
+      else
+        fscanf(sig, "%*[^\n\r]\n");
+      if (l == 0)
+        fscanf(sig, "%d\n", &l);
+      else
+        fscanf(sig, "%*d\n");
+    }
+   else {
+      fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
+      exit(1);
+    }
+    close(sig);
+  }
+
+  if (s)
+    srandom(s);
+  else
+    srandom(time(NULL) * getpid());
+
+  if (n > 0) {
+    n_signature = fread(signature, sizeof(char), i = NBITSTOBYTES(n), in);
+    nbit_signature = NBYTESTOBITS(n_signature);
+    if (n_signature < i) {
+      fprintf(stderr, "%s: failed to read all %d signature bits from %s\n", progname, n, input_name);
+      exit(1);
+    }
+  }
+  else {
+    if (fscanf(in, "%128[^\n\r]", signature) == EOF) {
+      fprintf(stderr, "%s: failed to read signature bits from %s\n", progname, input_name);
+      exit(1);
+    }
+    n_signature = strlen(signature);
+    nbit_signature = NBYTESTOBITS(n_signature);
+    fprintf(stderr, "%s: got %d signature bits\n", progname, nbit_signature);
+  }
+
+  fprintf(out, "KD2SG\n");
+  fprintf(out, "%d\n", nbit_signature);
+  fprintf(out, "%d\n", q);
+  fprintf(out, "%d\n", blocksize);
+  fprintf(out, "%d\n", e);
+  fprintf(out, "%d\n", f);
+  fprintf(out, "%s\n", F);
+  fprintf(out, "%d\n", l);
+  fprintf(out, "%d\n", random());
+  binstr = malloc((nbit_signature + 1) * sizeof(char));
+  sig_to_binstr(binstr);
+  fprintf(out, "%s\n", binstr);
+  free(binstr);
+
+  fclose(out);
+
+  exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/gen_kund3_sig.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,208 @@
+#include "wm.h"
+#include "signature.h"
+
+char *progname;
+
+void usage(void) {
+  fprintf(stderr, "usage: %s [-e n] [-f n] [-F file] [-l n] [-n n] [-o file] [-q n] [-s file] [-S n] [-v n] file\n\n", progname);
+  fprintf(stderr, "\t-h\t\tprint usage\n");
+  fprintf(stderr, "\t-e n\t\twavelet filtering method (default 2)\n");
+  fprintf(stderr, "\t-f n\t\tfilter number (default 1)\n");
+  fprintf(stderr, "\t-F file\t\tfilter definition file (default 'filter.dat')\n");
+  fprintf(stderr, "\t-l n\t\tembedding level (default 1)\n");
+  fprintf(stderr, "\t-n n\t\twatermark bit length\n");
+  fprintf(stderr, "\t-o file\t\toutput file\n");
+  fprintf(stderr, "\t-q n\t\tsignature strength (default 4)\n");
+  fprintf(stderr, "\t-s file\t\tuse signature file's embedding information\n");
+  fprintf(stderr, "\t-S n\t\tseed\n");
+  fprintf(stderr, "\t-v n\t\tverbosity level\n");
+  exit(0);
+}
+
+int main(int argc, char *argv[]) {
+  FILE *in = stdin;
+  FILE *out = stdout;
+  FILE *sig = NULL;
+
+  char output_name[MAXPATHLEN] = "(stdout)";
+  char input_name[MAXPATHLEN] = "(stdin)";
+  char signature_name[MAXPATHLEN];
+  char *binstr;
+
+  int verbose = 0;
+  int c;
+  int i;
+  int l = 1;
+  int n = 0;
+  int s = 0;
+  int q = 4;
+  int e = 2;
+  int f = 1;
+  char F[MAXPATHLEN] = "filter.dat";
+
+  progname = argv[0];
+
+  wm_init();
+
+  while ((c = getopt(argc, argv, "e:f:F:h?l:n:o:q:s:S:v:")) != EOF) {
+    switch (c) {
+      case 'e':
+        e = atoi(optarg);
+        if (e < 0) {
+          fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, e);
+        }
+        break;
+      case 'f':
+        f = atoi(optarg);
+        if (f <= 0) {
+          fprintf(stderr, "%s: filter number %d out of range\n", progname, f);
+          exit(1);
+        }
+        break;
+      case 'F':
+        strcpy(F, optarg);
+        break;
+      case 'h':
+      case '?':
+        usage();
+        break;
+      case 'l':
+        l = atoi(optarg);
+        if (l < 1) {
+          fprintf(stderr, "%s: embedding level out of range\n", progname);
+          exit(1);
+        }
+        break;
+      case 'n':
+        n = atoi(optarg);
+        if (n < 1 || n > 1000) {
+          fprintf(stderr, "%s: watermark length %d out of range\n", progname, n);
+          exit(1);
+        }
+        break;
+      case 'o':
+        if ((out = fopen(optarg, "wb")) == NULL) {
+          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(output_name, optarg);
+        break;
+      case 'q':
+        q = atoi(optarg);
+        if (q < 1) {
+          fprintf(stderr, "%s: signature strength %d out of range\n", progname, q);
+          exit(1);
+        }
+        break;
+     case 's':
+        if ((sig = fopen(optarg, "r")) == NULL) {
+          fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(signature_name, optarg);
+        break;
+      case 'S':
+        s = atoi(optarg);
+        break;
+      case 'v':
+        verbose = atoi(optarg);
+        if (verbose < 0) {
+          fprintf(stderr, "%s: verbosity level %d out of range", progname, verbose);
+          exit(1);
+        }
+        break;
+    }
+  }
+
+  argc -= optind;
+  argv += optind;
+
+  if (argc > 1) {
+    usage();
+    exit(1);
+  }
+
+  if (argc == 1 && *argv[0] != '-')
+  if ((in = fopen(argv[0], "rb")) == NULL) {
+    fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
+    exit(1);
+  }
+  else
+    strcpy(input_name, argv[0]);
+
+  if (sig) {
+    char line[32];
+    fgets(line, sizeof(line), sig);
+    if (strspn(line, "KD3SG") >= 5) {
+      if (n == 0)
+        fscanf(sig, "%d\n", &n);
+      else
+        fscanf(sig, "%*d\n");
+      if (q == 0)
+        fscanf(sig, "%d\n", &q);
+      else
+        fscanf(sig, "%*d\n");
+      if (e < 0)
+        fscanf(sig, "%d\n", &e);
+      else
+        fscanf(sig, "%*d\n");
+      if (f == 0)
+        fscanf(sig, "%d\n", &f);
+      else
+        fscanf(sig, "%*d\n");
+      if (!strcmp(F, ""))
+        fscanf(sig, "%[^\n\r]\n", &F);
+      else
+        fscanf(sig, "%*[^\n\r]\n");
+      if (l == 0)
+        fscanf(sig, "%d\n", &l);
+      else
+        fscanf(sig, "%*d\n");
+    }
+   else {
+      fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
+      exit(1);
+    }
+    close(sig);
+  }
+
+  if (s)
+    srandom(s);
+  else
+    srandom(time(NULL) * getpid());
+
+  if (n > 0) {
+    n_signature = fread(signature, sizeof(char), i = NBITSTOBYTES(n), in);
+    if (n_signature < i) {
+      fprintf(stderr, "%s: failed to read all %d signature bits from %s\n", progname, n, input_name);
+      exit(1);
+    }
+  }
+  else {
+    if (fscanf(in, "%128[^\n\r]", signature) == EOF) {
+      fprintf(stderr, "%s: failed to read signature bits from %s\n", progname, input_name);
+      exit(1);
+    }
+    n_signature = strlen(signature);
+    nbit_signature = NBYTESTOBITS(n_signature);
+    fprintf(stderr, "%s: got %d signature bits\n", progname, nbit_signature);
+  }
+
+  fprintf(out, "KD3SG\n");
+  fprintf(out, "%d\n", n);
+  fprintf(out, "%d\n", q);
+  fprintf(out, "%d\n", e);
+  fprintf(out, "%d\n", f);
+  fprintf(out, "%s\n", F);
+  fprintf(out, "%d\n", l);
+  fprintf(out, "%d\n", random());
+  nbit_signature = NBYTESTOBITS(n_signature);
+  binstr = malloc((nbit_signature + 1) * sizeof(char));
+  sig_to_binstr(binstr);
+  fprintf(out, "%s\n", binstr);
+  free(binstr);
+
+  fclose(out);
+
+  exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/gen_kund_sig.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,164 @@
+#include "wm.h"
+#include "signature.h"
+
+char *progname;
+
+void usage(void) {
+  fprintf(stderr, "usage: %s [-e n] [-f n] [-F file] [-l n] [-n n] [-o file] [-q n] [-s n] file\n\n", progname);
+  fprintf(stderr, "\t-h\t\tprint usage\n");
+  fprintf(stderr, "\t-e n\t\twavelet filtering method (default 2)\n");
+  fprintf(stderr, "\t-f n\t\tfilter number (default 1)\n");
+  fprintf(stderr, "\t-F file\t\tfilter definition file (default 'filter.dat')\n");
+  fprintf(stderr, "\t-l n\t\tembedding level (default 1)\n");
+  fprintf(stderr, "\t-n n\t\twatermark bit length\n");
+  fprintf(stderr, "\t-o file\t\toutput file\n");
+  fprintf(stderr, "\t-q n\t\tsignature strength (default 1.0)\n");
+  fprintf(stderr, "\t-s n\t\tseed\n");
+  exit(0);
+}
+
+int main(int argc, char *argv[]) {
+  FILE *in = stdin;
+  FILE *out = stdout;
+
+  char output_name[MAXPATHLEN] = "(stdout)";
+  char input_name[MAXPATHLEN] = "(stdin)";
+
+  int c;
+  int i;
+  int l = 1;
+  int n = 0, nb;
+  int s = 0;
+  double q = 1.0;
+  int e = 2;
+  int f = 1;
+  char F[MAXPATHLEN] = "filter.dat";
+
+  progname = argv[0];
+
+#ifdef __EMX__
+  _fsetmode(in, "b");
+  _fsetmode(out, "b");
+#endif
+
+  while ((c = getopt(argc, argv, "e:f:F:h?l:n:o:q:s:")) != EOF) {
+    switch (c) {
+      case 'e':
+        e = atoi(optarg);
+        if (e < 0) {
+          fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, e);
+        }
+        break;
+      case 'f':
+        f = atoi(optarg);
+        if (f <= 0) {
+          fprintf(stderr, "%s: filter number %d out of range\n", progname, f);
+          exit(1);
+        }
+        break;
+      case 'F':
+        strcpy(F, optarg);
+        break;
+      case 'h':
+      case '?':
+        usage();
+        break;
+      case 'l':
+        l = atoi(optarg);
+        if (l < 1) {
+          fprintf(stderr, "%s: embedding level out of range\n", progname);
+          exit(1);
+        }
+        break;
+      case 'n':
+        n = atoi(optarg);
+        if (n < 1 || n > 1000) {
+          fprintf(stderr, "%s: watermark length %d out of range\n", progname, n);
+          exit(1);
+        }
+        if (n % 4 != 0 || (int) sqrt(n / 4) * (int) sqrt(n / 4) != n) {
+          fprintf(stderr, "%s: watermark length not divisible by 4 or not a square number\n", progname);
+          exit(1);
+        }
+        break;
+      case 'o':
+        if ((out = fopen(optarg, "wb")) == NULL) {
+          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(output_name, optarg);
+        break;
+      case 'q':
+        q = atof(optarg);
+        if (q <= 0.0) {
+          fprintf(stderr, "%s: signature strength factor %f out of range\n", progname, q);
+          exit(1);
+        }
+        break;
+      case 's':
+        s = atoi(optarg);
+        break;
+    }
+  }
+
+  argc -= optind;
+  argv += optind;
+
+  if (argc > 0) {
+    usage();
+    exit(1);
+  }
+
+  if (argc == 1 && *argv[0] != '-')
+  if ((in = fopen(argv[0], "rb")) == NULL) {
+    fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
+    exit(1);
+  }
+  else
+    strcpy(input_name, argv[0]);
+
+  if (s)
+    srandom(s);
+  else
+    srandom(time(NULL) * getpid());
+
+  if (n > 0) {
+    nb = fread(signature, sizeof(char), i = NBITSTOBYTES(n), in);
+    if (nb < i) {
+      fprintf(stderr, "%s: failed to read all %d signature bits from %s\n", progname, n, input_name);
+      exit(1);
+    }
+  }
+  else {
+    int n_square;
+    if (fscanf(in, "%128[^\n\r]", signature) == EOF) {
+      fprintf(stderr, "%s: failed to read signature bits from %s\n", progname, input_name);
+      exit(1);
+    }
+    nb = strlen(signature);
+    n = NBYTESTOBITS(nb);
+    n_square = (int) sqrt(n) * (int) sqrt(n);
+    fprintf(stderr, "%s: got %d signature bits, truncated to %d\n", progname, n, n_square);
+    n = n_square;
+    nb = NBITSTOBYTES(n);
+    if (n < 1) {
+      fprintf(stderr, "%s: watermark length %d out of range\n", progname, n);
+      exit(1);
+    }
+  }
+
+  fprintf(out, "KDSG\n");
+  fprintf(out, "%d\n", n);
+  fprintf(out, "%d\n", e);
+  fprintf(out, "%d\n", f);
+  fprintf(out, "%s\n", F);
+  fprintf(out, "%d\n", l);
+  fprintf(out, "%f\n", q);
+  fprintf(out, "%d\n", random());
+  fwrite(signature, sizeof(char), nb, out);
+  fprintf(out, "\n");
+
+  fclose(out);
+
+  exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/gen_xie2_sig.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,213 @@
+#include "wm.h"
+#include "signature.h"
+
+char *progname;
+
+void usage(void) {
+  fprintf(stderr, "usage: %s [-a n] [-e n] [-f n] [-F file] [-l n] [-n n] [-o file] [-s file] [-S n] [-v n] file\n\n", progname);
+  fprintf(stderr, "\t-a n\t\tembedding strength (default 0.5)\n");
+  fprintf(stderr, "\t-e n\t\twavelet filtering method (default 2)\n");
+  fprintf(stderr, "\t-f n\t\tfilter number (default 1)\n");
+  fprintf(stderr, "\t-F file\t\tfilter definition file (default 'filter.dat')\n");
+  fprintf(stderr, "\t-h\t\tprint usage\n");
+  fprintf(stderr, "\t-l n\t\tembedding level (default 5)\n");
+  fprintf(stderr, "\t-n n\t\twatermark bit length\n");
+  fprintf(stderr, "\t-o file\t\toutput file\n");
+  fprintf(stderr, "\t-q n\t\tquantization level\n");
+  fprintf(stderr, "\t-s file\t\tuse signature file's embedding information\n");
+  fprintf(stderr, "\t-S n\t\tseed\n");
+  fprintf(stderr, "\t-v n\t\tverbosity level\n");
+  exit(0);
+}
+
+int main(int argc, char *argv[]) {
+  FILE *in = stdin;
+  FILE *out = stdout;
+  FILE *sig = NULL;
+
+  char output_name[MAXPATHLEN] = "(stdout)";
+  char input_name[MAXPATHLEN] = "(stdin)";
+  char signature_name[MAXPATHLEN];
+
+  int verbose = 0;
+  int c;
+  int i;
+  double a = 0.5;
+  int q = 4;
+  int l = 5;
+  int n = 0, nb;
+  int s = 0;
+  int e = 2;
+  int f = 1;
+  char F[MAXPATHLEN] = "filter.dat";
+
+  progname = argv[0];
+  wm_init();
+
+  while ((c = getopt(argc, argv, "a:e:f:F:h?l:n:o:s:S:v:q:")) != EOF) {
+    switch (c) {
+      case 'a':
+        a = atof(optarg);
+        if (a <= 0.0) {
+          fprintf(stderr, "%s: embedding strength %f out of range\n", progname, a);
+          exit(1);
+        }
+        break;
+      case 'e':
+        e = atoi(optarg);
+        if (e < 0) {
+          fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, e);
+        }
+        break;
+      case 'q':
+        q = atoi(optarg);
+        break;
+      case 'f':
+        f = atoi(optarg);
+        if (f <= 0) {
+          fprintf(stderr, "%s: filter number %d out of range\n", progname, f);
+          exit(1);
+        }
+        break;
+      case 'F':
+        strcpy(F, optarg);
+        break;
+      case 'h':
+      case '?':
+        usage();
+        break;
+      case 'l':
+        l = atoi(optarg);
+        if (l < 1) {
+          fprintf(stderr, "%s: embedding level out of range\n", progname);
+          exit(1);
+        }
+        break;
+      case 'n':
+        n = atoi(optarg);
+        if (n < 1 || n > 1000) {
+          fprintf(stderr, "%s: watermark length %d out of range\n", progname, n);
+          exit(1);
+        }
+        break;
+      case 'o':
+        if ((out = fopen(optarg, "wb")) == NULL) {
+          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(output_name, optarg);
+        break;
+     case 's':
+        if ((sig = fopen(optarg, "r")) == NULL) {
+          fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(signature_name, optarg);
+        break;
+      case 'S':
+        s = atoi(optarg);
+        break;
+      case 'v':
+        verbose = atoi(optarg);
+        if (verbose < 0) {
+          fprintf(stderr, "%s: verbosity level %d out of range", progname, verbose);
+          exit(1);
+        }
+        break;
+    }
+  }
+
+  argc -= optind;
+  argv += optind;
+
+  if (argc > 1) {
+    usage();
+    exit(1);
+  }
+
+  if (argc == 1 && *argv[0] != '-')
+  if ((in = fopen(argv[0], "rb")) == NULL) {
+    fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
+    exit(1);
+  }
+  else
+    strcpy(input_name, argv[0]);
+
+  if (sig) {
+    char line[32];
+    fgets(line, sizeof(line), sig);
+    if (strspn(line, "XE2SG") >= 5) {
+      if (n == 0)
+        fscanf(sig, "%d\n", &n);
+      else
+        fscanf(sig, "%*d\n");
+      if (a == 0.0)
+        fscanf(sig, "%lf\n", &a);
+      else
+        fscanf(sig, "%*lf\n");
+      if (e < 0)
+        fscanf(sig, "%d\n", &e);
+      else
+        fscanf(sig, "%*d\n");
+      if (f == 0)
+        fscanf(sig, "%d\n", &f);
+      else
+        fscanf(sig, "%*d\n");
+      if (!strcmp(F, ""))
+        fscanf(sig, "%[^\n\r]\n", &F);
+      else
+        fscanf(sig, "%*[^\n\r]\n");
+      if (q == 0)
+        fscanf(sig, "%d\n", &q);
+      else
+        fscanf(sig, "%*d\n");
+      if (l == 0)
+        fscanf(sig, "%d\n", &l);
+      else
+        fscanf(sig, "%*d\n");
+    }
+   else {
+      fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
+      exit(1);
+    }
+    close(sig);
+  }
+
+  if (s)
+    srandom(s);
+  else
+    srandom(time(NULL) * getpid());
+
+  if (n > 0) {
+    nb = fread(signature, sizeof(char), i = NBITSTOBYTES(n), in);
+    if (nb < i) {
+      fprintf(stderr, "%s: failed to read all %d signature bits from %s\n", progname, n, input_name);
+      exit(1);
+    }
+  }
+  else {
+    if (fscanf(in, "%128[^\n\r]", signature) == EOF) {
+      fprintf(stderr, "%s: failed to read signature bits from %s\n", progname, input_name);
+      exit(1);
+    }
+    nb = strlen(signature);
+    n = NBYTESTOBITS(nb);
+    fprintf(stderr, "%s: got %d signature bits\n", progname, n);
+  }
+
+  fprintf(out, "XE2SG\n");
+  fprintf(out, "%d\n", n);
+  fprintf(out, "%f\n", a);
+  fprintf(out, "%d\n", e);
+  fprintf(out, "%d\n", f);
+  fprintf(out, "%s\n", F);
+  fprintf(out, "%d\n", q);
+  fprintf(out, "%d\n", l);
+  fprintf(out, "%d\n", random());
+  fwrite(signature, sizeof(char), nb, out);
+  fprintf(out, "\n");
+
+  fclose(out);
+
+  exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/param_stuff.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,133 @@
+#ifdef PARAM_STUFF
+  {
+#define MAXNALPHA 32
+
+    double alpha[MAXNALPHA];
+    char *alpha_str = getenv("PARAM_ALPHA");
+    double alpha_value;
+    int alpha_len = 0;
+
+    int param_len[MAXNALPHA];
+    char *param_len_str = getenv("PARAM_LEN");
+    int param_len_value;
+    int param_len_len = 0;
+    int param_len_sum = 0;
+    
+    char buf[1024] = "";
+    char *v;
+
+    
+    if (alpha_str && strlen(alpha_str) < sizeof(buf)
+	&& strcmp(alpha_str, "") ) {
+
+      strcpy(buf, alpha_str);
+
+      v = strtok(buf, "\",; ");
+      do {
+     
+        alpha_value = atof(v);
+
+        if (alpha_value < -M_PI || alpha_value >= M_PI) {
+          fprintf(stderr, "%s: parametric - alpha %f out of range\n",
+		  progname, alpha_value);
+          exit(1);
+        }
+
+        alpha[alpha_len] = alpha_value;
+        alpha_len++;
+      } while (v = strtok(NULL, "\",; "));
+      
+
+      if( param_len_str && strlen(param_len_str) < sizeof(buf)
+	  && strcmp(param_len_str, "") ) {
+	/* There was an parameter length environment variable. */
+
+	strcpy(buf, param_len_str);
+
+	v = strtok(buf, "\",; ");
+	do {
+     
+	  param_len_value = atoi(v);
+
+	  if (param_len_value <= 0) {
+	    fprintf(stderr, "%s: parameter length %d out of range\n",
+		    progname, param_len_value);
+	    exit(1);
+	  }
+
+	  param_len[param_len_len] = param_len_value;
+	  param_len_len++;
+	  param_len_sum += param_len_value;
+
+	} while (v = strtok(NULL, "\",; "));
+
+      } else {
+	/* No length variable given.
+	   For backward compatability we use all parameters for 
+	   one filter and therefore for all levels.
+	*/
+
+	param_len[0] = alpha_len;
+	param_len_len = 1;
+	param_len_sum = alpha_len;
+      }
+
+
+      /* If we do not get a parameter length value for every
+	 decomposition level then we reuse the last supplied value
+	 for the remaining levels.
+      */
+      if (param_len_len < level+1) {
+	int last_param_len = param_len[ param_len_len - 1 ];
+
+	for(; param_len_len < level+1; param_len_len++ ) {
+	  param_len[ param_len_len ] = last_param_len;
+	  param_len_sum += last_param_len;
+	}
+      }
+
+
+      /* If the number of supplied alphas is lower than is required
+	 for by param_len then copy the last filter
+	 parameters to the remaining levels.
+      */
+      if( alpha_len < param_len_sum ) {
+	int i;
+	int last_param_len = param_len[ param_len_len - 1 ];
+	int last_start = alpha_len - last_param_len;
+
+	for( i=0; alpha_len < param_len_sum; alpha_len++, i++ ) {
+	  alpha[ alpha_len ] = alpha[ last_start + (i % last_param_len) ];
+	}
+      }
+
+      if (verbose > 1) {
+        int i, j;
+	int cur_sum = 0;
+
+	fprintf(stderr, "%s: parametric, number of levels: %d\n",
+		progname, level);
+
+	for (i = 0; i < level+1; i++) {
+
+	  fprintf(stderr, "    %d filter parameters for level %d: ",
+		  param_len[i], i);
+
+	  for (j = 0; j < param_len[i]; j++) {
+	    fprintf(stderr, "%f ", alpha[cur_sum + j]);
+	  }
+
+	  fprintf(stderr, "\n");
+
+	  cur_sum += param_len[i];
+	}
+      }
+
+
+      dwt_param_filter(alpha, param_len);
+
+
+    } /* if( alpha_str... */
+  }
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/pollen_stuff.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,27 @@
+#ifdef POLLEN_STUFF
+  {
+    double alpha, beta;
+    char *alpha_str = getenv("POLLEN_ALPHA"), *beta_str = getenv("POLLEN_BETA");
+    
+    if (alpha_str && beta_str) {
+      alpha = atof(alpha_str);  
+      beta = atof(beta_str);
+     
+      if (alpha < -M_PI || alpha >= M_PI) {
+        fprintf(stderr, "%s: pollen - alpha %f out of range\n", progname, alpha);
+        exit(1);
+      }
+      
+      if (beta < -M_PI || beta >= M_PI) {
+        fprintf(stderr, "%s: pollen - beta %f out of range\n", progname, beta);
+        exit(1);
+      }
+      
+      if (verbose > 7)
+        fprintf(stderr, "%s: pollen - alpha %f, beta %f\n", progname, alpha, beta);
+      
+      dwt_pollen_filter(alpha, beta);
+    }
+  }
+#endif
+
--- a/Meerwald/signature.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/signature.c	Tue Aug 14 21:11:21 2007 +0200
@@ -12,84 +12,107 @@
   bzero(signature2, sizeof(signature2));
 }
 
-int get_signature_bit(int n) {
-  int byte = n >> 3;
-  int bit = n & 7;
-
-#ifdef DEBUG
-  if (byte < 0 || byte >= NSIGNATURE)
-    fprintf(stderr, "get_signature_bit(): index out of range\n");
-#endif
-
-  return (signature[byte] & (1 << bit)) >> bit;
-}
-
-int get_signature1_bit(int n) {
+int _get_signature_bit(char *s, int lim, int n) {
   int byte = n >> 3;
   int bit = n & 7;
 
 #ifdef DEBUG
-  if (byte < 0 || byte >= NSIGNATURE)
-    fprintf(stderr, "get_signature1_bit(): index out of range\n");
+  if (byte < 0 || byte >= lim)
+    fprintf(stderr, "get_signature_bit?(): index out of range\n");
 #endif
 
-  return (signature1[byte] & (1 << bit)) >> bit;
+  return (s[byte] & (1 << bit)) >> bit;
+}
+
+int get_signature_bit(int n) {
+  return _get_signature_bit(signature, NSIGNATURE, n);
+}
+
+int get_signature1_bit(int n) {
+  return _get_signature_bit(signature1, NSIGNATURE, n);
 }
 
 int get_signature2_bit(int n) {
-  int byte = n >> 3;
-  int bit = n & 7;
-
-#ifdef DEBUG
-  if (byte < 0 || byte >= NSIGNATURE)
-    fprintf(stderr, "get_signature2_bit(): index out of range\n");
-#endif
-
-  return (signature2[byte] & (1 << bit)) >> bit;
+  return _get_signature_bit(signature2, NSIGNATURE, n);
 }
 
-void set_signature_bit(int n, int v) {
+void _set_signature_bit(char *s, int lim, int n, int v) {
   int byte = n >> 3;
   int bit = n & 7;
 
 #ifdef DEBUG
-  if (byte < 0 || byte >= NSIGNATURE)
-    fprintf(stderr, "get_signature_bit(): index out of range\n");
-#endif
-
-  if (v)
-    signature[byte] |= (1 << bit);
-  else
-    signature[byte] &= ~(1 << bit);
-}
-
-void set_signature1_bit(int n, int v) {
-  int byte = n >> 3;
-  int bit = n & 7;
-
-#ifdef DEBUG
-  if (byte < 0 || byte >= NSIGNATURE)
-    fprintf(stderr, "get_signature1_bit(): index out of range\n");
+  if (byte < 0 || byte >= limit / 8)
+    fprintf(stderr, "get_signature_bit?(): index out of range\n");
 #endif
 
   if (v)
-    signature1[byte] |= (1 << bit);
+    s[byte] |= (1 << bit);
   else
-    signature1[byte] &= ~(1 << bit);
+    s[byte] &= ~(1 << bit);
+}
+
+void set_signature_bit(int n, int v) {
+  _set_signature_bit(signature, NSIGNATURE, n, v);
+}
+
+void set_signature1_bit(int n, int v) {
+  _set_signature_bit(signature1, NSIGNATURE, n, v);
 }
 
 void set_signature2_bit(int n, int v) {
-  int byte = n >> 3;
-  int bit = n & 7;
+  _set_signature_bit(signature2, NSIGNATURE, n, v);
+}
+
+int _binstr_to_sig(const char *binstr, char *sig, int *bytes, int *bits) {
+  int n = strlen(binstr);
+  int i;
 
-#ifdef DEBUG
-  if (byte < 0 || byte >= NSIGNATURE)
-    fprintf(stderr, "get_signature2_bit(): index out of range\n");
-#endif
+  for (i = 0; i < n; i++) {
+    if (binstr[i] == '0')
+      _set_signature_bit(sig, NSIGNATURE, i, 0);
+    else if (binstr[i] == '1')
+      _set_signature_bit(sig, NSIGNATURE, i, 1);
+    else
+      return 0;
+  }
 
-  if (v)
-    signature2[byte] |= (1 << bit);
-  else
-    signature2[byte] &= ~(1 << bit);
+  *bytes = (n % 8 > 0) ? n / 8 + 1 : n / 8;
+  *bits = n;
+
+  return 1;  
+}
+
+int binstr_to_sig(const char *binstr) {
+  _binstr_to_sig(binstr, signature, &n_signature, &nbit_signature);
 }
 
+int binstr_to_sig1(const char *binstr) {
+  _binstr_to_sig(binstr, signature1, &n_signature1, &nbit_signature1);
+}
+
+int binstr_to_sig2(const char *binstr) {
+  _binstr_to_sig(binstr, signature2, &n_signature2, &nbit_signature2);
+}
+
+int _sig_to_binstr(char *binstr, char *sig, int bits) {
+  int i;
+
+  for (i = 0; i < bits; i++)
+    binstr[i] = _get_signature_bit(sig, NSIGNATURE, i) ? '1' : '0';
+
+  binstr[bits] = '\0';
+
+  return 1;
+}
+
+int sig_to_binstr(char *binstr) {
+  return _sig_to_binstr(binstr, signature, nbit_signature);
+}
+
+int sig1_to_binstr(char *binstr) {
+  return _sig_to_binstr(binstr, signature1, nbit_signature1);
+}
+
+int sig2_to_binstr(char *binstr) {
+  return _sig_to_binstr(binstr, signature2, nbit_signature2);
+}
--- a/Meerwald/signature.h	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/signature.h	Tue Aug 14 21:11:21 2007 +0200
@@ -29,4 +29,11 @@
 int get_signature2_bit(int n);
 void set_signature2_bit(int n, int v);
 
+int binstr_to_sig(const char *binstr);
+int binstr_to_sig1(const char *binstr);
+int binstr_to_sig2(const char *binstr);
+int sig_to_binstr(char *binstr);
+int sig1_to_binstr(char *binstr);
+int sig2_to_binstr(char *binstr);
+
 #endif
--- a/Meerwald/wm.h	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/wm.h	Tue Aug 14 21:11:21 2007 +0200
@@ -18,7 +18,7 @@
 #include <values.h>
 #include <sys/param.h>
 #else
-#error platform not supported
+#error plattform not supported
 #endif
 
 /*
--- a/Meerwald/wm_corvi_d.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/wm_corvi_d.c	Tue Aug 14 21:11:21 2007 +0200
@@ -40,7 +40,7 @@
   int filter = 0;
   char filter_name[MAXPATHLEN] = "";
 
-  int level;
+  int level = 0;
   double alpha = 0.0;
 
   int in_rows, in_cols, in_format;
@@ -221,10 +221,10 @@
 
   init_dwt(cols, rows, filter_name, filter, level, method);
 #ifdef POLLEN_STUFF
-#include "pollen_stuff.xxx"
+#include "pollen_stuff.c"
 #endif
 #ifdef PARAM_STUFF
-#include "param_stuff.xxx"
+#include "param_stuff.c"
 #endif
 
   input_dwts = fdwt(input_image);
--- a/Meerwald/wm_corvi_e.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/wm_corvi_e.c	Tue Aug 14 21:11:21 2007 +0200
@@ -36,7 +36,7 @@
 
   int filter = 0;
   int method = -1;
-  int level;
+  int level = 0;
   char filter_name[MAXPATHLEN] = "";
 
   int verbose = 0;
@@ -177,10 +177,10 @@
 
   init_dwt(cols, rows, filter_name, filter, level, method);
 #ifdef POLLEN_STUFF
-#include "pollen_stuff.xxx"
+#include "pollen_stuff.c"
 #endif
 #ifdef PARAM_STUFF
-#include "param_stuff.xxx"
+#include "param_stuff.c"
 #endif
 
   dwts = fdwt(image);
--- a/Meerwald/wm_dugad_d.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/wm_dugad_d.c	Tue Aug 14 21:11:21 2007 +0200
@@ -51,7 +51,7 @@
   int i;
   int n = 0;
   int method = -1;
-  int levels = 0;
+  int level = 0;
   int filter = 0;
   char filter_name[MAXPATHLEN] = "";
 
@@ -104,9 +104,9 @@
         usage();
         break;
       case 'l':      
-        levels = atoi(optarg);
-        if (levels <= 0) {
-          fprintf(stderr, "%s: decomposition level %d out of range\n", levels);
+        level = atoi(optarg);
+        if (level <= 0) {
+          fprintf(stderr, "%s: decomposition level %d out of range\n", level);
           exit(1);
         }
         break;
@@ -170,8 +170,8 @@
     fgets(line, sizeof(line), sig);
     if (strspn(line, "DGSG") >= 4) {
       fscanf(sig, "%d\n", &n);
-      if (levels == 0)
-        fscanf(sig, "%d\n", &levels);
+      if (level == 0)
+        fscanf(sig, "%d\n", &level);
       else
         fscanf(sig, "%*d\n");
       if (alpha == 0.0)
@@ -224,21 +224,21 @@
 
   fclose(in);
 
-  init_dwt(cols, rows, filter_name, filter, levels, method);
+  init_dwt(cols, rows, filter_name, filter, level, method);
 #ifdef POLLEN_STUFF
-#include "pollen_stuff.xxx"
+#include "pollen_stuff.c"
 #endif
 #ifdef PARAM_STUFF
-#include "param_stuff.xxx"
+#include "param_stuff.c"
 #endif
 
   dwts = fdwt(input_image);
 
   fprintf(out, "DGWM\n");
-  fprintf(out, "%d\n", levels);
+  fprintf(out, "%d\n", level);
   fprintf(out, "%f\n", alpha);
 
-  for (i = 0, s = dwts; i < levels; i++, s = s->coarse) {
+  for (i = 0, s = dwts; i < level; i++, s = s->coarse) {
     int m;
     double z, v;
 
--- a/Meerwald/wm_dugad_e.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/wm_dugad_e.c	Tue Aug 14 21:11:21 2007 +0200
@@ -47,7 +47,7 @@
   double alpha = 0.0;
   double t1 = 0.0;
 
-  int levels = 0;
+  int level = 0;
   int filter = 0;
   int method = -1;
   char filter_name[MAXPATHLEN] = "";
@@ -97,9 +97,9 @@
         usage();
         break;
       case 'l': 
-        levels = atoi(optarg);
-        if (levels <= 0) {
-          fprintf(stderr, "%s: decomposition level %d out of range\n", levels);
+        level = atoi(optarg);
+        if (level <= 0) {
+          fprintf(stderr, "%s: decomposition level %d out of range\n", level);
           exit(1);
         }
         break;
@@ -155,8 +155,8 @@
     fgets(line, sizeof(line), sig);
     if (strspn(line, "DGSG") >= 4) {
       fscanf(sig, "%d\n", &n);
-      if (levels == 0)
-        fscanf(sig, "%d\n", &levels);
+      if (level == 0)
+        fscanf(sig, "%d\n", &level);
       else
         fscanf(sig, "%*d\n");
       if (alpha == 0.0)
@@ -206,12 +206,12 @@
   fclose(in);
 
   // wavelet transform
-  init_dwt(cols, rows, filter_name, filter, 3, method);
+  init_dwt(cols, rows, filter_name, filter, level, method);
 #ifdef POLLEN_STUFF
-#include "pollen_stuff.xxx"
+#include "pollen_stuff.c"
 #endif
 #ifdef PARAM_STUFF
-#include "param_stuff.xxx"
+#include "param_stuff.c"
 #endif
 
   dwts = fdwt(image);
--- a/Meerwald/wm_kim_a.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/wm_kim_a.c	Tue Aug 14 21:11:21 2007 +0200
@@ -63,7 +63,7 @@
 
   double alpha_detail = 0.0;
   double alpha_approx = 0.0;
-  int level;
+  int level = 0;
 
   int filter = 0;
   int method = -1;
@@ -234,10 +234,10 @@
   // wavelet transform
   init_dwt(cols, rows, filter_name, filter, level, method);
 #ifdef POLLEN_STUFF
-#include "pollen_stuff.xxx"
+#include "pollen_stuff.c"
 #endif
 #ifdef PARAM_STUFF
-#include "param_stuff.xxx"
+#include "param_stuff.c"
 #endif
 
   dwts = fdwt(image);
--- a/Meerwald/wm_kim_d.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/wm_kim_d.c	Tue Aug 14 21:11:21 2007 +0200
@@ -262,10 +262,10 @@
 
   init_dwt(cols, rows, filter_name, filter, level, method);
 #ifdef POLLEN_STUFF
-#include "pollen_stuff.xxx"
+#include "pollen_stuff.c"
 #endif
 #ifdef PARAM_STUFF
-#include "param_stuff.xxx"
+#include "param_stuff.c"
 #endif
 
   input_dwts = fdwt(input_image);
--- a/Meerwald/wm_kim_e.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/wm_kim_e.c	Tue Aug 14 21:11:21 2007 +0200
@@ -230,10 +230,10 @@
   // wavelet transform
   init_dwt(cols, rows, filter_name, filter, level, method);
 #ifdef POLLEN_STUFF
-#include "pollen_stuff.xxx"
+#include "pollen_stuff.c"
 #endif
 #ifdef PARAM_STUFF
-#include "param_stuff.xxx"
+#include "param_stuff.c"
 #endif
 
   dwts = fdwt(image);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/wm_kund2_d.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,318 @@
+#include "wm.h"
+#include "signature.h"
+#include "dwt.h"
+#include "pgm.h"
+
+char *progname;
+
+void usage(void) {
+  fprintf(stderr, "usage: %s [-e n] [-f n] [-F n] [-h] [-l n] [-o file] [-q n] [-s file] [-v n] file\n\n", progname);
+  fprintf(stderr, "\t-a n\t\toverall embedding strength\n");
+  fprintf(stderr, "\t-e n\t\twavelet filtering method\n");
+  fprintf(stderr, "\t-f n\t\tfilter number\n");
+  fprintf(stderr, "\t-F file\t\tfilter definition file\n");
+  fprintf(stderr, "\t-h\t\tprint usage\n");
+  fprintf(stderr, "\t-l n\t\tembedding level\n");
+  fprintf(stderr, "\t-o file\t\textracted signature file\n");
+  fprintf(stderr, "\t-q n\t\tsignature strength\n");
+  fprintf(stderr, "\t-s file\t\toriginal signature file\n");
+  fprintf(stderr, "\t-v n\t\tverbosity level\n");
+  exit(0);
+}
+
+int main(int argc, char *argv[]) {
+
+  FILE *in = stdin;
+  FILE *out = stdout;
+  FILE *sig = NULL;
+
+  gray **input_image;
+
+  char signature_name[MAXPATHLEN];
+  char output_name[MAXPATHLEN] = "(stdout)";
+  char input_name[MAXPATHLEN] = "(stdin)";
+
+  int r, c;
+  int i;
+  int quality = 0;
+  int blocksize = 0;
+  int seed = 0;
+  int n = 0;
+  int method = -1;
+  int filter = 0;
+  char filter_name[MAXPATHLEN] = "";
+  char *binstr;
+
+  int level = 0;
+  double alpha = 0.0;
+
+  int in_rows, in_cols, in_format;
+  gray in_maxval;
+  int rows, cols;
+  int row, col;
+
+  Image_tree dwts, p;
+
+  int verbose = 0;
+
+  progname = argv[0];
+
+  pgm_init(&argc, argv);
+  wm_init();
+
+  while ((c = getopt(argc, argv, "a:e:f:F:h?l:o:q:s:v:")) != EOF) {
+    switch (c) {
+      case 'a':
+        alpha = atof(optarg);
+        break;
+      case 'e':
+        method = atoi(optarg);
+        if (method < 0) {
+          fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, method);
+          exit(1);
+        }
+        break;
+      case 'f':
+        filter = atoi(optarg);
+        if (filter <= 0) {
+          fprintf(stderr, "%s: filter number %d out of range\n", progname, filter);
+          exit(1);
+        }
+        break;
+      case 'F':
+        strcpy(filter_name, optarg);
+        break;
+      case 'h':
+      case '?':
+        usage();
+        break;
+      case 'l':
+        level = atoi(optarg);
+        if (level < 1) {
+          fprintf(stderr, "%s: embedding level out of range\n", progname);
+          exit(1);
+        }
+        break;
+      case 'o':
+        if ((out = fopen(optarg, "w")) == NULL) {
+          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(output_name, optarg);
+        break;
+      case 'q':
+        quality = atoi(optarg);
+        if (quality < 1) {
+          fprintf(stderr, "%s: quality level %d out of range\n", progname, quality);
+          exit(1);
+        }
+        break;
+      case 's':
+        if ((sig = fopen(optarg, "r")) == NULL) {
+          fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(signature_name, optarg);
+        break;
+      case 'v':
+        verbose = atoi(optarg);
+        if (verbose < 0) {
+          fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
+          exit(1);
+        }
+        break;
+    }
+  }
+
+  argc -= optind;
+  argv += optind;
+
+  if (argc > 1) {
+    usage();
+    exit(1);
+  }
+
+  if (argc == 1 && *argv[0] != '-')
+    if ((in = fopen(argv[0], "rb")) == NULL) {
+      fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
+      exit(1);
+    }
+    else
+      strcpy(input_name, argv[0]);
+
+  if (sig) {
+    char line[1024];
+    fgets(line, sizeof(line), sig);
+    if (strspn(line, "KD2SG") >= 5) {
+      fscanf(sig, "%d\n", &nbit_signature);
+      if (quality == 0)
+        fscanf(sig, "%d\n", &quality);
+      else
+        fscanf(sig, "%*d\n");
+      if (blocksize == 0)
+        fscanf(sig, "%d\n", &blocksize);
+      else
+        fscanf(sig, "%*d\n");
+      if (method < 0)
+        fscanf(sig, "%d\n", &method);
+      else
+        fscanf(sig, "%*d\n");
+      if (filter == 0)
+        fscanf(sig, "%d\n", &filter);
+      else
+        fscanf(sig, "%*d\n");
+      if (!strcmp(filter_name, ""))
+        fscanf(sig, "%[^\n\r]\n", &filter_name);
+      else
+        fscanf(sig, "%*[^\n\r]\n");
+      if (level == 0)
+        fscanf(sig, "%d\n", &level);
+      else
+        fscanf(sig, "%*d\n");
+      fscanf(sig, "%d\n", &seed);
+      srandom(seed);
+      nbit_signature2 = nbit_signature;
+      n_signature = n_signature2 = NBITSTOBYTES(nbit_signature2);
+      binstr = malloc((nbit_signature2 + 1) * sizeof(char));
+      fscanf(sig, "%[01]\n", binstr);
+      binstr_to_sig2(binstr);
+      free(binstr);
+      init_signature_bits();
+    }
+    else {
+      fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
+      exit(1);
+    }
+    fclose(sig);
+  }
+  else {
+    fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname);
+    exit(1);
+  }
+
+  pgm_readpgminit(in, &in_cols, &in_rows, &in_maxval, &in_format);
+
+  cols = in_cols;
+  rows = in_rows;
+
+  if (verbose > 0)
+    fprintf(stderr, "%s: extracting %d bits with quality %d from\n"
+                    "  %d x %d host image, decomposition level %d\n",
+                    progname, nbit_signature, quality, cols, rows, level);
+
+  input_image = pgm_allocarray(in_cols, in_rows);
+
+  for (row = 0; row < in_rows; row++)
+    pgm_readpgmrow(in, input_image[row], in_cols, in_maxval, in_format);
+
+  fclose(in);
+
+  init_dwt(cols, rows, filter_name, filter, level, method);
+#ifdef POLLEN_STUFF
+#include "pollen_stuff.c"
+#endif
+#ifdef PARAM_STUFF
+#include "param_stuff.c"
+#endif
+
+  fprintf(out, "KD2WM\n");
+  fprintf(out, "%d\n", nbit_signature);
+
+  dwts = fdwt(input_image);
+
+
+ p = dwts;
+
+  // consider each resolution level
+  while (p->coarse->level < level) {
+    int lwidth = p->vertical->image->width;
+    int lheight =  p->vertical->image->height;
+    int l = p->vertical->level;
+    int bx, by;
+    int nblock;
+
+    nblock = 0;
+    for (bx = 0; bx < lwidth; bx += blocksize) {
+      for (by = 0; by < lheight; by += blocksize) {
+        int bw = MIN(bx + blocksize, lwidth);
+        int bh = MIN(by + blocksize, lheight);
+        int STEP;
+
+    // start to extracting watermark from beginning at each level
+    // get width and height of detail images at current level
+  
+    if (verbose > 1)
+      fprintf(stderr, "%s: extracting at level %d now, size %d x %d\n",
+        progname, p->coarse->level, lwidth, lheight);
+
+    STEP = ROUND(alpha * (-15.555) +  10.777);
+    n = 0;
+    // consider each coefficient at resolution level
+    for (row = by; row < bh - STEP; row += STEP)
+      for (col = bx; col < bw - STEP; col += STEP) {
+          double h, v, d;
+          double *f1 = &h, *f2 = &v, *f3 = &d;
+          double delta;
+
+        // key-dependant coefficient selection
+        r = row + 1 + random() % (STEP-2);
+        c = col + 1 + random() % (STEP-2);
+
+         // get coefficient values, one from each detail image
+          h = get_pixel(p->horizontal->image, c, r);
+          v = get_pixel(p->vertical->image, c, r);
+          d = get_pixel(p->diagonal->image, c, r);
+
+          // order pointer to coefficient values such that f1 <= f2 <= f3
+#define SWAP(A, B) {double *t = A; A = B; B = t;}
+          if (*f1 > *f2) SWAP(f1, f2);
+          if (*f2 > *f3) SWAP(f2, f3);
+          if (*f1 > *f2) SWAP(f1, f2);
+
+          // calculate delta, the width of the bins
+          delta = (*f3 - *f1) / (double) (2 * quality - 1);
+
+          // set middle coefficient to closest appropriate bin,
+          // according to watermark bit
+          if (quality == 1) 
+            set_signature_bit(n, (*f3 - *f2) < (*f2 - *f1));
+          else {
+            double l = *f1;
+            int i = 0;
+            while ((l + delta) < *f2) {
+              l += delta; 
+              i++;
+            }
+            if (i % 2)
+              set_signature_bit(n, (l + delta - *f2) > (*f2 - l));
+            else
+              set_signature_bit(n, (l + delta - *f2) < (*f2 - l));
+          }
+
+          if (verbose > 2)
+            fprintf(stderr, "%s: extracted bit #%d (= %d =? %d) at (%d/%d),\n"
+                            "  f1=%lf, f2=%lf, f3=%lf\n", progname, n,
+                            get_signature_bit(n), get_signature2_bit(n),
+                            c, r, *f1, *f2, *f3);
+          n++;
+        }
+
+       nbit_signature = n;
+       binstr = malloc(sizeof(char) * (nbit_signature + 1));
+       sig_to_binstr(binstr);
+       fprintf(out, "%d\n", nbit_signature);
+       fprintf(out, "%s\n", binstr);
+       free(binstr);
+
+      }
+    }
+   // descend one level
+    p = p->coarse;
+  }
+
+  fclose(out);
+
+  pgm_freearray(input_image, rows);
+
+  exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/wm_kund2_e.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,330 @@
+#include "wm.h"
+#include "signature.h"
+#include "dwt.h"
+#include "pgm.h"
+
+char *progname;
+
+void usage(void) {
+  fprintf(stderr, "usage: %s [-e n] [-f n] [-F n] [-h] [-l n] [-o file] [-q n] [-v n] -s file file\n\n", progname);
+  fprintf(stderr, "\t-a n\t\toverall embedding strength\n");
+  fprintf(stderr, "\t-e n\t\twavelet filtering method\n");
+  fprintf(stderr, "\t-f n\t\tfilter number\n");
+  fprintf(stderr, "\t-F file\t\tfilter definition file\n");
+  fprintf(stderr, "\t-l n\t\tembedding level\n");
+  fprintf(stderr, "\t-h\t\tprint usage\n");
+  fprintf(stderr, "\t-o file\t\toutput (watermarked) file\n");
+  fprintf(stderr, "\t-q n\t\tsignature strength (default 4)\n");
+  fprintf(stderr, "\t-s file\t\tsignature to embed in input image\n");
+  fprintf(stderr, "\t-v n\t\tverbosity level\n");
+  exit(0);
+}
+
+int main(int argc, char *argv[]) {
+
+  FILE *in = stdin;
+  FILE *out = stdout;
+  FILE *sig = NULL;
+
+  char output_name[MAXPATHLEN] = "(stdout)";
+  char input_name[MAXPATHLEN] = "(stdin)";
+  char signature_name[MAXPATHLEN];
+
+  char *binstr;
+
+  int r, c, n;
+  int row, col;
+
+  int quality = 0;
+  int blocksize = 0;
+  int filter = 0;
+  int method = -1;
+  int level = 0;
+  char filter_name[MAXPATHLEN] = "";
+
+  double alpha = 0.0;
+  int seed;
+  int verbose = 0;
+
+  gray **image;
+  Image_tree dwts, p;
+
+  gray maxval;
+  int rows, cols, colors, format;
+
+  progname = argv[0];
+
+  pgm_init(&argc, argv);
+  wm_init();
+
+  while ((c = getopt(argc, argv, "a:e:f:F:h?l:o:q:s:v:")) != EOF) {
+    switch (c) {
+      case 'a':
+        alpha = atof(optarg);
+        break;
+      case 'e':
+        method = atoi(optarg);
+        if (method < 0) {
+          fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, method);
+          exit(1);
+        }
+        break;
+      case 'f':
+        filter = atoi(optarg);
+        if (filter <= 0) {
+          fprintf(stderr, "%s: filter number %d out of range\n", progname, filter);
+          exit(1);
+        }
+        break;
+      case 'F':
+        strcpy(filter_name, optarg);
+        break;
+      case 'h':
+      case '?':
+        usage();
+        break;
+      case 'l':
+        level = atoi(optarg);
+        if (level < 1) {
+          fprintf(stderr, "%s: embedding level out of range\n", progname);
+          exit(1);
+        }
+        break;       
+      case 'o':
+        if ((out = fopen(optarg, "wb")) == NULL) {
+          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(output_name, optarg);
+        break;
+      case 'q':
+        quality = atoi(optarg);
+        if (quality < 1) {
+          fprintf(stderr, "%s: quality factor %d out of range\n", progname, quality);
+          exit(1);
+        }
+        break;
+      case 's':
+        if ((sig = fopen(optarg, "r")) == NULL) {
+          fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(signature_name, optarg);
+        break;
+      case 'v':
+        verbose = atoi(optarg);
+        if (verbose < 0) {
+          fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
+          exit(1);
+        }
+        break;
+    }
+  }
+
+  argc -= optind;
+  argv += optind;
+
+  if (argc > 1) {
+    usage();
+    exit(1);
+  }
+
+  if (argc == 1 && *argv[0] != '-')
+    if ((in = fopen(argv[0], "rb")) == NULL) {
+      fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
+      exit(1);
+    }
+    else
+      strcpy(input_name, argv[0]);
+
+  if (sig) {
+    char line[1024];
+    fgets(line, sizeof(line), sig);
+    if (strspn(line, "KD2SG") >= 5) {
+      fscanf(sig, "%d\n", &nbit_signature);
+      if (quality == 0)
+        fscanf(sig, "%d\n", &quality);
+      else
+        fscanf(sig, "%*d\n");
+      if (blocksize == 0)
+        fscanf(sig, "%d\n", &blocksize);
+      else
+        fscanf(sig, "%*d\n");
+      if (method < 0)
+        fscanf(sig, "%d\n", &method);
+      else
+        fscanf(sig, "%*d\n");
+      if (filter == 0)
+        fscanf(sig, "%d\n", &filter);
+      else
+        fscanf(sig, "%*d\n");
+      if (!strcmp(filter_name, ""))
+        fscanf(sig, "%[^\n\r]\n", &filter_name);
+      else
+        fscanf(sig, "%*[^\n\r]\n");
+      if (level == 0)
+        fscanf(sig, "%d\n", &level);
+      else
+        fscanf(sig, "%*d\n");
+      fscanf(sig, "%d\n", &seed);
+      srandom(seed);
+      n_signature = NBITSTOBYTES(nbit_signature);
+      binstr = malloc((nbit_signature + 1) * sizeof(char));
+      fscanf(sig, "%[01]\n", binstr);
+      binstr_to_sig(binstr);
+      free(binstr);
+    }
+    else {
+      fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
+      exit(1);
+    }
+    fclose(sig);
+  }
+  else {
+    fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname);
+    exit(1);
+  }
+
+  pgm_readpgminit(in, &cols, &rows, &maxval, &format);
+
+  if (verbose > 0) 
+    fprintf(stderr, "%s: embedding %d bits with quality %d in\n"
+                    "  %d x %d host image, up to decomposition level %d\n",
+                    progname, nbit_signature, quality, cols, rows, level);
+
+  image = pgm_allocarray(cols, rows);
+
+  for (row = 0; row < rows; row++)
+    pgm_readpgmrow(in, image[row], cols, maxval, format);
+
+  fclose(in);
+
+  // decomposition of image
+  init_dwt(cols, rows, filter_name, filter, level, method);
+#ifdef POLLEN_STUFF
+#include "pollen_stuff.c"
+#endif
+#ifdef PARAM_STUFF
+#include "param_stuff.c"
+#endif
+
+  dwts = fdwt(image);
+
+  p = dwts;
+
+  // consider each resolution level
+  while (p->coarse->level < level) {
+    int lwidth = p->vertical->image->width;
+    int lheight =  p->vertical->image->height;
+    int l = p->vertical->level;
+    int bx, by;
+    int nblock;
+    int bits_per_level;
+
+    nblock = 0;
+    bits_per_level = 0;
+    for (bx = 0; bx < lwidth; bx += blocksize) {
+      for (by = 0; by < lheight; by += blocksize) {
+        int bw = MIN(bx + blocksize, lwidth);
+        int bh = MIN(by + blocksize, lheight);
+        int STEP;
+        float MIN_DIFF;
+
+    // start to embed signature from beginning at each level
+    // get width and height of detail images at current level 
+
+
+    if (verbose > 1) 
+      fprintf(stderr, "%s: embedding at level %d now, block %d, size %d x %d at %d, %d\n",
+        progname, l, nblock, bw, bh, bx, by);
+
+    MIN_DIFF = ROUND(120.0 * alpha);
+    STEP = ROUND(alpha * (-15.555) +  10.777);
+// fprintf(stderr, "XXX %d %f\n", STEP, MIN_DIFF);
+
+    n = 0;
+    // consider each coefficient at resolution level
+    for (row = by; row < bh - STEP; row += STEP)
+      for (col = bx; col < bw - STEP; col += STEP) {
+          double h, v, d;
+          double *f1 = &h, *f2 = &v, *f3 = &d;
+          double delta;
+
+          // key-dependant coefficient selection
+          r = row + 1+random() % (STEP-2);
+          c = col + 1+random() % (STEP-2);
+
+          // get coefficient values, one from each detail image
+          h = get_pixel(p->horizontal->image, c, r);
+          v = get_pixel(p->vertical->image, c, r);
+          d = get_pixel(p->diagonal->image, c, r);
+
+          // order pointer to coefficient values such that f1 <= f2 <= f3
+#define SWAP(A, B) {double *t = A; A = B; B = t;}
+          if (*f1 > *f2) SWAP(f1, f2);
+          if (*f2 > *f3) SWAP(f2, f3);
+          if (*f1 > *f2) SWAP(f1, f2);
+
+          if (verbose > 2) 
+            fprintf(stderr, "%s: embedding bit #%d (= %d) at (%d/%d),\n",
+                            progname, n, get_signature_bit(n % nbit_signature), c, r);
+          if (verbose > 5) 
+            fprintf(stderr, "  h=%lf, v=%lf, d=%lf\n", h, v, d);
+          if (verbose > 2)
+            fprintf(stderr, "  f1=%lf, f2=%lf", *f1, *f2);
+
+          if ((*f3 - *f1) < MIN_DIFF) {
+            double adj = (MIN_DIFF - (*f3 - *f1)) / 2.0;
+            *f1 -= adj;
+            *f3 += adj;            
+          }
+
+          // calculate delta, the width of the bins
+          delta = (*f3 - *f1) / (double) (2 * quality - 1);
+          
+          // set middle coefficient to closest appropriate bin, 
+          // according to watermark bit
+          bits_per_level++;
+          if (quality == 1)
+            *f2 = get_signature_bit(n % nbit_signature) ? *f3 : *f1;
+          else {
+            double l = get_signature_bit(n % nbit_signature) ? *f1 + delta : *f1;
+            while ((l + 2 * delta) < *f2) l += 2 * delta;
+            *f2 = (*f2 - l) < (l + 2 * delta - *f2) ? l : l + 2 * delta;
+          }
+
+          if (verbose > 2) 
+            fprintf(stderr, " -> %lf, f3=%lf\n", *f2, *f3);
+
+          // write pixels, one of them modified
+          set_pixel(p->horizontal->image, c, r, h);
+          set_pixel(p->vertical->image, c, r, v);
+          set_pixel(p->diagonal->image, c, r, d);
+
+          n++;
+
+        }
+      }
+    }
+
+    if (verbose > 1) 
+      fprintf(stderr, "%s: embedded %d bits at level %d\n", 
+        progname, bits_per_level, l);
+
+    // descend one level
+    p = p->coarse;
+  }
+
+  idwt(dwts, image);
+
+  pgm_writepgminit(out, cols, rows, maxval, 0);
+
+  for (row = 0; row < rows; row++)
+    pgm_writepgmrow(out, image[row], cols, maxval, 0);
+
+  fclose(out);
+
+  pgm_freearray(image, rows);
+
+  exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/wm_kund3_d.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,294 @@
+#include "wm.h"
+#include "signature.h"
+#include "dwt.h"
+#include "pgm.h"
+
+char *progname;
+
+void usage(void) {
+  fprintf(stderr, "usage: %s [-e n] [-f n] [-F n] [-h] [-l n] [-o file] [-q n] [-s file] [-v n] file\n\n", progname);
+  fprintf(stderr, "\t-e n\t\twavelet filtering method\n");
+  fprintf(stderr, "\t-f n\t\tfilter number\n");
+  fprintf(stderr, "\t-F file\t\tfilter definition file\n");
+  fprintf(stderr, "\t-h\t\tprint usage\n");
+  fprintf(stderr, "\t-l n\t\tembedding level\n");
+  fprintf(stderr, "\t-o file\t\textracted signature file\n");
+  fprintf(stderr, "\t-q n\t\tsignature strength\n");
+  fprintf(stderr, "\t-s file\t\toriginal signature file\n");
+  fprintf(stderr, "\t-v n\t\tverbosity level\n");
+  exit(0);
+}
+
+int main(int argc, char *argv[]) {
+
+  FILE *in = stdin;
+  FILE *out = stdout;
+  FILE *sig = NULL;
+
+  gray **input_image;
+
+  char signature_name[MAXPATHLEN];
+  char output_name[MAXPATHLEN] = "(stdout)";
+  char input_name[MAXPATHLEN] = "(stdin)";
+
+  int r, c;
+  int i;
+  int quality = 0;
+  int seed = 0;
+  int n = 0;
+  int method = -1;
+  int filter = 0;
+  char filter_name[MAXPATHLEN] = "";
+
+  char *binstr;
+
+  int level = 0;
+  double alpha = 0.0;
+
+  int in_rows, in_cols, in_format;
+  gray in_maxval;
+  int rows, cols;
+  int row, col;
+
+  Image_tree dwts, p;
+
+  int verbose = 0;
+
+  progname = argv[0];
+
+  pgm_init(&argc, argv);
+  wm_init();
+
+  while ((c = getopt(argc, argv, "e:f:F:h?l:o:q:s:v:")) != EOF) {
+    switch (c) {
+      case 'e':
+        method = atoi(optarg);
+        if (method < 0) {
+          fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, method);
+          exit(1);
+        }
+        break;
+      case 'f':
+        filter = atoi(optarg);
+        if (filter <= 0) {
+          fprintf(stderr, "%s: filter number %d out of range\n", progname, filter);
+          exit(1);
+        }
+        break;
+      case 'F':
+        strcpy(filter_name, optarg);
+        break;
+      case 'h':
+      case '?':
+        usage();
+        break;
+      case 'l':
+        level = atoi(optarg);
+        if (level < 1) {
+          fprintf(stderr, "%s: embedding level out of range\n", progname);
+          exit(1);
+        }
+        break;
+      case 'o':
+        if ((out = fopen(optarg, "w")) == NULL) {
+          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(output_name, optarg);
+        break;
+      case 'q':
+        quality = atoi(optarg);
+        if (quality < 1) {
+          fprintf(stderr, "%s: quality level %d out of range\n", progname, quality);
+          exit(1);
+        }
+        break;
+      case 's':
+        if ((sig = fopen(optarg, "r")) == NULL) {
+          fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(signature_name, optarg);
+        break;
+      case 'v':
+        verbose = atoi(optarg);
+        if (verbose < 0) {
+          fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
+          exit(1);
+        }
+        break;
+    }
+  }
+
+  argc -= optind;
+  argv += optind;
+
+  if (argc > 1) {
+    usage();
+    exit(1);
+  }
+
+  if (argc == 1 && *argv[0] != '-')
+    if ((in = fopen(argv[0], "rb")) == NULL) {
+      fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
+      exit(1);
+    }
+    else
+      strcpy(input_name, argv[0]);
+
+  if (sig) {
+    char line[32];
+    fgets(line, sizeof(line), sig);
+    if (strspn(line, "KD3SG") >= 5) {
+      fscanf(sig, "%d\n", &nbit_signature);
+      if (quality == 0)
+        fscanf(sig, "%d\n", &quality);
+      else
+        fscanf(sig, "%*d\n");
+      if (method < 0)
+        fscanf(sig, "%d\n", &method);
+      else
+        fscanf(sig, "%*d\n");
+      if (filter == 0)
+        fscanf(sig, "%d\n", &filter);
+      else
+        fscanf(sig, "%*d\n");
+      if (!strcmp(filter_name, ""))
+        fscanf(sig, "%[^\n\r]\n", &filter_name);
+      else
+        fscanf(sig, "%*[^\n\r]\n");
+      if (level == 0)
+        fscanf(sig, "%d\n", &level);
+      else
+        fscanf(sig, "%*d\n");
+      fscanf(sig, "%d\n", &seed);
+      srandom(seed);
+      nbit_signature2 = nbit_signature;
+      n_signature = n_signature2 = NBITSTOBYTES(nbit_signature2);
+      binstr = malloc((nbit_signature2 + 1) * sizeof(char));
+      fscanf(sig, "%[01]\n", binstr);
+      binstr_to_sig2(binstr);
+      free(binstr);
+      init_signature_bits();
+    }
+    else {
+      fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
+      exit(1);
+    }
+    fclose(sig);
+  }
+  else {
+    fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname);
+    exit(1);
+  }
+
+  pgm_readpgminit(in, &in_cols, &in_rows, &in_maxval, &in_format);
+
+  cols = in_cols;
+  rows = in_rows;
+
+  if (verbose > 0)
+    fprintf(stderr, "%s: extracting %d bits with quality %d from\n"
+                    "  %d x %d host image, decomposition level %d\n",
+                    progname, nbit_signature, quality, cols, rows, level);
+
+  input_image = pgm_allocarray(in_cols, in_rows);
+
+  for (row = 0; row < in_rows; row++)
+    pgm_readpgmrow(in, input_image[row], in_cols, in_maxval, in_format);
+
+  fclose(in);
+
+  init_dwt(cols, rows, filter_name, filter, level, method);
+/*#ifdef POLLEN_STUFF
+#include "pollen_stuff.c"
+#endif
+#ifdef PARAM_STUFF
+#include "param_stuff.c"
+#endif*/
+
+  dwts = fdwt(input_image);
+
+ p = dwts;
+
+#define STEP 3
+
+  // consider each resolution level
+  while (p->coarse->level < level)
+   // descend one level
+    p = p->coarse;
+
+    // start to extracting watermark from beginning at each level
+  {
+    // get width and height of detail images at current level
+    int lwidth = p->vertical->image->width;
+    int lheight =  p->vertical->image->height;
+  
+    if (verbose > 1)
+      fprintf(stderr, "%s: extracting at level %d now, size %d x %d\n",
+        progname, p->coarse->level, lwidth, lheight);
+
+    // consider each coefficient at resolution level
+    for (row = 0; row < lwidth - STEP; row += STEP)
+      for (col = 0; col < lheight - STEP; col += STEP) {
+          double h, v, d;
+          double *f1 = &h, *f2 = &v, *f3 = &d;
+          double delta;
+
+        // key-dependant coefficient selection
+        r = row + 1 + random() % (STEP-2);
+        c = col + 1 + random() % (STEP-2);
+
+         // get coefficient values, one from each detail image
+          h = get_pixel(p->horizontal->image, c, r);
+          v = get_pixel(p->vertical->image, c, r);
+          d = get_pixel(p->diagonal->image, c, r);
+
+          // order pointer to coefficient values such that f1 <= f2 <= f3
+#define SWAP(A, B) {double *t = A; A = B; B = t;}
+          if (*f1 > *f2) SWAP(f1, f2);
+          if (*f2 > *f3) SWAP(f2, f3);
+          if (*f1 > *f2) SWAP(f1, f2);
+
+          // calculate delta, the width of the bins
+          delta = (*f3 - *f1) / (double) (2 * quality - 1);
+
+          // set middle coefficient to closest appropriate bin,
+          // according to watermark bit
+          if (quality == 1) 
+            set_signature_bit(n, (*f3 - *f2) < (*f2 - *f1));
+          else {
+            double l = *f1;
+            int i = 0;
+            while ((l + delta) < *f2) {
+              l += delta; 
+              i++;
+            }
+            if (i % 2)
+              set_signature_bit(n, (l + delta - *f2) > (*f2 - l));
+            else
+              set_signature_bit(n, (l + delta - *f2) < (*f2 - l));
+          }
+
+          if (verbose > 2)
+            fprintf(stderr, "%s: extracted bit #%d (= %d =? %d) at (%d/%d),\n"
+                            "  f1=%lf, f2=%lf, f3=%lf\n", progname, n,
+                            get_signature_bit(n), get_signature2_bit(n),
+                            c, r, *f1, *f2, *f3);
+          n++;
+        }
+  }
+
+  fprintf(out, "KD3WM\n");
+  fprintf(out, "%d\n", n);
+  nbit_signature = n;
+  binstr = malloc(sizeof(char) * (nbit_signature + 1));
+  sig_to_binstr(binstr);
+  fprintf(out, "%s\n", binstr);
+  free(binstr);
+  fclose(out);
+
+  pgm_freearray(input_image, rows);
+
+  exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/wm_kund3_e.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,298 @@
+#include "wm.h"
+#include "signature.h"
+#include "dwt.h"
+#include "pgm.h"
+
+char *progname;
+
+void usage(void) {
+  fprintf(stderr, "usage: %s [-e n] [-f n] [-F n] [-h] [-l n] [-o file] [-q n] [-v n] -s file file\n\n", progname);
+  fprintf(stderr, "\t-e n\t\twavelet filtering method\n");
+  fprintf(stderr, "\t-f n\t\tfilter number\n");
+  fprintf(stderr, "\t-F file\t\tfilter definition file\n");
+  fprintf(stderr, "\t-l n\t\tembedding level\n");
+  fprintf(stderr, "\t-h\t\tprint usage\n");
+  fprintf(stderr, "\t-o file\t\toutput (watermarked) file\n");
+  fprintf(stderr, "\t-q n\t\tsignature strength (default 4)\n");
+  fprintf(stderr, "\t-s file\t\tsignature to embed in input image\n");
+  fprintf(stderr, "\t-v n\t\tverbosity level\n");
+  exit(0);
+}
+
+int main(int argc, char *argv[]) {
+
+  FILE *in = stdin;
+  FILE *out = stdout;
+  FILE *sig = NULL;
+
+  char output_name[MAXPATHLEN] = "(stdout)";
+  char input_name[MAXPATHLEN] = "(stdin)";
+  char signature_name[MAXPATHLEN];
+
+  char *binstr;
+
+  int r, c, n;
+  int row, col;
+
+  int quality = 0;
+
+  int filter = 0;
+  int method = -1;
+  int level = 0;
+  char filter_name[MAXPATHLEN] = "";
+
+  int seed;
+  int verbose = 0;
+
+  gray **image;
+  Image_tree dwts, p;
+
+  gray maxval;
+  int rows, cols, colors, format;
+
+  progname = argv[0];
+
+  pgm_init(&argc, argv);
+  wm_init();
+
+  while ((c = getopt(argc, argv, "e:f:F:h?l:o:q:s:v:")) != EOF) {
+    switch (c) {
+      case 'e':
+        method = atoi(optarg);
+        if (method < 0) {
+          fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, method);
+          exit(1);
+        }
+        break;
+      case 'f':
+        filter = atoi(optarg);
+        if (filter <= 0) {
+          fprintf(stderr, "%s: filter number %d out of range\n", progname, filter);
+          exit(1);
+        }
+        break;
+      case 'F':
+        strcpy(filter_name, optarg);
+        break;
+      case 'h':
+      case '?':
+        usage();
+        break;
+      case 'l':
+        level = atoi(optarg);
+        if (level < 1) {
+          fprintf(stderr, "%s: embedding level out of range\n", progname);
+          exit(1);
+        }
+        break;       
+      case 'o':
+        if ((out = fopen(optarg, "wb")) == NULL) {
+          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(output_name, optarg);
+        break;
+      case 'q':
+        quality = atoi(optarg);
+        if (quality < 1) {
+          fprintf(stderr, "%s: quality factor %d out of range\n", progname, quality);
+          exit(1);
+        }
+        break;
+      case 's':
+        if ((sig = fopen(optarg, "r")) == NULL) {
+          fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(signature_name, optarg);
+        break;
+      case 'v':
+        verbose = atoi(optarg);
+        if (verbose < 0) {
+          fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
+          exit(1);
+        }
+        break;
+    }
+  }
+
+  argc -= optind;
+  argv += optind;
+
+  if (argc > 1) {
+    usage();
+    exit(1);
+  }
+
+  if (argc == 1 && *argv[0] != '-')
+    if ((in = fopen(argv[0], "rb")) == NULL) {
+      fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
+      exit(1);
+    }
+    else
+      strcpy(input_name, argv[0]);
+
+  if (sig) {
+    char line[32];
+    fgets(line, sizeof(line), sig);
+    if (strspn(line, "KD3SG") >= 5) {
+      fscanf(sig, "%d\n", &nbit_signature);
+      if (quality == 0)
+        fscanf(sig, "%d\n", &quality);
+      else
+        fscanf(sig, "%*d\n");
+      if (method < 0)
+        fscanf(sig, "%d\n", &method);
+      else
+        fscanf(sig, "%*d\n");
+      if (filter == 0)
+        fscanf(sig, "%d\n", &filter);
+      else
+        fscanf(sig, "%*d\n");
+      if (!strcmp(filter_name, ""))
+        fscanf(sig, "%[^\n\r]\n", &filter_name);
+      else
+        fscanf(sig, "%*[^\n\r]\n");
+      if (level == 0)
+        fscanf(sig, "%d\n", &level);
+      else
+        fscanf(sig, "%*d\n");
+      fscanf(sig, "%d\n", &seed);
+      srandom(seed);
+      n_signature = NBITSTOBYTES(nbit_signature);
+      binstr = malloc((nbit_signature + 1) * sizeof(char));
+      fscanf(sig, "%[01]\n", binstr);
+      binstr_to_sig(binstr);
+      free(binstr);
+    }
+    else {
+      fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
+      exit(1);
+    }
+    fclose(sig);
+  }
+  else {
+    fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname);
+    exit(1);
+  }
+
+  pgm_readpgminit(in, &cols, &rows, &maxval, &format);
+
+  if (verbose > 0) 
+    fprintf(stderr, "%s: embedding %d bits with quality %d in\n"
+                    "  %d x %d host image, decomposition level %d\n",
+                    progname, nbit_signature, quality, cols, rows, level);
+
+  image = pgm_allocarray(cols, rows);
+
+  for (row = 0; row < rows; row++)
+    pgm_readpgmrow(in, image[row], cols, maxval, format);
+
+  fclose(in);
+
+  // decomposition of image
+  init_dwt(cols, rows, filter_name, filter, level, method);
+#ifdef POLLEN_STUFF
+#include "pollen_stuff.c"
+#endif
+#ifdef PARAM_STUFF
+#include "param_stuff.c"
+#endif
+
+  dwts = fdwt(image);
+
+  p = dwts;
+
+  // consider each resolution level
+  while (p->coarse->level < level) 
+    // descend one level
+    p = p->coarse;
+
+    // start to embed signature from beginning at each level
+    // get width and height of detail images at current level 
+  {
+    int lwidth = p->vertical->image->width;
+    int lheight =  p->vertical->image->height;
+
+    if (verbose > 1) 
+      fprintf(stderr, "%s: embedding at level %d now, size %d x %d\n", progname, 
+        p->coarse->level, lwidth, lheight);
+
+#define STEP 3
+    n = 0;
+    // consider each coefficient at resolution level
+    for (row = 0; row < lwidth - STEP; row += STEP)
+      for (col = 0; col < lheight - STEP; col += STEP) {
+          double h, v, d;
+          double *f1 = &h, *f2 = &v, *f3 = &d;
+          double delta;
+
+          // key-dependant coefficient selection
+          r = row + 1+random() % (STEP-2);
+          c = col + 1+random() % (STEP-2);
+
+          // get coefficient values, one from each detail image
+          h = get_pixel(p->horizontal->image, c, r);
+          v = get_pixel(p->vertical->image, c, r);
+          d = get_pixel(p->diagonal->image, c, r);
+
+          // order pointer to coefficient values such that f1 <= f2 <= f3
+#define SWAP(A, B) {double *t = A; A = B; B = t;}
+          if (*f1 > *f2) SWAP(f1, f2);
+          if (*f2 > *f3) SWAP(f2, f3);
+          if (*f1 > *f2) SWAP(f1, f2);
+
+          if (verbose > 2) 
+            fprintf(stderr, "%s: embedding bit #%d (= %d) at (%d/%d),\n",
+                            progname, n, get_signature_bit(n % nbit_signature), c, r);
+          if (verbose > 5) 
+            fprintf(stderr, "  h=%lf, v=%lf, d=%lf\n", h, v, d);
+          if (verbose > 2)
+            fprintf(stderr, "  f1=%lf, f2=%lf", *f1, *f2);
+
+#define MIN_DIFF 20.0
+          if (*f3 - *f1 < MIN_DIFF) {
+            double adj = (MIN_DIFF - (*f3 - *f1)) / 2.0;
+            *f1 -= adj;
+            *f3 += adj;            
+          }
+
+          // calculate delta, the width of the bins
+          delta = (*f3 - *f1) / (double) (2 * quality - 1);
+          
+          // set middle coefficient to closest appropriate bin, 
+          // according to watermark bit
+          if (quality == 1)
+            *f2 = get_signature_bit(n % nbit_signature) ? *f3 : *f1;
+          else {
+            double l = get_signature_bit(n % nbit_signature) ? *f1 + delta : *f1;
+            while ((l + 2 * delta) < *f2) l += 2 * delta;
+            *f2 = (*f2 - l) < (l + 2 * delta - *f2) ? l : l + 2 * delta;
+          }
+
+          if (verbose > 2) 
+            fprintf(stderr, " -> %lf, f3=%lf\n", *f2, *f3);
+
+          // write pixels, one of them modified
+          set_pixel(p->horizontal->image, c, r, h);
+          set_pixel(p->vertical->image, c, r, v);
+          set_pixel(p->diagonal->image, c, r, d);
+
+          n++;
+
+        }
+  }
+
+  idwt(dwts, image);
+
+  pgm_writepgminit(out, cols, rows, maxval, 0);
+
+  for (row = 0; row < rows; row++)
+    pgm_writepgmrow(out, image[row], cols, maxval, 0);
+
+  fclose(out);
+
+  pgm_freearray(image, rows);
+
+  exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/wm_kund_d.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,2 @@
+int main(int argc, char *argv[]) {
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/wm_kund_e.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,257 @@
+#include "wm.h"
+#include "signature.h"
+#include "wm_dwt.h"
+#include "pgm.h"
+
+char *progname;
+
+void usage(void) {
+  fprintf(stderr, "usage: %s [-e n] [-f n] [-F n] [-h] [-o file] [-q n] [-v n] -s file file\n\n", progname);
+  fprintf(stderr, "\t-e n\t\twavelet filtering method\n");
+  fprintf(stderr, "\t-f n\t\tfilter number\n");
+  fprintf(stderr, "\t-F file\t\tfilter definition file\n");
+  fprintf(stderr, "\t-h\t\tprint usage\n");
+  fprintf(stderr, "\t-o file\t\toutput (watermarked) file\n");
+  fprintf(stderr, "\t-q n\t\tquantization/quality factor\n");
+  fprintf(stderr, "\t-s file\t\tsignature to embed in input image\n");
+  fprintf(stderr, "\t-v n\t\tverbosity level\n");
+  exit(0);
+}
+
+int main(int argc, char *argv[]) {
+
+  FILE *in = stdin;
+  FILE *out = stdout;
+  FILE *sig = NULL;
+
+  char output_name[MAXPATHLEN] = "(stdout)";
+  char input_name[MAXPATHLEN] = "(stdin)";
+  char signature_name[MAXPATHLEN];
+
+  int c;
+  int row, col;
+
+  int n;
+
+  double quality = 0.0;
+
+  int filter = 0;
+  int method = -1;
+  int level = 0;
+  char filter_name[MAXPATHLEN] = "";
+
+  int seed;
+  int verbose = 0;
+
+  gray **image;
+  Image_tree dwts;
+
+  gray maxval;
+  int rows, cols, colors, format;
+
+  progname = argv[0];
+
+  pgm_init(&argc, argv);
+
+#ifdef __EMX__
+  _fsetmode(in, "b");
+  _fsetmode(out, "b");
+#endif
+
+  while ((c = getopt(argc, argv, "e:f:F:h?l:o:q:s:v:")) != EOF) {
+    switch (c) {
+      case 'e':
+        method = atoi(optarg);
+        if (method < 0) {
+          fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, method);
+          exit(1);
+        }
+        break;
+      case 'f':
+        filter = atoi(optarg);
+        if (filter <= 0) {
+          fprintf(stderr, "%s: filter number %d out of range\n", progname, filter);
+          exit(1);
+        }
+        break;
+      case 'F':
+        strcpy(filter_name, optarg);
+        break;
+      case 'h':
+      case '?':
+        usage();
+        break;
+      case 'l':
+        level = atoi(optarg);
+        if (level < 1) {
+          fprintf(stderr, "%s: embedding level out of range\n", progname);
+          exit(1);
+        }
+        break;       
+      case 'o':
+        if ((out = fopen(optarg, "wb")) == NULL) {
+          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(output_name, optarg);
+        break;
+      case 'q':
+        quality = atoi(optarg);
+        if (quality <= 0) {
+          fprintf(stderr, "%s: quality factor %d out of range\n", progname, quality);
+          exit(1);
+        }
+        break;
+      case 's':
+        if ((sig = fopen(optarg, "r")) == NULL) {
+          fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(signature_name, optarg);
+        break;
+      case 'v':
+        verbose = atoi(optarg);
+        if (verbose < 0) {
+          fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
+          exit(1);
+        }
+        break;
+    }
+  }
+
+  argc -= optind;
+  argv += optind;
+
+  if (argc > 1) {
+    usage();
+    exit(1);
+  }
+
+  if (argc == 1 && *argv[0] != '-')
+    if ((in = fopen(argv[0], "rb")) == NULL) {
+      fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
+      exit(1);
+    }
+    else
+      strcpy(input_name, argv[0]);
+
+  if (sig) {
+    char line[32];
+    fgets(line, sizeof(line), sig);
+    if (strspn(line, "KDSG") >= 4) {
+      fscanf(sig, "%d\n", &n);
+      if (quality == 0.0)
+        fscanf(sig, "%lf\n", &quality);
+      else
+        fscanf(sig, "%*lf\n");
+      if (method < 0)
+        fscanf(sig, "%d\n", &method);
+      else
+        fscanf(sig, "%*d\n");
+      if (filter == 0)
+        fscanf(sig, "%d\n", &filter);
+      else
+        fscanf(sig, "%*d\n");
+      if (!strcmp(filter_name, ""))
+        fscanf(sig, "%[^\n\r]\n", &filter_name);
+      else
+        fscanf(sig, "%*[^\n\r]\n");
+      if (level == 0)
+        fscanf(sig, "%d\n", &level);
+      else
+        fscanf(sig, "%*d\n");
+      fscanf(sig, "%d\n", &seed);
+      srandom(seed);
+      n_signature = NBITSTOBYTES(nbit_signature);
+      fread(signature, sizeof(char), n_signature, sig);
+      fscanf(sig, "\n");
+    }
+    else {
+      fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
+      exit(1);
+    }
+    fclose(sig);
+  }
+  else {
+    fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname);
+    exit(1);
+  }
+
+  pgm_readpgminit(in, &cols, &rows, &maxval, &format);
+
+  image = pgm_allocarray(cols, rows);
+
+  for (row = 0; row < rows; row++)
+    pgm_readpgmrow(in, image[row], cols, maxval, format);
+
+  fclose(in);
+
+  // check watermark dimensions and decomposition level
+
+
+  // decomposition of image
+  init_dwt(cols, rows, filter_name, filter, level, method);
+#ifdef POLLEN_STUFF
+  {
+    double alpha, beta;
+    char *alpha_str = getenv("POLLEN_ALPHA"), *beta_str = getenv("POLLEN_BETA");
+    
+    if (alpha_str && beta_str) {
+      alpha = atof(alpha_str);  
+      beta = atof(beta_str);
+     
+      if (alpha < -M_PI || alpha >= M_PI) {
+        fprintf(stderr, "%s: pollen - alpha %f out of range\n", progname, alpha);
+        exit(1);
+      }
+      
+      if (beta < -M_PI || beta >= M_PI) {
+        fprintf(stderr, "%s: pollen - beta %f out of range\n", progname, beta);
+        exit(1);
+      }
+      
+      if (verbose > 7)
+        fprintf(stderr, "%s: pollen - alpha %f, beta %f\n", progname, alpha, beta);
+      
+      dwt_pollen_filter(alpha, beta);
+    }
+  }
+#endif
+
+  dwts = fdwt(image);
+
+  // create 'image' from binary watermark 
+
+  // decomposition of watermark
+  init_dwt(cols, rows, filter_name, filter, 1, method);
+//  dwts = fdwt(watermark);
+
+  // calculate mean value of image and set alpha
+
+  // setup of contrast sensitivity matrix 
+
+  // segment detail images at each level
+
+  // calculate DFT of each segment
+
+  // compute salience for each segment
+
+  // calculate gamma or each detail image
+
+  // embed watermark
+
+  // reconstruction of watermarked image
+
+  idwt(dwts, image);
+
+  pgm_writepgminit(out, cols, rows, maxval, 0);
+
+  for (row = 0; row < rows; row++)
+    pgm_writepgmrow(out, image[row], cols, maxval, 0);
+
+  fclose(out);
+
+  pgm_freearray(image, rows);
+
+  exit(0);
+}
--- a/Meerwald/wm_wang_d.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/wm_wang_d.c	Tue Aug 14 21:11:21 2007 +0200
@@ -44,7 +44,7 @@
   int filter = 0;
   char filter_name[MAXPATHLEN] = "";
 
-  int level, levels;
+  int level = 0;
   double alpha = 0.0;
   double beta = 0.0;
 
@@ -225,14 +225,14 @@
   fclose(orig);
 
   // complete decomposition
-  levels = find_deepest_level(cols, rows) - 1;
+  level = find_deepest_level(cols, rows) - 1;
 
-  init_dwt(cols, rows, filter_name, filter, levels, method);
+  init_dwt(cols, rows, filter_name, filter, level, method);
 #ifdef POLLEN_STUFF
-#include "pollen_stuff.xxx"
+#include "pollen_stuff.c"
 #endif
 #ifdef PARAM_STUFF
-#include "param_stuff.xxx"
+#include "param_stuff.c"
 #endif
 
   input_dwts = fdwt(input_image);
--- a/Meerwald/wm_wang_e.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/wm_wang_e.c	Tue Aug 14 21:11:21 2007 +0200
@@ -40,7 +40,7 @@
 
   int filter = 0;
   int method = -1;
-  int levels;
+  int level = 0;
   char filter_name[MAXPATHLEN] = "";
 
   int verbose = 0;
@@ -185,15 +185,15 @@
   fclose(in);
 
   // complete decomposition
-  levels = find_deepest_level(cols, rows) - 1;
+  level = find_deepest_level(cols, rows) - 1;
 
   // wavelet transform
-  init_dwt(cols, rows, filter_name, filter, levels, method); 
+  init_dwt(cols, rows, filter_name, filter, level, method); 
 #ifdef POLLEN_STUFF
-#include "pollen_stuff.xxx"
+#include "pollen_stuff.c"
 #endif
 #ifdef PARAM_STUFF
-#include "param_stuff.xxx"
+#include "param_stuff.c"
 #endif
 
   dwts = fdwt(image);
--- a/Meerwald/wm_xia_d.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/wm_xia_d.c	Tue Aug 14 21:11:21 2007 +0200
@@ -249,10 +249,10 @@
 
   init_dwt(cols, rows, filter_name, filter, level, method);
 #ifdef POLLEN_STUFF
-#include "pollen_stuff.xxx"
+#include "pollen_stuff.c"
 #endif
 #ifdef PARAM_STUFF
-#include "param_stuff.xxx"
+#include "param_stuff.c"
 #endif
 
   input_dwts = fdwt(input_image);
--- a/Meerwald/wm_xia_e.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/wm_xia_e.c	Tue Aug 14 21:11:21 2007 +0200
@@ -211,10 +211,10 @@
   // wavelet transform
   init_dwt(cols, rows, filter_name, filter, level, method);
 #ifdef POLLEN_STUFF
-#include "pollen_stuff.xxx"
+#include "pollen_stuff.c"
 #endif
 #ifdef PARAM_STUFF
-#include "param_stuff.xxx"
+#include "param_stuff.c"
 #endif
 
   dwts = fdwt(image);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/wm_xie2_d.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,269 @@
+#include "wm.h"
+#include "signature.h"
+#include "dwt.h"
+#include "pgm.h"
+
+char *progname;
+
+// inverse watermarking transformation, extract embedded bit, check quantization boundaries
+double wm_transform(int quant, double f1, double f2, double f3) {
+  double s = (fabs(f3) - fabs(f1)) / (double) quant;
+  double l = f1;
+  int x;
+  
+  x = 0;
+  while (l  < f2) {
+    l += s;
+    x++;
+  }
+
+  if (fabs(l - s - f2) < fabs(l-f2))
+    return (x+1) % 2;
+  else 
+    return (x) % 2;
+}
+
+void usage(void) {
+  fprintf(stderr, "usage: %s [-a n] [-e n] [-f n] [-F n] [-h] [-l n] [-o file] [-v n] -s file file\n\n", progname);
+  fprintf(stderr, "\t-a n\t\tembedding strength (default 0.05)\n");
+  fprintf(stderr, "\t-e n\t\twavelet filtering method\n");
+  fprintf(stderr, "\t-f n\t\tfilter number\n");
+  fprintf(stderr, "\t-F file\t\tfilter definition file\n");
+  fprintf(stderr, "\t-l n\t\tembedding level\n");
+  fprintf(stderr, "\t-h\t\tprint usage\n");
+  fprintf(stderr, "\t-o file\t\textracted signature file\n");
+  fprintf(stderr, "\t-q n\t\tquantization level\n");
+  fprintf(stderr, "\t-s file\t\tsignature to embed in input image\n");
+  fprintf(stderr, "\t-v n\t\tverbosity level\n");
+  exit(0);
+}
+
+int main(int argc, char *argv[]) {
+
+  FILE *in = stdin;
+  FILE *out = stdout;
+  FILE *sig = NULL;
+
+  char output_name[MAXPATHLEN] = "(stdout)";
+  char input_name[MAXPATHLEN] = "(stdin)";
+  char signature_name[MAXPATHLEN];
+
+  int c, n;
+  int row, col;
+
+  double alpha = 0.0;
+  int quant = 0;
+  int filter = 0;
+  int method = -1;
+  int level = 0;
+  char filter_name[MAXPATHLEN] = "";
+
+  int seed;
+  int verbose = 0;
+
+  gray **image;
+  Image_tree dwts, p;
+
+  gray maxval;
+  int rows, cols, colors, format;
+
+  progname = argv[0];
+
+  pgm_init(&argc, argv); wm_init2();
+
+  while ((c = getopt(argc, argv, "a:e:f:F:h?l:o:s:v:q:")) != EOF) {
+    switch (c) {
+      case 'e':
+        method = atoi(optarg);
+        if (method < 0) {
+          fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, method);
+          exit(1);
+        }
+        break;
+      case 'f':
+        filter = atoi(optarg);
+        if (filter <= 0) {
+          fprintf(stderr, "%s: filter number %d out of range\n", progname, filter);
+          exit(1);
+        }
+        break;
+      case 'F':
+        strcpy(filter_name, optarg);
+        break;
+      case 'h':
+      case '?':
+        usage();
+        break;
+      case 'l':
+        level = atoi(optarg);
+        if (level < 1) {
+          fprintf(stderr, "%s: embedding level out of range\n", progname);
+          exit(1);
+        }
+        break;       
+      case 'o':
+        if ((out = fopen(optarg, "wb")) == NULL) {
+          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(output_name, optarg);
+        break;
+      case 'q':
+        quant = atoi(optarg);
+        break;
+      case 'a':
+        alpha = atof(optarg);
+        if (alpha <= 0.0) {
+          fprintf(stderr, "%s: embedding strength factor %f out of range\n", progname, alpha);
+          exit(1);
+        }
+        break;
+      case 's':
+        if ((sig = fopen(optarg, "r")) == NULL) {
+          fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(signature_name, optarg);
+        break;
+      case 'v':
+        verbose = atoi(optarg);
+        if (verbose < 0) {
+          fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
+          exit(1);
+        }
+        break;
+    }
+  }
+
+  argc -= optind;
+  argv += optind;
+
+  if (argc > 1) {
+    usage();
+    exit(1);
+  }
+
+  if (argc == 1 && *argv[0] != '-')
+    if ((in = fopen(argv[0], "rb")) == NULL) {
+      fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
+      exit(1);
+    }
+    else
+      strcpy(input_name, argv[0]);
+
+  if (sig) {
+    char line[32];
+    fgets(line, sizeof(line), sig);
+    if (strspn(line, "XE2SG") >= 5) {
+      fscanf(sig, "%d\n", &nbit_signature);
+      if (alpha == 0.0)
+        fscanf(sig, "%lf\n", &alpha);
+      else
+        fscanf(sig, "%*lf\n");
+      if (method < 0)
+        fscanf(sig, "%d\n", &method);
+      else
+        fscanf(sig, "%*d\n");
+      if (filter == 0)
+        fscanf(sig, "%d\n", &filter);
+      else
+        fscanf(sig, "%*d\n");
+      if (!strcmp(filter_name, ""))
+        fscanf(sig, "%[^\n\r]\n", &filter_name);
+      else
+        fscanf(sig, "%*[^\n\r]\n");
+      if (quant == 0)
+        fscanf(sig, "%d\n", &quant);
+      else
+        fscanf(sig, "%*d\n");
+      if (level == 0)
+        fscanf(sig, "%d\n", &level);
+      else
+        fscanf(sig, "%*d\n");
+      fscanf(sig, "%d\n", &seed);
+      srandom(seed);
+      n_signature = NBITSTOBYTES(nbit_signature);
+      fread(signature, sizeof(char), n_signature, sig);
+      fscanf(sig, "\n");
+    }
+    else {
+      fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
+      exit(1);
+    }
+    fclose(sig);
+  }
+  else {
+    fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname);
+    exit(1);
+  }
+
+  pgm_readpgminit(in, &cols, &rows, &maxval, &format);
+  if (verbose > 0) 
+    fprintf(stderr, "%s: embedding %d bits with strength %d in\n"
+                    "  %d x %d host image, decomposition level %d\n",
+                    progname, nbit_signature, quant, cols, rows, level);
+
+  image = pgm_allocarray(cols, rows);
+  for (row = 0; row < rows; row++)
+    pgm_readpgmrow(in, image[row], cols, maxval, format);
+  fclose(in);
+
+  // decomposition of image
+  init_dwt(cols, rows, filter_name, filter, level, method);
+#ifdef POLLEN_STUFF
+#include "pollen_stuff.c"
+#endif
+#ifdef PARAM_STUFF
+#include "param_stuff.c"
+#endif
+
+  dwts = fdwt(image);
+
+  p = dwts;
+
+  // consider each resolution level
+  while (p->level < level) 
+    // descend one level
+    p = p->coarse;
+
+  // repeat binary watermark by sliding a 3-pixel window of approximation image
+  n = 0;
+  for (row = 0; row < p->image->height; row++) {
+    col = 0;
+    while (col < p->image->width - 3) {
+      double b1, b2, b3;
+      double *f1 = &b1, *f2 = &b2, *f3 = &b3;
+
+      // get all three approximation pixels in window
+      b1 = get_pixel(p->image, col + 0, row);
+      b2 = get_pixel(p->image, col + 1, row);
+      b3 = get_pixel(p->image, col + 2, row);
+
+      // bring selected pixels in ascending order
+#define SWAP(A, B) {double *t = A; A = B; B = t;}
+      if (*f1 > *f2) SWAP(f1, f2);
+      if (*f2 > *f3) SWAP(f2, f3);
+      if (*f1 > *f2) SWAP(f1, f2);
+
+      set_signature_bit(n, wm_transform(quant, *f1, *f2, *f3));
+
+      if (verbose > 1)
+        fprintf(stderr, "%s: extracting #%d (= %d) at (%d/%d); %f < %f < %f\n",
+          progname, n, get_signature_bit(n % nbit_signature), col, row, *f1, *f2, *f3);
+
+      n++;
+      col += 3;
+      col += (2.0 / alpha);
+    }
+  }
+
+  fprintf(out, "XE2WM\n");  
+  fprintf(out, "%d\n", n);
+  fwrite(signature, sizeof(char), NBITSTOBYTES(n), out);
+  fprintf(out, "\n");
+  fclose(out);
+
+  pgm_freearray(image, rows);
+
+  exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Meerwald/wm_xie2_e.c	Tue Aug 14 21:11:21 2007 +0200
@@ -0,0 +1,287 @@
+#include "wm.h"
+#include "signature.h"
+#include "dwt.h"
+#include "pgm.h"
+
+char *progname;
+
+// watermarking transformation, set median pixel to quantization boundary
+double wm_transform(int quant, double f1, double f2, double f3, int x) {
+  double s = (fabs(f3) - fabs(f1)) / (double) quant;
+  double l = x ? (f1 + s) : f1;
+  double f2new;
+  
+  while ((l + 2 * s) < f2) l += 2 * s;
+  f2new = ((f2 - l) < (l + 2 * s - f2)) ? l : (l + 2 * s);
+
+  return f2new;
+}
+
+void usage(void) {
+  fprintf(stderr, "usage: %s [-a n] [-e n] [-f n] [-F n] [-h] [-l n] [-o file] [-v n] -s file file\n\n", progname);
+  fprintf(stderr, "\t-a n\t\tembedding strength (default 0.05)\n");
+  fprintf(stderr, "\t-e n\t\twavelet filtering method\n");
+  fprintf(stderr, "\t-f n\t\tfilter number\n");
+  fprintf(stderr, "\t-F file\t\tfilter definition file\n");
+  fprintf(stderr, "\t-l n\t\tembedding level\n");
+  fprintf(stderr, "\t-h\t\tprint usage\n");
+  fprintf(stderr, "\t-o file\t\toutput (watermarked) file\n");
+  fprintf(stderr, "\t-q n\t\tquantization level\n");
+  fprintf(stderr, "\t-s file\t\tsignature to embed in input image\n");
+  fprintf(stderr, "\t-v n\t\tverbosity level\n");
+  exit(0);
+}
+
+int main(int argc, char *argv[]) {
+
+  FILE *in = stdin;
+  FILE *out = stdout;
+  FILE *sig = NULL;
+
+  char output_name[MAXPATHLEN] = "(stdout)";
+  char input_name[MAXPATHLEN] = "(stdin)";
+  char signature_name[MAXPATHLEN];
+
+  int c, n;
+  int row, col;
+
+  double alpha = 0.0;
+  int filter = 0;
+  int method = -1;
+  int level = 0;
+  int quant = 0;
+  char filter_name[MAXPATHLEN] = "";
+
+  int seed;
+  int verbose = 0;
+
+  gray **image;
+  Image_tree dwts, p;
+
+  gray maxval;
+  int rows, cols, colors, format;
+
+  progname = argv[0];
+
+  pgm_init(&argc, argv); wm_init();
+
+  while ((c = getopt(argc, argv, "a:e:f:F:h?l:o:s:v:")) != EOF) {
+    switch (c) {
+      case 'e':
+        method = atoi(optarg);
+        if (method < 0) {
+          fprintf(stderr, "%s: wavelet filtering method %d out of range\n", progname, method);
+          exit(1);
+        }
+        break;
+      case 'f':
+        filter = atoi(optarg);
+        if (filter <= 0) {
+          fprintf(stderr, "%s: filter number %d out of range\n", progname, filter);
+          exit(1);
+        }
+        break;
+      case 'F':
+        strcpy(filter_name, optarg);
+        break;
+      case 'h':
+      case '?':
+        usage();
+        break;
+      case 'l':
+        level = atoi(optarg);
+        if (level < 1) {
+          fprintf(stderr, "%s: embedding level out of range\n", progname);
+          exit(1);
+        }
+        break;       
+      case 'o':
+        if ((out = fopen(optarg, "wb")) == NULL) {
+          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(output_name, optarg);
+        break;
+      case 'q':
+        quant = atoi(optarg);
+        break;
+      case 'a':
+        alpha = atof(optarg);
+        if (alpha <= 0.0) {
+          fprintf(stderr, "%s: embedding strength factor %f out of range\n", progname, alpha);
+          exit(1);
+        }
+        break;
+      case 's':
+        if ((sig = fopen(optarg, "r")) == NULL) {
+          fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);
+          exit(1);
+        }
+        strcpy(signature_name, optarg);
+        break;
+      case 'v':
+        verbose = atoi(optarg);
+        if (verbose < 0) {
+          fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
+          exit(1);
+        }
+        break;
+    }
+  }
+
+  argc -= optind;
+  argv += optind;
+
+  if (argc > 1) {
+    usage();
+    exit(1);
+  }
+
+  if (argc == 1 && *argv[0] != '-')
+    if ((in = fopen(argv[0], "rb")) == NULL) {
+      fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
+      exit(1);
+    }
+    else
+      strcpy(input_name, argv[0]);
+
+  if (sig) {
+    char line[32];
+    fgets(line, sizeof(line), sig);
+    if (strspn(line, "XE2SG") >= 5) {
+      fscanf(sig, "%d\n", &nbit_signature);
+      if (alpha == 0.0)
+        fscanf(sig, "%lf\n", &alpha);
+      else
+        fscanf(sig, "%*lf\n");
+      if (method < 0)
+        fscanf(sig, "%d\n", &method);
+      else
+        fscanf(sig, "%*d\n");
+      if (filter == 0)
+        fscanf(sig, "%d\n", &filter);
+      else
+        fscanf(sig, "%*d\n");
+      if (!strcmp(filter_name, ""))
+        fscanf(sig, "%[^\n\r]\n", &filter_name);
+      else
+        fscanf(sig, "%*[^\n\r]\n");
+      if (quant == 0)
+        fscanf(sig, "%d\n", &quant);
+      else
+        fscanf(sig, "%*d\n");
+      if (level == 0)
+        fscanf(sig, "%d\n", &level);
+      else
+        fscanf(sig, "%*d\n");
+      fscanf(sig, "%d\n", &seed);
+      srandom(seed);
+      n_signature = NBITSTOBYTES(nbit_signature);
+      fread(signature, sizeof(char), n_signature, sig);
+      fscanf(sig, "\n");
+    }
+    else {
+      fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);
+      exit(1);
+    }
+    fclose(sig);
+  }
+  else {
+    fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname);
+    exit(1);
+  }
+
+  pgm_readpgminit(in, &cols, &rows, &maxval, &format);
+
+  if (verbose > 0) 
+    fprintf(stderr, "%s: embedding %d bits with strength %d in\n"
+                    "  %d x %d host image, decomposition level %d\n",
+                    progname, nbit_signature, quant, cols, rows, level);
+
+  image = pgm_allocarray(cols, rows);
+
+  for (row = 0; row < rows; row++)
+    pgm_readpgmrow(in, image[row], cols, maxval, format);
+
+  fclose(in);
+
+  // decomposition of image
+  init_dwt(cols, rows, filter_name, filter, level, method);
+#ifdef POLLEN_STUFF
+#include "pollen_stuff.c"
+#endif
+#ifdef PARAM_STUFF
+#include "param_stuff.c"
+#endif
+
+  dwts = fdwt(image);
+
+  p = dwts;
+
+  // consider each resolution level
+  while (p->level < level) 
+    // descend one level
+    p = p->coarse;
+
+  // repeat binary watermark by sliding a 3-pixel window of approximation image
+  n = 0;
+  for (row = 0; row < p->image->height; row++) {
+    col = 0;
+    while (col < p->image->width - 3) {
+      double MIN_DIFF = (20.0 * alpha);
+      double b1, b2, b3;
+      double *f1 = &b1, *f2 = &b2, *f3 = &b3;
+      double f2new;
+
+      // get all three approximation pixels in window
+      b1 = get_pixel(p->image, col + 0, row);
+      b2 = get_pixel(p->image, col + 1, row);
+      b3 = get_pixel(p->image, col + 2, row);
+
+      // bring selected pixels in ascending order
+#define SWAP(A, B) {double *t = A; A = B; B = t;}
+      if (*f1 > *f2) SWAP(f1, f2);
+      if (*f2 > *f3) SWAP(f2, f3);
+      if (*f1 > *f2) SWAP(f1, f2);
+
+      if ((*f3 - *f1) < MIN_DIFF) {
+        double adj = (MIN_DIFF - (*f3 - *f1)) / 2.0;
+        *f1 -= adj;
+        *f3 += adj;
+      }
+
+      // apply watermarking transformation (modify median pixel)
+      f2new = wm_transform(quant, *f1, *f2, *f3, get_signature_bit(n % nbit_signature));
+
+      if (verbose > 1)
+        fprintf(stderr, "%s: embedding #%d (= %d) at (%d/%d); %f < %f -> %f < %f\n",
+          progname, n, get_signature_bit(n % nbit_signature), col, row, *f1, *f2, f2new, *f3);
+
+      *f2 = f2new;
+
+      // write modified pixel     
+      set_pixel(p->image, col + 0, row, b1);
+      set_pixel(p->image, col + 1, row, b2);
+      set_pixel(p->image, col + 2, row, b3);
+      n++;
+      col += 3;
+      col+= (2.0 / alpha);
+    }
+  }
+
+    
+  // skip over some pixels
+
+  idwt(dwts, image);
+
+  pgm_writepgminit(out, cols, rows, maxval, 0);
+
+  for (row = 0; row < rows; row++)
+    pgm_writepgmrow(out, image[row], cols, maxval, 0);
+
+  fclose(out);
+
+  pgm_freearray(image, rows);
+
+  exit(0);
+}
--- a/Meerwald/wm_xie_d.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/wm_xie_d.c	Tue Aug 14 21:11:21 2007 +0200
@@ -202,10 +202,10 @@
   // decomposition of image
   init_dwt(cols, rows, filter_name, filter, level, method);
 #ifdef POLLEN_STUFF
-#include "pollen_stuff.xxx"
+#include "pollen_stuff.c"
 #endif
 #ifdef PARAM_STUFF
-#include "param_stuff.xxx"
+#include "param_stuff.c"
 #endif
 
   dwts = fdwt(image);
--- a/Meerwald/wm_xie_e.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/wm_xie_e.c	Tue Aug 14 21:11:21 2007 +0200
@@ -199,10 +199,10 @@
   // decomposition of image
   init_dwt(cols, rows, filter_name, filter, level, method);
 #ifdef POLLEN_STUFF
-#include "pollen_stuff.xxx"
+#include "pollen_stuff.c"
 #endif
 #ifdef PARAM_STUFF
-#include "param_stuff.xxx"
+#include "param_stuff.c"
 #endif
 
   dwts = fdwt(image);
--- a/Meerwald/wm_zhu_d.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/wm_zhu_d.c	Tue Aug 14 21:11:21 2007 +0200
@@ -227,10 +227,10 @@
 
   init_dwt(cols, rows, filter_name, filter, levels, method);
 #ifdef POLLEN_STUFF
-#include "pollen_stuff.xxx"
+#include "pollen_stuff.c"
 #endif
 #ifdef PARAM_STUFF
-#include "param_stuff.xxx"
+#include "param_stuff.c"
 #endif
 
   input_dwts = fdwt(input_image);
--- a/Meerwald/wm_zhu_e.c	Tue Aug 14 19:59:48 2007 +0200
+++ b/Meerwald/wm_zhu_e.c	Tue Aug 14 21:11:21 2007 +0200
@@ -190,10 +190,10 @@
   // wavelet transform
   init_dwt(cols, rows, filter_name, filter, level, method);
 #ifdef POLLEN_STUFF
-#include "pollen_stuff.xxx"
+#include "pollen_stuff.c"
 #endif
 #ifdef PARAM_STUFF
-#include "param_stuff.xxx"
+#include "param_stuff.c"
 #endif
 
   dwts = fdwt(image);
--- a/README	Tue Aug 14 19:59:48 2007 +0200
+++ b/README	Tue Aug 14 21:11:21 2007 +0200
@@ -1,5 +1,11 @@
 Watermarking source
 
+version 0.5
+  * added algorithm kund2 and kund3
+  * added xie2
+  * fixed uninitialized variable level in wm_kim_{e|d}.c
+  * updated netpbm include file names (for netpbm 10.x)
+
 version 0.4
   * bug fixes
       - wm_xia_{e|d}.c variable level uninitialized
@@ -23,7 +29,7 @@
  * initial release
 
 Peter Meerwald  
-Dept. of Scientific Computing, University of Salzburg
+Dept. of Computer Sciences, University of Salzburg, Austria
 
 pmeerw@cosy.sbg.ac.at
 http://www.cosy.sbg.ac.at/~pmeerw/Watermarking
--- a/make/make.linux	Tue Aug 14 19:59:48 2007 +0200
+++ b/make/make.linux	Tue Aug 14 21:11:21 2007 +0200
@@ -2,8 +2,8 @@
 CFLAGS = -O2 -g -DLINUX
 LDFLAGS = -g
 LIBS = -lm
-PGMLIBS = -lnetpbm -lm
-WMLIB = -L. -lwm
+PGMLIBS = -lnetpbm
+WMLIB = -L. -lwm -lm
 WAVELIB = -L. -lwavelet
 EXE =
 MAKEDEP = makedepend
--- a/manual.lyx	Tue Aug 14 19:59:48 2007 +0200
+++ b/manual.lyx	Tue Aug 14 21:11:21 2007 +0200
@@ -1,81 +1,105 @@
-#LyX 1.1 created this file. For more info see http://www.lyx.org/
-\lyxformat 218
+#LyX 1.5.0rc2 created this file. For more info see http://www.lyx.org/
+\lyxformat 276
+\begin_document
+\begin_header
 \textclass paper
 \language english
 \inputencoding auto
-\fontscheme default
+\font_roman default
+\font_sans default
+\font_typewriter default
+\font_default_family default
+\font_sc false
+\font_osf false
+\font_sf_scale 100
+\font_tt_scale 100
 \graphics default
 \paperfontsize default
-\spacing single 
-\papersize Default
-\paperpackage a4
-\use_geometry 0
-\use_amsmath 0
+\spacing single
+\papersize default
+\use_geometry false
+\use_amsmath 1
+\use_esint 0
+\cite_engine basic
+\use_bibtopic false
 \paperorientation portrait
 \secnumdepth 3
 \tocdepth 3
 \paragraph_separation skip
 \defskip smallskip
 \quotes_language english
-\quotes_times 2
 \papercolumns 1
 \papersides 1
 \paperpagestyle default
-
-\layout Title
+\tracking_changes false
+\output_changes false
+\author "Anonymous" 
+\end_header
 
+\begin_body
+
+\begin_layout Title
 Watermarking Source Code
-\layout SubTitle
+\end_layout
 
-version 0.4
-\layout Author
+\begin_layout SubTitle
+version 0.5
+\end_layout
 
+\begin_layout Author
 Peter Meerwald
-\layout Address
+\end_layout
 
+\begin_layout Address
 Dept.
- of Scientific Computing, University of Salzburg
-\newline 
+ of Computer Sciences, University of Salzburg
+\newline
 Jakob-Haringer-Str.
  2, A-5020 Salzburg, Austria
-\newline 
+\newline
 
-\begin_inset LatexCommand \url{mailto:pmeerw@cosy.sbg.ac.at}
+\begin_inset LatexCommand url
+target "mailto:pmeerw@cosy.sbg.ac.at"
 
-\end_inset 
+\end_inset
 
 
-\newline 
+\newline
 
-\begin_inset LatexCommand \url{http://www.cosy.sbg.ac.at/~pmeerw/Watermarking}
+\begin_inset LatexCommand url
+target "http://www.cosy.sbg.ac.at/~pmeerw/Watermarking"
 
-\end_inset 
+\end_inset
 
 
-\layout Abstract
+\end_layout
 
+\begin_layout Abstract
 This package provides source code for some watermarking algorithms in hopefully
  portable C code.
  The programs can be used to study watermarking techniques, perform comparative
  robustness tests and develop new attacks against embedded watermarks.
-\layout Abstract
+\end_layout
 
+\begin_layout Abstract
 However, the provided programs are by no means suitable for real-world applicati
 on (i.e.
  copyright protection) and the code solely serves some educational purpose.
-\layout Standard
+\end_layout
+
+\begin_layout Standard
+\begin_inset LatexCommand tableofcontents
+
+\end_inset
 
 
-\begin_inset LatexCommand \tableofcontents{}
-
-\end_inset 
-
+\end_layout
 
-\layout Section
-
+\begin_layout Section
 Introduction
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Academic research in the watermarking field has grown dramatically since
  approximately 1995.
  But surprisingly, source code for the proposed watermarking schemes has
@@ -83,117 +107,143 @@
  The reason is most likely the security of many watermarking systems lies
  at least to some extent in the embedding and detection algorithm itself,
  and not in the keys used -- violating the Kerckhoff principle 
-\begin_inset LatexCommand \cite{Kerckhoff1883a}
+\begin_inset LatexCommand cite
+key "Kerckhoff1883a"
 
-\end_inset 
+\end_inset
 
 .
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 With the availability of public robustness test for watermarking algorithms,
  StirMark 
-\begin_inset LatexCommand \cite{Petitcolas99c, Petitcolas98b, Petitcolas98a}
+\begin_inset LatexCommand cite
+key "Petitcolas99c, Petitcolas98b, Petitcolas98a"
 
-\end_inset 
+\end_inset
 
 , Unzign
-\begin_float footnote 
-\layout Standard
+\begin_inset Foot
+status collapsed
+
+\begin_layout Standard
+\begin_inset LatexCommand url
+target "http://www.altern.org/watermark"
+
+\end_inset
 
 
-\begin_inset LatexCommand \url{http://www.altern.org/watermark}
+\end_layout
 
-\end_inset 
-
+\end_inset
 
-\end_float 
  and very recently Checkmark
-\begin_inset LatexCommand \cite{Pereira01b}
+\begin_inset LatexCommand cite
+key "Pereira01b"
 
-\end_inset 
+\end_inset
 
 , the situation begins to improve.
  Now it is possible to measure the performance of watermarking systems.
  
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 In order the compare and evaluate new embedding and detection techniques,
  it is also necessary to have some reference implementations of the older,
  now often called classical schemes.
  In this work, we provide some implementations of watermarking schemes,
  some of which can be considered 'classical'.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 It was the goal to capture the main ideas of the proposed algorithms, as
  layed out in the respective papers.
  This is clearly not an easy task as some papers do not disclose all details
  or state which particular parameters were used to obtain the results outlined
  in the communications.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 I am very interested in hearing your comments, complaints and suggestions
  regarding this software.
  Moreover, if you have source code for a watermarking scheme not yet covered
  or some useful utility I would be happy to include your code in this distributi
 on.
  Please see the contact information at the top of this document.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 If you use the accompanying code, please cite my thesis:
-\layout Quotation
+\end_layout
 
+\begin_layout Quotation
 Peter Meerwald, Digital Image Watermarking in the Wavelet Transform Domain,
  Master's Thesis, Department of Scientific Computing, University of Salzburg,
  Austria, January 2001.
-\layout Section
+\end_layout
 
+\begin_layout Section
 Software
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Most of the software provided herein was written by myself, as part of my
  Master thesis.
  Some contributions were made by Vassilis Fotopoulos
-\begin_float footnote 
-\layout Standard
+\begin_inset Foot
+status collapsed
+
+\begin_layout Standard
+\begin_inset LatexCommand url
+target "mailto:vfotop1@physics.upatras.gr"
+
+\end_inset
 
 
-\begin_inset LatexCommand \url{mailto:vfotop1@physics.upatras.gr}
+\end_layout
 
-\end_inset 
+\end_inset
 
-
-\end_float 
 .
  The software in the archive is organized in the following sub-directories:
-\layout Description
+\end_layout
 
+\begin_layout Description
 Fotopoulos/ contains contributions by Vassilis Fotopoulos
-\layout Description
+\end_layout
 
+\begin_layout Description
 Meerwald/ contains my work
-\layout Description
+\end_layout
 
+\begin_layout Description
 images/ contains the Lena image in PGM format; the default parameters of
  most algorithms are tuned to work best with that image
-\layout Description
+\end_layout
 
+\begin_layout Description
 linux_bin/ the place where the Linux executables are stored in the binary
  distribution
-\layout Description
+\end_layout
 
+\begin_layout Description
 win32_bin/ the place where Windows 32-bit executables are distributed; tested
  with Windows NT 4.0 only
-\layout Description
+\end_layout
 
+\begin_layout Description
 make/ contains the 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 Makefile
-\family default 
-\size default 
+\family default
+\size default
  options to build the code on supported platforms
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 For the purpose of this software package, a watermarking system comprises
  four parts, namely: signature generation, watermark embedding, watermark
  extraction and signature comparison or detection -- with the exception
@@ -201,387 +251,501 @@
  to watermark embedding and detection).
  Signature is used more less as a synonym for mark and can be thought of
  as the payload (at least for some schemes :-).
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 All programs only accept the image in NetPBM format and will also produce
  only NetPBM-format files (see section 
-\begin_inset LatexCommand \ref{sec:prereq}
+\begin_inset LatexCommand ref
+reference "sec:prereq"
 
-\end_inset 
+\end_inset
 
 ).
  Unfortunately, most programs have only been tested with 8-bit gray-scale
  images of size 
-\begin_inset Formula \( 512\times 512. \)
-\end_inset 
+\begin_inset Formula $512\times512.$
+\end_inset
 
  
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 In order to simplify batch testing, the programs allow to read either from
  a file, e.g.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 
-\family typewriter 
-\size small 
-wm_cox_e -s cox.sig 
-\series bold 
+\family typewriter
+\size small
+wm_cox_e -s cox.sig
+\family default
+ 
+\family typewriter
+\series bold
 image.pgm
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 or from standard input, i.e.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 wm_cox_e -s cox.sig 
-\series bold 
+\series bold
 < image.pgm
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 The output is usually written to standard output, i.e.
  
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 
-\family typewriter 
-\size small 
-wm_cox_e -s cox.sig image.pgm 
-\series bold 
+\family typewriter
+\size small
+wm_cox_e -s cox.sig image.pgm
+\family default
+ 
+\family typewriter
+\series bold
 > wm_image.pgm
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 unless redirected to a file, e.g.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 
-\family typewriter 
-\size small 
-wm_cox_e -s cox.sig 
-\series bold 
+\family typewriter
+\size small
+wm_cox_e -s cox.sig
+\family default
+ 
+\family typewriter
+\series bold
 -o wm_image.pgm
-\series default 
- image.pgm
-\layout Subsection
+\family default
+\series default
+ 
+\family typewriter
+image.pgm
+\end_layout
 
+\begin_layout Subsection
 Featured algorithms
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Currently it includes the following watermarking algorithms
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 Bruyndonckx [bruyn], refer to
-\layout Quotation
+\end_layout
 
+\begin_layout Quotation
 O.
  Bruyndonckx, Jean-Jacques Quisquater, and Benoit M.
  Macq.
  Spatial method for copyright labeling of digital images.
  In IEEE Workshop on Nonlinear Signal and Image Processing '95, Thessaloniki,
  Greece, pages 456 - 459, 1995.
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 Corvi, refer to
-\layout Quotation
+\end_layout
 
+\begin_layout Quotation
 Marco Corvi and Gianluca Nicchiotti.
  Wavelet-based image watermarking for copyright protection.
  In Scandinavian Conference on Image Analysis SCIA '97, Lappeenranta, Finland,
  June 1997.
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 Cox, refer to
-\layout Quotation
+\end_layout
 
+\begin_layout Quotation
 Ingemar J.
  Cox, Joe Kilian, Tom Leighton, and Talal G.
  Shamoon.
  Secure spread spectrum watermarking for multimedia.
  In Proceedings of the IEEE ICIP '97, volume 6, pages 1673 - 1687, Santa
  Barbara, California, USA, 1997.
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 Dugad, refer to
-\layout Quotation
+\end_layout
 
+\begin_layout Quotation
 Rakesh Dugad, Krishna Ratakonda, and Narendra Ahuja.
  A new wavelet-based scheme for watermarking images.
  In Proceedings of the IEEE International Conference on Image Processing,
  ICIP '98, Chicago, IL, USA, October 1998.
  
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 Fridrich (2.
  scheme), refer to
-\layout Quotation
+\end_layout
 
+\begin_layout Quotation
 Jiri Fridrich.
  Combining low-frequency and spread spectrum watermarking.
  In Proceedings of the SPIE Symposium on Optical Science, Engineering and
  Instrumentation, San Diego, USA, July 1998.
  
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 Kim, refer to 
-\layout Quotation
+\end_layout
 
+\begin_layout Quotation
 Jong Ryul Kim and Young Shik Moon.
  A robust wavelet-based digital watermark using level-adaptive thresholding.
  In Proceedings of the 6th IEEE International Conference on Image Processing
  ICIP '99, page 202, Kobe, Japan, October 1999.
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 Koch, refer to
-\layout Quotation
+\end_layout
 
+\begin_layout Quotation
 Eckhard Koch and Jian Zhao.
  Towards robust and hidden image copyright labeling.
  In Proceedings of the IEEE International Workshop on Nonlinear Signal and
  Image Processing, pages 452 - 455, Halkidiki, Marmaras, Greece, June 1995.
-\layout Itemize
+\end_layout
+
+\begin_layout Itemize
+Kundur, refer to 
+\end_layout
+
+\begin_layout Quotation
+Deepa Kundur and Dimitrios Hatzinakos.
+ Digital watermarking using multiresolution wavelet decomposition.
+ In Proceedings of IEEE ICASSP '98, volume 5, pages 2969-2972, Seattle,
+ WA, USA, May 1998.
+ 
+\end_layout
 
+\begin_deeper
+\begin_layout Standard
+and 
+\end_layout
+
+\end_deeper
+\begin_layout Quotation
+Deepa Kundur and D.
+ Hatzinakos.
+ Diversity and attack characterization for improved robust watermarking.
+ IEEE Transactions on Signal Processing, 29(10):2383-2396, October 2001.
+\end_layout
+
+\begin_layout Itemize
 Wang, refer to
-\layout Quotation
+\end_layout
 
+\begin_layout Quotation
 Houng-Jyh Wang, Po-Chyi Su, and C.-C.
  Jay Kuo.
  Wavelet-based digital image watermarking.
  Optics Express, volume 3, pp.
  497, December 1998.
  
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 Xia, refer to
-\layout Quotation
+\end_layout
 
+\begin_layout Quotation
 Xiang-Gen Xia, Charles G.
  Boncelet, and Gonzalo R.
  Arce.
  Wavelet transform based watermark for digital images.
  Optics Express, volume 3, pp.
  497, December 1998.
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 Xie, refer to
-\layout Quotation
+\end_layout
 
+\begin_layout Quotation
 Liehua Xie and Gonzalo R.
  Arce.
  Joint wavelet compression and authentication watermarking.
  In Proceedings of the IEEE International Conference on Image Processing,
  ICIP '98, Chicago, IL, USA, 1998.
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 Zhu, refer to
-\layout Quotation
+\end_layout
 
+\begin_layout Quotation
 Wenwu Zhu, Zixiang Xiong, and Ya-Qin Zhang.
  Multiresolution watermarking for images and video: a unified approach.
  In Proceedings of the IEEE International Conference on Image Processing,
  ICIP '98, Chicago, IL, USA, October 1998.
  
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 Piva/Fotopoulos [cast|test-pv,hart,sub], contribution by Vassilis Fotopoulos,
  refer to
-\layout Quotation
+\end_layout
 
+\begin_layout Quotation
 M.Barni, F.
  Bartolini, V.
  Cappellini, A.
  Piva.
  A DCT-Domain System for Robust Image Watermarking, Signal Processing, vol.
  66, pp 357 - 372, 1998.
-\begin_deeper 
-\layout Standard
-\added_space_top smallskip \added_space_bottom smallskip 
+\end_layout
+
+\begin_deeper
+\begin_layout Standard
+\begin_inset VSpace smallskip
+\end_inset
+
 and
-\end_deeper 
-\layout Quotation
+\begin_inset VSpace smallskip
+\end_inset
+
 
+\end_layout
+
+\end_deeper
+\begin_layout Quotation
 V.
  Fotopoulos, A.
  N.
  Skodras, A Subband DCT approach to image watermarking, X European Signal
  Processing Conference, September 4 - 8, 2000, Tampere, Finland.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 More algorithms will be added over time, I have implemented about 13 watermarkin
 g algorithms in the spatial-, DCT-, and wavelet domain so far.
-\layout Subsection
-
+\end_layout
 
-\begin_inset LatexCommand \label{sec:utility_programs}
+\begin_layout Subsection
+\begin_inset LatexCommand label
+name "sec:utility_programs"
 
-\end_inset 
+\end_inset
 
 Utility programs
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 A good way to check the effect of a watermarking algorithm is computing
  the difference image, i.e.
  subtracting the original image from the watermarked image.
  Alternatively, one can also have a look at the modified coefficients in
  the transform domain.
  The following programs facilitate these tasks:
-\layout Description
+\end_layout
 
+\begin_layout Description
 cmp_pgm compute difference image, PSNR, ...
-\layout Description
+\end_layout
 
+\begin_layout Description
 cmp_dct compute full-frame DCT domain difference image
-\layout Description
+\end_layout
 
+\begin_layout Description
 cmp_dct8x8 compute 8x8 block-based DCT difference image
-\layout Description
+\end_layout
 
+\begin_layout Description
 cmp_dwt compute DWT domain difference image
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 For example, to produce the difference image of two PGM files and compute
  the PSNR along with some other measures, the following command can be used:
-\layout Standard
-
+\end_layout
 
-\family typewriter 
-\size small 
+\begin_layout Standard
+
+\family typewriter
+\size small
 cmp_pgm -p -i original.pgm -o diff.pgm watermarked.pgm
-\layout Section
+\end_layout
 
+\begin_layout Section
 Usage
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Note, almost all programs will output usage information if called with the
  
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 -h
-\family default 
-\size default 
+\family default
+\size default
  argument.
-\layout Subsection
+\end_layout
 
+\begin_layout Subsection
 Generating a mark
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 First, you have to generate an appropriate signature file for the corresponding
  embedding/detection algorithm; e.g.
  if you are going to use Cox' scheme, then you would run
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 gen_cox_sig
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 The programs outputs some parameters and a sequence of Gaussian distributed
  random numbers (which is the watermark sequence).
  You want to save that into a signature file, so you run
-\layout Standard
-
+\end_layout
 
-\family typewriter 
-\size small 
+\begin_layout Standard
+
+\family typewriter
+\size small
 gen_cox_sig > cox.sig or 
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 gen_cox_sig -o cox.sig
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 You can influence e.g.
  the embedding strength that will be used in the embedding step by running
-\layout Standard
+\end_layout
+
+\begin_layout Standard
+
+\family typewriter
+\size small
+gen_cox_sig -a 0.5 > too_strong_cox.sig
+\end_layout
+
+\begin_layout Standard
+Usually, the programs for generating a signature will supply reasonable
+ default values for marking a 8-bit gray-scale image of size 
+\begin_inset Formula $512\times512.$
+\end_inset
 
 
-\family typewriter 
-\size small 
-gen_cox_sig -a 0.5 > too_strong_cox.sig
-\layout Standard
+\end_layout
 
-Usually, the programs for generating a signature will supply reasonable
- default values for marking a 8-bit gray-scale image of size 
-\begin_inset Formula \( 512\times 512. \)
-\end_inset 
-
+\begin_layout Subsection
+Watermark embedding
+\end_layout
 
-\layout Subsection
-
-Watermark embedding
-\layout Standard
-
+\begin_layout Standard
 Watermark embedding is performed with the following command (for our example,
  we are using Cox' scheme):
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 wm_cox_e -s cox.sig -o cox_lena.pgm lena.pgm
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 The signature file is parsed to obtain the particular watermark sequence
  and the embedding strength.
  The watermarked image is written to the file 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 cox_lena.pgm
-\family default 
-\size default 
+\family default
+\size default
 .
  Now it the time to check the perceptual quality of the produced image and
  also have a look at the difference image (see section 
-\begin_inset LatexCommand \ref{sec:utility_programs}
+\begin_inset LatexCommand ref
+reference "sec:utility_programs"
 
-\end_inset 
+\end_inset
 
 ).
-\layout Subsection
+\end_layout
 
+\begin_layout Subsection
 Watermark extraction
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 To extract the embedded signature, we execute the command 
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 wm_cox_d -s cox.sig -i lena.pgm -o cox.wm cox_lena.pgm 
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Since Cox' algorithm is not blind, the original image is needed as a reference
  to extract the embedded mark.
  The embedded mark will be stored in 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 cox.wm
-\family default 
-\size default 
+\family default
+\size default
 .
  The original signature, 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 cox.sig
-\family default 
-\size default 
+\family default
+\size default
 , is used to get the auxiliary embedding parameter correct (e.g.
  embedding strength).
  
-\layout Subsection
+\end_layout
 
+\begin_layout Subsection
 Comparing the mark
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 The final step is comparing the original signature against the extracted
  signature.
  The result here is usually a correlation factor.
  Values around 0 indicate that the mark has not been found, values around
- 1 
-\layout Standard
+ 1.
+\end_layout
 
+\begin_layout Standard
 In most programs a analytical detection threshold for some detection probability
  is not used.
  Hence, one has to observe the output of the detector for many different
@@ -589,365 +753,459 @@
  detection.
  A good value to go with initially might be 0.2 which means we claim the
  watermark detected if the correlation factor is > 0.2.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 The appropriate command for comparing the mark is
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 cmp_cox_sig -s cox.sig cox.wm 
-\layout Subsection
+\end_layout
 
+\begin_layout Subsection
 Batch testing - benchmarking
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 If you want to run many test you can pipe the images to be do be watermarked
  (and tested) through the embedder and detector.
  The programs then act like a filter.
  Try something like the following in a Unix shell script:
-\layout Standard
-
+\end_layout
 
-\family typewriter 
-\size small 
+\begin_layout Standard
+
+\family typewriter
+\size small
 gen_cox_sig > cox.sig 
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 for i in *.pgm 
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 do 
-\layout Standard
-
+\end_layout
 
-\family typewriter 
-\size small 
-\SpecialChar ~
-\SpecialChar ~
+\begin_layout Standard
+
+\family typewriter
+\size small
+\InsetSpace ~
+\InsetSpace ~
 wm_cox_e -s cox.sig $i | 
-\backslash 
+\backslash
 
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 
-\family typewriter 
-\size small 
-\SpecialChar ~
-\SpecialChar ~
+\family typewriter
+\size small
+\InsetSpace ~
+\InsetSpace ~
 wm_cox_d -s cox.sig -i $i | 
-\backslash 
+\backslash
 
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 
-\family typewriter 
-\size small 
-\SpecialChar ~
-\SpecialChar ~
+\family typewriter
+\size small
+\InsetSpace ~
+\InsetSpace ~
 cmp_cox_sig -s cox.sig 
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 done
-\layout Section
+\end_layout
 
+\begin_layout Section
+\begin_inset LatexCommand label
+name "sec:recompile"
 
-\begin_inset LatexCommand \label{sec:recompile}
-
-\end_inset 
+\end_inset
 
 Recompiling
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Note, that most watermark embedding/extraction programs use the built-in
  random number generator of the C library, i.e.
  
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 srandom()
-\family default 
-\size default 
+\family default
+\size default
  and 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 random().
+
+\family default
  
-\family default 
-\size default 
+\size default
 Therefore, if you recompile, chances are that you won't be able to use your
  images watermarked with the previous version.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 The Makefile options for compiling on the different platforms can be found
  in the 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 make/
-\family default 
-\size default 
+\family default
+\size default
  sub-directory of the archive.
-\layout Subsection
-
+\end_layout
 
-\begin_inset LatexCommand \label{sec:prereq}
+\begin_layout Subsection
+\begin_inset LatexCommand label
+name "sec:prereq"
 
-\end_inset 
+\end_inset
 
 Prerequisites
-\layout Subsubsection
+\end_layout
 
+\begin_layout Subsubsection
 NetPBM
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 NetPBM is responsible for image file I/O and provides a definition of a
  simple image file format along with many image file format filters that
  allow to convert images to and from NetPBM format.
  
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 You need to get and install the NetPBM library at 
-\begin_inset LatexCommand \url{http://wuarchive.wustl.edu/graphics/graphics/packages/NetPBM/}
+\begin_inset LatexCommand url
+target "http://wuarchive.wustl.edu/graphics/graphics/packages/NetPBM/"
 
-\end_inset 
+\end_inset
 
  or 
-\begin_inset LatexCommand \url{http://netpbm.sourceforge.net}
+\begin_inset LatexCommand url
+target "http://netpbm.sourceforge.net"
 
-\end_inset 
+\end_inset
 
 .
  The library provides 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 pgm.h
-\family default 
-\size default 
+\family default
+\size default
  and the appropriate implementation.
-\layout Subsection
+\end_layout
+
+\begin_layout Subsubsection
+getopt
+\end_layout
 
+\begin_layout Standard
+When compiling on Windows, the getopt() function call required.
+ An implementation of getopt() can be found in the NetPBM package.
+ 
+\end_layout
+
+\begin_layout Subsection
 Unix/Linux platform
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 All programs were developed using Linux and GNU C.
  The programs should compile and work with all recent versions of Linux
  and GNU C.
  
-\layout Subsection
-
+\end_layout
 
-\begin_inset LatexCommand \label{sec:win32_compile}
+\begin_layout Subsection
+\begin_inset LatexCommand label
+name "sec:win32_compile"
 
-\end_inset 
+\end_inset
 
 Win32 platform
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 The programs were ported to the Windows platform using the Cygwin
-\begin_float footnote 
-\layout Standard
+\begin_inset Foot
+status collapsed
+
+\begin_layout Standard
+\begin_inset LatexCommand url
+target "http://www.cygwin.com"
+
+\end_inset
+
+ 
+\end_layout
+
+\end_inset
+
+and Mingw
+\begin_inset Foot
+status collapsed
+
+\begin_layout Standard
+\begin_inset LatexCommand url
+target "http://www.mingw.org"
+
+\end_inset
 
 
-\begin_inset LatexCommand \url{http://www.cygwin.com}
-
-\end_inset 
+\end_layout
 
- 
-\end_float 
-and Mingw
-\begin_float footnote 
-\layout Standard
-
+\end_inset
 
-\begin_inset LatexCommand \url{http://www.mingw.org}
-
-\end_inset 
-
-
-\end_float 
  environment.
  Most notable, the file mode for standard input and standard output has
  to be set to binary mode.
  This is accomplished with the 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 setmode()
-\family default 
-\size default 
+\family default
+\size default
  or 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 _fsetmode()
-\family default 
-\size default 
+\family default
+\size default
  commands.
-\layout Section
+\end_layout
 
+\begin_layout Section
 FAQ
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Q: How can I report problems?
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 A: See the contact information at the beginning of this document.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Q: The compiler complains about 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 pgm.h
-\family default 
-\size default 
+\family default
+\size default
 ?
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 A: You need to get and install the NetPBM library, see section 
-\begin_inset LatexCommand \ref{sec:prereq}
+\begin_inset LatexCommand ref
+reference "sec:prereq"
 
-\end_inset 
+\end_inset
 
 .
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Q: What is the best algorithm? 
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 A: Depends on your application.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Q: What is the most robust algorithm?
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 A: Depends on the attack.
  See some results on 
-\begin_inset LatexCommand \url{http://www.cosy.sbg.ac.at/~pmeerw/Watermarking}
+\begin_inset LatexCommand url
+target "http://www.cosy.sbg.ac.at/~pmeerw/Watermarking"
 
-\end_inset 
+\end_inset
 
 .
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Q: I need code for a full-frame DCT?
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 A: See the files Meerwald/dct.* in the archive.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Q: I need code for a 8x8 block DCT?
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 A: See the files 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 Meerwald/dct.*
-\family default 
-\size default 
+\family default
+\size default
  in the archive.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Q: I need code for the wavelet transform (DWT)?
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 A: See the files 
-\family typewriter 
-\size small 
+\family typewriter
+\size small
 Meerwald/wavelet.*
-\family default 
-\size default 
+\family default
+\size default
  in the archive.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Q: I get the message 'unable to open filter.dat' - what to do?
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 A: Make sure the file filter.dat is in the current directory or accessible
  via path/filename specified in the signature file.
  Use the signature generation command to specify an absolute path if necessary.
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 Q: I can't compile the code using some Microsoft product?
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 A: Make your life easier, install GNU software! See section 
-\begin_inset LatexCommand \ref{sec:recompile}
+\begin_inset LatexCommand ref
+reference "sec:recompile"
 
-\end_inset 
+\end_inset
 
 .
-\layout Section
+\end_layout
 
+\begin_layout Section
 Revision history
-\layout Standard
+\end_layout
+
+\begin_layout Standard
+version 0.5 (December, 2005)
+\end_layout
 
+\begin_layout Itemize
+added algorithm kund3, kund2 and xie2
+\end_layout
+
+\begin_layout Standard
 version 0.4 (June 21, 2001)
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 bug fixes 
-\begin_deeper 
-\layout Itemize
+\end_layout
 
+\begin_deeper
+\begin_layout Itemize
 wm_xia_{e|d}.c variable level uninitialized 
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 wm_zhu_{e|d}.c variable level uninitialized
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 issue with random() vs.
  rand() and RAND_MAX in frid2_common.c
-\end_deeper 
-\layout Itemize
+\end_layout
 
+\end_deeper
+\begin_layout Itemize
 added option to bruyn algorithm to disable block skipping
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 added algorithm kim
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 version 0.3 (June 18, 2001)
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 created a nice (?) manual/documentation
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 added algorithms by Dugad, Wang, Zhu, Fridrich
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 added Makefiles for Win32 platform (mingw32)
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 version 0.2 (February 22, 2001)
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 added contribution by Vassilis Fotopoulos (Piva's algorithm,
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 DCT, Hartley and subband domain) - see Fotopoulos/ subdirectory
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 stuff moved to Meerwald/ subdirectory
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 added Bruyndonckx, Corvi, Koch, Xia, Xie algorithms
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 version 0.1 (February 18, 2001)
-\layout Itemize
+\end_layout
 
+\begin_layout Itemize
 initial release
-\layout Section
+\end_layout
 
+\begin_layout Section
 Legal statement
-\layout Standard
+\end_layout
 
+\begin_layout Standard
 My license is called "I-don't-care" license: (1) You can do with the accompanyin
 g software whatever you want, but don't blame me if it doesn't work or it
  causes damage.
@@ -955,12 +1213,17 @@
  not obliged to do so.
  I suggest not to remove information contained in this other documentation
  file.
-\layout Standard
+\end_layout
+
+\begin_layout Standard
+\begin_inset LatexCommand bibtex
+options "plain"
+bibfiles "watermarking"
+
+\end_inset
 
 
-\begin_inset LatexCommand \BibTeX[plain]{watermarking}
+\end_layout
 
-\end_inset 
-
-
-\the_end
+\end_body
+\end_document
Binary file manual.pdf has changed

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