Bresenham直线算法/Wu反走样实例

void NcLine ( int x0, int y0, 
int x1, int y1, uint p32BitVram, int pitch, uint color ) {

p32BitVram += (x0 << 2) + y0 * pitch;

int absX = x1 - x0,
absY = y1 - y0,

absXTemp = absX >> 31,
absYTemp = absY >> 31;

int vx_dir = ((absXTemp - ~absXTemp) << 2);
pitch = (pitch ^ absYTemp) - absYTemp,

absX = (absX ^ absXTemp) - absXTemp,
absY = (absY ^ absYTemp) - absYTemp;

int rtqX = absX << 1,
rtqY = absY << 1;

int error,
incEx, rtqL_Ex;

if (absX > absY) { /* near X */

error = rtqY - absX;
incEx = vx_dir + pitch;

rtqL_Ex = error - absX;
while (--absX) {
*cast (uint*) p32BitVram = color;
if (error < 0) {
p32BitVram += vx_dir;
error += rtqY;
} else {
p32BitVram += incEx;
error += rtqL_Ex;
}
} *cast (uint*) p32BitVram = color;
return;
}
error = rtqX - absY;
incEx = vx_dir + pitch;

rtqL_Ex = error - absY;
while (--absY) {
*cast (uint*) p32BitVram = color;
if (error < 0) {
p32BitVram += pitch;
error += rtqX;
} else {
p32BitVram += incEx;
error += rtqL_Ex;
}
} *cast (uint*) p32BitVram = color;
}

void WuLine ( uint * p32bitVram, uint VramPitch, int xPosStart, int yPosStart, int xPosEnd, int yPosEnd, uint clrLine ){ 

int XDir,
DeltaX,
DeltaY;

uint grayl, grayb,
ErrorAdj, ErrorAcc,
Weighting, ErrorAccTemp;

uint* LastEndWriteAddr = p32bitVram;

ubyte Mix[4];
ubyte Line[4];
ubyte Bg[4];

double WeightingShrink;

VramPitch >>= 2;

if (yPosStart > yPosEnd) {
int Temp = yPosEnd; yPosEnd = yPosStart; yPosStart = Temp;
Temp = xPosStart; xPosStart = xPosEnd; xPosEnd = Temp;
} *( p32bitVram += xPosStart + yPosStart * VramPitch ) = clrLine;

if ( ( DeltaX = xPosEnd - xPosStart ) >= 0 )
XDir = 1;
else
XDir = -1, DeltaX = -DeltaX;

if ( ( DeltaY = yPosEnd - yPosStart ) == 0 ) { /* Horizontal line */
if ( XDir > 0 ) {
while (--DeltaX != 0)
*(++p32bitVram) = clrLine;
*(++p32bitVram) = clrLine;
} else {
while (--DeltaX != 0)
*(--p32bitVram) = clrLine;
*(--p32bitVram) = clrLine;
} return;
} else if ( DeltaX == 0 ) { /* Vertical line */
do {
*(p32bitVram += VramPitch) = clrLine;
} while (--DeltaY != 0); return;
} else if ( DeltaX == DeltaY ) { /* Diagonal line */
if ( XDir > 0 ) {
do {
*(++p32bitVram += VramPitch) = clrLine;
} while (--DeltaY != 0);
} else /* Diagonal line Dec */ {
do {
*(--p32bitVram += VramPitch) = clrLine;
} while (--DeltaY != 0);
} return;
}

*cast (uint*) Line = clrLine, ErrorAcc = 0;

grayl = ( ( cast(uint) Line[2] << 2 ) + cast(uint) Line[1] * 5 + cast(uint) Line[0]);

if (DeltaY > DeltaX) {
Error
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值