diff options
Diffstat (limited to 'linden/indra/llmath/llquantize.h')
-rw-r--r-- | linden/indra/llmath/llquantize.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/linden/indra/llmath/llquantize.h b/linden/indra/llmath/llquantize.h index a4fd67a..817c4c3 100644 --- a/linden/indra/llmath/llquantize.h +++ b/linden/indra/llmath/llquantize.h | |||
@@ -3,6 +3,8 @@ | |||
3 | * @brief useful routines for quantizing floats to various length ints | 3 | * @brief useful routines for quantizing floats to various length ints |
4 | * and back out again | 4 | * and back out again |
5 | * | 5 | * |
6 | * $LicenseInfo:firstyear=2001&license=viewergpl$ | ||
7 | * | ||
6 | * Copyright (c) 2001-2007, Linden Research, Inc. | 8 | * Copyright (c) 2001-2007, Linden Research, Inc. |
7 | * | 9 | * |
8 | * Second Life Viewer Source Code | 10 | * Second Life Viewer Source Code |
@@ -25,6 +27,7 @@ | |||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | 27 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO |
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | 28 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, |
27 | * COMPLETENESS OR PERFORMANCE. | 29 | * COMPLETENESS OR PERFORMANCE. |
30 | * $/LicenseInfo$ | ||
28 | */ | 31 | */ |
29 | 32 | ||
30 | #ifndef LL_LLQUANTIZE_H | 33 | #ifndef LL_LLQUANTIZE_H |
@@ -40,6 +43,18 @@ const U8 FIRSTVALIDCHAR = 54; | |||
40 | const U8 MAXSTRINGVAL = U8MAX - FIRSTVALIDCHAR; //we don't allow newline or null | 43 | const U8 MAXSTRINGVAL = U8MAX - FIRSTVALIDCHAR; //we don't allow newline or null |
41 | 44 | ||
42 | 45 | ||
46 | inline U16 F32_to_U16_ROUND(F32 val, F32 lower, F32 upper) | ||
47 | { | ||
48 | val = llclamp(val, lower, upper); | ||
49 | // make sure that the value is positive and normalized to <0, 1> | ||
50 | val -= lower; | ||
51 | val /= (upper - lower); | ||
52 | |||
53 | // round the value. Sreturn the U16 | ||
54 | return (U16)(llround(val*U16MAX)); | ||
55 | } | ||
56 | |||
57 | |||
43 | inline U16 F32_to_U16(F32 val, F32 lower, F32 upper) | 58 | inline U16 F32_to_U16(F32 val, F32 lower, F32 upper) |
44 | { | 59 | { |
45 | val = llclamp(val, lower, upper); | 60 | val = llclamp(val, lower, upper); |
@@ -67,6 +82,19 @@ inline F32 U16_to_F32(U16 ival, F32 lower, F32 upper) | |||
67 | return val; | 82 | return val; |
68 | } | 83 | } |
69 | 84 | ||
85 | |||
86 | inline U8 F32_to_U8_ROUND(F32 val, F32 lower, F32 upper) | ||
87 | { | ||
88 | val = llclamp(val, lower, upper); | ||
89 | // make sure that the value is positive and normalized to <0, 1> | ||
90 | val -= lower; | ||
91 | val /= (upper - lower); | ||
92 | |||
93 | // return the rounded U8 | ||
94 | return (U8)(llround(val*U8MAX)); | ||
95 | } | ||
96 | |||
97 | |||
70 | inline U8 F32_to_U8(F32 val, F32 lower, F32 upper) | 98 | inline U8 F32_to_U8(F32 val, F32 lower, F32 upper) |
71 | { | 99 | { |
72 | val = llclamp(val, lower, upper); | 100 | val = llclamp(val, lower, upper); |