#pragma once
|
|
// templateÀ» »ç¿ëÇÑ ¹è¿ °ø°£ »ý¼º, ±âº»ÀûÀ¸·Î ¸Þ¸ð¸®´Â Àç»ç¿ë ¸ñÀû.
|
// 1Â÷¿ø : CMosisLine
|
// 2Â÷¿ø : CMosisSquare, CSquareSquare
|
|
|
template<typename Ty>
|
class CMosisLine
|
{
|
Ty *m_pData;
|
int m_nData;
|
int m_nSpace;
|
|
public:
|
CMosisLine() : m_pData(NULL), m_nData(0), m_nSpace(0) {}
|
~CMosisLine() {Release();}
|
public:
|
void Release() {if(m_pData) delete[] m_pData; m_pData= NULL; m_nData= m_nSpace= 0; }
|
BOOL SetSize(int n);
|
public:
|
Ty *GetAddr() {return m_pData;}
|
Ty *GetData(int i) {return m_pData+ i;}
|
int GetSize() {return m_nData;}
|
BOOL CopyFrom(Ty *p, int n) {if(! SetSize(n)) return FALSE; memcpy(GetAddr(), p, sizeof(Ty)*n); return TRUE;}
|
};
|
|
|
|
template<typename Ty>
|
class CMosisSquare
|
{
|
Ty *m_pData;
|
int m_nWidth;
|
int m_nHeight;
|
int m_nSpace; // Àç»ç¿ëÀ» À§ÇØ ½ÇÁ¦ ¸Þ¸ð¸®»óÀÇ Å©±â.
|
|
public:
|
CMosisSquare(): m_pData(NULL), m_nSpace(0), m_nWidth(0), m_nHeight(0) {}
|
~CMosisSquare() {Release();}
|
|
protected:
|
void Release(){if(m_pData) delete[] m_pData; m_pData= NULL; m_nWidth= m_nHeight= m_nSpace= 0;}
|
|
public:
|
BOOL SetSize(int w, int h);
|
static int GetSquareNum(int n){ int sq= 1; while(sq < n){sq= sq<< 1;} return sq; }
|
|
public:
|
Ty* GetData(int x, int y) {return m_pData+ x+ y*m_nWidth;};
|
Ty* GetAddress() {return m_pData;}
|
int GetWidth() {return m_nWidth;}
|
int GetHeight() {return m_nHeight;}
|
int GetDataSize(){return GetWidth()*GetHeight();}
|
|
public:
|
BOOL IsValidBuff(){return (GetAddress() != NULL) && (GetWidth()>0) && (GetHeight()>0);}
|
};
|
|
|
// FFT¿¡¼ 2^n °³ÀÇ µ¥ÀÌÅ͸¦ ¸ð»çÇϱâ À§ÇØ ¸Þ¸ð¸® °ø°£°ú ½ÇÁ¦ »ç¿ë µ¥ÀÌÅÍ °³¼ö¸¦ º°µµ ºÐ¸®.
|
template<typename Ty>
|
class CSquareSquare
|
{
|
Ty *m_pData;
|
int m_nRealWidth, m_nWidth;
|
int m_nRealHeight, m_nHeight;
|
int m_nSpace; // Àç»ç¿ëÀ» À§ÇØ ½ÇÁ¦ ¸Þ¸ð¸®»óÀÇ Å©±â.
|
|
public:
|
CSquareSquare(): m_pData(NULL), m_nWidth(0), m_nRealWidth(0), m_nHeight(0), m_nRealHeight(0), m_nSpace(0) {}
|
~CSquareSquare() {Release();}
|
|
protected:
|
void Release(){if(m_pData) delete[] m_pData; m_pData= NULL; m_nWidth= m_nRealWidth= m_nHeight= m_nRealHeight= m_nSpace= 0;}
|
|
public:
|
BOOL SetSize(int w, int h);
|
static int GetSquareNum(int n){ int sq= 1; while(sq < n){sq= sq<< 1;} return sq; }
|
public:
|
Ty* GetData(int x, int y) {return m_pData+ x+ y*m_nWidth;};
|
Ty* GetAddress() {return m_pData;}
|
int GetWidth() {return m_nWidth;}
|
int GetRealWidth() {return m_nRealWidth;}
|
int GetHeight() {return m_nHeight;}
|
int GetRealHeight() {return m_nRealHeight;}
|
};
|
|
|
|
|
template<typename Ty> BOOL CMosisLine<Ty>::SetSize(int n)
|
{
|
if(m_pData)
|
{
|
if(n < m_nSpace)
|
{
|
m_nData= n;
|
return TRUE;
|
}
|
Release();
|
}
|
|
m_pData= new Ty[n];
|
|
if(m_pData == NULL) return FALSE;
|
|
m_nData= m_nSpace= n;
|
return TRUE;
|
}
|
|
|
template<typename Ty> BOOL CMosisSquare<Ty>::SetSize(int width, int height)
|
{
|
int space= width*height;
|
|
if(m_pData)
|
{
|
if(space <= m_nSpace)
|
{
|
m_nWidth= width;
|
m_nHeight= height;
|
return TRUE;
|
}
|
Release();
|
}
|
|
m_pData= new Ty[space];
|
if(m_pData == NULL) return FALSE;
|
|
m_nWidth= width;
|
m_nHeight= height;
|
m_nSpace= space;
|
|
return TRUE;
|
}
|
|
|
template<typename Ty> BOOL CSquareSquare<Ty>::SetSize(int w, int h)
|
{
|
int width= GetSquareNum(w);
|
int height= GetSquareNum(h);
|
int space= width*height;
|
|
if(m_pData)
|
{
|
if(space <= m_nSpace)
|
{
|
m_nWidth= width;
|
m_nRealWidth= w;
|
m_nHeight= height;
|
m_nRealHeight= h;
|
return TRUE;
|
}
|
Release();
|
}
|
|
m_pData= new Ty[space];
|
if(m_pData == NULL) return FALSE;
|
|
m_nWidth= width;
|
m_nRealWidth= w;
|
m_nHeight= height;
|
m_nRealHeight= h;
|
m_nSpace= space;
|
|
return TRUE;
|
}
|