资源简介
c实现的wu反走样算法,编译可运行,是一种很好的反走样反锯齿算法,Michael Abrash强烈推荐的算法
代码片段和文件信息
void DrawWuLine( CDC *pDC int X0 int Y0 int X1 int Y1 COLORREF clrLine )//clrline表示要画线的颜色
{ pDC->SetPixel( X0 Y0 clrLine );
int XDir DeltaX = X1 - X0;
if( DeltaX >= 0 ) {
XDir = 1; }
else {
XDir = -1;
DeltaX = 0 - DeltaX; /* make DeltaX positive */
}
XDir = 1;
unsigned short ErrorAdj;
unsigned short ErrorAccTemp Weighting;
/* Line is not horizontal diagonal or vertical */
unsigned short ErrorAcc = 0; /* initialize the line error accumulator to 0 */
BYTE rl = GetRValue( clrLine );
BYTE gl = GetGValue( clrLine );
BYTE bl = GetBValue( clrLine );
double grayl = rl * 0.299 + gl * 0.587 + bl * 0.114;
/* Is this an X-major or Y-major line? */
if (DeltaY > DeltaX)
{
/* Y-major line; calculate 16-bit fixed-point fractional part of a
pixel that X advances each time Y advances 1 pixel truncating the
result so that we won‘t overrun the endpoint along the X axis */
ErrorAdj = ((unsigned long) DeltaX < < 16) / (unsigned long) DeltaY;
/* Draw all pixels other than the first and last */
while (--DeltaY) {
ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */
ErrorAcc += ErrorAdj; /* calculate error for next pixel */
if (ErrorAcc <= ErrorAccTemp)
{
/* The error accumulator turned over so advance the X coord */
X0 += XDir;
}
Y0++; /* Y-major so always advance Y */
/* The IntensityBits most significant bits of ErrorAcc give us the
intensity weighting for this pixel and the complement of the
weighting for the paired pixel */
Weighting = ErrorAcc >> 8;
ASSERT( Weighting < 256 );
ASSERT( ( Weighting ^ 255 ) < 256 );
COLORREF clrBackGround = ::GetPixel( pDC->m_hDC X0 Y0 );
BYTE rb = GetRValue( clrBackGround );
BYTE gb = GetGValue( clrBackGround );
BYTE bb = GetBValue( clrBackGround );
double grayb = rb * 0.299 + gb * 0.587 + bb * 0.114;
BYTE rr = ( rb > rl ? ( ( BYTE )( ( ( double )( grayl BYTE gr = ( gb > gl ? ( ( BYTE )( ( ( double )( grayl BYTE br = ( bb > bl ? ( ( BYTE )( ( ( double )( grayl
- 上一篇:CentOS-7-x86_64镜像文件
- 下一篇:VC环境下的图形学消隐算法代码
评论
共有 条评论