CopyRectangle: add mask
throw correct exceptions