tonecurve: fix serious logical flaw. This should fix #9855