BOOL ConvoluteDIB(HDIB hDib,KERNEL *lpKernel,int Strength,int nKernelNum)
{
WaitCursorBegin();
HDIB hNewDib=NULL;
WORD wBitCount=DIBBitCount(hDib);
if(wBitCount!=24)
hNewDib=ConvertDIBFormat(hDib,24,NULL);
else
hNewDib=CopyHandle(hDib);
if(! hNewDib)
{
WaitCursorEnd();
return FALSE;
}
WORD wDIBWidth=(WORD)DIBWidth(hNewDib);
WORD wDIBHeight=(WORD)DIBHeight(hNewDib);
WORD wBytesPerLine=(WORD)BytesPerLine(hNewDib);
DWORD dwImageSize=wBytesPerLine*wDIBHeight;
HGLOBAL hFilteredBits=GlobalAlloc(GHND,dwImageSize);
if(!hFilteredBits)
{
WaitCursorEnd();
return FALSE;
}
LPBYTE lpDestImage=(LPBYTE)GlobalLock(hFilteredBits);
LPBYTE lpDIB=(LPYTE)GlobalLock(hNewDib);
LPBYTE lpDIBits=FindDIBBits(lpDIB);
for (int i=1; i<wDIBHeight-1; i++)
for(int j=1;j<wDIBWidth-1;j++)
{
int red=0,green=0,blue=0;
for(int k=0;k<nKernelNum;++k)
{
int r=0,g=0,b=0;
DoConvoluteDIB(&r,&g,&b,I,j,wBytesPerLine,lpDIBits,lpKernel+k);
if(r>red)
red=r;
if(g>green)
green=g;
if(b>blue)
blue=b;
}
评论0