Add support for PGM format.

The code has been split into different source files.

This breaks for now rotation for tiled images and PPM format. The focus
is now on the PGM format.