00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 #ifndef MANIP_H
00014 #define MANIP_H
00015 
00016 #ifdef _cplusplus
00017 extern "C" {
00018 #endif
00019 
00020 ILboolean ilFlipImage(void);
00021 ILboolean ilMirrorImage(void);  
00022 
00023 
00024 
00025 
00026 
00027 
00028 #ifndef NOINLINE
00029 
00030 #if defined(_MSC_VER)
00031         #pragma warning(push)
00032         #pragma warning(disable : 4756)  // Disables 'named type definition in parentheses' warning
00033 #endif
00034 INLINE ILfloat  ilFloatToHalfOverflow() {
00035         ILfloat f = 1e10;
00036         ILint j;
00037         for (j = 0; j < 10; j++)
00038                 f *= f;                         
00039         
00040         return f;
00041 }
00042 #if defined(_MSC_VER)
00043         #pragma warning(pop)
00044 #endif
00045 
00046 
00047 
00048 
00049 
00050 INLINE ILushort ILAPIENTRY ilFloatToHalf(ILuint i) {
00051         
00052         
00053         
00054         
00055         
00056         
00057         
00058         
00059         
00060 
00061         register int s =  (i >> 16) & 0x00008000;
00062         register int e = ((i >> 23) & 0x000000ff) - (127 - 15);
00063         register int m =   i        & 0x007fffff;
00064 
00065         
00066         
00067         
00068 
00069         if (e <= 0)
00070         {
00071                 if (e < -10)
00072                 {
00073                         
00074                         
00075                         
00076                         
00077                         
00078                         
00079                         
00080 
00081                         return 0;
00082                 }
00083 
00084                 
00085                 
00086                 
00087                 
00088                 
00089                 
00090 
00091                 m = (m | 0x00800000) >> (1 - e);
00092 
00093                 
00094                 
00095                 
00096                 
00097                 
00098                 
00099                 
00100                 
00101 
00102                 if (m &  0x00001000)
00103                         m += 0x00002000;
00104 
00105                 
00106                 
00107                 
00108 
00109                 return s | (m >> 13);
00110         }
00111         else if (e == 0xff - (127 - 15))
00112         {
00113                 if (m == 0)
00114                 {
00115                         
00116                         
00117                         
00118                         
00119 
00120                         return s | 0x7c00;
00121                 }
00122                 else
00123                 {
00124                         
00125                         
00126                         
00127                         
00128                         
00129                         
00130                         
00131                         
00132 
00133                         m >>= 13;
00134                         return s | 0x7c00 | m | (m == 0);
00135                 }
00136         }
00137         else
00138         {
00139                 
00140                 
00141                 
00142                 
00143 
00144                 
00145                 
00146                 
00147 
00148                 if (m &  0x00001000)
00149                 {
00150                         m += 0x00002000;
00151 
00152                         if (m & 0x00800000)
00153                         {
00154                                 m =  0;         
00155                                 e += 1;         
00156                         }
00157                 }
00158 
00159                 
00160                 
00161                 
00162 
00163                 if (e > 30)
00164                 {
00165                         ilFloatToHalfOverflow();        
00166                         return s | 0x7c00;      
00167                 }                       
00168 
00169                 
00170                 
00171                 
00172 
00173                 return s | (e << 10) | (m >> 13);
00174         }
00175 }
00176 
00177 
00178 INLINE ILuint ILAPIENTRY ilHalfToFloat (ILushort y) {
00179 
00180         int s = (y >> 15) & 0x00000001;
00181         int e = (y >> 10) & 0x0000001f;
00182         int m =  y                & 0x000003ff;
00183 
00184         if (e == 0)
00185         {
00186                 if (m == 0)
00187                 {
00188                         
00189                         
00190                         
00191 
00192                         return s << 31;
00193                 }
00194                 else
00195                 {
00196                         
00197                         
00198                         
00199 
00200                         while (!(m & 0x00000400))
00201                         {
00202                                 m <<= 1;
00203                                 e -=  1;
00204                         }
00205 
00206                         e += 1;
00207                         m &= ~0x00000400;
00208                 }
00209         }
00210         else if (e == 31)
00211         {
00212                 if (m == 0)
00213                 {
00214                         
00215                         
00216                         
00217 
00218                         return (s << 31) | 0x7f800000;
00219                 }
00220                 else
00221                 {
00222                         
00223                         
00224                         
00225 
00226                         return (s << 31) | 0x7f800000 | (m << 13);
00227                 }
00228         }
00229 
00230         
00231         
00232         
00233 
00234         e = e + (127 - 15);
00235         m = m << 13;
00236 
00237         
00238         
00239         
00240 
00241         return (s << 31) | (e << 23) | m;
00242 }
00243 #endif //NOINLINE
00244 
00245 #ifdef _cplusplus
00246 }
00247 #endif
00248 
00249 #endif//MANIP_H