1 | <html> |
---|
2 | <head> |
---|
3 | <title>OgreBitwise.h Source File - OGRE Documentation</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
---|
4 | <link type="text/css" rel="stylesheet" href="style.css"> |
---|
5 | </head> |
---|
6 | |
---|
7 | <body> |
---|
8 | <!-- Generated by Doxygen 1.3.6 --> |
---|
9 | <div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a> | <a class="qindex" href="pages.html">Related Pages</a></div> |
---|
10 | <h1>OgreBitwise.h</h1><a href="OgreBitwise_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*</span> |
---|
11 | 00002 <span class="comment">-----------------------------------------------------------------------------</span> |
---|
12 | 00003 <span class="comment">This source file is part of OGRE</span> |
---|
13 | 00004 <span class="comment"> (Object-oriented Graphics Rendering Engine)</span> |
---|
14 | 00005 <span class="comment">For the latest info, see http://www.ogre3d.org/</span> |
---|
15 | 00006 <span class="comment"></span> |
---|
16 | 00007 <span class="comment">Copyright (c) 2000-2005 The OGRE Team</span> |
---|
17 | 00008 <span class="comment">Also see acknowledgements in Readme.html</span> |
---|
18 | 00009 <span class="comment"></span> |
---|
19 | 00010 <span class="comment">This program is free software; you can redistribute it and/or modify it under</span> |
---|
20 | 00011 <span class="comment">the terms of the GNU Lesser General Public License as published by the Free Software</span> |
---|
21 | 00012 <span class="comment">Foundation; either version 2 of the License, or (at your option) any later</span> |
---|
22 | 00013 <span class="comment">version.</span> |
---|
23 | 00014 <span class="comment"></span> |
---|
24 | 00015 <span class="comment">This program is distributed in the hope that it will be useful, but WITHOUT</span> |
---|
25 | 00016 <span class="comment">ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS</span> |
---|
26 | 00017 <span class="comment">FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.</span> |
---|
27 | 00018 <span class="comment"></span> |
---|
28 | 00019 <span class="comment">You should have received a copy of the GNU Lesser General Public License along with</span> |
---|
29 | 00020 <span class="comment">this program; if not, write to the Free Software Foundation, Inc., 59 Temple</span> |
---|
30 | 00021 <span class="comment">Place - Suite 330, Boston, MA 02111-1307, USA, or go to</span> |
---|
31 | 00022 <span class="comment">http://www.gnu.org/copyleft/lesser.txt.</span> |
---|
32 | 00023 <span class="comment">-----------------------------------------------------------------------------</span> |
---|
33 | 00024 <span class="comment">*/</span> |
---|
34 | 00025 <span class="preprocessor">#ifndef _Bitwise_H__</span> |
---|
35 | 00026 <span class="preprocessor"></span><span class="preprocessor">#define _Bitwise_H__</span> |
---|
36 | 00027 <span class="preprocessor"></span> |
---|
37 | 00028 <span class="preprocessor">#include "<a class="code" href="OgrePrerequisites_8h.html">OgrePrerequisites.h</a>"</span> |
---|
38 | 00029 |
---|
39 | 00030 <span class="keyword">namespace </span>Ogre { |
---|
40 | 00031 |
---|
41 | <a name="l00034"></a><a class="code" href="classOgre_1_1Bitwise.html">00034</a> <span class="keyword">class </span><a class="code" href="classOgre_1_1Bitwise.html">Bitwise</a> { |
---|
42 | 00035 <span class="keyword">public</span>: |
---|
43 | <a name="l00038"></a><a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee0">00038</a> <span class="keyword">static</span> <a class="code" href="OgrePlatform_8h.html#a10">FORCEINLINE</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee0">mostSignificantBitSet</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> value) |
---|
44 | 00039 { |
---|
45 | 00040 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> result = 0; |
---|
46 | 00041 <span class="keywordflow">while</span> (value != 0) { |
---|
47 | 00042 ++result; |
---|
48 | 00043 value >>= 1; |
---|
49 | 00044 } |
---|
50 | 00045 <span class="keywordflow">return</span> result-1; |
---|
51 | 00046 } |
---|
52 | <a name="l00051"></a><a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee1">00051</a> <span class="keyword">static</span> <a class="code" href="OgrePlatform_8h.html#a10">FORCEINLINE</a> <a class="code" href="namespaceOgre.html#a455">uint32</a> <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee1">firstPO2From</a>(<a class="code" href="namespaceOgre.html#a455">uint32</a> n) |
---|
53 | 00052 { |
---|
54 | 00053 --n; |
---|
55 | 00054 n |= n >> 16; |
---|
56 | 00055 n |= n >> 8; |
---|
57 | 00056 n |= n >> 4; |
---|
58 | 00057 n |= n >> 2; |
---|
59 | 00058 n |= n >> 1; |
---|
60 | 00059 ++n; |
---|
61 | 00060 <span class="keywordflow">return</span> n; |
---|
62 | 00061 } |
---|
63 | 00065 <span class="keyword">template</span><<span class="keyword">typename</span> T> |
---|
64 | <a name="l00066"></a><a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee2">00066</a> <span class="keyword">static</span> <a class="code" href="OgrePlatform_8h.html#a10">FORCEINLINE</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee2">getBitShift</a>(T mask) |
---|
65 | 00067 { |
---|
66 | 00068 <span class="keywordflow">if</span> (mask == 0) |
---|
67 | 00069 <span class="keywordflow">return</span> 0; |
---|
68 | 00070 |
---|
69 | 00071 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> result = 0; |
---|
70 | 00072 <span class="keywordflow">while</span> ((mask & 1) == 0) { |
---|
71 | 00073 ++result; |
---|
72 | 00074 mask >>= 1; |
---|
73 | 00075 } |
---|
74 | 00076 <span class="keywordflow">return</span> result; |
---|
75 | 00077 } |
---|
76 | 00078 |
---|
77 | 00084 <span class="keyword">template</span><<span class="keyword">typename</span> SrcT, <span class="keyword">typename</span> DestT> |
---|
78 | <a name="l00085"></a><a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee3">00085</a> <span class="keyword">static</span> <span class="keyword">inline</span> DestT <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee3">convertBitPattern</a>(SrcT srcValue, SrcT srcBitMask, DestT destBitMask) |
---|
79 | 00086 { |
---|
80 | 00087 <span class="comment">// Mask off irrelevant source value bits (if any)</span> |
---|
81 | 00088 srcValue = srcValue & srcBitMask; |
---|
82 | 00089 |
---|
83 | 00090 <span class="comment">// Shift source down to bottom of DWORD</span> |
---|
84 | 00091 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> srcBitShift = <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee2">getBitShift</a>(srcBitMask); |
---|
85 | 00092 srcValue >>= srcBitShift; |
---|
86 | 00093 |
---|
87 | 00094 <span class="comment">// Get max value possible in source from srcMask</span> |
---|
88 | 00095 <span class="keyword">const</span> SrcT srcMax = srcBitMask >> srcBitShift; |
---|
89 | 00096 |
---|
90 | 00097 <span class="comment">// Get max avaiable in dest</span> |
---|
91 | 00098 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> destBitShift = <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee2">getBitShift</a>(destBitMask); |
---|
92 | 00099 <span class="keyword">const</span> DestT destMax = destBitMask >> destBitShift; |
---|
93 | 00100 |
---|
94 | 00101 <span class="comment">// Scale source value into destination, and shift back</span> |
---|
95 | 00102 DestT destValue = (srcValue * destMax) / srcMax; |
---|
96 | 00103 <span class="keywordflow">return</span> (destValue << destBitShift); |
---|
97 | 00104 } |
---|
98 | 00105 |
---|
99 | <a name="l00110"></a><a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee4">00110</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee4">fixedToFixed</a>(<a class="code" href="namespaceOgre.html#a455">uint32</a> value, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> n, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> p) |
---|
100 | 00111 { |
---|
101 | 00112 <span class="keywordflow">if</span>(n > p) |
---|
102 | 00113 { |
---|
103 | 00114 <span class="comment">// Less bits required than available; this is easy</span> |
---|
104 | 00115 value >>= n-p; |
---|
105 | 00116 } |
---|
106 | 00117 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(n < p) |
---|
107 | 00118 { |
---|
108 | 00119 <span class="comment">// More bits required than are there, do the fill</span> |
---|
109 | 00120 <span class="comment">// Use old fashioned division, probably better than a loop</span> |
---|
110 | 00121 <span class="keywordflow">if</span>(value == 0) |
---|
111 | 00122 value = 0; |
---|
112 | 00123 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(value == (static_cast<unsigned int>(1)<<n)-1) |
---|
113 | 00124 value = (1<<p)-1; |
---|
114 | 00125 <span class="keywordflow">else</span> value = value*(1<<p)/((1<<n)-1); |
---|
115 | 00126 } |
---|
116 | 00127 <span class="keywordflow">return</span> value; |
---|
117 | 00128 } |
---|
118 | 00129 |
---|
119 | <a name="l00134"></a><a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee5">00134</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee5">floatToFixed</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> value, <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> bits) |
---|
120 | 00135 { |
---|
121 | 00136 <span class="keywordflow">if</span>(value <= 0.0f) <span class="keywordflow">return</span> 0; |
---|
122 | 00137 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (value >= 1.0f) <span class="keywordflow">return</span> (1<<bits)-1; |
---|
123 | 00138 <span class="keywordflow">else</span> <span class="keywordflow">return</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)(value * (1<<bits)); |
---|
124 | 00139 } |
---|
125 | 00140 |
---|
126 | <a name="l00144"></a><a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee6">00144</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">float</span> <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee6">fixedToFloat</a>(<span class="keywordtype">unsigned</span> value, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> bits) |
---|
127 | 00145 { |
---|
128 | 00146 <span class="keywordflow">return</span> (<span class="keywordtype">float</span>)value/(<span class="keywordtype">float</span>)((1<<bits)-1); |
---|
129 | 00147 } |
---|
130 | 00148 |
---|
131 | <a name="l00152"></a><a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee7">00152</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee7">intWrite</a>(<span class="keyword">const</span> <span class="keywordtype">void</span> *dest, <span class="keyword">const</span> <span class="keywordtype">int</span> n, <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> value) |
---|
132 | 00153 { |
---|
133 | 00154 <span class="keywordflow">switch</span>(n) { |
---|
134 | 00155 <span class="keywordflow">case</span> 1: |
---|
135 | 00156 ((<a class="code" href="namespaceOgre.html#a457">uint8</a>*)dest)[0] = (<a class="code" href="namespaceOgre.html#a457">uint8</a>)value; |
---|
136 | 00157 <span class="keywordflow">break</span>; |
---|
137 | 00158 <span class="keywordflow">case</span> 2: |
---|
138 | 00159 ((<a class="code" href="namespaceOgre.html#a456">uint16</a>*)dest)[0] = (<a class="code" href="namespaceOgre.html#a456">uint16</a>)value; |
---|
139 | 00160 <span class="keywordflow">break</span>; |
---|
140 | 00161 <span class="keywordflow">case</span> 3: |
---|
141 | 00162 <span class="preprocessor">#if OGRE_ENDIAN == OGRE_ENDIAN_BIG </span> |
---|
142 | 00163 <span class="preprocessor"></span> ((<a class="code" href="namespaceOgre.html#a457">uint8</a>*)dest)[0] = (<a class="code" href="namespaceOgre.html#a457">uint8</a>)((value >> 16) & 0xFF); |
---|
143 | 00164 ((<a class="code" href="namespaceOgre.html#a457">uint8</a>*)dest)[1] = (<a class="code" href="namespaceOgre.html#a457">uint8</a>)((value >> 8) & 0xFF); |
---|
144 | 00165 ((<a class="code" href="namespaceOgre.html#a457">uint8</a>*)dest)[2] = (<a class="code" href="namespaceOgre.html#a457">uint8</a>)(value & 0xFF); |
---|
145 | 00166 <span class="preprocessor">#else</span> |
---|
146 | 00167 <span class="preprocessor"></span> ((<a class="code" href="namespaceOgre.html#a457">uint8</a>*)dest)[2] = (<a class="code" href="namespaceOgre.html#a457">uint8</a>)((value >> 16) & 0xFF); |
---|
147 | 00168 ((<a class="code" href="namespaceOgre.html#a457">uint8</a>*)dest)[1] = (<a class="code" href="namespaceOgre.html#a457">uint8</a>)((value >> 8) & 0xFF); |
---|
148 | 00169 ((<a class="code" href="namespaceOgre.html#a457">uint8</a>*)dest)[0] = (<a class="code" href="namespaceOgre.html#a457">uint8</a>)(value & 0xFF); |
---|
149 | 00170 <span class="preprocessor">#endif</span> |
---|
150 | 00171 <span class="preprocessor"></span> <span class="keywordflow">break</span>; |
---|
151 | 00172 <span class="keywordflow">case</span> 4: |
---|
152 | 00173 ((<a class="code" href="namespaceOgre.html#a455">uint32</a>*)dest)[0] = (<a class="code" href="namespaceOgre.html#a455">uint32</a>)value; |
---|
153 | 00174 <span class="keywordflow">break</span>; |
---|
154 | 00175 } |
---|
155 | 00176 } |
---|
156 | <a name="l00180"></a><a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee8">00180</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee8">intRead</a>(<span class="keyword">const</span> <span class="keywordtype">void</span> *src, <span class="keywordtype">int</span> n) { |
---|
157 | 00181 <span class="keywordflow">switch</span>(n) { |
---|
158 | 00182 <span class="keywordflow">case</span> 1: |
---|
159 | 00183 <span class="keywordflow">return</span> ((<a class="code" href="namespaceOgre.html#a457">uint8</a>*)src)[0]; |
---|
160 | 00184 <span class="keywordflow">case</span> 2: |
---|
161 | 00185 <span class="keywordflow">return</span> ((<a class="code" href="namespaceOgre.html#a456">uint16</a>*)src)[0]; |
---|
162 | 00186 <span class="keywordflow">case</span> 3: |
---|
163 | 00187 <span class="preprocessor">#if OGRE_ENDIAN == OGRE_ENDIAN_BIG </span> |
---|
164 | 00188 <span class="preprocessor"></span> <span class="keywordflow">return</span> ((<a class="code" href="namespaceOgre.html#a455">uint32</a>)((<a class="code" href="namespaceOgre.html#a457">uint8</a>*)src)[0]<<16)| |
---|
165 | 00189 ((<a class="code" href="namespaceOgre.html#a455">uint32</a>)((<a class="code" href="namespaceOgre.html#a457">uint8</a>*)src)[1]<<8)| |
---|
166 | 00190 ((<a class="code" href="namespaceOgre.html#a455">uint32</a>)((<a class="code" href="namespaceOgre.html#a457">uint8</a>*)src)[2]); |
---|
167 | 00191 <span class="preprocessor">#else</span> |
---|
168 | 00192 <span class="preprocessor"></span> <span class="keywordflow">return</span> ((<a class="code" href="namespaceOgre.html#a455">uint32</a>)((<a class="code" href="namespaceOgre.html#a457">uint8</a>*)src)[0])| |
---|
169 | 00193 ((<a class="code" href="namespaceOgre.html#a455">uint32</a>)((<a class="code" href="namespaceOgre.html#a457">uint8</a>*)src)[1]<<8)| |
---|
170 | 00194 ((<a class="code" href="namespaceOgre.html#a455">uint32</a>)((<a class="code" href="namespaceOgre.html#a457">uint8</a>*)src)[2]<<16); |
---|
171 | 00195 <span class="preprocessor">#endif</span> |
---|
172 | 00196 <span class="preprocessor"></span> <span class="keywordflow">case</span> 4: |
---|
173 | 00197 <span class="keywordflow">return</span> ((<a class="code" href="namespaceOgre.html#a455">uint32</a>*)src)[0]; |
---|
174 | 00198 } |
---|
175 | 00199 <span class="keywordflow">return</span> 0; <span class="comment">// ?</span> |
---|
176 | 00200 } |
---|
177 | 00201 |
---|
178 | <a name="l00205"></a><a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee9">00205</a> <span class="keyword">static</span> <span class="keyword">inline</span> <a class="code" href="namespaceOgre.html#a456">uint16</a> <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee9">floatToHalf</a>(<span class="keywordtype">float</span> i) |
---|
179 | 00206 { |
---|
180 | 00207 <span class="keywordflow">return</span> <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee10">floatToHalfI</a>(*reinterpret_cast<uint32*>(&i)); |
---|
181 | 00208 } |
---|
182 | <a name="l00211"></a><a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee10">00211</a> <span class="keyword">static</span> <span class="keyword">inline</span> <a class="code" href="namespaceOgre.html#a456">uint16</a> <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee10">floatToHalfI</a>(<a class="code" href="namespaceOgre.html#a455">uint32</a> i) |
---|
183 | 00212 { |
---|
184 | 00213 <span class="keyword">register</span> <span class="keywordtype">int</span> s = (i >> 16) & 0x00008000; |
---|
185 | 00214 <span class="keyword">register</span> <span class="keywordtype">int</span> e = ((i >> 23) & 0x000000ff) - (127 - 15); |
---|
186 | 00215 <span class="keyword">register</span> <span class="keywordtype">int</span> m = i & 0x007fffff; |
---|
187 | 00216 |
---|
188 | 00217 <span class="keywordflow">if</span> (e <= 0) |
---|
189 | 00218 { |
---|
190 | 00219 <span class="keywordflow">if</span> (e < -10) |
---|
191 | 00220 { |
---|
192 | 00221 <span class="keywordflow">return</span> 0; |
---|
193 | 00222 } |
---|
194 | 00223 m = (m | 0x00800000) >> (1 - e); |
---|
195 | 00224 |
---|
196 | 00225 <span class="keywordflow">return</span> s | (m >> 13); |
---|
197 | 00226 } |
---|
198 | 00227 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (e == 0xff - (127 - 15)) |
---|
199 | 00228 { |
---|
200 | 00229 <span class="keywordflow">if</span> (m == 0) <span class="comment">// Inf</span> |
---|
201 | 00230 { |
---|
202 | 00231 <span class="keywordflow">return</span> s | 0x7c00; |
---|
203 | 00232 } |
---|
204 | 00233 <span class="keywordflow">else</span> <span class="comment">// NAN</span> |
---|
205 | 00234 { |
---|
206 | 00235 m >>= 13; |
---|
207 | 00236 <span class="keywordflow">return</span> s | 0x7c00 | m | (m == 0); |
---|
208 | 00237 } |
---|
209 | 00238 } |
---|
210 | 00239 <span class="keywordflow">else</span> |
---|
211 | 00240 { |
---|
212 | 00241 <span class="keywordflow">if</span> (e > 30) <span class="comment">// Overflow</span> |
---|
213 | 00242 { |
---|
214 | 00243 <span class="keywordflow">return</span> s | 0x7c00; |
---|
215 | 00244 } |
---|
216 | 00245 |
---|
217 | 00246 <span class="keywordflow">return</span> s | (e << 10) | (m >> 13); |
---|
218 | 00247 } |
---|
219 | 00248 } |
---|
220 | 00249 |
---|
221 | <a name="l00254"></a><a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee11">00254</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">float</span> <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee11">halfToFloat</a>(<a class="code" href="namespaceOgre.html#a456">uint16</a> y) |
---|
222 | 00255 { |
---|
223 | 00256 <a class="code" href="namespaceOgre.html#a455">uint32</a> r = <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee12">halfToFloatI</a>(y); |
---|
224 | 00257 <span class="keywordflow">return</span> *reinterpret_cast<float*>(&r); |
---|
225 | 00258 } |
---|
226 | <a name="l00262"></a><a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee12">00262</a> <span class="keyword">static</span> <span class="keyword">inline</span> <a class="code" href="namespaceOgre.html#a455">uint32</a> <a class="code" href="classOgre_1_1Bitwise.html#Ogre_1_1Bitwisee12">halfToFloatI</a>(<a class="code" href="namespaceOgre.html#a456">uint16</a> y) |
---|
227 | 00263 { |
---|
228 | 00264 <span class="keyword">register</span> <span class="keywordtype">int</span> s = (y >> 15) & 0x00000001; |
---|
229 | 00265 <span class="keyword">register</span> <span class="keywordtype">int</span> e = (y >> 10) & 0x0000001f; |
---|
230 | 00266 <span class="keyword">register</span> <span class="keywordtype">int</span> m = y & 0x000003ff; |
---|
231 | 00267 |
---|
232 | 00268 <span class="keywordflow">if</span> (e == 0) |
---|
233 | 00269 { |
---|
234 | 00270 <span class="keywordflow">if</span> (m == 0) <span class="comment">// Plus or minus zero</span> |
---|
235 | 00271 { |
---|
236 | 00272 <span class="keywordflow">return</span> s << 31; |
---|
237 | 00273 } |
---|
238 | 00274 <span class="keywordflow">else</span> <span class="comment">// Denormalized number -- renormalize it</span> |
---|
239 | 00275 { |
---|
240 | 00276 <span class="keywordflow">while</span> (!(m & 0x00000400)) |
---|
241 | 00277 { |
---|
242 | 00278 m <<= 1; |
---|
243 | 00279 e -= 1; |
---|
244 | 00280 } |
---|
245 | 00281 |
---|
246 | 00282 e += 1; |
---|
247 | 00283 m &= ~0x00000400; |
---|
248 | 00284 } |
---|
249 | 00285 } |
---|
250 | 00286 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (e == 31) |
---|
251 | 00287 { |
---|
252 | 00288 <span class="keywordflow">if</span> (m == 0) <span class="comment">// Inf</span> |
---|
253 | 00289 { |
---|
254 | 00290 <span class="keywordflow">return</span> (s << 31) | 0x7f800000; |
---|
255 | 00291 } |
---|
256 | 00292 <span class="keywordflow">else</span> <span class="comment">// NaN</span> |
---|
257 | 00293 { |
---|
258 | 00294 <span class="keywordflow">return</span> (s << 31) | 0x7f800000 | (m << 13); |
---|
259 | 00295 } |
---|
260 | 00296 } |
---|
261 | 00297 |
---|
262 | 00298 e = e + (127 - 15); |
---|
263 | 00299 m = m << 13; |
---|
264 | 00300 |
---|
265 | 00301 <span class="keywordflow">return</span> (s << 31) | (e << 23) | m; |
---|
266 | 00302 } |
---|
267 | 00303 |
---|
268 | 00304 |
---|
269 | 00305 }; |
---|
270 | 00306 } |
---|
271 | 00307 |
---|
272 | 00308 <span class="preprocessor">#endif</span> |
---|
273 | </pre></div><hr> |
---|
274 | <p> |
---|
275 | Copyright © 2000-2005 by The OGRE Team<br /> |
---|
276 | <!--Creative Commons License--><a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/"><img alt="Creative Commons License" border="0" src="http://creativecommons.org/images/public/somerights20.png"/></a><br/> |
---|
277 | This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/">Creative Commons Attribution-ShareAlike 2.5 License</a>.<br/> |
---|
278 | <!--/Creative Commons License--><!-- <rdf:RDF xmlns="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> |
---|
279 | <Work rdf:about=""> |
---|
280 | <license rdf:resource="http://creativecommons.org/licenses/by-sa/2.5/" /> |
---|
281 | <dc:type rdf:resource="http://purl.org/dc/dcmitype/Text" /> |
---|
282 | </Work> |
---|
283 | <License rdf:about="http://creativecommons.org/licenses/by-sa/2.5/"><permits rdf:resource="http://web.resource.org/cc/Reproduction"/><permits rdf:resource="http://web.resource.org/cc/Distribution"/><requires rdf:resource="http://web.resource.org/cc/Notice"/><requires rdf:resource="http://web.resource.org/cc/Attribution"/><permits rdf:resource="http://web.resource.org/cc/DerivativeWorks"/><requires rdf:resource="http://web.resource.org/cc/ShareAlike"/></License></rdf:RDF> --> |
---|
284 | |
---|
285 | Last modified Sun Mar 12 14:37:37 2006 |
---|
286 | </p> |
---|
287 | </body> |
---|
288 | </html> |
---|