added gray conversion func