#if !defined( _IOAFITSFRAMEFORMAT_H )
#define _IOAFITSFRAMEFORMAT_H

#include "FITSFileBuffer.h"
#include "FrameBuffer.h"

class IoAFrameFITSFileBuffer : public IoAFITSFileBuffer
{
public:
    IoAFrameFITSFileBuffer( )
    {
        Reset( );
    }

    int Allocate( const IoAFrameBuffer& FrameBuffer, int MaxFrameCount = 1, int ChannelCount = 1 )
    {
        int FrameXSize = FrameBuffer.XSize( );
        int FrameYSize = FrameBuffer.YSize( );

        return Allocate( FrameXSize, FrameYSize, MaxFrameCount, ChannelCount );
    }

    int Allocate( int FrameXSize, int FrameYSize, int MaxFrameCount = 1, int ChannelCount = 1 );

    void Free( );

    int Open( );

    int IsOpen( ) { return m_FrameCount < m_MaxFrameCount; }

    int Close( );

    int AddFrame( const IoAFrameBuffer& FrameBuffer )
    {
        const IoAFrameBuffer *FrameBuffers[ 1 ];

        FrameBuffers[ 0 ] = &FrameBuffer;

        return AddFrame( FrameBuffers, 1 );
    }

    int AddFrame( const IoAFrameBuffer *FrameBuffers[ ], int ChannelCount = -1 );

private:
    Reset( )
    {
        m_FrameNumber = NULL;
        m_FrameTime   = NULL;
        m_CPUClock    = NULL;
        m_DMABufferID = NULL;

        m_AxisCount = 0;

        m_FrameXSize = 0;
        m_FrameYSize = 0;

        m_MaxFrameCount = 0;
        m_ChannelCount  = 0;
    }

    int m_FrameXSize;
    int m_FrameYSize;

    int m_MaxFrameCount;
    int m_ChannelCount;

    int m_FrameCount;

    int     *m_FrameNumber;
    __int64 *m_FrameTime;
    __int64 *m_CPUClock;
    int     *m_DMABufferID;
};

#endif
