svgtopt/nvgdecoder/inc/FloatFixPt.h
changeset 46 88edb906c587
equal deleted inserted replaced
-1:000000000000 46:88edb906c587
       
     1 /*
       
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  NVG Decoder header file
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef NVGFLOATFIX_H_
       
    19 #define NVGFLOATFIX_H_
       
    20 
       
    21 #include <e32def.h>
       
    22 #include <s32mem.h>
       
    23 
       
    24 const TInt32 KFixPtFrac = 16;
       
    25 const TInt32 KFixPtFracVal = (1 << KFixPtFrac);
       
    26 #   define svgFloatBits(f) (*(int*)&f)
       
    27 
       
    28 inline int svgScalarFromFloat(float f)
       
    29     {
       
    30     int a;
       
    31     int sign;
       
    32     int exponent;
       
    33     
       
    34     int r;
       
    35     
       
    36     
       
    37     a           = svgFloatBits(f);
       
    38     sign        = a >> 31;
       
    39     exponent    = (127 + 15) - ((a >> 23) & 0xff);
       
    40     
       
    41     r = (int)((((int)(a) << 8) | (1U << 31)) >> exponent);
       
    42     r &= ((exponent - 32) >> 31);
       
    43     
       
    44     r = (r ^ sign) - sign;
       
    45     
       
    46     return r;
       
    47     
       
    48     }
       
    49 class TFloatFixPt
       
    50     {
       
    51     public:
       
    52         
       
    53         /**
       
    54          * Construct a TFixPt.  The default value is 0.0.
       
    55          *
       
    56          * @since 1.0
       
    57          * @return
       
    58          */
       
    59         TFloatFixPt();
       
    60 
       
    61         /**
       
    62          * Construct a TFixPt from the given integer value.
       
    63          *
       
    64          * @since 1.0
       
    65          * @param aVal : integer value
       
    66          * @return
       
    67          */
       
    68         TFloatFixPt(TInt aVal);
       
    69         TFloatFixPt(TInt32 aVal);
       
    70         TFloatFixPt(TReal32 aVal);
       
    71         TFloatFixPt(TInt aVal, TBool aBool);
       
    72         TFloatFixPt&   operator=(TReal32 aVal);
       
    73         TFloatFixPt           operator+(const TFloatFixPt& aVal) const;
       
    74         operator TReal32() const;
       
    75         TInt32           Round();
       
    76         TInt32           RawData();
       
    77         void copyfloatfix(TInt aVal);
       
    78     public:
       
    79         TInt                    iValue;    // Must be the first data member of this class!
       
    80         
       
    81     };
       
    82 
       
    83 #endif
       
    84