Add \(i)clip support to the Relocator mask operations

This patch adds a "clip mode" to the following mask operations in Relocator:
* extend mask
* expand mask
* flip mask

I also refactored the code i touched a little to avoid further code duplication.