抗鋸齒線條 實現

2021-04-01 04:56:55 字數 3134 閱讀 2376

draw an anti-aliased line?

uses

graphics, windows;

type

trgbtriplearray = array[0..1000] of trgbtriple;

prgbtriplearray = ^trgbtriplearray;

// anti-aliased line

procedure wuline(abitmap : tbitmap ; point1, point2 : tpoint ; acolor : tcolor);

vardeltax, deltay, loop, start, finish : integer;

dx, dy, dydx : single; // fractional parts

lr, lg, lb : byte;

x1, x2, y1, y2 : integer;

begin

x1 := point1.x; y1 := point1.y;

x2 := point2.x; y2 := point2.y;

deltax := abs(x2 - x1); // calculate deltax and deltay for initialisation

deltay := abs(y2 - y1);

if (deltax = 0) or (deltay = 0) then begin // straight lines

abitmap.canvas.pen.color := acolor;

abitmap.canvas.moveto(x1, y1);

abitmap.canvas.li***o(x2, y2);

exit;

end;

lr := (acolor and $000000ff);

lg := (acolor and $0000ff00) shr 8;

lb := (acolor and $00ff0000) shr 16;

if deltax > deltay then

begin // horizontal or vertical

if y2 > y1 then // determine rise and run

dydx := -(deltay / deltax)

else

dydx := deltay / deltax;

if x2 < x1 then

begin

start := x2; // right to left

finish := x1;

dy := y2;

end else

begin

start := x1; // left to right

finish := x2;

dy := y1;

dydx := -dydx; // inverse slope

end;

for loop := start to finish do

begin

alphablendpixel(abitmap, loop, trunc(dy), lr, lg, lb, 1 - frac(dy));

alphablendpixel(abitmap, loop, trunc(dy) + 1, lr, lg, lb, frac(dy));

dy := dy + dydx; // next point

end;

end else

begin

if x2 > x1 then // determine rise and run

dydx := -(deltax / deltay)

else

dydx := deltax / deltay;

if y2 < y1 then

begin

start := y2; // right to left

finish := y1;

dx := x2;

end else

begin

start := y1; // left to right

finish := y2;

dx := x1;

dydx := -dydx; // inverse slope

end;

for loop := start to finish do

begin

alphablendpixel(abitmap, trunc(dx), loop, lr, lg, lb, 1 - frac(dx));

alphablendpixel(abitmap, trunc(dx) + 1, loop, lr, lg, lb, frac(dx));

dx := dx + dydx; // next point

end;

end;

end;

// blend a pixel with the current colour

procedure alphablendpixel(abitmap : tbitmap ; x, y : integer ; r, g, b : byte ; aratio : real);

varlback, lnew : trgbtriple;

lminusratio : real;

lscan : prgbtriplearray;

begin

if (x < 0) or (x > abitmap.width - 1) or (y < 0) or (y > abitmap.height - 1) then

exit; // clipping

lscan := abitmap.scanline[y];

lminusratio := 1 - aratio;

lback := lscan[x];

lnew.rgbtblue := round(b*aratio + lback.rgbtblue*lminusratio);

lnew.rgbtgreen := round(g*aratio + lback.rgbtgreen*lminusratio);

lnew.rgbtred := round(r*aratio + lback.rgbtred*lminusratio);

lscan[x] := lnew;

end;

抗鋸齒渲染

乙個圖形的大小總與其數學模型相對應.又稱為反鋸齒或者反走樣,就是對影象的邊緣進行平滑處理,使其看起來更加柔和流暢的一種技術.qpainter進行繪製時可以使用qpainter renderhint渲染提示來指定是否要使用抗鋸齒功能,渲染提示的取值如下.qpainter的渲染提示常量 描述qpaint...

openGL中的抗鋸齒實現

圖形繪製到螢幕時,光柵化影象通過離散的畫素點來表示,因此所繪製的圖元 比如直線 會產生鋸齒,這種鋸齒也稱作走樣。消除鋸齒的技術稱為反走樣,也叫做抗鋸齒,通過這種處理可在一定程度上消除鋸齒的影響,增強顯示效果。在opengl中,可通過函式glhint 來對影象質量和繪製速度之間的權衡作一些控制,其函式...

抗鋸齒 西村將由畫素畫教科書 AA手工抗鋸齒

摘要 西村將由畫素畫教科書 aa手工抗鋸齒 西村將由畫素畫教科書,這套系列教程是偏新手向的基礎課程,適合0基礎和新人入門。由於編寫的年代比較早,使用的軟體是windows畫圖。畫素畫是由畫素方塊組成,不可避免的會產生許多缺口。畫素畫家使用中間顏色來過渡,就可以在視覺上產生抗鋸齒效果。下圖左邊版本沒有...