examples/Multimedia/ICL/ICLCodec/ImageUtils.h

00001 //
00002 // ImageUtils.h
00003 //
00004 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
00005 // All rights reserved.
00006 // This component and the accompanying materials are made available
00007 // under the terms of "Eclipse Public License v1.0"
00008 // which accompanies this distribution, and is available
00009 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00010 //
00011 // Initial Contributors:
00012 // Nokia Corporation - initial contribution.
00013 //
00014 // Contributors:
00015 //
00016 // Description:
00017 //
00018 //
00019 
00020 #ifndef __ImageUtils_h
00021 #define __ImageUtils_h
00022 
00023 
00024 //
00025 // PtrReadUtil - utility class with methods for standard 
00026 // reading data from a TUint8* string
00027 //
00028 
00029 class PtrReadUtil
00030         {
00031 public:
00032         // This calls decode from TUint8*
00033         static TInt8 ReadInt8(const TUint8* aPtr);
00034         static TUint8 ReadUint8(const TUint8* aPtr);
00035         static TInt16 ReadInt16(const TUint8* aPtr);
00036         static TInt16 ReadBigEndianInt16(const TUint8* aPtr);
00037         static TUint16 ReadUint16(const TUint8* aPtr);
00038         static TUint16 ReadBigEndianUint16(const TUint8* aPtr);
00039         static TInt32 ReadInt32(const TUint8* aPtr);
00040         static TInt32 ReadBigEndianInt32(const TUint8* aPtr);
00041         static TUint32 ReadUint32(const TUint8* aPtr);
00042         static TUint32 ReadBigEndianUint32(const TUint8* aPtr);
00043         // these calls also increment the pointer
00044         static TInt8 ReadInt8Inc(const TUint8*& aPtr);
00045         static TUint8 ReadUint8Inc(const TUint8*& aPtr);
00046         static TInt16 ReadInt16Inc(const TUint8*& aPtr);
00047         static TInt16 ReadBigEndianInt16Inc(const TUint8*& aPtr);
00048         static TUint16 ReadUint16Inc(const TUint8*& aPtr);
00049         static TUint16 ReadBigEndianUint16Inc(const TUint8*& aPtr);
00050         static TInt32 ReadInt32Inc(const TUint8*& aPtr);
00051         static TInt32 ReadBigEndianInt32Inc(const TUint8*& aPtr);
00052         static TUint32 ReadUint32Inc(const TUint8*& aPtr);
00053         static TUint32 ReadBigEndianUint32Inc(const TUint8*& aPtr);
00054         };
00055 
00056 inline TUint8 PtrReadUtil::ReadUint8(const TUint8* aPtr)
00057         {
00058         return *aPtr ;
00059         }
00060 
00061 inline TInt8 PtrReadUtil::ReadInt8(const TUint8* aPtr)
00062         {
00063         return TInt8(ReadUint8(aPtr));
00064         }
00065 
00066 inline TUint16 PtrReadUtil::ReadUint16(const TUint8* aPtr)
00067         {
00068         return TUint16(aPtr[0] | (aPtr[1]<<8));
00069         }
00070 
00071 inline TInt16 PtrReadUtil::ReadInt16(const TUint8* aPtr)
00072         {
00073         return TInt16(ReadUint16(aPtr));
00074         }
00075 
00076 inline TUint32 PtrReadUtil::ReadUint32(const TUint8* aPtr)
00077         {
00078         return TUint32(aPtr[0] | (aPtr[1]<<8) | (aPtr[2]<<16) | (aPtr[3]<<24));
00079         }
00080 
00081 inline TInt32 PtrReadUtil::ReadInt32(const TUint8* aPtr)
00082         {
00083         return TInt32(ReadUint32(aPtr));
00084         }
00085 
00086 inline TUint16 PtrReadUtil::ReadBigEndianUint16(const TUint8* aPtr)
00087         {
00088         return TUint16((aPtr[0]<<8) | aPtr[1]);
00089         }
00090 
00091 inline TInt16 PtrReadUtil::ReadBigEndianInt16(const TUint8* aPtr)
00092         {
00093         return TInt16(ReadBigEndianInt16(aPtr));
00094         }
00095 
00096 inline TUint32 PtrReadUtil::ReadBigEndianUint32(const TUint8* aPtr)
00097         {
00098         return TUint32((aPtr[0]<<24) | (aPtr[1]<<16) | (aPtr[2]<<8) | aPtr[3]);
00099         }
00100 
00101 inline TInt32 PtrReadUtil::ReadBigEndianInt32(const TUint8* aPtr)
00102         {
00103         return TInt32(ReadBigEndianInt32(aPtr));
00104         }
00105 
00106 inline TInt8 PtrReadUtil::ReadInt8Inc(const TUint8*& aPtr)
00107         {
00108         TInt8 result = ReadInt8(aPtr);
00109         aPtr += 1;
00110         return result;
00111         }
00112 
00113 inline TUint8 PtrReadUtil::ReadUint8Inc(const TUint8*& aPtr)
00114         {
00115         TUint8 result = ReadUint8(aPtr);
00116         aPtr += 1;
00117         return result;
00118         }
00119 
00120 inline TInt16 PtrReadUtil::ReadInt16Inc(const TUint8*& aPtr)
00121         {
00122         TInt16 result = ReadInt16(aPtr);
00123         aPtr += 2;
00124         return result;
00125         }
00126 
00127 inline TUint16 PtrReadUtil::ReadUint16Inc(const TUint8*& aPtr)
00128         {
00129         TUint16 result = ReadUint16(aPtr);
00130         aPtr += 2;
00131         return result;
00132         }
00133 
00134 inline TInt16 PtrReadUtil::ReadBigEndianInt16Inc(const TUint8*& aPtr)
00135         {
00136         TInt16 result = ReadBigEndianInt16(aPtr);
00137         aPtr += 2;
00138         return result;
00139         }
00140 
00141 inline TUint16 PtrReadUtil::ReadBigEndianUint16Inc(const TUint8*& aPtr)
00142         {
00143         TUint16 result = ReadBigEndianUint16(aPtr);
00144         aPtr += 2;
00145         return result;
00146         }
00147 
00148 inline TInt32 PtrReadUtil::ReadInt32Inc(const TUint8*& aPtr)
00149         {
00150         TInt32 result = ReadInt32(aPtr);
00151         aPtr += 4;
00152         return result;
00153         }
00154 
00155 inline TUint32 PtrReadUtil::ReadUint32Inc(const TUint8*& aPtr)
00156         {
00157         TUint32 result = ReadUint32(aPtr);
00158         aPtr += 4;
00159         return result;
00160         }
00161 
00162 inline TInt32 PtrReadUtil::ReadBigEndianInt32Inc(const TUint8*& aPtr)
00163         {
00164         TInt32 result = ReadBigEndianInt32(aPtr);
00165         aPtr += 4;
00166         return result;
00167         }
00168 
00169 inline TUint32 PtrReadUtil::ReadBigEndianUint32Inc(const TUint8*& aPtr)
00170         {
00171         TUint32 result = ReadBigEndianUint32(aPtr);
00172         aPtr += 4;
00173         return result;
00174         }
00175 
00176 class PtrWriteUtil
00177         {
00178 public:
00179         static void WriteInt8(TUint8* aPtr, TInt aData);
00180         static void WriteInt16(TUint8* aPtr, TInt aData);
00181         static void WriteInt32(TUint8* aPtr, TInt aData);
00182         // Big endian version
00183         static void WriteBigEndianInt32(TUint8* aPtr, TInt32 aData);
00184         };
00185 
00186 inline void PtrWriteUtil::WriteInt8(TUint8* aPtr, TInt aData)
00187         {
00188         aPtr[0] = TUint8(aData);
00189         }
00190 
00191 inline void PtrWriteUtil::WriteInt16(TUint8* aPtr, TInt aData)
00192         {
00193         aPtr[0] = TUint8(aData);
00194         aPtr[1] = TUint8(aData>>8);
00195         }
00196 
00197 inline void PtrWriteUtil::WriteInt32(TUint8* aPtr, TInt aData)
00198         {
00199         aPtr[0] = TUint8(aData);
00200         aPtr[1] = TUint8(aData>>8);
00201         aPtr[2] = TUint8(aData>>16);
00202         aPtr[3] = TUint8(aData>>24);
00203         }
00204 
00205 inline void PtrWriteUtil::WriteBigEndianInt32(TUint8* aPtr, TInt32 aData)
00206         {
00207         aPtr[0] = TUint8(aData>>24);
00208         aPtr[1] = TUint8(aData>>16);
00209         aPtr[2] = TUint8(aData>>8);
00210         aPtr[3] = TUint8(aData);
00211         }
00212 
00213 #endif // __ImageUtils_h

Generated by  doxygen 1.6.2