More improvements to colour processing

I introduced a bug, which I then fixed.