Page 1 of 1

mask canvas

Posted: Tue Mar 24, 2015 12:44 am
by monte
Is there any way to apply a mask to the canvas? At this stage I'm thinking specifically of drawing an image and then applying a mask to it like a circle. Perhaps we could draw an image into a path rather than just a rectangle?

Re: mask canvas

Posted: Tue Mar 24, 2015 10:06 am
by LCMark
@monte: We do need to add a clip to path ability to the canvas which would be the easiest way to do this... For now you could try using the image as a pattern, and fill the path. If the pattern has a suitable transform (translated appropriately) then you should be able to get much the same effect.

Re: mask canvas

Posted: Tue Mar 24, 2015 11:20 am
by LCMark
@monte: Having thought about this for a bit, it is far more efficient to use the pattern approach if you only need to mask a single image. General soft clipping to an arbitrary path is a relatively expensive operation as the mask has to be precomputed (and intersected ahead of time with any existing clip region). Filling a path with a pattern requires no precomputation - rasterisation can occur scanline by scanline simultaneously using the data from the pattern and path.

I wonder if adding a 'draw image with mask' syntax might be a good idea here - the mask could either be an image (treated as a mask) or a path and the command can do the necessary twiddling to fill as a pattern rather than setting a clip and filling.

Re: mask canvas

Posted: Wed Mar 25, 2015 12:02 am
by monte
@LCMark that sounds very nice