#ifndef __ALC_H__
#define __ALC_H__

#include "defines.h"
#include "global.h"

#ifndef CLIP
#define CLIP(x,min,max) ( (x)<(min)?(min):((x)>(max)?(max):(x)) )
#endif

typedef imgpel XPel;

//thickness of template. Is expressed in pixels
#if SAIT_ALC_SIMP_D0116
#define MAX_TEMPLATE_SIZE                                       (1)
#else
#define MAX_TEMPLATE_SIZE                                       (4)
#endif
// max MB Size 16
#define MAX_TEMPLATE_VOLUME										((MAX_TEMPLATE_SIZE * 16) * 2 + (MAX_TEMPLATE_SIZE * MAX_TEMPLATE_SIZE))

//Threshold of difference between template values in reference and decoded frames
#define REF_DEC_LUMA_DIF_THRESHOLD								(30)          // if REF_DEC_LUMA_DIF_THRESHOLD == 256, then no comparison between ref and dec to be applied at all

//  EARLY_ALC_OFF_DETECTION -this define allows to compare sums of templates and exclude ALC_Correction if templates differencies are not crucial
//  EARLY_ALC_OFF_DETECTION_THRESHOLD defines how strong ref_sum/dec_sum will be quantizaed before comparison; it uses as follows:
//  ref_sum >> = EARLY_ALC_OFF_DETECTION_THRESHOLD;
//  dec_sum >> = EARLY_ALC_OFF_DETECTION_THRESHOLD;
#define EARLY_ALC_OFF_DETECTION                                                      (1)
#define EARLY_ALC_OFF_DETECTION_THRESHOLD                                            (4)

// fixed point macroses
#define SINGL_MULT_FACT_PREC                                                          (15)
#define MULT_FACTOR_X_255                                                             (255 << SINGL_MULT_FACT_PREC)

#define ALCOK													(0)

#define TM_EMPTY												(0)
#define TM_FILLED												(1)

void ALC_Create();
void ALC_Destroy();
int ALC_GetTM(	XPel **ppRef, int RefTM_startY, int RefTM_startX, 
				XPel **ppDec, int DecTM_startY, int DecTM_startX, int Blk_height, int Blk_width);
Boolean IsTMFilled();
void ALC_TurnOFF();
XPel** ALC_RetTM_buf();
int** ALC_RetTM_tempbuf();
void PiLC_TMPelCorHist_2DArray( XPel **ppOut, int XOut, int h, int w);
void PiLC_TMPelCorHist_1DArray(	XPel *pIn, XPel *pOut, int StrideIn, int StrideOut, int h, int w);

#endif //__ALC_H__
