src/hbcore/svgext/hbnvgdecoder/hbnvgicondata.cpp
changeset 0 16d8024aca5e
child 1 f7ac710697a9
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbCore module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include "hbnvgicondata_p.h"
       
    27 
       
    28 HbNvgIconData::HbNvgIconData(uint length)
       
    29         : mNvgData(0),
       
    30         totalRead(0),
       
    31         readStream(0)
       
    32 {
       
    33     mNvgData = new QByteArray(NULL , length);
       
    34     Q_CHECK_PTR(mNvgData);
       
    35 }
       
    36 
       
    37 HbNvgIconData::HbNvgIconData(const QByteArray &buffer)
       
    38         : mNvgData(0),
       
    39         totalRead(0),
       
    40         readStream(0)
       
    41 {
       
    42     mNvgData = new QByteArray(buffer);
       
    43     Q_CHECK_PTR(mNvgData);
       
    44     dataSize = mNvgData->length();
       
    45     
       
    46     //set the reading pointers
       
    47     beginRead();
       
    48 }
       
    49 
       
    50 HbNvgIconData::~HbNvgIconData()
       
    51 {
       
    52     delete mNvgData;
       
    53 }
       
    54 
       
    55 int HbNvgIconData::encodeData(const void *data, quint32 length)
       
    56 {    
       
    57     mNvgData->append((const char*)data , length);
       
    58     return (int)HbNvgEngine::NvgErrNone; //in error case, exception will be thrown 
       
    59 }
       
    60 
       
    61 void HbNvgIconData::beginRead()
       
    62 {
       
    63     dataSize = mNvgData->length();
       
    64     totalRead = 0;
       
    65     readStream = (quint8 *)mNvgData->data();
       
    66 }
       
    67 
       
    68 void HbNvgIconData::endRead()
       
    69 {
       
    70 }
       
    71 
       
    72 #define STR_TO_OTHER_DIR(TOTYPE) do {\
       
    73                                 TOTYPE data = *(TOTYPE *)&readStream[totalRead];\
       
    74                                 totalRead += sizeof(TOTYPE);\
       
    75                                 return data;\
       
    76                            } while (0)
       
    77 
       
    78 
       
    79 #define STR_TO_OTHER_IDIR(TOTYPE) do {\
       
    80                                 TOTYPE data;\
       
    81                                 quint8 * dataPtr = (quint8 *)&data;\
       
    82                                 for (int i = 0; i < sizeof(TOTYPE); ++i)\
       
    83                                     {\
       
    84                                     dataPtr[i] = readStream[totalRead+i];\
       
    85                                     }\
       
    86                                 totalRead += sizeof(TOTYPE);\
       
    87                                 return data;\
       
    88                             } while (0)
       
    89 
       
    90 #define STR_TO_OTHER(TOTYPE) do {\
       
    91                                 checkOutOfBound(sizeof(TOTYPE));\
       
    92                                 if (reinterpret_cast<int>(&readStream[totalRead]) & (sizeof(TOTYPE) - 1))\
       
    93                                     {\
       
    94                                     STR_TO_OTHER_IDIR(TOTYPE);\
       
    95                                     }\
       
    96                                 else\
       
    97                                     {\
       
    98                                     STR_TO_OTHER_DIR(TOTYPE);\
       
    99                                     }\
       
   100                             } while (0)
       
   101 
       
   102 qint16 HbNvgIconData::readInt16()
       
   103 {
       
   104     STR_TO_OTHER(qint16);
       
   105 }
       
   106 
       
   107 qint32 HbNvgIconData::readInt32()
       
   108 {
       
   109     STR_TO_OTHER(qint32);
       
   110 }
       
   111 
       
   112 qint8 HbNvgIconData::readInt8()
       
   113 {
       
   114     STR_TO_OTHER_DIR(qint8);
       
   115 }
       
   116 
       
   117 float HbNvgIconData::readReal32()
       
   118 {
       
   119     STR_TO_OTHER(float);
       
   120 }
       
   121 
       
   122 qreal HbNvgIconData::readReal64()
       
   123 {
       
   124     checkOutOfBound(sizeof(qreal));
       
   125     STR_TO_OTHER(qreal);
       
   126 }
       
   127 
       
   128 void HbNvgIconData::read(quint8 *ptr, int length)
       
   129 {
       
   130 	checkOutOfBound(length);
       
   131     memcpy(ptr, &readStream[totalRead], length);
       
   132     totalRead += length;
       
   133 }
       
   134 
       
   135 void HbNvgIconData::skip(int length)
       
   136 {
       
   137     checkOutOfBound(length);
       
   138     totalRead += length;
       
   139 }