提供展示代码:

agg::rendering_buffer &rbuf = rbuf_window();
      agg::pixfmt_bgr24 pixf(rbuf);

typedef agg::renderer_base<agg::pixfmt_bgr24> renderer_base_type;
      renderer_base_type renb(pixf);

typedef agg::renderer_scanline_aa_solid<renderer_base_type> renderder_scanline_type;
      renderder_scanline_type rensl(renb);

agg::rasterizer_scanline_aa<> ras;
      agg::scanline_u8 sl;
      ras.reset();

double x[4];
      double y[4];
      double h =100.33;

x[0] = 10;  y[0] = 10;
      x[1] = 100; y[1] = 10;
      x[2] = 100; y[2] = y[0]+h;
      x[3] = 10;  y[3] = y[0]+h;

agg::path_storage ps;
      ps.move_to(x[0],y[0]);
      ps.line_to(x[1],y[1]);
      ps.line_to(x[2],y[2]);
      ps.line_to(x[3],y[3]);
      ps.close_polygon();
      ras.add_path(ps);
      agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255, 0, 0));
      ps.remove_all();
      ras.reset();
      ps.move_to(x[0]+10,y[0]+h);
      ps.line_to(x[1]+10,y[1]+h);
      ps.line_to(x[2]+10,y[2]+h);
      ps.line_to(x[3]+10,y[3]+h);
      ps.close_polygon();
      ras.add_path(ps);

agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255, 0, 0));

非常明显的看出两个矩形相邻的边界上出现一条浅浅的白边。

邮件质疑:

As you can see there is a brighter line between the two rectangles. I

know where it is from - this is a result of alpha blending of two

partially covered scanlines. And this is a problem form me.

Do you have any idea how to get rid of this line? I mean how to make

it in the same color as the rectangles. My application draws metafiles

and sometimes there are such shapes in them and I get ugly banded

drawings... Do you have any ideas?

如下是作者的解释:

it's a well known problem that can't be eliminated easily. It exists in

all SVG engies and appears as thin "web" upon the p_w_picpath, when you draw adjacent

shapes:http://www.antigrain.com/svg/index.htmlSay, initially you have color (0,0,0). Then you draw a white pixel on it with

0.5 opacity (which is equivalent 0.5 of pixel coverage). You will have

(0.5,0.5,0.5) which is correct. Then you draw another pixel upon it, also with

opacity=0.5. According to the color blending rules you will have

(0.75,0.75,0.75), not (1,1,1). This is what happens when you draw your

rectrangles.

The problem can't be easily solved. In the SVG example I use conv_contour to

dilate all polygons. But this solution isn't perfect and kinda unfair.

But you can't render a multicolor scene in such a way. It's possible only in

Macromedia Flash, but it requires not only another rasterization algorithm, but

also changing the whole data model. Your data shall be represented not as a set

of polygons, but as a set of edges with attributes - color on the left and

color on the right.

> Say, initially you have color (0,0,0). Then you draw a white pixel on it with

> 0.5 opacity (which is equivalent 0.5 of pixel coverage). You will have

> (0.5,0.5,0.5) which is correct. Then you draw another pixel upon it, also with

> opacity=0.5. According to the color blending rules you will have

> (0.75,0.75,0.75), not (1,1,1). This is what happens when you draw your

> rectrangles.

This is the color from the original post:

> >         ren_aa.color(agg::rgba(0.4, 0.3, 0.2, 1.0));

The opacity of the color is 1.0, not 0.5. So what Maxim tried to say is I

guess something like this: "Then you draw a white pixel on it with 0.5

pixel coverage (which is equivalent to 0.5 opacity)."

Now, forgive me for my ignorance if this is trivial, I really haven't had

to think about this particular problem, but here's an idea: suppose you

are doing a flash-like multicolor fill where you know that no polygon

overlaps another (triangulation, tesselation, whatever). Can the blending

rule in AGG be changed so that the alpha channel is not interpreted as a

genuine alpha, but as a coverage percentage instead? So that for example

in this particular case 0.5+0.5 would be 1.0? This wouldn't work if you

also want alpha, but the presumption here is that you really don't need it.

> Now, forgive me for my ignorance if this is trivial, I really haven't had

> to think about this particular problem, but here's an idea: suppose you

> are doing a flash-like multicolor fill where you know that no polygon

> overlaps another (triangulation, tesselation, whatever). Can the blending

> rule in AGG be changed so that the alpha channel is not interpreted as a

> genuine alpha, but as a coverage percentage instead? So that for example

> in this particular case 0.5+0.5 would be 1.0? This wouldn't work if you

> also want alpha, but the presumption here is that you really don't need it.

Actually, that's an idea, I'm not sure it's doable, but it's seems to be. One

pixel can be overlapped by many polygons even if the polygons themselves do not

overlap.

http://antigrain.com/stuff/multipoly_cover.gif - the central pixel is covered

by 6 triangles. It means that there are 6 different cover values and 6 colors.

And the resulting color must be calculated as the weigted average, where weight

is coverage. But we should keep a whole list of coverage values for each pixel!

Another solution is to use the alpha channel for coverage values. Suppose we

have not RGBA, but RGBC color space. Initially all cover values are 0. At a

