//
// Tools_AVI_Writer.h
//
// Created by Richard Rice - 08/05/2002
// 
// Copyright (C) 2002 Rebellion, All Rights Reserved.
//


#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef _TOOLS_AVI_WRITER_H_
#define _TOOLS_AVI_WRITER_H_

#include "Core/Asura_PlatformBasics.h"
#include <vfw.h>
#include "Rendering/Asura_Direct3D.h"


#define TOOLS_AVIFLAG_HALFSIZE 0x00000001 //screen is halfed before being cropped to the passed width and height
#define TOOLS_AVIFLAG_USEPREVIOUSCOMPRESSIONSETTINGS 0x00000002
#define TOOLS_AVIFLAG_WRITEBMPS 0x00000004 //Writes a sequence of bmps instead of an avi

class Tools_AVI_Writer
{
	public :
		Tools_AVI_Writer();
		~Tools_AVI_Writer();
		
		bool StartAVI(const char* filename,float fFrameRate);
		bool StartAVI(const char* filename,float fFrameRate,int iWidth,int iHeight,u_int uFlags);
		void WriteFrame();
		void EndAVI();

		bool IsWritingFile(){return AviBuffer!=0;}
		float GetAviFrameRate(){return m_fFrameRate;}

		void PreD3DReset();
		void PostD3DReset();

	private :
		bool OpenFile(bool bUsePreviousSettings);
		void CloseFile();
		bool StartNewFileIfRequired();
		bool WriteBmpFrame();

		bool CreateTempSurface();

		void OutputMessage(int iColour,const char* pszString,...);

		PAVIFILE AviFile;
		AVISTREAMINFO AviStreamInfo;
		PAVISTREAM AviStream;
		PAVISTREAM AviStreamCompressed;
		AVICOMPRESSOPTIONS AviCompressOptions;
		AVICOMPRESSOPTIONS FAR * AviOptionsArray[1];
		BITMAPINFOHEADER BitmapInfo;
		char* AviBuffer;
		int Frame;
		float m_fFrameRate;
		int m_iBitDepth;
		int m_iPitch;
		bool m_bHalfSize;
		bool m_bWriteBmps;

		char m_szFilename[MAX_PATH];
		char* m_pszPartPosition;

		int m_iFileSize;
		int m_iMaxFrameSize;
		int m_iPart;

		Direct3D_Surface* m_pxTempSurface;
		D3DFORMAT m_eSurfaceFormat;
};

extern Tools_AVI_Writer TheAviWriter;




#endif //_TOOLS_AVI_WRITER_H_
