adjacent shapes抗锯齿情况下的alpha blending问题

问题描述:

Unfortunately I stumbled across the issue with adjacent shapes.
On a transparent background (in the plain color space) I draw mutiple 
polygons, some are connected others are not and each polygon has a 
different color. The polygons do never overlap. If two polygons are 
connected, instead of a smooth transition from the color of one polygon 
to the color of the other I get a contour. I know this is a well known 
issue and in my case it comes from a slightly drop of the alpha-channel 
on the transition from one polygon to the other.
I wanted to know if there are any good work arounds? In one example 
conv_contour was used but this is not possible for me I think. In an 
other post I read something about using a different blending rule (0.5 + 
0.5 = 1.0 instead of 0.5 + 0.5 = 0.75).

该问题主要是在渲染有覆盖区域的图像的时候,为了实现抗锯齿的功能,从而调用alpha blending会有一个颜色渲染的问题。如下是作者提供的解决方案:

es, there is a problem. The alpha blend operation works namely in this very 
way, that is 0.5 over 0.5 is 0.75. It looks like you have a glass and paint 
with a translucent color on it. In case of translucent ink you theoretically 
will never achieve full opacity. And anti-aliasing is implemented namely via 
alpha-blending (and I don't see any other reasonable way to do so).

But in certain cases it's quite possible to get rid of those adjacent edges 
artifacts. First, you need an RGBA buffer with premultiplied colors. 
Initially you clear it with rgba8(0,0,0,0) - and no other color. Then you 
use compositing operation "plus" instead of alpha-blend:

        typedef agg::comp_op_rgba_plus<color_type, component_order> 
blender_pre_type;
        typedef agg::comp_adaptor_rgba<blender_pre_type> blender_type;
        typedef agg::pixfmt_custom_blend_rgba<blender_type> pixfmt_type;

And the restriction is that the shapes must not overlap.
Then, after you render the scene you can alpha-blend the buffer over the 
parent layer. BTW, it can be RGB, not obligatory RGBA. But since your buffer 
is premultiplied, you are supposed to use a premultiplied renderer too, for 
example:

        typedef agg::pixfmt_rgba32_pre pixfmt_pre;
        typedef agg::renderer_base<pixfmt_pre> base_ren_pre_type;
        . . .
        pixfmt_pre pf_pre(rbuf_window());
        base_ren_pre_type ren_base_pre(pf_pre);

        ren_base_pre.blend_from(image_buffer);


你可能感兴趣的:(问题,agg)