Rebase of #540 (TRANSFORM_ROT90 and TRANSFORM_ROT270 implemented)

Making this easy for people to look at the diffs.

These are my (very minor) edits to shanky93's pull request #540, but rebased onto a more modern trunk, fix the formatting to conform to our code style, and just a couple other obvious minor fixes.