#if !defined( _IOAIMAGEFILEFORMAT_H )
#define _IOAIMAGEFILEFORMAT_H

#include "FrameBuffer.h"
#include "FileBuffer.h"

// Class to collect together functions for converting IoAFrameBuffer contents
// into and out of various file formats: FITS and Lucky compressed

class IoAImageFileFormat
{
public:
    enum ImageFileFormat { FITSFormat, LuckyFormat };

    IoAImageFileFormat( ) : m_FileFormat( FITSFormat ) { }

    IoAImageFileFormat( ImageFileFormat FileFormat ) : m_FileFormat( FileFormat ) { }

    void SetFileFormat( ImageFileFormat FileFormat )
    {
        m_FileFormat = FileFormat;
    }

    ImageFileFormat FileFormat( )
    {
        return m_FileFormat;
    }

    int FileBytes( const IoAFrameBuffer& FrameBuffer )
    {
        switch ( m_FileFormat )
        {
            case FITSFormat:  return FITSFileBytes ( FrameBuffer );
            case LuckyFormat: return LuckyFileBytes( FrameBuffer );
        }
    }

    int DataBytes( const IoAFrameBuffer& FrameBuffer )
    {
        switch ( m_FileFormat )
        {
            case FITSFormat:  return FITSDataBytes ( FrameBuffer );
            case LuckyFormat: return LuckyDataBytes( FrameBuffer );
        }
    }

    int Encode( const IoAFrameBuffer& FrameBuffer, IoAFileBuffer& FileBuffer, int Append = FALSE )
    {
        switch ( m_FileFormat )
        {
            case FITSFormat:  return FITSFileFormat ( FrameBuffer, FileBuffer, Append );
            case LuckyFormat: return LuckyFileFormat( FrameBuffer, FileBuffer, Append );
        }
    }

    int Decode( const IoAFileBuffer& FileBuffer, IoAFrameBuffer& FrameBuffer )
    {
        switch ( m_FileFormat )
        {
            case FITSFormat:  return FITSFileFormat ( FileBuffer, FrameBuffer );
            case LuckyFormat: return LuckyFileFormat( FileBuffer, FrameBuffer );
        }
    }

    // FITS file format
    static int FITSBlankBytes( int DataBytes );

    static int FITSFileBytes( const IoAFrameBuffer& FrameBuffer );
    static int FITSDataBytes( const IoAFrameBuffer& FrameBuffer );

    static int FITSFileFormat( const IoAFrameBuffer& FrameBuffer, IoAFileBuffer&   FileBuffer, int Append = FALSE );
    static int FITSFileFormat( const IoAFileBuffer&   FileBuffer, IoAFrameBuffer& FrameBuffer );

    // Lucky compressed file format
    static int LuckyFileBytes( const IoAFrameBuffer& FrameBuffer );
    static int LuckyDataBytes( const IoAFrameBuffer& FrameBuffer );

    static int LuckyFileFormat( const IoAFrameBuffer& FrameBuffer, IoAFileBuffer&   FileBuffer, int Append = FALSE );
    static int LuckyFileFormat( const IoAFileBuffer&   FileBuffer, IoAFrameBuffer& FrameBuffer );

private:
    ImageFileFormat m_FileFormat;
};

#endif
