C++ and Qt: Paint Program - Rendering Transparent Lines Without Alpha Joint Overlap -


i have started create paint program interacts drawing tablets. depending on pressure of pen on tablet change alpha value of line being drawn. mechanism works.

thin lines decent , looks real sketch. since drawing lines between 2 points (like in qt scribble tutorial) paint there alpha overlap between line joints , noticeable thick strokes.

this effect line line conjuction:

as can see, there ugly alpha blend between line segments.

in order solve decided use qpainterpath render lines. 2 problems this:

  1. a long, continuous, thick path lags program.
  2. since path connected acts one, change alpha value affects the entire path(which don't want since want preserve blending effect).

the following images use qpainterpath.

the blend effect want keep.

the following image shows 2nd problem changes alpha , thickness of entire pathenter image description here

the red text should read: "if more pressure added without removing pen tablet surface line thickens" (and alpha becomes opaque)

another thing approach can blending trail dark light (or thick thin path width) not light dark. not sure why effect occurs best guess has line segments of path updating whole.

i did make program increase/decrease alpha , line thickness based on pressure of pen on tablet.

the problem want render lines without alpha overlap , qpainterpath updates entire path's alpha , thickness don't want.

this code creates path:

    switch(event->type()){     case qevent::tabletpress:         if(!ontablet){             ontablet = true;              //empty new segment             freepainterpath();             path = new qpainterpath(event->pos());         }   break;      case qevent::tabletrelease:         if(ontablet)             ontablet = false;             break;      case qevent::tabletmove:         if(path != null)             path->lineto(event->pos());          if(ontablet){              //checks pressure of pen on tablet change alpha/line thickness             brusheffect(event);              qpainter painter(&pixmap);              //renders path             paintpixmap(painter, event);         }   break;     default:; } update(); 

the desired effect want single path (image created krita paint program):enter image description here

to emulate krita paint program:

  1. keep backup of original target surface.
  2. paint brush onto scratch surface starts out transparent.
  3. on surface, composting rule "take maximum opacity".
  4. keep track of dirty regions of surface, , traditional composite of (scratch surface) onto (original target surface) , display result. make sure operation doesn't damage original target surface.

now, don't have keep entire original target surface -- parts have drawn on tool. (a tile based lazy-write imaging system make easy).

depending on segment size drawing with, may want interpolate between segments make strength of brush bit less sharp. shape of brush may need work. these independent of transparency problem.

as qt strangeness, don't know enough qt tell how deal quirks of qt's brush code. above "key-mask" strategy should solve alpha overlap problem.

i not know how in qt. glancing @ qt compositing modes don't see obvious way "take maximum" resulting alpha. maybe involving both color , alpha channels in clever way.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -