系統(tǒng)運維
代碼如下:
agg::path_storage path;
for (int i = 100; i < 500; i=i 100)
{
path.move_to(i, 100);
path.line_to(i, 400);
}
for (int ii = 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_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255,0,0));
分析:不知道你有沒有發(fā)現(xiàn)浮點坐標(biāo)渲染的線段似乎更加細,然后似乎深些??梢岳^續(xù)替換
輪廓線寬為0.5,效果一樣。當(dāng)然完全局限于當(dāng)前的顯示屏的分辨率,這就是為什么需要專業(yè)
的電腦處理圖像的原因。如果線寬設(shè)置為1.5,目前暫時沒有發(fā)現(xiàn)什么不同。
從郵件中分析得出,為什么浮點型0.5渲染的線會顏色深些,這是由于像素實際上是在100和101之間,在這里我對于像素不做過多的定義,假設(shè)像素有50%%u5728100點上,50%%u5728101上,這個時候如果移動到100.5如果線寬剛好是1,實際上就是一個完整的像素點,一個完整的矩形,但是如果少了0.5實際上就是橫跨兩個像素點,這個情況下,實際上就引入了亞像素精度,將像素也就是坐標(biāo)格子進行了劃分,對于坐標(biāo)格子實際上采用了透明色的處理,之所以沒有鋸齒,不是因為不存在,而是因為被透明處理了,設(shè)置了一定的透明度,使得我們并沒有注意到,如果在高分辨率的顯示器,還是可以看出來的。
郵件中提及到了,如果渲染橫線或者豎線,實際上可以采用低級的渲染器,其中包括render_base,這種情況下,避免了引入亞像素精度,提高了性能,這種情況,在其他的章節(jié)會提及。
如下摘錄,相關(guān)的討論:
> is the use of copy/blend hline/vline advised for efficiency or for
> better rendering?
only for the sake of performance. and if you need subpixel positioning, you can
draw two adjacent horizontal/vertical lines calculating the intensity according
to the position (i.e, simulating the rasterizer for this simple case) – it will
be more efficient because of excluding some expensive operations.
maxim> actually, if you need to draw horizontal and vertical lines
maxim> of exactly 1 pixel width, always aligned to pixels (say,
maxim> coordinate grid), and if you are absolutely sure you won\\\’t
maxim> need to transform them using agg converters, it\\\’s better to
maxim> use low level renderer_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_vspan(). the latest require an array of
maxim> covers, that can be 0 for gaps and 255 for
maxim> dashes. intermediate values will be drawn with respective
maxim> opacity.
actually, i don\\\’t know that they will be exactly 1 pixel wide (but i
am drawing a coordinate grid so would like to align them to pixels).
i missed that the pixels were aligned to the 0.5 point rather than the
integer point.
is the use of copy/blend hline/vline advised for efficiency or for
better rendering?
> that\\\’s just what i needed to know.
actually, if you need to draw horizontal and vertical lines of exactly 1 pixel
width, always aligned to pixels (say, coordinate grid), and if you are
absolutely sure you won\\\’t need to transform them using agg converters, it\\\’s
better to use low level renderer_base::copy_hline(), copy_vline(),
blend_hline(), blend_vline(), or, if you need to draw dashed/dotted lines,
blend_solid_hspan(), blend_solid_vspan(). the latest require an array of
covers, that can be 0 for gaps and 255 for dashes. intermediate values will
be drawn with respective opacity.
pierre> here you put the line centered exactly on the center of
pierre> the pixels sitting between x=200 and x=201. when painting
pierre> with 1.0 width, you will fill exactly one pixel (at
pierre> x=200).
pierre> so the matter here is not about agg handling ints and
pierre> floats in different ways, just that agg accepts sub-pixel
pierre> positioning, and its anti-aliasing machinery handles it
pierre> quite well.
探討:嘗試修改浮點坐標(biāo)為整型, 0.5替換為1,發(fā)現(xiàn)兩根線完全沒有什么分別
摘自:http://sourceforge.net/p/vector-agg/mailman/vector-agg-general/?viewmonth=200403
i am drawing some horizontal and vertical paths and notice that the
rasterized line width depends on whether i use an integer or float as
the x coordinate below. i know i can fix this by always passing and
integer