/* -*- mode: c++; c-basic-offset: 3 -*-
 *
 * PANTHEON Project
 *
 * GREYC IMAGE
 * 6 Boulevard Maréchal Juin
 * F-14050 Caen Cedex France
 *
 * This file is free software. You can use it, distribute it
 * and/or modify it. However, the entire risk to the quality
 * and performance of this program is with you.
 *
 * Please email any bugs, comments, and/or additions to this file to:
 * pandore@greyc.ensicaen.fr
 * http://www.greyc.ensicaen.fr/EquipeImage/Pandore/
 */

/**
 * @author Jalal Fadili 
 * @date 2007-05-30
 *
 */

/*
 * @file fatomfm2sym.cpp
 * @brief Forward transform of wave atom tight frame with redundancy 2, symmetric version
 */

#include <math.h>
#include <complex>
#include <iostream>
using namespace std;
#include "complexe.h"
using namespace pandore;



#ifdef MAIN
#undef MAIN

namespace FatomSym{
#include "fatom2sym.cpp"
}
#define MAIN
#else
namespace FatomSym{
#include "fatom2sym.cpp"
}
#endif


/**
 * Function Fatomfm2Sym - Forward transform of wave atom tight frame with redundancy 2, symmetric version
 *
 * input x:  	the input N-by-N image
 * output c:    image of wave atom coefficients
 *		2N-by-N image containing all wave atom coefficients
 *		the coefficients with b=1 are in the first half, while
 *		the coefficients with b=2 are in the second half.
 *		b=1, for frequency bumps which live in the second and fourth quadrants.
 *		b=2; for frequency bumps which live in the first and third quadrants.
 *
 * @param pat : type of frequency partition which satsifies parabolic scaling relationship
 *         equal to 'p' or 'q'
 */
Errc Fatomfm2Sym(Img2dsf& x, Img2dsf& c, char pat) {

   Short tp[2];
   Img2dsf c1, c2;
   
   c.New(2*x.Height(),x.Width());
   
   tp[0] = 1;tp[1] = 1;
   FatomSym::Fatom2Sym(x, c1, pat, tp);   // Standard transform.
   tp[0] = -1;tp[1] = -1;
   FatomSym::Fatom2Sym(x, c2, pat, tp); // Hilbert transformed version.
   
   for(int i=0;i < x.Height();i++)
   for(int j=0;j < x.Width();j++){
   	c[i][j]   	   = (c1[i][j]+c2[i][j])/2;
	c[i+x.Height()][j] = (c1[i][j]-c2[i][j])/2;
   }
   
   return SUCCESS;
}


#ifdef MAIN
#define USAGE   "usage: %s pat(p or q) [-m mask] [im_in|-] [im_out|-]"
#define PARC    1
#define FINC    1
#define FOUTC   1
#define MASK    0

int main(int argc,char* argv[]) {
   Errc result;			// The result code of the execution.
   Pobject *mask;		// The mask.
   Pobject *objin[FINC+1];	// The input objects;
   Pobject *objs[FINC+1];	// The source objects masked by mask.
   Pobject *objout[FOUTC+1];	// The output object unmasked by mask.
   Pobject *objd[FOUTC+1];	// The result object.
   char *parv[PARC+1];		// The input parameters.
  
   ReadArgs(argc,argv,PARC,FINC,FOUTC,&mask,objin,objs,objout,objd,parv,USAGE,MASK);

   switch(objs[0]->Type()){
   case Po_Img2dsf :{
      Img2dsf* const ims=(Img2dsf*)objs[0];
      objd[0] = new Img2dsf();
      Img2dsf* imd = (Img2dsf*) objd[0];

      result=Fatomfm2Sym(*ims, *imd, parv[0][0]);
   }break;
   default :
      PrintErrorFormat(objin,FINC);
      result =FAILURE;
   }
  
   if (result)
      WriteArgs(argc,argv,PARC,FINC,FOUTC,&mask,objin,objs,objout,objd,MASK);
   Exit(result);
   return 0;
}

#endif
