#ifndef _SIGNATURES_H_
#define _SIGNATURES_H_
/**
 *  \file signatures.h
 *  \brief a header for signatures.c
 *
 *
 *  \ingroup corefiles
 *  \date Jul 10, 2009
 *  \author Alexander Pimenov
 */
#ifdef __cplusplus
	extern "C" {
#endif

#include <stdint.h>
#include "g12buffer.h"
#include "integral.h"


#define LESS_EPS_BIT	0
#define MIDDLE_EPS_BIT  1
#define MORE_EPS_BIT	2
#define TENARY_SYSTEM_BASE    3

#define SIGNATURE_PATTERNS_NUMBER 15

/**
 * \brief The type alias for the signature. In this project it is considered to be less than 32bit
 */
typedef uint32_t signature_t;

/**
 * \brief The macro to access the element of the signature buffer
 */
#define SELEM(Sbuf, X, Y)  (Sbuf)->data[(Sbuf)->w * (Y) + (X)]

/**
 * \brief This structure describes the signature buffer
 *
 */
typedef struct signaturesBuffer_TAG {
	int h;              /**< Height of the buffer */
	int w;              /**< Width of the buffer */
	signature_t *data;     /**< Pointer to the data. Line by line */
} signaturesBuffer;

/**
 * \brief This structure describes the parameters for the 3piece epsilon function
 *
 */
typedef struct SignatureParameters_TAG {
	uint16_t epsilonLowLimit;
	uint16_t epsilonHighLimit;
	uint16_t sdevLowLimit;
	uint16_t sdevHighLimit;
	uint32_t mask;   /**< mask - selects the patters no apply, this parameter is ignored by the fast implementaions*/
} SignatureParameters;




signaturesBuffer *signaturesBufferCreate(int h, int w);
void signaturesBufferDelete(signaturesBuffer *toDelete);

signaturesBuffer *signaturesBufferCreateFromIntegralABC (integralBuffer *integral, double A, double B, double C);

signaturesBuffer *signaturesBufferCreateFromIntegral3piece4i (integralBuffer *integral, uint16_t epsilonLowLimit, uint16_t epsilonHighLimit, uint16_t sdevLowLimit, uint16_t sdevHighLimit, uint32_t mask);
signaturesBuffer *signaturesBufferCreateFromIntegral3piece (integralBuffer *integral, SignatureParameters *sParams);

signaturesBuffer *signaturesBufferCreateFromIntegralx86fast (integralBuffer *integral, SignatureParameters *sParams);
signaturesBuffer *signaturesBufferCreateFromIntegralx86fastIP (integralBuffer *integral, SignatureParameters *sParams);


signature_t signature3piece (
			uint16_t data[],
			SignatureParameters *p,
			uint16_t *_mean, uint32_t *_sdev, uint32_t *_baseEpsilon);

int prettyPrintSignature(signature_t sig, char *buffer, int size);
int signatureBufferCompare(signaturesBuffer *S1, signaturesBuffer *S2);

#ifdef __cplusplus
	} // 	extern "C"
#endif

#endif
