Problem with blending edges of connected shapes

Source: Internet
Author: User

Provide display code:

Agg::rendering_buffer &rbuf = Rbuf_window ();
Agg::p ixfmt_bgr24 pixf (RBUF);

typedef agg::renderer_base<agg::p ixfmt_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::p ath_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));


It is evident that a shallow white edge appears on the adjacent boundary of two rectangles.

Email query:

As you can see there are a brighter line between the rectangles. Iknow where it is from-this a result of alpha blending of twopartially covered scanlines. And this is a problem form me. Does you have any idea how to get rid of this line? I mean how to Makeit in the same color as the rectangles. My application draws Metafilesand sometimes there is such shapes in them and I get ugly bandeddrawings ... Does any ideas?

The following is the author's explanation:

 it ' S a well known problem that can ' t be eliminated easily.  It exists inall SVG engies and appears as thin  "Web"   upon the image, when you draw adjacentshapes:http://www.antigrain.com/svg/ index.htmlsay, initially you have color  (0,0,0).  then you draw a  white pixel on it with0.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 withopacity=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  Yourrectrangles. the problem&Nbsp;can ' T be easily solved. in the svg example i use conv_ Contour todilate 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 inmacromedia flash, but it requires not  Only another rasterization algorithm, butalso changing the whole data  model. Your data shall be represented not as a setof  Polygons, but as a set of edges with attributes - color  on the left andcolor 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&nBsp;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. onepixel can be overlapped by many polygons  even if the polygons themselves do notoverlap. http://antigrain.com/ Stuff/multipoly_cover.gif - the central pixel is coveredby 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 weightis 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 wehave not rgba, but rgbc color space. initially  all cover values are 0. At atime we always operate  With 2 colors and two coverage values. we accumulate thecoverage  values  (with clipping at 1.0)  and calculate the resulting  Color as theweighted average of 2 colors/covers. it looks very  familiar, and remainds methe 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&NBSP;+&NBSP;W4*A4)/(DEN+W4)   den += w4expanding 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.


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

Problem with blending edges of connected shapes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.