Range validation and gamma correction seudo-code