 
#ifndef __MM40API_H
#define __MM40API_H

#ifdef MM40API_EXPORTS
#define MM40_API __declspec(dllexport)
#else
#define MM40_API __declspec(dllimport)
#endif

// winbase.h has IN and OUT but not both
#ifndef INOUT
#define INOUT
#endif

//
typedef int MM40_RETURN;
typedef unsigned long U32, *PU32;
typedef UCHAR U8, *PU8;

// Eror codes
#define MM40_OK 					0
#define MM40_INVALID_HANDLE			1
#define MM40_READREG				2
#define MM40_WRITEREG				3
#define	MM40_FREE_RESOURCES			4
#define	MM40_FREE_CHANNEL			5
#define	MM40_FREE_BANDWIDTH			6
#define	MM40_READBLK				7
#define	MM40_WRITEBLK				8
#define	MM40_NO_IMAGE				9
#define	MM40_TIMEOUT				10
#define	MM40_INVALID_ARG			11
#define	MM40_NOT_SUPPORTED			12
#define	MM40_ISOCH_ATTACH_BUFFERS	13
#define	MM40_GET_OVERLAPPED_RESULT	14
#define	MM40_MEMORY_ALLOCATION		15
#define	MM40_DLLCONTEXTISNULL		16
#define	MM40_DLLCONTEXTISNONZERO	17
#define	MM40_DLLCONTEXTEXIST		18
#define	MM40_TOOMANYDEVICES			19
#define	MM40_ERRORCAMCONTEXT		20
#define MM40_UNKNOWN_HARDWARE		21
#define	MM40_INVALID_TM_FILE		22
#define	MM40_INVALID_TM_TAG			23
#define	MM40_INCOMPLETE_TM			24
#define	MM40_BUS_RESET_FAILED		25
#define	MM40_NOT_IMPLEMENTED		26
#define	MM40_SHADING_TOOBRIGHT		27
#define	MM40_SHADING_TOODARK		28
#define	MM40_TOO_LOW_GAIN			29
#define	MM40_INVALID_BPL			30
#define	MM40_BPL_REALLOC			31
#define	MM40_INVALID_PIXEL_LIST		32
#define	MM40_INVALID_FFS			33
#define	MM40_INVALID_PROFILE		34
#define	MM40_INVALID_CALIBRATION	35
#define	MM40_INVALID_BUFFER			36
#define	MM40_INVALID_DATA			37


#define	szMM40_Name		"SoftHard Technology MV4.0 Camera"

