Fix fault in python ImageOutput.write_* functions

The buffer to be written was assumed to be of the same format as
specified in the ImageOutput's spec, which in generally is not true and
leads to a wrong calculation of the buffer size.

This commit makes the python write_* functions do something similar to
the C++ ImageOutput::write_image function to calculate the buffer size.

It works for me. I hope I didn't overlook anything.
Perhaps we can make this easier, and reduce the amount of repetition, if we change make_read_buffer to take the format rather than the size?  So you'd change these lines to simply

    const void *array = make_read_buffer (buffer, format);

and the extra logic is implemented just once inside make_read_buffer?