Added improved dirty rectangles algorithm.

Authors: Mark Logan and Ian Langworth, Artillery
Improvements to error messages.
Merge pull request #427 from statico/dirty-rectangles

Improved dirty rectangles algorithm