//---------------------------------------------------------------------------

#ifndef SvImageH
#define SvImageH

#include <Classes.hpp>
#include <stdio.h>
//---------------------------------------------------------------------------

#define MAX_PIXEL 256
#define BYTE_BIT_COUNT 8

class SImage {
    protected : //Var.
        int             m_iWidth    ;  //이미지의 넓이.
        int             m_iHeight   ;  //이미지의 높이.
        int             m_iBitCnt   ;  //이미지의 비트수. (8==흑백 , 24==컬러)

        BITMAPINFO    * m_pBitInfo8  ;  //8비트  원이미지용 BITMAPINFO
        BITMAPINFO    * m_pBitInfo24 ;  //24비트 원이미지용 BITMAPINFO
        
        BITMAPINFO    * m_pBitInfo   ;  //변환 디스플레이용. 비트맵인포. ex)falseColor , Binary.. etc..

        unsigned char * m_pImage    ;  //이미지의 처음 시작 포인터 그레이 이미지.
        unsigned char * m_pImageC   ;  //이미지의 처음 시작 포인터 컬러 이미지.

        unsigned char * m_pImageR   ;  //칼라 카메라 디스플레이용.
        unsigned char * m_pImageG   ;
        unsigned char * m_pImageB   ;

    protected : //Func.
        void SetSize(int _iWidth , int _iHeight , int _iBitCnt); //사이즈 바꾸는 함수 인데.

    public : //생성자 소멸자.
        SImage();
        ~SImage();

    public : //인라인 , 오퍼레이터 함수들...
        inline bool          CheckRangeOver(int _x , int _y) { return (0>_x || _x>=m_iWidth || 0>_y || _y>=m_iHeight);}

        inline unsigned char * GetImg (){ if(!m_pImage ) return NULL ; return m_pImage  ; };  //픽셀밝기값을 얻어 온다.
        inline unsigned char * GetImgC(){ if(!m_pImageC) return NULL ; return m_pImageC ; };  //픽셀밝기값을 얻어 온다.
        inline unsigned char * GetImgR(){ if(!m_pImageR) return NULL ; return m_pImageR ; };
        inline unsigned char * GetImgG(){ if(!m_pImageG) return NULL ; return m_pImageG ; };
        inline unsigned char * GetImgB(){ if(!m_pImageB) return NULL ; return m_pImageB ; };

    public :

        bool LoadBmp (AnsiString _FilePath); //이미지를 로드 하는 함수.
        bool SaveBmp (AnsiString _FilePath); //이미지를 세이브 하는 함수.

        int ShowImg      (HDC _hHdc , int _x, int _y, int _iWidth, int _iHeight);

        int  GetImageHeight(){return m_iHeight ;}
        int  GetImageWidth (){return m_iWidth  ;}
        int  GetImageBit   (){return m_iBitCnt ;}

        //디버깅용 비트맵인포해더 저장.
        bool SaveBmIf()
        {
            AnsiString filename = "d:\\BC6Works\\ImageView\\bin\\info.sss";

            FILE * file = fopen(filename.c_str(),"wb") ;
            if(file == NULL) {return false ;}

            fwrite(m_pBitInfo8  , sizeof(BITMAPINFOHEADER)+MAX_PIXEL*sizeof(RGBQUAD), 1, file); //DWORD  biSize;           40
            fwrite(m_pBitInfo24 , sizeof(BITMAPINFOHEADER)                          , 1, file); //DWORD  biSize;           40

            //fwrite(&DpInfo->bmiHeader.biSize          , 4, 1, file); //DWORD  biSize;           40
            //fwrite(&DpInfo->bmiHeader.biWidth         , 4, 1, file); //LONG   biWidth;          1024
            //fwrite(&DpInfo->bmiHeader.biHeight        , 4, 1, file); //LONG   biHeight;         768
            //fwrite(&DpInfo->bmiHeader.biPlanes        , 2, 1, file); //WORD   biPlanes;         1
            //fwrite(&DpInfo->bmiHeader.biBitCount      , 2, 1, file); //WORD   biBitCount        8
            //fwrite(&DpInfo->bmiHeader.biCompression   , 4, 1, file); //DWORD  biCompression;    0
            //fwrite(&DpInfo->bmiHeader.biSizeImage     , 4, 1, file); //DWORD  biSizeImage;      786432
            //fwrite(&DpInfo->bmiHeader.biXPelsPerMeter , 4, 1, file); //LONG   biXPelsPerMeter;  1
            //fwrite(&DpInfo->bmiHeader.biYPelsPerMeter , 4, 1, file); //LONG   biYPelsPerMeter;  1
            //fwrite(&DpInfo->bmiHeader.biClrUsed       , 4, 1, file); //DWORD  biClrUsed;        0
            //fwrite(&DpInfo->bmiHeader.biClrImportant  , 4, 1, file); //DWORD  biClrImportant;   0

            fclose(file);
            return true ;
        }
};


extern int  g_iDrawLine ;
extern int  g_iDrawPx   ;



#endif




