hostsupport/hostopengles20/src/half.c
branchbug235_bringup_0
changeset 55 09263774e342
parent 53 c2ef9095503a
child 76 24381b61de5c
equal deleted inserted replaced
54:067180f57b12 55:09263774e342
       
     1 /* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2  *
       
     3  * Permission is hereby granted, free of charge, to any person obtaining a
       
     4  * copy of this software and associated documentation files (the "Software"),
       
     5  * to deal in the Software without restriction, including without limitation
       
     6  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
       
     7  * and/or sell copies of the Software, and to permit persons to whom the
       
     8  * Software is furnished to do so, subject to the following conditions:
       
     9  *
       
    10  * The above copyright notice and this permission notice shall be included
       
    11  * in all copies or substantial portions of the Software.
       
    12  *
       
    13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
       
    14  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
       
    15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
       
    16  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
       
    17  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
       
    18  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
       
    19  *
       
    20  * Initial Contributors:
       
    21  * Nokia Corporation - initial contribution.
       
    22  *
       
    23  * Contributors:
       
    24  *
       
    25  * Description:
       
    26  *
       
    27  */
       
    28 
       
    29 #include "half.h"
       
    30 
       
    31 GLfloat dglConvertHalfToFloat(khronos_int16_t half)
       
    32 {
       
    33 	// INF and NaN are mapped to floating point values.
       
    34 
       
    35 	khronos_int32_t exponent = half & 0x7c00;
       
    36 	khronos_int16_t mantissa = half & 0x03ff;
       
    37 	if(!exponent)
       
    38 	{
       
    39 		if(mantissa)
       
    40 		{
       
    41 			// Subnormals are mapped to zero.
       
    42 			mantissa = 0;
       
    43 		}
       
    44 	}
       
    45 	else
       
    46 	{
       
    47 		// Convert bias.
       
    48 		exponent += 0x1c000;
       
    49 	}
       
    50 
       
    51 	{
       
    52 		khronos_int32_t conv = ((half & 0x8000) << 16) |
       
    53 							   (exponent << 13) |
       
    54 							   (mantissa << 13);
       
    55 		return *(GLfloat*)&conv;
       
    56 	}
       
    57 }