Problem with mask

Scott Rossi scott at tactilemedia.com
Thu Oct 16 13:53:25 EDT 2008


Recently, James Hurley wrote:

> In the past I have always used Freehand to deal with masking of images.
> 
> But I thought I would see if I couldn't roll one of my own in RR.
> 
> It worked after a fashion but is rough around the edges. In
> particular when masking to an ellipse, the results is flat on the
> right edge and the bottom edge. I do this by running over the image
> and masking all pixels that are not within the ellipse--using the
> "within" function. That should work.
> 
> But it doesn't quite. There must be something  about images I don't
> understand. I would appreciate any thoughts.

I think what you're running into is antialiasing -- the smoothing of the
edge of the mask graphic.  If you look closely at the edge of the oval,
you'll see it is composed of translucent pixels which are equivalent to
shades of grey.  This effect is easier to see with a black graphic: the
interior of the oval is black, but around the edge of the oval are pixels of
various translucent values that give the oval a smoother appearance and
allow the edge to blend with whatever is behind the oval.

Your script appears to work only in values of black and white (block and
clear).  If you want to achieve and antialiased edge you need to include
in-between (grey) values as well.

Here are a couple of ways you can get the effect:

If you really want to mask an image directly, I think the fastest way to do
this is to group the oval in a 0 margins group, import a snapshot image of
the group, and store the alphaData of the snapshot in a variable to use as a
mask on the target image.  Why a group?  Because the resulting image will
contain the mask information you need.

  import snapshot from rect (rect of grp 1) of grp 1
  put the alphaData of last img into myMaskData

You can crop the target image to the oval's rect as you suggest in your
script and then set the alphaData of the cropped target image to the
alphaData you collected from the snapshot.


If you only want the "effect" of a masked image, a simpler (and arguably
more flexible) way to mask an image is using groups and ink effects.  I
posted a sample stack that shows the result.  In your message box:

  go url "http://www.tactilemedia.com/site_files/downloads/masked_abe.rev"

This is the same effect illustrated in the spotlight demo stack posted here:

  go url "http://www.tactilemedia.com/site_files/downloads/spotlight.rev"

Hope this helps.

Regards,

Scott Rossi
Creative Director
Tactile Media, Multimedia & Design





More information about the use-livecode mailing list