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

关键词: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/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值