examples/Multimedia/ICL/ICLCodec/ImageUtils.h

00001 /*
00002 Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 
00031 #ifndef __ImageUtils_h
00032 #define __ImageUtils_h
00033 
00034 
00035 //
00036 // PtrReadUtil - utility class with methods for standard 
00037 // reading data from a TUint8* string
00038 //
00039 
00040 class PtrReadUtil
00041         {
00042 public:
00043         // This calls decode from TUint8*
00044         static TInt8 ReadInt8(const TUint8* aPtr);
00045         static TUint8 ReadUint8(const TUint8* aPtr);
00046         static TInt16 ReadInt16(const TUint8* aPtr);
00047         static TInt16 ReadBigEndianInt16(const TUint8* aPtr);
00048         static TUint16 ReadUint16(const TUint8* aPtr);
00049         static TUint16 ReadBigEndianUint16(const TUint8* aPtr);
00050         static TInt32 ReadInt32(const TUint8* aPtr);
00051         static TInt32 ReadBigEndianInt32(const TUint8* aPtr);
00052         static TUint32 ReadUint32(const TUint8* aPtr);
00053         static TUint32 ReadBigEndianUint32(const TUint8* aPtr);
00054         // these calls also increment the pointer
00055         static TInt8 ReadInt8Inc(const TUint8*& aPtr);
00056         static TUint8 ReadUint8Inc(const TUint8*& aPtr);
00057         static TInt16 ReadInt16Inc(const TUint8*& aPtr);
00058         static TInt16 ReadBigEndianInt16Inc(const TUint8*& aPtr);
00059         static TUint16 ReadUint16Inc(const TUint8*& aPtr);
00060         static TUint16 ReadBigEndianUint16Inc(const TUint8*& aPtr);
00061         static TInt32 ReadInt32Inc(const TUint8*& aPtr);
00062         static TInt32 ReadBigEndianInt32Inc(const TUint8*& aPtr);
00063         static TUint32 ReadUint32Inc(const TUint8*& aPtr);
00064         static TUint32 ReadBigEndianUint32Inc(const TUint8*& aPtr);
00065         };
00066 
00067 inline TUint8 PtrReadUtil::ReadUint8(const TUint8* aPtr)
00068         {
00069         return *aPtr ;
00070         }
00071 
00072 inline TInt8 PtrReadUtil::ReadInt8(const TUint8* aPtr)
00073         {
00074         return TInt8(ReadUint8(aPtr));
00075         }
00076 
00077 inline TUint16 PtrReadUtil::ReadUint16(const TUint8* aPtr)
00078         {
00079         return TUint16(aPtr[0] | (aPtr[1]<<8));
00080         }
00081 
00082 inline TInt16 PtrReadUtil::ReadInt16(const TUint8* aPtr)
00083         {
00084         return TInt16(ReadUint16(aPtr));
00085         }
00086 
00087 inline TUint32 PtrReadUtil::ReadUint32(const TUint8* aPtr)
00088         {
00089         return TUint32(aPtr[0] | (aPtr[1]<<8) | (aPtr[2]<<16) | (aPtr[3]<<24));
00090         }
00091 
00092 inline TInt32 PtrReadUtil::ReadInt32(const TUint8* aPtr)
00093         {
00094         return TInt32(ReadUint32(aPtr));
00095         }
00096 
00097 inline TUint16 PtrReadUtil::ReadBigEndianUint16(const TUint8* aPtr)
00098         {
00099         return TUint16((aPtr[0]<<8) | aPtr[1]);
00100         }
00101 
00102 inline TInt16 PtrReadUtil::ReadBigEndianInt16(const TUint8* aPtr)
00103         {
00104         return TInt16(ReadBigEndianInt16(aPtr));
00105         }
00106 
00107 inline TUint32 PtrReadUtil::ReadBigEndianUint32(const TUint8* aPtr)
00108         {
00109         return TUint32((aPtr[0]<<24) | (aPtr[1]<<16) | (aPtr[2]<<8) | aPtr[3]);
00110         }
00111 
00112 inline TInt32 PtrReadUtil::ReadBigEndianInt32(const TUint8* aPtr)
00113         {
00114         return TInt32(ReadBigEndianInt32(aPtr));
00115         }
00116 
00117 inline TInt8 PtrReadUtil::ReadInt8Inc(const TUint8*& aPtr)
00118         {
00119         TInt8 result = ReadInt8(aPtr);
00120         aPtr += 1;
00121         return result;
00122         }
00123 
00124 inline TUint8 PtrReadUtil::ReadUint8Inc(const TUint8*& aPtr)
00125         {
00126         TUint8 result = ReadUint8(aPtr);
00127         aPtr += 1;
00128         return result;
00129         }
00130 
00131 inline TInt16 PtrReadUtil::ReadInt16Inc(const TUint8*& aPtr)
00132         {
00133         TInt16 result = ReadInt16(aPtr);
00134         aPtr += 2;
00135         return result;
00136         }
00137 
00138 inline TUint16 PtrReadUtil::ReadUint16Inc(const TUint8*& aPtr)
00139         {
00140         TUint16 result = ReadUint16(aPtr);
00141         aPtr += 2;
00142         return result;
00143         }
00144 
00145 inline TInt16 PtrReadUtil::ReadBigEndianInt16Inc(const TUint8*& aPtr)
00146         {
00147         TInt16 result = ReadBigEndianInt16(aPtr);
00148         aPtr += 2;
00149         return result;
00150         }
00151 
00152 inline TUint16 PtrReadUtil::ReadBigEndianUint16Inc(const TUint8*& aPtr)
00153         {
00154         TUint16 result = ReadBigEndianUint16(aPtr);
00155         aPtr += 2;
00156         return result;
00157         }
00158 
00159 inline TInt32 PtrReadUtil::ReadInt32Inc(const TUint8*& aPtr)
00160         {
00161         TInt32 result = ReadInt32(aPtr);
00162         aPtr += 4;
00163         return result;
00164         }
00165 
00166 inline TUint32 PtrReadUtil::ReadUint32Inc(const TUint8*& aPtr)
00167         {
00168         TUint32 result = ReadUint32(aPtr);
00169         aPtr += 4;
00170         return result;
00171         }
00172 
00173 inline TInt32 PtrReadUtil::ReadBigEndianInt32Inc(const TUint8*& aPtr)
00174         {
00175         TInt32 result = ReadBigEndianInt32(aPtr);
00176         aPtr += 4;
00177         return result;
00178         }
00179 
00180 inline TUint32 PtrReadUtil::ReadBigEndianUint32Inc(const TUint8*& aPtr)
00181         {
00182         TUint32 result = ReadBigEndianUint32(aPtr);
00183         aPtr += 4;
00184         return result;
00185         }
00186 
00187 class PtrWriteUtil
00188         {
00189 public:
00190         static void WriteInt8(TUint8* aPtr, TInt aData);
00191         static void WriteInt16(TUint8* aPtr, TInt aData);
00192         static void WriteInt32(TUint8* aPtr, TInt aData);
00193         // Big endian version
00194         static void WriteBigEndianInt32(TUint8* aPtr, TInt32 aData);
00195         };
00196 
00197 inline void PtrWriteUtil::WriteInt8(TUint8* aPtr, TInt aData)
00198         {
00199         aPtr[0] = TUint8(aData);
00200         }
00201 
00202 inline void PtrWriteUtil::WriteInt16(TUint8* aPtr, TInt aData)
00203         {
00204         aPtr[0] = TUint8(aData);
00205         aPtr[1] = TUint8(aData>>8);
00206         }
00207 
00208 inline void PtrWriteUtil::WriteInt32(TUint8* aPtr, TInt aData)
00209         {
00210         aPtr[0] = TUint8(aData);
00211         aPtr[1] = TUint8(aData>>8);
00212         aPtr[2] = TUint8(aData>>16);
00213         aPtr[3] = TUint8(aData>>24);
00214         }
00215 
00216 inline void PtrWriteUtil::WriteBigEndianInt32(TUint8* aPtr, TInt32 aData)
00217         {
00218         aPtr[0] = TUint8(aData>>24);
00219         aPtr[1] = TUint8(aData>>16);
00220         aPtr[2] = TUint8(aData>>8);
00221         aPtr[3] = TUint8(aData);
00222         }
00223 
00224 #endif // __ImageUtils_h

Generated by  doxygen 1.6.2