Compute gray levels correctly.