📄 graytrans.cpp
字号:
// GrayTrans.cpp: implementation of the GrayTrans class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Express.h"
#include "GrayTrans.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
GrayTrans::GrayTrans()
{
m_pImgDataOut=NULL;
m_lpColorTableOut=NULL;
m_nColorTableLengthOut=0;
m_nBitCountOut=0;
m_imgWidthOut=0;
m_imgHeightOut=0;
}
GrayTrans::~GrayTrans()
{
if (m_pImgDataOut!=NULL)
{
delete[] m_pImgDataOut;
m_pImgDataOut=NULL;
}
if (m_lpColorTableOut!=NULL)
{
delete[] m_lpColorTableOut;
m_lpColorTableOut=NULL;
}
}
GrayTrans::GrayTrans(CSize size,int nBitCount,LPRGBQUAD lpColorTable,unsigned char *pImgData):
ImgCenterDib(size,nBitCount,lpColorTable,pImgData)
{
m_pImgDataOut=NULL;
m_lpColorTableOut=NULL;
m_nColorTableLengthOut=0;
m_nBitCountOut=0;
m_imgWidthOut=0;
m_imgHeightOut=0;
}
void GrayTrans::ColorToGray()
{
if(m_nBitCount==8)
return;
if (m_pImgDataOut!=NULL)
{
delete[] m_pImgDataOut;
m_pImgDataOut=NULL;
}
if (m_lpColorTableOut!=NULL)
{
delete[] m_lpColorTableOut;
m_lpColorTableOut=NULL;
}
m_nBitCountOut=8;
m_nColorTableLengthOut=ComputerColorTableLength(m_nBitCountOut);
int i,j;
if(m_nColorTableLengthOut!=0)
{
m_lpColorTableOut=new RGBQUAD[m_nColorTableLengthOut];
for (i=0;i<m_nColorTableLengthOut;i++)
{
m_lpColorTableOut[i].rgbBlue=i;
m_lpColorTableOut[i].rgbGreen=i;
m_lpColorTableOut[i].rgbRed=i;
m_lpColorTableOut[i].rgbReserved=0;
}
}
int lineByteIn=(m_imgWidth*3+3)/4*4;
m_imgWidthOut=m_imgWidth;
m_imgHeightOut=m_imgHeight;
int lineByteOut=(m_imgWidth*m_nBitCountOut/8+3)/4*4;
m_pImgDataOut=new unsigned char[lineByteOut*m_imgHeight];
for (i=0;i<m_imgHeight;i++)
{
for(j=0;j<m_imgWidth;j++)
{
*(m_pImgDataOut+i*lineByteOut+j)=
0.11**(m_pImgData+i*lineByteIn+j*3+0)
+0.59**(m_pImgData+i*lineByteIn+j*3+1)
+0.30**(m_pImgData+i*lineByteIn+j*3+2)+0.5;
}
}
}
CSize GrayTrans::GetDimensions()
{
if(m_pImgDataOut==NULL)
return CSize(0,0);
return CSize(m_imgWidthOut,m_imgHeightOut);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -