## Section 5.1 - Selection Masks

We
have always applied the effects to the whole bitmap. It will sometimes be useful
to use an intermediary project to "filter" this effect:

Example:
You have two projects 0 and 1, a mask in project 2 and want to draw the result
in project 3:

0:**AA****
**; 1:**BB****
**; and 2:**01** will result in 3:**A****B**

In
this example, you could have obtained project one applying some effect to
project zero.

This
works a bit like an alpha channel, project two holding that alpha value (of
course projects one and two may be two completely different loaded pictures).

Let's
say that a value of zero in project 2 results in outputing the value of project
0 and a value of 255 outputs project 1.

To
read from zero, you put **r(0,x,y)*(255-r(2,x,y))/255**, and reading from one
is

**r(1,x,y)*r(2,x,y)/255**

Note
that if you only use 0 or 255 (i.e. none or full alpha), you may make your mask
have only values zero and one, so that you aren't required to divide by 255
everytime.

Note well that r(r(2,x,y),x,y) is not allowed, as the project number must be a __constant
value__! (Because of freezing problems)

Well,
now add the two values, to obtain: **(r(0,x,y)*(255-r(2,x,y))+r(1,x,y)*r(2,x,y))/255**

In all components, you obtain:

r(3,x,y)=**(r(0,x,y)*(255-r(2,x,y))+r(1,x,y)*r(2,x,y))/255**

g(3,x,y)=**(g(0,x,y)*(255-r(2,x,y))+g(1,x,y)*r(2,x,y))/255**

b(3,x,y)=**(b(0,x,y)*(255-r(2,x,y))+b(1,x,y)*r(2,x,y))/255**.

You may also read the different components from the mask to have different
transparencies for the different components, if you want, instead of having one
mask for the whole picture.

To
obtain these masks, you can use colour extraction (section 4.1)

Some mathematic formula (e.g. implicit graphes, section 3.2,
but anything else is ok :-))

You can combine these two ways. If for example you did some colour extraction
and got some superfluous areas, you can try to find a function that covers
everything but these areas and multiply both.

If
you want to add masks (a bit like a logic OR), use the max() function between
them. Another way to do it is to multiply their inverses, something like
r(2,x,y)=**255-(255-r(0,x,y))*(255-r(1,x,y))**.

And
to apply a mask to a transformation, you can 'multiply the changes' by
c(k,x,y)/255, replacing c and k accordingly.

This is mostly useful for instance with blur and other convolution effects, and
mayve with colour effects.

Index

#### Chapter four:
Inter-referencing

4.1: Having fun with colours

4.2:
Convolutions

4.3: Linear transformations

#### Chapter five:
Using masks

5.1: Selection
masks

5.2: Translation
masks

5.3:
Absolute masks