#ifdef __cplusplus
extern "C" {
#endif

// Get Number of devices with same friendly name
MM40_API MM40_RETURN __cdecl mm40GetNumberDevices ( 
			IN LPCSTR pFriendlyName,			// Device name
			OUT LPDWORD pNumberDevices);		// Ptr to number


// Get Device - returns camera unique number
MM40_API MM40_RETURN __cdecl mm40GetDevice ( 
			IN  DWORD nIndex,					// Index
			OUT LPDWORD pChipId);				// Ptr to chip ID

// Initialize
MM40_API MM40_RETURN __cdecl mm40Initialize(
			IN LPCSTR pFriendlyName,			// Device friendly name 	
			IN DWORD lChipId,					// chip ID
			OUT PHANDLE drvHandle);				// Returned driver handle

MM40_API MM40_RETURN __cdecl mm40IsDeviceExist			(IN HANDLE hDevice);

// Uninitialize
MM40_API MM40_RETURN __cdecl mm40Uninitialize			(IN HANDLE hDevice);

VOID                 __cdecl mm40Abandon				(VOID);

MM40_API MM40_RETURN __cdecl mm40BusReset				(IN HANDLE hDevice );

MM40_API MM40_RETURN __cdecl mm40StartImageAcquisition	(IN HANDLE hDevice);
MM40_API MM40_RETURN __cdecl mm40StartImageShooting		(IN HANDLE hDevice);
MM40_API MM40_RETURN __cdecl mm40AcquireImage			(IN HANDLE hDevice, OUT PVOID *ppData );
MM40_API MM40_RETURN __cdecl mm40AcquireFirstImage		(IN HANDLE hDevice, OUT PVOID *ppData );
MM40_API MM40_RETURN __cdecl mm40StopImageAcquisition	(IN HANDLE hDevice);
MM40_API MM40_RETURN __cdecl mm40IsImageReady			(IN HANDLE hDevice);
MM40_API MM40_RETURN __cdecl mm40WaitForImage			(IN HANDLE hDevice, IN  DWORD dwTimeOut );
MM40_API MM40_RETURN __cdecl mm40GetLastTimeStamp		(IN HANDLE hDevice, PDWORD pSec, PDWORD pCycle );

MM40_API MM40_RETURN __cdecl mm40StartImageStreaming	(IN HANDLE hDevice, DWORD nPackets, DWORD dwRsrc, DWORD dwDescr, DWORD dwBufCnt);
MM40_API MM40_RETURN __cdecl mm40StopImageStreaming		(IN HANDLE hDevice);
MM40_API MM40_RETURN __cdecl mm40GetStreamingChunkSize	(IN HANDLE hDevice, INOUT PDWORD pdwChunkSize );

MM40_API MM40_RETURN __cdecl mm40StartImageCapture		(IN HANDLE hDevice, OUT PVOID *ppData );
MM40_API MM40_RETURN __cdecl mm40CaptureImage			(IN HANDLE hDevice, OUT PVOID *ppData );
MM40_API MM40_RETURN __cdecl mm40StopImageCapture		(IN HANDLE hDevice);

MM40_API MM40_RETURN __cdecl mm40GetModeCount			(IN HANDLE hDevice, OUT LPDWORD lpdwModeCount );
MM40_API MM40_RETURN __cdecl mm40SetMode				(IN HANDLE hDevice, IN  DWORD dwMode);
MM40_API MM40_RETURN __cdecl mm40SetModeEx				(IN HANDLE hDevice, IN  DWORD dwMode, IN DWORD dwX0, IN DWORD dwY0, IN DWORD dwCX, IN DWORD dwCY);
MM40_API MM40_RETURN __cdecl mm40GetMode				(IN HANDLE hDevice, OUT LPDWORD lpdwMode );
MM40_API MM40_RETURN __cdecl mm40SetExposure			(IN HANDLE hDevice, IN  DWORD dwExposure);
MM40_API MM40_RETURN __cdecl mm40GetExposure			(IN HANDLE hDevice, OUT LPDWORD lpdwExposure );
MM40_API MM40_RETURN __cdecl mm40SetTemperature			(IN HANDLE hDevice, IN  DWORD dwTemp );
MM40_API MM40_RETURN __cdecl mm40GetTemperature			(IN HANDLE hDevice, OUT LPDWORD lpdwTemp );
MM40_API MM40_RETURN __cdecl mm40GetCurrTemp			(IN HANDLE hDevice, OUT int * lpTChip, OUT int * lpTHousing );
MM40_API MM40_RETURN __cdecl mm40SetOffset				(IN HANDLE hDevice, IN  DWORD dwOffset );
MM40_API MM40_RETURN __cdecl mm40GetOffset				(IN HANDLE hDevice, OUT LPDWORD lpdwOffset );
MM40_API MM40_RETURN __cdecl mm40SetGain				(IN HANDLE hDevice, IN  DWORD dwGain );
MM40_API MM40_RETURN __cdecl mm40GetGain				(IN HANDLE hDevice, OUT LPDWORD lpdwGain );

MM40_API MM40_RETURN __cdecl mm40GetSerialNumber		(IN HANDLE hDevice, OUT LPDWORD lpdwSern );
MM40_API MM40_RETURN __cdecl mm40SetSerialNumber		(IN HANDLE hDevice, IN  DWORD dwSern );
MM40_API MM40_RETURN __cdecl mm40GetModelName			(IN HANDLE hDevice, OUT LPDWORD lpdwModel );

// HWN2:  CCCM.FRA
MM40_API MM40_RETURN __cdecl mm40GetHWN2				(IN HANDLE hDevice, OUT PDWORD pExten );
#define MM40_HWN2_CHIP(dw)		(((dw)>>20) & 0xFFF)
#define	MM40_HWN2_ICX282		0x282
#define	MM40_HWN2_ICX252		0x252
#define	MM40_HWN2_ICX285		0x285
#define	MM40_HWN2_TC285			0xC85
#define	MM40_HWN2_IBIS4_6M		0xC66
#define	MM40_HWN2_KAI4021M		0xA41
#define	MM40_HWN2_KAI11002M		0xA12

#define MM40_HWN2_MOSAIC(dw)	(((dw)>>16) & 0xF)
#define	MM40_HWN2_MOSAIC_BW		0x0
#define	MM40_HWN2_MOSAIC_RGB	0x1
#define	MM40_HWN2_MOSAIC_CMYG	0x2
#define	MM40_HWN2_HW_REL		(((dw)>>4) & 0xF)
#define MM40_HWN2_ADC(dw)		((dw) & 0xF)
#define MM40_HWN2_ADC_9224		0x1
#define MM40_HWN2_ADC_9844		0x2
#define MM40_HWN2_ADC_9845B		0x3
#define MM40_HWN2_ADC_9824		0x4
#define MM40_HWN2_ADC_9949A		0x5
#define MM40_HWN2_ADC_2247		0x6
#define MM40_HWN2_ADC_9942		0x7
#define MM40_HWN2_ADC_9970		0x8

MM40_API MM40_RETURN __cdecl mm40GetModeExtension		(IN HANDLE hDevice, OUT PDWORD pExten );
#define	MM40_MODEXT_BWHBIN	0x00	// B/W mode of multicolor shift
#define	MM40_MODEXT_RGGB	0x01	// Color mode RG/GB mosaic filter (ICX252AK,etc)
#define	MM40_MODEXT_CMYG	0x02	// Color mode CM/YG mosaic filter (ICX252AQ,etc)
#define	MM40_MODEXT_RGR		0x03	// Color mode RG/GB mosaic filter mixed readout (ICX282AQ,etc)
#define	MM40_MODEXT_MAX		4
#define	MM40_MODEXT_MASK	0x03

#define	MM40_MODEXT_SHOOT	0x04	// Mode supports shooting

MM40_API MM40_RETURN __cdecl mm40GetModeShooting		(IN HANDLE hDevice );

MM40_API MM40_RETURN __cdecl mm40EnableTrigger			(IN HANDLE hDevice, IN BOOL bEnable, IN BOOL bNegative, IN BOOL bOutput );
MM40_API MM40_RETURN __cdecl mm40SetTrigger				(IN HANDLE hDevice, IN DWORD dwMode, IN BOOL bNegative );
MM40_API MM40_RETURN __cdecl mm40GetTrigger				(IN HANDLE hDevice, OUT DWORD *lpdwMode, OUT DWORD * lpbNegative );

#define	MM40_TRIG_OFF		0		// No trigger
#define	MM40_TRIG_IN_EDGE	1		// Input positive/negative edge starts exposure
#define	MM40_TRIG_IN_LEVEL	2		// Input positive/negative level defines exposure
#define	MM40_TRIG_OUT		3		// Output is high when exposure is active
#define	MM40_TRIG_MAX		4		// Maximum mode

MM40_API MM40_RETURN __cdecl mm40PingTrigger			(IN HANDLE hDevice );

MM40_API BOOL		 __cdecl mm40IsBufferOK					(IN HANDLE hDevice, IN LPVOID pBuf, IN LPDWORD pFrameNum );
//****************************************************************************

// Get Firmware Version
MM40_API MM40_RETURN __cdecl mm40GetFWVersion( 
						IN HANDLE drvHandle, 			// driver handle
						OUT LPDWORD  pSoftwareVersion);	// Returned firmware version

// Get mm40api.dll Version
MM40_API MM40_RETURN __cdecl mm40GetDLLVersion( 
						OUT LPDWORD pSoftwareVersion);	// Returned software version

// Get mm40dcam.sys version
MM40_API MM40_RETURN __cdecl mm40GetSYSVersion( 
						IN HANDLE drvHandle, 			// driver handle
						OUT LPDWORD pSoftwareVersion);	// Returned software version

// Get camera resolution in human readable form
MM40_API MM40_RETURN __cdecl mm40GetResolution( 
						IN HANDLE	hDevice,			// driver handle
						OUT PSIZE	pResolution,		// mode resolution
						OUT PDWORD	uBufwidth,			// line pitch in bytes
						OUT PDWORD	uF1offs,			// offset to the second field
						OUT PDWORD	uPixsize);			// bits per pixel

MM40_API MM40_RETURN __cdecl mm40ReadQlet( 
						IN HANDLE	hDevice,
						IN DWORD	Offset,
						OUT LPDWORD	pData);

MM40_API MM40_RETURN __cdecl mm40WriteQlet(
						IN HANDLE	hDevice,
						IN DWORD	Offset,
						IN DWORD	uData);

MM40_API MM40_RETURN __cdecl mm40ReadBlock( 
						IN HANDLE	hDevice,
						IN DWORD	Offset,
						IN DWORD    Count,
						OUT PVOID	pData);

MM40_API MM40_RETURN __cdecl mm40WriteBlock( 
						IN HANDLE	hDevice,
						IN DWORD	Offset,
						IN DWORD    Count,
						IN PVOID	pData);

MM40_API MM40_RETURN __cdecl mm40ReadBlockRaw( 
						IN HANDLE	hDevice,
						IN WORD		OffsetHi,
						IN DWORD	OffsetLo,
						IN DWORD    Count,
						OUT PVOID	pData);

MM40_API MM40_RETURN __cdecl mm40WriteBlockRaw( 
						IN HANDLE	hDevice,
						IN WORD		OffsetHi,
						IN DWORD	OffsetLo,
						IN DWORD    Count,
						IN PVOID	pData);

/**************************************************************************/
/* Support for MM cameras *************************************************/
/**************************************************************************/
typedef struct {
	double	blackDummy;				// Black level from dummy pixels
	double	blackDark;				// Black level from dark pixels
	double	blackLeftUp;			// Black level from black pixels on top left
	double	blackLeftMid;			// Black level from black pixels on mid left
	double	blackLeftDown;			// Black level from black pixels on down left
	double	blackRight;				// Black level from black pixels on the right

	double	noiseShift;				// noise from dummy (shift reg and output)
	double	noiseCCD;				// noise from all black pixels

	double	black[3][4];			//
} DARKSIDE, * LPDARKSIDE;

typedef enum {
	MMM_NONE = 0x000,		// B/W sensors
	MMM_RGGB = 0x001,		// Regular RGGB readout
	MMM_CMYG = 0x002,		// AK Sony sensors
	MMM_RGR  = 0x003,		// 2R+G readout of RGGB sensor
	MMM_BGGR = 0x004		// BGGR readout
	// etc
} MMMOSAIC;

typedef	struct {
	DWORD		dwCx, dwCy;			// total spacial resolution
	DWORD		dwFields;			// number of fields to get one full frame
	DWORD		dwBinX, dwBinY;		// Binning along x and y
	MMMOSAIC	mmMosaic;			// Mosaic of raw data
	DWORD		dwRDO;				// Readout schema
#define	RP_PS_COLOR	0		// Progressive scan color
#define	RP_PS_MONO	1		// Progressive scan mono
#define	RP_IL_1LINE	2		// Interlace 1 line - each field with individual colors: lines F0:0,2,4,6...   F1:1,3,5,7...
#define	RP_IL_2LINE	3		// Interlace 2 line - each field with equivalent colors: lines F0:0,1,4,5...   F1:2,3,6,7...
} MMMODE, LPMMMODE;

typedef	struct {
	LPVOID	bp;				// data
	LONG	z;				// zoom 
	DWORD	w, h;			// full image size
	DWORD	cx, cy;			// retrieve area size
	LONG	x0, y0;			// retrieve area position
	DWORD	fn;				// last field number
	DWORD	fpf;			// Fields per frame
	DWORD	binX;			// Required software binning X
	DWORD	binY;			// Required software binning Y
	DARKSIDE	darkSide;	// Black level and noise parameters
} MMGETBITMAP, * LPMMGETBITMAP;

typedef	struct {
	BOOL	bDoAll;			// Processes all pixels, including blind, etc.
	BOOL	bTranspose;		// Flip image along diagonal
	BOOL	bBW;			// Convert into BW bitmap
	DWORD	dwBin;			// Software binning (=1, =2)
	DWORD	x0, y0, xc, yc;	// ROI coordinates

} MMGETBITMAPOPT, * LPMMGETBITMAPOPT;

typedef	struct {
	DWORD	dwFilter;				// Filter routine used
		#define	MMF_NONE		0	// No interpolation
		#define	MMF_RGB9331		1	// Standard 9331 color interpolation
		#define	MMF_SHTNEW		2	// SHT new
		#define	MMF_BWNONE		3	// Intensity

	double	rgbWhiteBal[3];			// White balance correction				(0.0..8.0)
	double	rgbCorrection[4][4];	// Full RGB->RGB correction matrix		(0.0..16.0)
	double	sharpStrength;			// Sharpening filter strength			(0.0..4.0)
	double	gammaY;					// Intensity gamma						(0.01..1.0)
	double	gammaC;					// Stauration (color) gamma				(0.0..1.0)
	DWORD	dwBPP;					// Output precision of color components (8 or 16)
} MMFILTER, * LPMMFILTER;

typedef	struct {
	LPVOID	bp;				// pointer to internal MM data buffer
	DWORD	modeX0, modeCX;	// user defined X origin and extension
	DWORD	modeY0, modeCY;	// user defined Y origin and extension
	DWORD	modeBinX, modeBinY;	// current mode X and Y binning
	DWORD	modeFPF;		// current mode fields per frame
	DWORD	modeBPP;		// Bits per pixel
	DWORD	modeMTX;		// Color matrix code
	DWORD	modeRDO;		// Read out schema (RP_xxxx)

	DWORD	curX0, curCX;	// partial readout Y origin and extention used - covers some guard areas for interpolation
	DWORD	curY0, curCY;	// partial readout X origin and extention used - covers full width
	DWORD	curBinX, curBinY;// current data X and Y binning
	DWORD	curBPP;			// Current data bits per pixel
	DWORD	curMTX;			// Color matrix code
	DWORD	curFN;			// current field (frame?) number
} MMGETFRAME, * LPMMGETFRAME;

typedef	struct {
	LPVOID	bp;				// pointer to internal MM data buffer
	DWORD	modeX0, modeCX;	// user defined X origin and extension
	DWORD	modeY0, modeCY;	// user defined Y origin and extension
	DWORD	modeBinX, modeBinY;	// current mode X and Y binning
	DWORD	modeFPF;		// current mode fields per frame
	DWORD	modeBPP;		// Bits per pixel
	DWORD	modeMTX;		// Color matrix code
	DWORD	modeRDO;		// Read out schema (RP_xxxx)

	DWORD	curX0, curCX;	// partial readout Y origin and extention used - covers some guard areas for interpolation
	DWORD	curY0, curCY;	// partial readout X origin and extention used - covers full width
	DWORD	curBinX, curBinY;// current data X and Y binning
	DWORD	curBPP;			// Current data bits per pixel
	DWORD	curMTX;			// Color matrix code
	DWORD	curFN;			// current field (frame?) number

	DWORD	origX0, origY0;	// Points to the origin of data to process
} MMGETFRAMEEX, * LPMMGETFRAMEEX;

typedef	struct {
	DWORD	shCX;			// Dimensions
	DWORD	shCY;			// 
	LPVOID	lpSub;			// Pointer to Sub image - orphan, must be released by application
	LPVOID	lpMul;			// Pointer to Mul image - orphan, must be released by application
} MMSHADING, * LPMMSHADING;

MM40_API MM40_RETURN __cdecl mmInitializeHardware (IN HANDLE hDevice );
MM40_API MM40_RETURN __cdecl mmResetHardware	(IN HANDLE hDevice );

MM40_API MM40_RETURN __cdecl mmGetModeDescriptor (IN HANDLE hDevice, IN DWORD dwModeNum, OUT MMMODE * mode);

MM40_API MM40_RETURN __cdecl mmSetMode			(IN HANDLE hDevice, DWORD dwExpUsec, DWORD dwModeNum, DWORD x0, DWORD y0, DWORD cx, DWORD cy);

MM40_API MM40_RETURN __cdecl mmGetModeTiming	(IN HANDLE hDevice, INOUT float *fTPFI0, INOUT float *fTPFIe, INOUT float *fTPFR0, INOUT float *fTPFRe);

MM40_API MM40_RETURN __cdecl mmStartAcquisition	(IN HANDLE hDevice);

MM40_API MM40_RETURN __cdecl mmStopAcquisition	(IN HANDLE hDevice);

MM40_API MM40_RETURN __cdecl mmIsFieldReady		(IN HANDLE hDevice);

MM40_API MM40_RETURN __cdecl mmWaitForField		(IN HANDLE hDevice, IN  DWORD dwTimeOut );

MM40_API MM40_RETURN __cdecl mmAcquireField		(IN HANDLE hDevice, OUT HANDLE * hImage );

MM40_API MM40_RETURN __cdecl mmUpdateFrame		(IN HANDLE hDevice, IN HANDLE hImage );
MM40_API MM40_RETURN __cdecl mmUpdateFrameShading (IN HANDLE hDevice, IN HANDLE hFieldBuffer, IN LPMMSHADING lpSahding);
MM40_API BOOL        __cdecl mmIsFrameComplete	(IN HANDLE hDevice);
MM40_API MM40_RETURN __cdecl mmProcessFrame		(IN HANDLE hDevice);

MM40_API MM40_RETURN __cdecl mmRetrieveFrame	(IN HANDLE hDevice, INOUT LPMMGETFRAME lpGF );
MM40_API MM40_RETURN __cdecl mmRetrieveFrameEx	(IN HANDLE hDevice, INOUT LPMMGETFRAMEEX lpGF );
MM40_API MM40_RETURN __cdecl mmGetMeans			(IN HANDLE hDevice, IN DWORD dwX0, IN DWORD dwY0, IN DWORD dwCX, IN DWORD dwCY, INOUT float * fMeans );

MM40_API MM40_RETURN __cdecl mmSetupFilter		(IN HANDLE hDevice, IN LPMMFILTER lpFlt );
MM40_API MM40_RETURN __cdecl mmSetupCE			(IN HANDLE hDevice, IN DWORD dwLow, IN DWORD dwHigh );
MM40_API MM40_RETURN __cdecl mmRetrieveBitmap	(IN HANDLE hDevice, INOUT LPMMGETBITMAP lpGB );
MM40_API MM40_RETURN __cdecl mmRetrieveBitmapEx	(IN HANDLE hDevice, INOUT LPMMGETBITMAP lpGB );
MM40_API MM40_RETURN __cdecl mmRetrieveBitmapAdv(IN HANDLE hDevice, INOUT LPMMGETBITMAP lpGB, INOUT LPMMGETBITMAPOPT lpGBopt );
MM40_API MM40_RETURN __cdecl mmFreeBitmap		(IN HANDLE hDevice, INOUT LPMMGETBITMAP lpGB );

MM40_API MM40_RETURN __cdecl mmSetGain			(IN HANDLE hDevice, IN WORD wGain );
#define	MM_GAIN_RANGE	1024
MM40_API MM40_RETURN __cdecl mmGetGainInfo		(IN HANDLE hDevice, INOUT float * fLow_dB, INOUT float * fHigh_dB, INOUT LPDWORD lpdwStops, INOUT LPDWORD lpdwDefGain);
MM40_API MM40_RETURN __cdecl mmGetGain			(IN HANDLE hDevice, IN LPWORD pwGain );

MM40_API MM40_RETURN __cdecl mmSetLED			(IN HANDLE hDevice, IN BYTE bLED );

MM40_API MM40_RETURN __cdecl mmPingTrigger		(IN HANDLE hDevice );

MM40_API MM40_RETURN __cdecl mmGetDarkSide		(IN HANDLE hDevice, OUT LPDARKSIDE pDS );

MM40_API MM40_RETURN __cdecl mmGetRawPixel		(IN HANDLE hDevice, IN DWORD dwX, IN DWORD dwY,  INOUT LPWORD pPix );
MM40_API MM40_RETURN __cdecl mmGetRawPixelEx	(IN HANDLE hDevice, IN DWORD dwX, IN DWORD dwY,  INOUT LPWORD pPix );

MM40_API MM40_RETURN __cdecl mmGetTemperature	(IN HANDLE hDevice, INOUT LPDWORD pTemp );
MM40_API MM40_RETURN __cdecl mmGetTemperatureEx	(IN HANDLE hDevice, INOUT float * pThousing, INOUT float * pTchip );
MM40_API MM40_RETURN __cdecl mmCalibrateTemperature	(IN HANDLE hDevice, IN float fThousing, IN float fTchip );
MM40_API MM40_RETURN __cdecl mmCalibrateTemperature2P (IN HANDLE hDevice, IN float fThousing, IN float fTchip );
MM40_API MM40_RETURN __cdecl mmSetCooling		(IN HANDLE hDevice, IN BOOL bOn, float fTargetCT);

MM40_API MM40_RETURN __cdecl mmResetCamera		(IN HANDLE hDevice );

MM40_API MM40_RETURN __cdecl mmInitializeShading(IN HANDLE hDevice, INOUT LPMMSHADING lpMMS, DWORD dwCX, DWORD dwCY, WORD wOff, WORD wMul );
#define	MMSHADING_MUL1	0x4000
#define	MMSHADING_SUB0	0x0000

MM40_API MM40_RETURN __cdecl mmCalculateShading (IN HANDLE hDevice, INOUT LPMMSHADING lpMMS, DWORD dwCX, DWORD dwCY, LPWORD pBlack, LPWORD pWhite );

MM40_API MM40_RETURN __cdecl mmSetTrigger		(IN HANDLE hDevice, IN DWORD dwMode, IN BOOL bNegative );
MM40_API MM40_RETURN __cdecl mmGetTrigger		(IN HANDLE hDevice, OUT DWORD *lpdwMode, OUT DWORD * lpbNegative );

#define	MM_TRIG_OFF			0		// No trigger
#define	MM_TRIG_IN_EDGE		1		// Input positive/negative edge starts exposure
#define	MM_TRIG_IN_LEVEL	2		// Input positive/negative level defines exposure
#define	MM_TRIG_OUT			3		// Output is high when exposure is active
#define	MM_TRIG_SOFTW		4		// Software ping triggers exposure
#define	MM_TRIG_MAX			5		// Maximum mode

MM40_API MM40_RETURN __cdecl mmPingTrigger		(IN HANDLE hDevice );

MM40_API MM40_RETURN __cdecl mmSetFlashMode		(IN HANDLE hDevice, IN BOOL bFlash );
MM40_API MM40_RETURN __cdecl mmGetFlashMode		(IN HANDLE hDevice, INOUT BOOL* pbFlash );

MM40_API MM40_RETURN __cdecl mmGetFactoryInfo	(IN HANDLE hDevice, LPSTR pCygnal, LPSTR pFPGA, LPSTR pCygnalLck, LPSTR pUser, LPDWORD pPdate);


#define	MM_BPL_MAXCNT	8		// Maximum number of pixels used for correction
typedef struct {
	DWORD	dwFlags;			// Bit mask of bad pixel
#define MM_BPL_END			0x01	// End of the list - no correction required
#define MM_BPL_REQ			0x02	// This pixel requires correction
#define MM_BPL_COLUMN		0x04	// This is a column defect
#define MM_BPL_ROW			0x08	// This is a row defect
#define MM_BPL_CLUSTER		0x10	// This is a cluster defect
#define MM_BPL_DARKPOINT	0x20	// This is a Dark point defect
#define MM_BPL_HIGHDPIX		0x40	// This is a HighDPIX point defect
#define MM_BPL_BRIGHTPOINT	0x80	// This is a Bright point defect

	DWORD	dwX, dwY; 			// bad pixel location
	DWORD	dwCnt;				// Number of pixels used for correction
	int		ox[MM_BPL_MAXCNT];	// X and Y Offsets to correction pixel
	int		oy[MM_BPL_MAXCNT];	//
} BADPIXEL, *LPBADPIXEL;

typedef struct {
	DWORD	dwPoints;		// Count of bad pixels
	DWORD	dwColumns;		// Count of bad columns
	DWORD	dwRows;			// Count of bad rows
	DWORD	dwClusters;		// Count of clusters
	DWORD	dwPixClusters;	// Count of bad pixels in clusters
	DWORD	dwTotal;		// Count of bad pixels
	char	cCCD[256];		// CCD type
	char	cCCDSN[256];	// CCD serial number
	float	fVAB;			// Anti Blooming Voltage
	BOOL	bColor;			// Sensor is color
	LPBADPIXEL lpBP;		// Pointer to bad pixel structures array
} BADPIXELSTATISTICS, *LPBADPIXELSTATISTICS;

MM40_API MM40_RETURN __cdecl mmCorrectBadPixels		(IN HANDLE hDevice, LPBADPIXELSTATISTICS lpBPS);

MM40_API MM40_RETURN __cdecl mmParseBadPixelsList	(IN HANDLE hDevice, LPSTR szText, LPBADPIXELSTATISTICS lpBPS, BOOL bColor);

MM40_API MM40_RETURN __cdecl mmReleaseBadPixelsList	(IN HANDLE hDevice, LPBADPIXELSTATISTICS lpBPS);

MM40_API MM40_RETURN __cdecl mmParseProfile			(IN HANDLE hDevice, LPSTR szText);

MM40_API MM40_RETURN __cdecl mmApplyCameraProfile	(IN HANDLE hDevice );

MM40_API MM40_RETURN __cdecl mmSaveCameraProfile	(IN HANDLE hDevice );

//***********************Raw Data**********************************
MM40_API MM40_RETURN __cdecl mmRetrieveRaw(IN HANDLE hDevice, LPVOID * output, DWORD * data_size);
MM40_API MM40_RETURN __cdecl mmSetRawData(LPVOID input);
MM40_API MM40_RETURN __cdecl mmSetupFilterRaw (IN LPMMFILTER lpFlt );
MM40_API MM40_RETURN __cdecl mmSetupCERaw (IN DWORD dwLow, IN DWORD dwHigh );
MM40_API MM40_RETURN __cdecl mmProcessRawFrame ();
MM40_API MM40_RETURN __cdecl mmRetrieveBitmapAdvRaw ( INOUT LPMMGETBITMAP lpGB,	INOUT LPMMGETBITMAPOPT lpGBopt );
MM40_API MM40_RETURN __cdecl mmGetFilterRaw (IN LPMMFILTER lpFlt );
MM40_API MM40_RETURN __cdecl mmReleaseRaw(LPVOID output, DWORD data_size);
MM40_API MM40_RETURN __cdecl mmFreeBitmapRaw( INOUT LPMMGETBITMAP lpGB );
MM40_API MM40_RETURN __cdecl mmGetRawMeans ( IN DWORD dwX0,	IN DWORD dwY0, IN DWORD dwCX, IN DWORD dwCY, INOUT float * fMeans );

#ifdef __cplusplus
}
#endif

#endif /* __MM40API_H */
