作业帮 > 综合 > 作业

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

来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/04/29 13:08:14
数字图像处理
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;
}