///////////////////////
// Raster operations //
///////////////////////

#ifndef __RASTER_H
#define __RASTER_H

#include "misc.h"
#include "lang.h"
#include "globals.h"
#include "config.h"
#include "format.h"
#include "color.h"
#include "list.h"

#include "x86_8.h"
#include "x86_16.h"
#include "x86_32.h"
#include "x86_fake.h"
#include "x86_copy.h"

#include "mmx_8.h"
#include "mmx_16.h"
#include "mmx_32.h"
#include "mmx_fake.h"
#include "mmx_copy.h"

#include "cpp_8.h"
#include "cpp_16.h"
#include "cpp_32.h"
#include "cpp_copy.h"

#include "clear.h"







class RASTER
{
    public:

        // converter class
        class CONVERTER
        {
            // friend classes
            friend class RASTER;

            public:
                                
                // setup
                CONVERTER();
                ~CONVERTER();

                // interface
                int Convert(void *src,void *dest,uint pixels,void *extra); 
                int Convert(AREADATA data,void *extra);
                int Convert(void *src,void *dest,uint start_byte,uint stop_byte,void *extra); 

            private:

                // internal setup
                void SetupFormats(FORMAT const &src,FORMAT const &dest);
                void SetupFunctions(CONVERT_FUNCTION convert,AREACONVERT_FUNCTION area,PARTIALCONVERT_FUNCTION partial);

                // internal convert
                int InternalConvert(void *src,void *dest,uint pixels,void *extra);
                int InternalConvert(AREADATA &data,void *extra);
                int InternalConvert(void *src,void *dest,uint start_byte,uint stop_byte,void *extra);

                // data
                FORMAT SourceFormat;
                FORMAT DestinationFormat;
                int Extra;
                int Copy;

                // functions
                CONVERT_FUNCTION ConvertFunction; 
                AREACONVERT_FUNCTION AreaConvertFunction;
                PARTIALCONVERT_FUNCTION PartialConvertFunction;
        };

    public:
            
        // setup
        RASTER();
        ~RASTER();

        // converter access
        CONVERTER* RequestConverter(int src_id,int dest_id);
        CONVERTER* RequestConverter(FORMAT const &src,FORMAT const &dest);

    private:

        // static converter setup
        static void InitConverters();
        static void CloseConverters();
        static void DefaultConverters();
        static int DefaultConverters_X86();
        static int DefaultConverters_CPP();
        static int DefaultConverters_MMX();
        static int SetupConverter(int src_id,int dest_id,CONVERT_FUNCTION convert,AREACONVERT_FUNCTION area,PARTIALCONVERT_FUNCTION partial);
        static int GenerateTable16_X86(void *dest,FORMAT const &format);

        // static reference count
        static int ReferenceCount;

        // static copy converters
        static CONVERTER *StaticCopyConverter;

        // static 32bit -> X converters
        static CONVERTER *StaticConverter32;

        // static 16bit -> X converters
        static CONVERTER *StaticConverter16;

        // static 8bit -> X converters
        static CONVERTER *StaticConverter8;
        static CONVERTER *StaticConverter8_4BYTE;
        static CONVERTER *StaticConverter8_3BYTE;
        static CONVERTER *StaticConverter8_2BYTE;
        static CONVERTER *StaticConverter8_1BYTE;

};








#endif
