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:
- a long, continuous, thick path lags program.
- 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 path
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):
to emulate krita paint program:
- keep backup of original target surface.
- paint brush onto scratch surface starts out transparent.
- on surface, composting rule "take maximum opacity".
- 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
Post a Comment