陈奇网络工作室

AGG第47课渲染抗锯齿线宽度问题探讨

系统运输

代码如下所示。

agg:path_storage path;

for(intI=100; i 500; i=i 100 )

{

path.move_to(I,100 );

path.line_to(I,400 );

}

for(intii=120; ii 550; ii=ii 100 )

{

path.move _ to ( ii 0.5,100;

path.line _ to ( ii 0.5,400;

}

agg: conv _ stroke agg: path _ storage stroke ( path;

stroke.width(1.0;

ras.add_path(stroke );

agg: render _ scan lines _ aa _ solid ( ras,sl,renb,AgG:RGBA8 ) 255,0,0 ) );

分析:不知道用浮点坐标渲染的线段看起来更细,而且更深。 您可以继续替换

轮廓线的宽度为0.5,效果相同。 当然,完全受限于目前显示器的分辨率,所以需要专家

的计算机处理图像的理由。 如果线宽设定为1.5的话,目前看不出任何不同。

从邮件分析,以浮点型0.5渲染的线条颜色变深的原因是像素实际上在100到101之间。 这里不怎么定义像素。 假设像素为50%%u5728100点,50%%u5728101点。 此时,如果移动到100.5且线宽正好为1,则实际上是完整的像素点,但是如果减少0.5,则实际上跨越了两个像素点。 在这种情况下,实际上引入了子像素精度,划分了像素或坐标网格。 对坐标网格实际上采用了透明色的处理。 之所以没有锯齿,并不是因为它不存在,而是因为它经过了透明处理,并设置了一定的透明度,因此在高分辨率的显示器上是不可见的。

正如邮件中提到的,渲染水平线或垂直线实际上可以采用包含render_base的低级渲染器。 在这种情况下,可以避免引入子像素精度,从而提高性能。 其他章节将提到这一点。

以下摘录,相关讨论:

istheuseofcopy/blend hline/vlineadvisedforefficiencyorfor

better rendering?

onlyforthesakeofperformance.andifyouneedsubpixelpositioning,you can

drawtwoadjacenthorizontal/verticallinescalculatingtheintensityaccording

totheposition(I.e,simulatingtherasterizerforthissimplecase )- it will

bemoreefficientbecauseofexcludingsomeexpensiveoperations。

Maxim Actually,ifyouneedtodrawhorizontalandverticallines

Maxim of exactly 1 pixel width,Alwaysalignedtopixels ( )

Maxim coordinate grid (,andifyouareabsolutelysureyouwon\\ & amp; quot; t

maximneedtotransformthemusingaggconverters,it\\\& #039; s better to

maximuselowlevelrenderer _ base: copy _ hline (,copy_vline )、

Maxim blend_hline (,blend_vline ),or,if you need to draw

Maxim dashed/dotted lines,blend_solid_hspan (

maxim blend _ solid _ v span (.thelatestrequireanarrayof

Maxim covers,that can be 0 for gaps and 255 for

maxim dashes.intermediatevalueswillbedrawnwithrespective

最大补偿。

Actually,id on \’tknowthattheywillbeexactly1pixel wide ( buti

amdrawingacoordinategridsowouldliketoalignthemtopixels )。

imissedthatthepixelswerealignedtothe 0.5 pointratherthanthe

智能点。

istheuseofcopy/blend hline/vlineadvisedforefficiencyorfor

better rendering?

That\\\& #039; s just what I needed to know .

Actually,ifyouneedtodrawhorizontalandverticallinesofexactly1pixel

width,alwaysalignedtopixels(Say,coordinate grid ),and if you are

absolutelysureyouwon\\ ' tneedtotransformthemusingaggconverters,it\\\& #039; s

bettertouselowlevelrenderer _ base: copy _ hline (,copy_vline )、

blend_hline (,blend_vline )、or、ifyouneedtodrawdashed/dotted lines、

blend_solid_hspan (,blend_solid_vspan ).The latest require an array of

covers,that can be0forgapsand 255 for dashes.intermediatevalueswill

be drawn with respective opacity。

pierrehereyouputthelinecenteredexactlyonthecenterof

pierrethepixelssittingbetweenx=200 andx=201.when painting

Pierre with 1.0 width,youwillfillexactlyonepixel (

Pierre x=200 )。

pierresothematterhereisnotaboutagghandlingintsand

Pierre floats in different ways,just that AGG accepts sub-pixel

Pierre positioning,and its anti-aliasingmachineryhandlesit

Pierre quite well。

讨论:尝试将浮点坐标修改为整数,并将0.5替换为1,发现两条线完全没有区别

摘录: http://source forge.net/p/vector-agg/mailman/vector-agg-general/view month=200403

iamdrawingsomehorizontalandverticalpathsandnoticethatthe

rasterizedlinewidthdependsonwhetheriuseanintegerorfloatas

thexcoordinatebelow.iknowicanfixthisbyalwayspassingand

integer ( butthiscausesothercomplications )、but am wondering if

this is the desired behavior,and if there is some bit of agg magic

thatwilldisplaythelineswiththesamethicknessevenifthex

coords are sometimes integers,sometimes floats。

thecriticalbitishere ( completeexamplebelow )。

agg:path_storage path;

Rb.clear(AgG:rgba(1.0、1.0、1.0 ) );

path.move _ to ( 100,100 );

path.line _ to ( 100,400 );

path.move _ to ( 200.5,100 );

path.line _ to ( 200.5,400 );

agg: conv _ stroke agg: path _ storage stroke ( path;

stroke.width(1.0;

ras.add_path(stroke );

And here is a complete example。

Thanks!

约翰亨特

#include fstream

#include agg_path_storage.h

#include agg_pixfmt_rgb24.h

#include agg_pixfmt_rgba32.h

# include agg _ rasterizer _ scanline _ aa.h

# include agg _ renderer _ scanline.h

#include agg_rendering_buffer.h

#include agg_scanline_bin.h

#include agg_scanline_p32.h

#include agg_conv_stroke.h

typedef agg: pixel _ formats _ rgba 32 agg: order _ rgba 32 pix fmt;

typedef agg: renderer _ basepixfmtrenderer _ base;

typedef agg: rasterizer _ scanline _ aa rasterizer;

//未校准

//typedef agg: renderer _ scanline _ p _ solid renderer _ base renderer;

//typedef agg: scanline _ P8 scanline;

//aliased

typedef agg: scanline _ bin scanline;

typedef agg: renderer _ scanline _ bin _ solid renderer _ base renderer;

intmain(intargc,char* argv[] ) ) ) )

unsignedwidth(512 )、height ( 512 );

无符号滑动( width * 4;

size_tnumbytes(width*height*4);

agg:int8u buffer[NUMBYTES];

agg:rendering_buffer rbuf;

rbuf.attach(buffer,width,height,stride );

//draw_anti_aliased

pixfmtpixf(rbuf );

renderer_baseRb(pixf;

rendererren(Rb;

raster ras;

扫描线;

agg:path_storage path;

Rb.clear(AgG:rgba(1.0、1.0、1.0 ) );

path.move _ to ( 100,100 );

path.line _ to ( 100,400 );

path.move _ to ( 200.5,100 );

path.line _ to ( 200.5,400 );

agg: conv _ stroke agg: path _ storage stroke ( path;

//stroke.line_cap(cap;

//stroke.line_join(join;

stroke.width(1.0;

ras.add_path(stroke );

ren.color ( agg: rgba ( 0.0,0.0,0.0,1.0 ) );

ras.render(sline,ren );

size_t i;

STD:ofstreamof2(line_aa.raw,std:ios:binary|std:ios:out );

for(I=0; iNUMBYTES; I )

of2.write ( ) char* ) buffer[i],sizeof(char );

}

摘录: http://permalink.gmane.org/gmane.com p.graphics.agg/1428

问题:

isitpossibletodrawnon-anti-aliaseddashedlinesusingabresenham-typealgorithminantigrain? For instance,I\\\& #039; d like to draw a 45o dotted line,where every other pixel is solid。

I\\\& #039; ve tried several approaches, includingusingagg: renderer _ outline _ p _ w _ picpathwithanp _ w _ picpaththatdefinesthedashes ( 3358 permalink.gg old(0.5 ) http://permalink.gmane.org/gmane.com p.graphic ical

2/iwouldliketorenderaliasedlines.aftersometests,I\\\& #039; m not able

torenderoddlinewidth.ifitrytorenderalinewithawidth=3,I

got a4 pixel line.whatdoineedtodoto?

讨论:

That\\\& #039; s not easy. In short words,thevisualwidthofthehorizontalorvertical

linesdependsnotonlyonthestrokewidthyouhaveset,but also on the

subpixelpositionofthatline.acommonwaytodraweverythingaliasedisto

set AA gamma :

ras.Gamma(AgG:Gamma_Threshold ) 0.5 );

hereyoucanusescanline _ binandrenderer _ scanline _ bin _ solidthatworkfaster。

But the problem still persists; iwroteaboutithere:http://anti grain.com/tips/line _ alignment/line _ alignment.ag doc.htmlnowimaginethathatyoudrawalioudrawalid

exceeds a certain threshold。

inotherwordsyoucaneasilydrawaliasedlinesofexactly1pixel width

( Bresenham-like algorithm ).everythingwiderleadstoproblems.but even

reguilarjaggedlinesof1pixelwidthhavedifferentvisualthickness

dependingonthetangent.aline of45 degreesteephasvisualthicknessof

1/sqrt(2)=0.7像素。

详情请访问云服务器、域名注册、虚拟主机的问题,请访问西部数码代理商官方网站: www.chenqinet.cn

相关推荐

后台-系统设置-扩展变量-手机广告位-内容页底部广告位3