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.
Hmm, I wonder if this helps… Depending on which function is called (e. g. write_scanline or write_image), the buffer size has to calculated differently (`format.size()*nchannels*width` vs. `format.size()*nchannels*image_pixels()`)…