멤버 함수 선언을 포함한 IppImage 클래스 전체 정의를 소스 4-9에 나타내었다. 이제부터는 각각의 멤버 함수들의 역할과 구현 방법에 대해 알아보자.

    소스 4-9 IppImage 클래스의 정의(IppImage.h)
    #pragma once
    
    template<typename T>
    class IppImage
    {
    protected:
        int width;  // 영상의 가로 크기(픽셀 단위)
        int height; // 영상의 세로 크기(픽셀 단위)
        T** pixels; // 픽셀 데이터
    
    public:
        // 생성자와 소멸자
        IppImage();
        IppImage(int w, int h);
        IppImage(const IppImage<T>& img);
        ~IppImage();
    
        // 이미지 생성과 소멸
        void CreateImage(int w, int h);
        void DestroyImage();
    
        // 픽셀 값 접근
        T* GetPixels() const {
            if (pixels) return pixels[0];
            else return NULL;
        }
        T** GetPixels2D() const { return pixels; }
    
        // 치환 연산자 재정의
        IppImage<T>& operator=(const IppImage<T>& img);
        template<typename U> IppImage<T>& operator=(const IppImage<U>& img);
    
        // 영상 정보 반환
        int GetWidth()   const { return width; }
        int GetHeight()  const { return height; }
        int GetSize()    const { return width * height; }
        bool IsValid()   const { return (pixels != NULL); }
    };
    
    typedef IppImage<BYTE>     IppByteImage;
    typedef IppImage<int>      IppIntImage;
    typedef IppImage<float>    IppFloatImage;
    typedef IppImage<double>   IppDoubleImage;
    typedef IppImage<RGBBYTE>  IppRgbImage;
    
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.