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.
Maybe better way to do things would be to have
    ImageSpec buf_spec(m_output->spec());
    buf_spec.set_format(format);
    const void* array = make_read_buffer (buffer, buf_spec.image_bytes())
or `scanline_bytes()` or `tile_bytes()` respectively. I think this should cover all cases and not duplicate bytes-per-image/scanline/tile calculations that are implemented for ImageSpec anyways.