diff options
| author | Simon <simon@hardwired.org.uk> | 2010-08-26 09:53:15 (GMT) |
|---|---|---|
| committer | Simon <simon@hardwired.org.uk> | 2010-08-26 09:53:15 (GMT) |
| commit | 5751fea35f31640fddfaea1459503e366ae39729 (patch) | |
| tree | ad4180fdfba2b0600ac61b919f3ed3f5486dab8e /utils.c | |
| parent | 470519c92ed917b41c6ccae2e193eb59bdfe2ece (diff) | |
| download | powder-5751fea35f31640fddfaea1459503e366ae39729.zip powder-5751fea35f31640fddfaea1459503e366ae39729.tar.gz | |
More work
Diffstat (limited to 'utils.c')
| -rw-r--r-- | utils.c | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -0,0 +1,41 @@ +#include "utils.h" + +//Signum function +#ifdef WIN32 +_inline int sign(float i) +#else +inline int sign(float i) +#endif +{ + if (i<0) + return -1; + if (i>0) + return 1; + return 0; +} + +#ifdef WIN32 +_inline unsigned clamp_flt(float f, float min, float max) +#else +inline unsigned clamp_flt(float f, float min, float max) +#endif +{ + if(f<min) + return 0; + if(f>max) + return 255; + return (int)(255.0f*(f-min)/(max-min)); +} + +#ifdef WIN32 +_inline float restrict_flt(float f, float min, float max) +#else +inline float restrict_flt(float f, float min, float max) +#endif +{ + if(f<min) + return min; + if(f>max) + return max; + return f; +}
\ No newline at end of file |
