// avi.h: interface for the CMyAvi class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_AVI_H__5309061E_B5B3_49FB_9562_CDEBCF15F906__INCLUDED_)
#define AFX_AVI_H__5309061E_B5B3_49FB_9562_CDEBCF15F906__INCLUDED_


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Vfw.h"
#include "ximage.h"

#define BMP 0
#define BIN 0
#define PNG 1
#define JPEG 2
#define IFRAME 2
#define PFRAME 1
#define OFRAME 0

typedef struct MyPixel{
	short x;
	short y;
	BYTE r;
	BYTE g;
	BYTE b;
}Pixel;

class CMyAvi  
{
public:
	CMyAvi();
	virtual ~CMyAvi();

	unsigned short GetHeight();
	unsigned short GetWidth();
	AVIFILEINFO* GetAviFileInfo();
	BITMAPINFOHEADER* GetBMPInfo();

	void SetFilterRange(BYTE value);
	void SetFilterType(BYTE value);
	void SetPixelThreshold(int value);
	void SetPFrameType(BYTE value);
	void SetIFrameType(BYTE value);
	void SetIFrameInterval(int);
	void SetProbeInterval(int);
	void SetPFrameThreshold(unsigned short);
	void SetIFrameThresdRelative(float);

	void AviInit(CString string);
	BOOL AviProcess(CWnd *pFrame);

private:
	CFile m_fileInf;
	CFile m_fileBin;
	unsigned short m_wWidth;
	unsigned short m_wHeight;

	long m_lIFrameThreshold;
	float m_fIFrameThresdRelative;
	short m_wPFrameThreshold;
	short m_nPixelThreshold;

	int m_iProbeInterval;
	int m_iMaxIFrameInterval;

	BYTE m_byPFrameType;
	BYTE m_byIFrameType;

	BYTE m_byFilterRange;
	BYTE m_byFilterType;

	AVIFILEINFO *m_pAviFileInfo;
	BITMAPINFOHEADER *m_lpBMPInfoHeader,*m_lpBMPInfoHeader2;

	MyPixel *m_pTempPixel;

	BYTE m_byRunningProbeFlag;
	CxImage m_Ximage1,m_Ximage2,* m_XimageP;

	PGETFRAME m_pGetFrame,m_pGetFrame2;

	PAVIFILE m_pAviFile;
	PAVISTREAM m_pAviStream;
	AVISTREAMINFO m_AviStreamInfo;

	LPBYTE m_pBmpData,m_pBmpData2;

	void WriteBmpFile(int num);
	void WriteBinFile_P(long NumOfDiff);
	void WritePngFile(int num);
	void WritePngFile_P(int num);
	void WriteJpegFile(int num);
	void WriteJpegFile_P(int num);

	void InitCompare();
	long Compare2Frame(int lframe, int lframe2);
	long Compare2Frame_24(int lframe, int lframe2);

	BYTE GetMedianValue(BYTE *a, BYTE num);

};

#endif // !defined(AFX_AVI_H__5309061E_B5B3_49FB_9562_CDEBCF15F906__INCLUDED_)
