📄 ieimage.cpp
字号:
// IEImage.cpp: implementation of the IEImage class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "IEImage.h"
#include "IEDib.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
template class IEImage< BYTE >;
template class IEImage< int >;
template class IEImage< float >;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
template< class T > IEImage< T >::IEImage()
{
width = height = 0;
pixels = NULL;
}
template< class T > IEImage< T >::IEImage(int w, int h)
{
width = w;
height = h;
int size = w*h; // size = GetSize(); 客 鞍促.
// 捞固瘤 单捞磐(侨伎) 历厘 傍埃 且寸 棺 2-D Interface 累己
//
// pixels ---> [ ] pixels[0] ---> [ ][ ][ ]...[ ][ ][ ]...[ ][ ][ ]
// [ ] pixels[1] ------------------| |
// ... |
// [ ] pixels[h-1]------------------------------
//
pixels = new T*[sizeof(T *)*height];
pixels[0] = new T[sizeof(T)*size];
for( int i = 1 ; i < h ; i++ )
pixels[i] = pixels[i-1] + width;
// 侨伎 蔼 檬扁拳(zero)
memset(pixels[0], 0, sizeof(T)*size);
}
template< class T > IEImage< T >::IEImage(const IEImage<T>& img)
{
width = img.width;
height = img.height;
int size = width*height; // size = GetSize(); 客 鞍促.
// 捞固瘤 单捞磐(侨伎) 历厘 傍埃 且寸 棺 2-D Interface 累己
pixels = new T*[sizeof(T *)*height];
pixels[0] = new T[sizeof(T)*size];
for( int i = 1 ; i < height ; i++ )
pixels[i] = pixels[i-1] + width;
// 侨伎 蔼 檬扁拳(copy)
memcpy(pixels[0], img.pixels[0], sizeof(T)*size);
}
template< class T > IEImage< T >::~IEImage()
{
DestroyImage();
}
template< class T > void IEImage< T >::MakeImage(int w, int h)
{
DestroyImage();
width = w;
height = h;
int size = w*h; // size = GetSize(); 客 鞍促.
// 捞固瘤 单捞磐(侨伎) 历厘 傍埃 且寸 棺 2-D Interface 累己
pixels = new T*[sizeof(T *)*height];
pixels[0] = new T[sizeof(T)*size];
for( int i = 1 ; i < height ; i++ )
pixels[i] = pixels[i-1] + width;
// 侨伎 蔼 檬扁拳(zero)
memset(pixels[0], 0, sizeof(T)*size);
}
template< class T > void IEImage< T >::DestroyImage()
{
if( pixels != NULL )
{
delete [] pixels[0];
delete [] pixels;
pixels = NULL;
}
width = height = 0;
}
template< class T > BOOL IEImage< T >::ReadImage(char * name)
{
//
return TRUE;
}
template< class T > BOOL IEImage< T >::WriteImage(char * name)
{
//
return TRUE;
}
template< class T > void IEImage< T >::SetPixels(int w, int h, T* data)
{
MakeImage(w, h);
memcpy(pixels, data, GetSize()*sizeof(T));
}
template< class T > T IEImage< T >::GetMax()
{
T res = pixels[0][0];
int size = GetSize();
for( int i = 0 ; i < size ; i++ )
res = ( res > pixels[0][i] ) ? res : pixels[0][i];
return res;
}
template< class T > T IEImage< T >::GetMin()
{
T res = pixels[0][0];
int size = GetSize();
for( int i = 0 ; i < size ; i++ )
res = ( res < pixels[0][i] ) ? res : pixels[0][i];
return res;
}
template< class T > IEImage< T >& IEImage< T >::operator=(const IEImage< T >& img)
{
if( this != &img )
{
width = img.width;
height = img.height;
MakeImage(width, height);
memcpy(pixels[0], img.pixels[0], GetSize()*sizeof(T));
}
return *this;
}
template< class T > BOOL IEImage< T >::operator==(const IEImage< T >& img)
{
if( width == img.width && height == img.height )
return (!memcmp(pixels[0], img.pixels[0], GetSize()*sizeof(T)));
else
return FALSE;
}
template< class T > BOOL IEImage< T >::operator!=(const IEImage< T >& img)
{
if( width == img.width && height == img.height )
return (memcmp(pixels[0], img.pixels[0], GetSize()*sizeof(T)));
else
return (width != img.width && height != img.height);
}
template< class T > BOOL IEImage< T >::FromDib(IEDib* pDib)
{
int i, j;
int w = pDib->GetWidth();
int h = pDib->GetHeight();
MakeImage(w, h);
BYTE** src = pDib->GetPtr();
for( j = 0 ; j < h ; j++ )
for( i = 0 ; i < w ; i++ )
{
pixels[j][i] = (T)src[j][i];
}
pDib->FreePtr(src);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -