19,468
社区成员
发帖
与我相关
我的任务
分享
void Csmoothorsharp::FilterImg(int* temp){
int nW=img.GetWidth()-1;
int nH=img.GetHeight()-1;
byte *pRealData;
pRealData=(byte*)img.GetBits();
int pit=img.GetPitch();
int bitCount=img.GetBPP()/8;
for (int i=1;i<nH;i++)
{
for (int j=1;j<nW;j++)
{
int Rval=0,Gval=0,Bval=0,indx=0;
for ( int row=-1;row<=1;row++)
{
for (int col=-1;col<=1;col++)
{
int xxx=(int)(int)(*(pRealData));//在这个地方会发生访问0xxx地址的错误,可能是指针越界,但是pRealData是有值的。求解!!!
Bval+=((int)(int)(*(pRealData+pit*(i+row)+(j+col)*bitCount))) *temp[indx];
Gval=((int)(int)(*(pRealData+pit*(i+row)+(j+col)*bitCount+1)))*temp[indx];
Rval=((int)(int)(*(pRealData+pit*(i+row)+(j+col)*bitCount+2)))*temp[indx];
indx++;
}
}
//template work is over,You need get the center point pixel.
Rval=(int)(Rval*cval);
if (Rval>255)
Rval=255;
else if(Rval<0)
Rval=0;
Gval=(int)(Gval*cval);
if (Gval>255)
Gval=255;
else if(Gval<0)
Gval=0;
Bval=(int)(Bval*cval);
if (Bval>255)
Bval=255;
else if (Bval<0)
Bval=0;
//ok,write the new pixel into the pic.
*(pRealData+pit*(i-1)+(j-1)*bitCount)=Bval;
*(pRealData+pit*(i-1)+(j-1)*bitCount+1)=Gval;
*(pRealData+pit*(i-1)+(j-1)*bitCount+2)=Rval;
}
}