Skip to content

Instantly share code, notes, and snippets.

@ThePhD
Created January 31, 2014 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThePhD/8744826 to your computer and use it in GitHub Desktop.
Save ThePhD/8744826 to your computer and use it in GitHub Desktop.
template <typename T, typename TValue, typename TIntermediate = double>
T color_normalize( TValue value, TValue valuemax = color_limits<TValue>::max( ), TValue valuemin = color_limits<TValue>::max( ), T max = color_limits<T>::max( ), T min = color_limits<T>::min( ) ) {
TIntermediate valuerange = static_cast<TIntermediate>( value - valuemin ) / static_cast<TIntermediate>( valuemax );
return static_cast<T>( valuerange * ( max - min ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment