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

来源:学生作业帮助网 编辑:作业帮 时间:2024/10/05 20:07:08
数字图像处理Floyd-Steinberg算法!
xUMo@+|ITHMJF=xEƶ"Nzm/QڪRU ɱ޵>͌D'4~n}z n\݊1͞~?{qp>Q  F!I@{mH-"EzDz?02=n҆$!{c@˼SA|j!S?@ 2"7c XCap/54-N݀tB  G $Æ^uhM7 57*-Ab)MTy PaBنJdw>By$Zӑ'MWDϨS)ӓ)*[oH2R6p9;VTj G$&P5ZAM&pه' bUSJ_qCz+d~Cfҙrs.Er4Z53S. *rǖ;CouCeۻVEJ-?

数字图像处理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;
}