///////////////////////////////////////////////////////////////////////////
//	fwxVideo.h: Interface for the fwxVideo library to process video
//				images from a 1394 digital camera.
////	BusView Sample Application Static Library
//	Copyright (c) 1997-1998 by 3A International, Inc.  All Rights Reserved.
///////////////////////////////////////////////////////////////////////////

#ifndef LIB_FWXVIDEO_H
#define LIB_FWXVIDEO_H


// FWX_VIDEO_ERROR codes
#define FWX_VIDEO_ERROR_BASE				1000
#define FWX_VIDEO_ERROR_NONE				FWX_VIDEO_ERROR_BASE
#define FWX_VIDEO_ERROR_PARAMETER			FWX_VIDEO_ERROR_BASE+1
#define FWX_VIDEO_ERROR_DATA				FWX_VIDEO_ERROR_BASE+2
#define FWX_VIDEO_ERROR_ALLOCATION			FWX_VIDEO_ERROR_BASE+3
#define FWX_VIDEO_ERROR_CREATEPALETTE		FWX_VIDEO_ERROR_BASE+4
#define FWX_VIDEO_ERROR_GETDC				FWX_VIDEO_ERROR_BASE+5
#define FWX_VIDEO_ERROR_CREATECOMPATIBLEDC	FWX_VIDEO_ERROR_BASE+6
#define FWX_VIDEO_ERROR_CREATEDIBSECTION	FWX_VIDEO_ERROR_BASE+7
#define FWX_VIDEO_ERROR_SELECTBITMAP		FWX_VIDEO_ERROR_BASE+8
#define FWX_VIDEO_ERROR_SELECTPALETTE		FWX_VIDEO_ERROR_BASE+9
#define FWX_VIDEO_ERROR_BITBLT				FWX_VIDEO_ERROR_BASE+10
#define FWX_VIDEO_ERROR_CREATEFILE			FWX_VIDEO_ERROR_BASE+11
#define FWX_VIDEO_ERROR_WRITEFILE			FWX_VIDEO_ERROR_BASE+12


// Macro to calc the YUV index into the color trans table 555-bit format
#define CALC_YUV_INDEX(Y,U,V) ((UINT)((((UINT)Y & 0x00F8) << 7) | (((UINT)U & 0x00F8) << 2) | (((UINT)V & 0x00F8) >> 3) & 0x7FFF))

// fwxVideo functions

class  CVideoProcess 
{

public:
	CVideoProcess( void ) ; 
	~CVideoProcess( void ) { }; 

	int  fInitialized ; 
protected:

	// Global data used by functions
	LPVOID fwx_pGrayTransTable;
	LPVOID fwx_pColorTransTable;
	LPBITMAPINFO fwx_pBI;
	HBITMAP fwx_hBitmap;
	HBITMAP fwx_holdBitmap;
	LPVOID fwx_pRGBData;
	LPLOGPALETTE fwx_pLogColorPal;
	LPLOGPALETTE fwx_pLogGrayPal;
	HPALETTE fwx_hColorPal;
	HPALETTE fwx_hGrayPal;
	HPALETTE fwx_holdPal;
	HDC fwx_hDisplayDC;
	HDC fwx_hMemDC;
	UINT fwx_nBPP;
	UINT fwx_nWidth, fwx_nHeight;
	BOOL fwx_bColor;
	ULONG fwx_nLastError;

	UINT YUVidx;
	long nFrameSize;

private:
	// Function prototypes that are private to the library
	BYTE fwxCalcYUVRed(int Y, int V);
	BYTE fwxCalcYUVGreen(int Y, int U, int V);
	BYTE fwxCalcYUVBlue(int Y, int U);
	BOOL fwxInitTransTables(UINT nBPP);

public:
	// Initialize the bitmaps, dib sections, palettes and color tables
	BOOL fwxInitDisplay(UINT nBPP, UINT nWidth, UINT nHeight, HWND hWnd);
	// Delete all the objects creating during fwxInit Display
	BOOL fwxDeleteDisplay(HWND hWnd);

	// Decode the YUV video data into RGB and display it in the window
	BOOL fwxProcessFrame(UINT nMode, BYTE *pFrame);
	
	BOOL fwxValidateParam( void ); 

	// Move the image from the memory dc to the client dc
	BOOL fwxShowFrame(UINT nMode);

	// Select the color palette (8-bit mode only) and set color mode
	BOOL fwxSelectColorPalette(void);
	// Select the grayscale palette (8-bit mode only) and set grayscale mode
	BOOL fwxSelectGrayPalette(void);

	// Save the image on the screen to a .bmp file
	BOOL fwxSaveScreenShot(void);
	// Save the image on the screen in a 24-bit bitmap
	BOOL fwxSaveTrueBitmap(UINT nMode, BYTE *pFrame, TCHAR *szFileName);

	// Get the last error that occured
	ULONG fwxGetLastVideoError(void);
	// Get the text for an error code
	LPCTSTR fwxGetVideoErrorText(ULONG nErrorCode);

};  // end class CVideoProcess


#endif // LIB_FWXVIDEO_H
