
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
//																				   //
//		Filename:		CIDAR.h												       //
//																				   //
//		Description:	Container ID Automatic Reader.							   //
//																				   //
//		Date:			February - 2009							  				   //
//																				   //
//		Developed by:	NEURAL LABS S.L.										   //
//																				   //
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////
// Definitions.
/////////////////////////////////////////////////////////////////////////////////////

#ifdef CIDAR_EXPORTS
#define CIDAR_API __declspec(dllexport)
#else
#define CIDAR_API __declspec(dllimport)
#endif


#define FUNCTION_MOD WINAPI


#define CODE_FORMAT_HORIZONTAL					1
#define CODE_FORMAT_VERTICAL					2
#define CODE_FORMAT_HORIZONTAL_OR_VERTICAL		3

#define CODE_FORMAT_ONE_LINE					1
#define CODE_FORMAT_TWO_LINES					2
#define CODE_FORMAT_THREE_LINES					3
#define CODE_FORMAT_ANY_LINES					4

#define CODE_FORMAT_BLACK_ON_WHITE				1
#define CODE_FORMAT_WHITE_ON_BLACK				2
#define CODE_FORMAT_ANY_ON_ANY					3




/////////////////////////////////////////////////////////////////////////////////////
// cidarInit
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Initalizes the Container ID Automatic Reader. Allocates Memory,  
//				loads the Artificial Neural Networks, etc...
//
//	Parameters:	
//
//			lAvCharacterHeight:	Aproximate average height of the characteres within
//								the images (in pixels). -1 ==> Automatic (finds charaters 
//								between 25 and 100 pixels in height).
//	
//			bDuplicateLines:	This parameter must be true	when the imaging hardware 
//								only acquires half of the horizontal lines. 
//
//			bTrace:				This parameter must be set to false.
// 
//	Return Value:	OK    --> 1
//					ERROR --> 0
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API 
long FUNCTION_MOD cidarInit(long lAvCharacterHeight = -1, 
							bool bDuplicateLines = false, 
							bool bTrace = false);




/////////////////////////////////////////////////////////////////////////////////////
// cidarEnd
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Frees memory and closes the CIDAR.
// 
//	Return Value:	OK    --> 1
//					ERROR --> 0
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API void FUNCTION_MOD cidarEnd(void);




/////////////////////////////////////////////////////////////////////////////////////
// cidarSetCorrectionCoefficients
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Sets the distortion correction coefficients that will be applied 
//				to all the images before being analyzed.
//
//	Parameters:	
//
//			fDistance:			Approximate Distance between camera and object (in meters).
//
//			fVerticalCoeff:		Coefficient for correcting Vertical Perspective).
//
//			fHorizontalCoeff:	Coefficient for correcting Horizontal Perspective).
//
//			fAngle:				Angle for correcting Rotation.
//			 
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API void FUNCTION_MOD  cidarSetCorrectionCoefficients(float fDistance, 
																	   float fVerticalCoeff, 
																	   float fHorizontalCoeff, 
																	   float fAngle);



/////////////////////////////////////////////////////////////////////////////////////
// cidarSetDistortionCorrectionOff
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Deactivates the distortion correction pre-process.
//				Use cidarSetCorrectionCoefficients to activate it again.
// 
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API void FUNCTION_MOD  cidarSetDistortionCorrectionOff();



/////////////////////////////////////////////////////////////////////////////////////
// cidarConfigureAutomaticCharacterHeight
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Configures the Automatic Character Height range.
//				When cidarInit is called with the argument lAvCharacterHeight set to -1 
//				the automatic character height mode is selected. By default, the range of 
//				character heights scanned in this mode is from 25 pixels to 100 pixels.
//				By using this function, the user can select a different height range.
//
//	Parameters:	
//
//			lMinCharHeight:	Minimum character height (in pixels) of the characters to read.
//
//			lMaxCharHeight: Maximum character height (in pixels) of the characters to read.
//
//	Return Value:	OK    --> 1
//					ERROR --> 0
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API long FUNCTION_MOD  cidarConfigureAutomaticCharacterHeight(long lMinCharHeight, 
																			   long lMaxCharHeight);



/////////////////////////////////////////////////////////////////////////////////////
// cidarSetRectangle
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Sets the rectangle where the inspection process will take place. 
//				Only the provided region will be inspected.
//				This function can be used to speed up the process when the approximate position  
//				of the ID code within the image is known.
//
//	Parameters:	
//
//			lLeft, lTop:	 Top and left coordinates of the rectangle (in pixels).
//
//			lWidth, lHeight: Rectangle dimensions (in pixels).
//			 
//	Return Value:	OK    --> 1
//					ERROR --> 0
//
//	Remarks:	The inspection rectangle specified will be applied to all the further inspections until
//				cidarSetRectangle is called again with different parameters.
//				In order to inspect the whole image, cidarSetRectangle must be called with all its
//				parameters set to 0. --> cidarSetRectangle(0, 0, 0, 0);
//				By default, after library initialization with cidarInit, the inspection rectangle is set 
//				to inspect the whole image.
//
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API long FUNCTION_MOD  cidarSetRectangle(long lLeft, long lTop, long lWidth, long lHeight);



