Fix coding to handle pixels with both gain and loss.