数字图像处理Floyd-Steinberg算法!

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/22 01:55:55
数字图像处理Floyd-Steinberg算法!数字图像处理Floyd-Steinberg算法!数字图像处理Floyd-Steinberg算法!BOOLDitherFloydSteinberg(CDi

数字图像处理Floyd-Steinberg算法!
数字图像处理
Floyd-Steinberg算法!

数字图像处理Floyd-Steinberg算法!
BOOL DitherFloydSteinberg(CDibImage *dibimg,LPSTR lpDIB)
{
BYTE * lpSrc;
LONG lWidth;
LONG lHeight;
LONG lLineBytes;
CSize SizeDim;
SizeDim = pDib->GetDimensions();
lWidth = SizeDim.cx;
CSize SizeRealDim;
SizeRealDim = pDib->GetDibSaveDim();
lWidth =dibimg->DIBWidth(lpDIB);
lHeight =dibimg->DIBHeight(lpDIB);
lLineBytes = WIDTHBYTES(lWidth*8);
LPSTR lpDIBBits = dibimg->FindDIBBits(lpDIB);
int i, j;
double temp, error;
int nPixelValue;
for (j = 0; j < lHeight; j++)
{
for(i = 0; i < lLineBytes; i++)
{
lpSrc = (unsigned char *)lpDIBBits + lLineBytes * j + i;

nPixelValue = *lpSrc;
if ( nPixelValue > 128 )
{
*lpSrc=255;
error = (double)(nPixelValue-255.0);
}

else
{
*lpSrc=0;
error = (double)nPixelValue;
}
if(i < lLineBytes-1)
{
temp = (float)*(lpSrc+1);
temp = temp + error * (1.5/8.0);
if(temp > 255.0)
temp = 255.0;
*(lpSrc+1)=(int)temp;

}
if(j < lHeight - 1)
{
temp = (float)*(lpSrc + lLineBytes);

temp = temp + error * (1.5/8.0);

*(lpSrc+lLineBytes) = (int)temp;

if(i < lLineBytes-1)
{
temp = (float)*(lpSrc + lLineBytes + 1);

temp = temp + error * (2.0/16.0);

*(lpSrc + lLineBytes + 1) = (int)temp;
}
}

}

}

return true;
}