/////////////////////////////////////////////////////////////////////////////////////
// cidarConfigureCodeFormat
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Informs the CIDAR library about the format of the ID codes that will be processed.
//				It is highly desirable to limit the scope of the codes to recognize, in order to reduce 
//				the procesing time and increase the effciency of the engine.
//
//	Parameters:	
//
//			lOrientation:	This parameter informs the library about the possible orientation of the codes
//							to be recognized. Valid values:
//							CODE_FORMAT_HORIZONTAL				-->  Only horizontal codes.
//							CODE_FORMAT_VERTICAL				-->  Only vertical codes.
//							CODE_FORMAT_HORIZONTAL_OR_VERTICAL	-->  Horizontal and vertical codes.
//
//			wLines:			This parameter informs the library about the possible number of lines for the 
//							horizontal codes. Valid values:
//							CODE_FORMAT_ONE_LINE		-->  Only one-line codes.
//							CODE_FORMAT_TWO_LINES		-->  Only two-lines codes.
//							CODE_FORMAT_THREE_LINES		-->  Only three-lines codes.
//							CODE_FORMAT_ANY_LINES		-->  One, two or three lines horizontal codes.
//
//			wPolarity:		This parameter informs the library about the possible polarity of the characters 
//							over the background. Valid values:
//							CODE_FORMAT_BLACK_ON_WHITE	-->  Characters darker than background.
//							CODE_FORMAT_WHITE_ON_BLACK	-->  Characters lighter than background.
//							CODE_FORMAT_ANY_ON_ANY	-->  Characters darker or lighter than background.
//			 
//	Return Value:	OK    --> 1
//					ERROR --> 0
//
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API long FUNCTION_MOD  cidarConfigureCodeFormat(WORD wOrientation, 
																 WORD wLines, 
																 WORD wPolarity);




/////////////////////////////////////////////////////////////////////////////////////
// cidarRead
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Analyzes an input image, finds the Container ID code and recognizes 
//				the characters.
//
//	Parameters:	
//
//			lWidth:	Image Width (in pixels).
//
//			lHeight: Image Height (in pixels).
//
//			pbImageData: Buffer with the image pixels (greylevel, 8 bits/pixel).
//			 
//	Return Value:	OK    --> 1
//					ERROR --> 0
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API long FUNCTION_MOD cidarRead(long lWidth, long lHeight, unsigned char* pbImageData);




/////////////////////////////////////////////////////////////////////////////////////
// cidarReadRGB24
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Analyzes an input image from a 24 bits RGB buffer, finds the Container ID code and recognizes 
//				the characters.
//
//	Parameters:	
//
//			lWidth:	Image Width (in pixels).
//
//			lHeight: Image Height (in pixels).
//
//			pbImageDataRGB: Buffer with the image pixels (RGB, 24 bits / pixel).
//
//			bFlip: true to perform a Vertical Flip of the image buffer.
// 
//	Return Value:	OK    --> 1
//					ERROR --> 0
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API long FUNCTION_MOD cidarReadRGB24(long lWidth, long lHeight, unsigned char* pbImageDataRGB, bool bFlip = false);




/////////////////////////////////////////////////////////////////////////////////////
// cidarReadRGB32
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Analyzes an input image from a 32 bits RGB buffer, finds the Container ID code and recognizes 
//				the characters.
//
//	Parameters:	
//
//			lWidth:	Image Width (in pixels).
//
//			lHeight: Image Height (in pixels).
//
//			pbImageDataRGB: Buffer with the image pixels (RGB, 32 bits / pixel).
//
//			bFlip: true to perform a Vertical Flip of the image buffer.
// 
//	Return Value:	OK    --> 1
//					ERROR --> 0
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API long FUNCTION_MOD cidarReadRGB32(long lWidth, long lHeight, unsigned char* pbImageDataRGB, bool bFlip = false);




/////////////////////////////////////////////////////////////////////////////////////
// cidarReadBMP
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Analyzes an input image from a BMP file, finds the Container ID code and recognizes 
//				the characters.
//
//	Parameters:	
//
//			pcFilename:	Filename of a standard BMP file (24 bits/pixel).
// 
//	Return Value:	OK    --> 1
//					ERROR --> 0
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API long FUNCTION_MOD cidarReadBMP(char* pcFilename);




/////////////////////////////////////////////////////////////////////////////////////
// cidarReadJPG
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Analyzes an input image from a JPG file, finds the Container ID code and recognizes 
//				the characters.
//
//	Parameters:	
//
//			pcFilename:	Filename of a standard JPG file.
// 
//	Return Value:	OK    --> 1
//					ERROR --> 0
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API long FUNCTION_MOD cidarReadJPG(char* pcFilename);




/////////////////////////////////////////////////////////////////////////////////////
// cidarCodeFound
/////////////////////////////////////////////////////////////////////////////////////
// 
//	Purpose:	Returns whether the code was found or not.
// 
//
//	Return Value:		Code found --> true 
//						Code not found --> false 
// 
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API bool FUNCTION_MOD cidarCodeFound();




