Fix ImageCache::get_pixels() data offset

This should fix the problem described in #759, whereby channels are offset horizontally when calling ImageCache::get_pixels() with a non-zero chbegin and where the source datatype is not the same size as the destination datatype. I also made a small fix to ImageBufAlgo::flatten() which was needed to get it to compile.

I confess to not having run the unit tests properly for this - they all fail for me both with and without the change, and I don't know why. I have however run the tests that Luke presented in #759 and verified that this fixes them.