time we always operate with 2 colors and two coverage values. We accumulate the

coverage values (with clipping at 1.0) and calculate the resulting color as the

weighted average of 2 colors/covers. It looks very familiar, and remainds me

the formulae for alpha blending in plain (non-premultiplied) color space.

> And the resulting color must be calculated as the weigted average, where weight

> is coverage. But we should keep a whole list of coverage values for each pixel!

Assume for example that you have calculated values

nom = (w1*a1+w2*a2+w3*a3)/(w1+w2+w3)   (the weighted mean so far)

den = w1+w2+w3                         (the sum of weights so far)

Then you can calculate new values

nom = (nom*den + w4*a4)/(den+w4)

den += w4

Expanding those formulas you will get the correct results. That is, you do

not need to keep a record of all the colors in order to calculate an

update to the weighted mean, the mean so far plus the weight (kept in

alpha) is sufficient.

摘自:http://sourceforge.net/p/vector-agg/mailman/vector-agg-general/?viewmonth=200504

转载于:https://blog.51cto.com/fengyuzaitu/1972915

AGG第四十四课 渲染问题:绘制较宽轮廓和尖锐边缘相关推荐

  1. NeHe OpenGL第四十六课:全屏反走样

    NeHe OpenGL第四十六课:全屏反走样 全屏反走样 当今显卡的强大功能,你几乎什么都不用做,只需要在创建窗口的时候该一个数据.看看吧,驱动程序为你做完了一切.   在图形的绘制中,直线的走样是非 ...

  2. NeHe OpenGL教程 第四十五课:顶点缓存

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  3. NeHe OpenGL教程 第四十四课:3D光晕

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  4. NeHe OpenGL第四十四课:3D光晕

    NeHe OpenGL第四十四课:3D光晕 3D 光晕 当镜头对准太阳的时候就会出现这种效果,模拟它非常的简单,一点数学和纹理贴图就够了.好好看看吧.   大家好,欢迎来到新的一课,在这一课中我们将扩 ...

  5. 风炫安全Web安全学习第四十节课 反序列化漏洞攻击利用演示

    风炫安全Web安全学习第四十节课 反序列化漏洞攻击利用演示 0x02 反序列化漏洞利用 反序列化漏洞的成因在于代码中的 unserialize() 接收的参数可控,从上面的例子看,这个函数的参数是一个 ...

  6. 风炫安全WEB安全学习第四十四节课 敏感信息泄漏

    第四十四节课 敏感信息泄漏 敏感信息泄漏 0x01 漏洞简介 敏感数据包括但不限于:口令.密钥.证书.会话标识.License.隐私数据(如短消息的内容).授权凭据.个人数据(如姓名.住址.电话等)等 ...

  7. 风炫安全Web安全学习第四十三节课 路径遍历漏洞

    风炫安全Web安全学习第四十三节课 路径遍历漏洞 路径遍历 0x01 漏洞概述 路径遍历攻击(也称作目录遍历)的目标是访问web根目录外存储的文件和目录.通过操纵使用"点-斜线(-/)&qu ...

  8. NeHe OpenGL教程 第四十八课:轨迹球

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  9. 四十四、深入Java 的序列化和反序列化

    @Author:Runsen @Date:2020/6/8 作者介绍:Runsen目前大三下学期,专业化学工程与工艺,大学沉迷日语,Python, Java和一系列数据分析软件.导致翘课严重,专业排名 ...

最新文章

  1. Charles(HTTP抓包工具软件)中文版
  2. .NET内存性能分析指南
  3. 前端学习(3239):react生命周期setstate流程
  4. css 网页整体缩小_css实现缩放自适应网页--手机web
  5. [译]Profile and debug your ASP.NET MVC app with Glimpse
  6. Cesium 环境配置笔记(使用node.js 或者WampServer服务器)
  7. python实现对解析之后的DOM进行层次化处理升序输出
  8. macbook proc 如何设置touch bar 为F键
  9. 软考程序员-C专题(1)
  10. 塞班S60v3版平台手机证书权限内容大解析
  11. python哪些模板引擎比较_3 个 Python 模板库比较
  12. Python:同花顺全数据接口
  13. 手持PDA功能及优势
  14. 135、易燃液体的火灾危险性
  15. 我与博友们分享我的工作经验
  16. windows关闭445、3389端口
  17. 朱清时院士:不可思议的量子意识
  18. 搜索引擎(三)-- PageRank和HITS算法
  19. python获取网站代码_python爬虫1——获取网站源代码(豆瓣图书top250信息)
  20. UE4-地形材质函数创建及使用

热门文章

  1. glxinfo: not found
  2. python接口自动化(一)--什么是接口、接口优势、类型(详解)
  3. Java 笔记——在 IDEA 中使用 Maven 配置和使用 MyBatis
  4. 数据结构期末复习(に)--链式栈定义及使用
  5. varchar类型字段排序混乱问题
  6. 20155207实验2 Windows口令破解
  7. MVC初学 - The type or namespace name 'DbContext' could not be found
  8. 什么是大数据「实时流计算」?深度解析它的4大应用及4个特点
  9. 分析89万招聘数据后发现:华为平均月薪35K,Java需求下降
  10. 数据可视化及数据保存