/////////////////////////////////////////////////////////////////////////////////////
// cidarCodeVerified
/////////////////////////////////////////////////////////////////////////////////////
// 
//	Purpose:	Returns whether the code was verified successfully or not.
// 
//
//	Return Value:		Code Checksum verified --> true 
//						Code Checksum not verified --> false 
// 
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API bool FUNCTION_MOD cidarCodeVerified();





/////////////////////////////////////////////////////////////////////////////////////
// cidarGetCode
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Returns the container ID code read.
// 
//	Parameters: 
//
//			strResult:	Text string with the result.
//
//	Return Value:		OK    --> true
//						ERROR --> false 
//  
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API long FUNCTION_MOD cidarGetCode(char * strResult);



/////////////////////////////////////////////////////////////////////////////////////
// cidarGetNumberOfCharacters
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Returns the number of characters in the last Container ID code read.
//  
//	Return Value:	Number of Characters.
// 
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API long FUNCTION_MOD cidarGetNumberOfCharacters();



/////////////////////////////////////////////////////////////////////////////////////
// cidarGetGlobalConfidence
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Returns the confidence factor (0 - 100%) for the last Container ID code read.
//
//	Parameters: 
//
//	Return Value:	Overall Confidence Factor.
// 
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API  float FUNCTION_MOD cidarGetGlobalConfidence();



/////////////////////////////////////////////////////////////////////////////////////
// cidarGetCharacterConfidence
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Returns the confidence factor (0 - 100%) for a specific character.
//
//	Parameters:	
//
//			lIndex:	Index of the character [0 .. NumberOfCharacters-1]
// 
//	Return Value:	Character Confidence Factor.
//
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API float FUNCTION_MOD cidarGetCharacterConfidence(long lIndex);




/////////////////////////////////////////////////////////////////////////////////////
// cidarGetAverageCharacterHeight
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Returns the average height in pixels of the characters recognized in the last 
//				Container ID code read.
// 
//	Return Value:	Average Character Height.
//
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API  float FUNCTION_MOD cidarGetAverageCharacterHeight();




/////////////////////////////////////////////////////////////////////////////////////
// cidarGetRectangle
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:	Returns the coordinates of the rectangle containing the last Container ID code read.
//
//	Parameters:	
//
//			plLeft:		The LEFT coordinate (or X1) is returned here.
//
//			plTop:		The TOP coordinate (or Y1) is returned here.
//
//			plRight:	The RIGHT coordinate (or X2) is returned here.
//
//			plBottom:	The TOP coordinate (or Y2) is returned here.
//
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API void FUNCTION_MOD cidarGetRectangle(long* plLeft, long* plTop, long* plRight, long* plBottom);



/////////////////////////////////////////////////////////////////////////////////////
// cidarGetProcessingTime
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:		Returns the time taken to process the last image.
//
//	Return Value:	Process time in milliseconds.
//
// 
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API long FUNCTION_MOD cidarGetProcessingTime();



/////////////////////////////////////////////////////////////////////////////////////
// cidarSetTimeOut
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:		Sets a maximum processing time for the "Read" functions. 
//					If the process has not finished after the specified timeout, 
//					the "Read" functions will time-out and quit.
//
//	Parameters:
//
//			lMilliseconds:	Maximum processing time in milliseconds.
// 
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API void FUNCTION_MOD cidarSetTimeOut(DWORD dwMilliseconds);




/////////////////////////////////////////////////////////////////////////////////////
// cidarWriteHASP
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:		Escribe datos en la memoria interna de la mochila de 
//					protección (dongle). Esta capacidad de almacenar datos en 
//					el HASP puede ser usada por el usuario para cualquier propósito. 
//					Los datos son encriptados automáticamente antes de escribirse 
//					en la memoria del HASP.
//					Pueden almacenarse un máximo de 24 bytes.
//
//	Parameters:
//
//			pData:	Buffer con los datos a escribir en la memoria del HASP.		
//
//			lSize:	Tamaño (en bytes) de los datos a escribir (máximo 24).
// 
//	Return Value:	OK    --> 1
//					ERROR --> 0
//
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API long FUNCTION_MOD cidarWriteHASP(BYTE* pData, long lSize);



/////////////////////////////////////////////////////////////////////////////////////
// cidarReadHASP
/////////////////////////////////////////////////////////////////////////////////////
//
//	Purpose:		Lee los datos almacenados en la memoria interna de la mochila 
//					de protección (dongle). Esta capacidad de almacenar datos 
//					en el HASP puede ser usada por el usuario para cualquier 
//					propósito. Los datos son desencriptados automáticamente después 
//					de leerse de la memoria del HASP.
//
//	Parameters:
//
//			pData:		Buffer donde se almacenarán los datos leídos de la memoria 
//						del HASP.
//
//			lSize:		Tamaño (en bytes) de los datos a leer.
// 
//	Return Value:	OK    --> 1
//					ERROR --> 0
//
/////////////////////////////////////////////////////////////////////////////////////
extern "C" CIDAR_API long FUNCTION_MOD cidarReadHASP(BYTE* pData, long lSize);




