Bug 312780 - Add undo to foreground selection tool

Implement undoing strokes by keeping copies of the changed parts
of the trimap around in internal undo/redo stacks.