您的位置:首页 > 其它

嵌入式系统中圆角矩形填充的一种实现思路

2012-01-24 11:31 399 查看
关键词:anti-aliasing 反锯齿| 抗锯齿| 反走样| 抗锯齿处理

相关开源项目: freetype,libart

1 概述

本文介绍了一种绘制带圆角的矩形区域的思路,即在内存上或者一个图片上画一个带圆角的矩形区域,可以应用在嵌入式系统中自己实现按钮或者OSD菜单等。

2 关键问题

画圆弧的关键是实现抗锯齿,即使圆弧看的比较圆润些。

3 技术路线

1) FreeType库是一个完全免费(开源)的、高质量的且可移植的字体引擎,它提供统一的接口来访问多种字体格式文件,包括TrueType, OpenType, Type1, CID, CFF, Windows FON/FNT, X11 PCF等。支持单色位图、反走样位图的渲染。

既然FreeType提供了抗锯齿的渲染方法,应该可以使用类似方法实现抗锯齿。

2) 在freetype的源代码中提到:

/* This is a new anti-aliasing scan-converter for FreeType 2. The */

/* algorithm used here is _very_ different from the one in the standard */

/* `ftraster' module. Actually, `ftgrays' computes the _exact_ */

/* coverage of the outline on each pixel cell. */

/* */

/* It is based on ideas that I initially found in Raph Levien's */

/* excellent LibArt graphics library (see http://www.levien.com/libart */

/* for more information, though the web pages do not tell anything */

/* about the renderer; you'll have to dive into the source code to */

/* understand how it works).

说明,用Libart也可以实现抗锯齿。

3) 看一下libart的介绍:

Libart is a library for high-performance 2D graphics. It is currently being used as the antialiased rendering engine for theGnome Canvas. It is also the rendering engine forGill,
the Gnome Illustration app.

没错,用libart就行了。

4 具体实现思路

1)参考libart库函数art_vpath_new_circle()实现,形成ArtVpath

2)调用art_svp_from_vpath()函数将vpath转化为svp。

3)保存svp,当需要显示时候调用art_rgb_svp_alpha(svp)进行显示

4)当不需要显示时候,释放内存占用:art_free(svp)

效果如下:





5 后记

抗锯齿的具体实现可以参考libart的代码,是否有优化的方法? 另外,圆弧的产生也可以使用快速算法。如果你有更好的方法请联系我,谢谢。

版权所有,转载请注明出处

http://www.agilevideo.net/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: