crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianStructuresLib/Compression/Common/SymbianDecompressor.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 
       
     2 /*
       
     3 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     4 * All rights reserved.
       
     5 * This component and the accompanying materials are made available
       
     6 * under the terms of "Eclipse Public License v1.0"
       
     7 * which accompanies this distribution, and is available
       
     8 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 *
       
    10 * Initial Contributors:
       
    11 * Nokia Corporation - initial contribution.
       
    12 *
       
    13 * Contributors:
       
    14 * 
       
    15 * Description:
       
    16 *
       
    17 */
       
    18 using System;
       
    19 using System.Collections.Generic;
       
    20 using System.Text;
       
    21 using System.IO;
       
    22 using System.Runtime.InteropServices;
       
    23 using SymbianUtils;
       
    24 using SymbianStructuresLib.Compression.BytePair;
       
    25 using SymbianStructuresLib.Compression.Inflate;
       
    26 
       
    27 namespace SymbianStructuresLib.Compression.Common
       
    28 {
       
    29     public abstract class SymbianDecompressor : DisposableObject
       
    30     {
       
    31         #region Factory
       
    32         public static SymbianDecompressor NewByType( TSymbianCompressionType aType )
       
    33         {
       
    34             SymbianDecompressor ret = null;
       
    35             //
       
    36             switch ( aType )
       
    37             {
       
    38             case TSymbianCompressionType.EBytePair:
       
    39                 ret = new SymbianDecompressorBytePair();
       
    40                 break;
       
    41             case TSymbianCompressionType.EDeflate:
       
    42                 ret = new SymbianDecompressorInflate();
       
    43                 break;
       
    44             }
       
    45             //
       
    46             return ret;
       
    47         }
       
    48         #endregion
       
    49 
       
    50         #region Constructors
       
    51         protected SymbianDecompressor()
       
    52         {
       
    53         }
       
    54         #endregion
       
    55 
       
    56         #region Framework API
       
    57         public abstract TSymbianCompressionType Type
       
    58         {
       
    59             get;
       
    60         }
       
    61 
       
    62         protected abstract int DoDecompressRaw( IntPtr aSource, int aSourceLength, IntPtr aDestination, int aDestinationLength );
       
    63 
       
    64         protected virtual int DoDecompressImage( IntPtr aSource, int aSourceLength, IntPtr aDestination, int aDestinationLength, out int aAmountOfSourceRead )
       
    65         {
       
    66             throw new NotImplementedException();
       
    67         }
       
    68         #endregion
       
    69 
       
    70         #region API
       
    71         public int DecompressRaw( byte[] aSource, byte[] aDestination )
       
    72         {
       
    73             if ( aSource == null || aDestination == null )
       
    74             {
       
    75                 throw new ArgumentException( "Must supply data buffers" );
       
    76             }
       
    77             //
       
    78             int ret = 0;
       
    79             //
       
    80             unsafe
       
    81             {
       
    82                 fixed ( byte* source = aSource )
       
    83                 {
       
    84                     fixed ( byte* dest = aDestination )
       
    85                     {
       
    86                         IntPtr pSource = new IntPtr( source );
       
    87                         IntPtr pDest = new IntPtr( dest );
       
    88                         //
       
    89                         ret = DoDecompressRaw( pSource, aSource.Length, pDest, aDestination.Length );
       
    90                     }
       
    91                 }
       
    92             }
       
    93             //
       
    94             return ret;
       
    95         }
       
    96 
       
    97         public int DecompressImage( byte[] aSource, byte[] aDestination, out int aAmountOfSourceRead )
       
    98         {
       
    99             if ( aSource == null || aDestination == null )
       
   100             {
       
   101                 throw new ArgumentException( "Must supply data buffers" );
       
   102             }
       
   103             //
       
   104             int ret = 0;
       
   105             //
       
   106             unsafe
       
   107             {
       
   108                 fixed ( byte* source = aSource )
       
   109                 {
       
   110                     fixed ( byte* dest = aDestination )
       
   111                     {
       
   112                         IntPtr pSource = new IntPtr( source );
       
   113                         IntPtr pDest = new IntPtr( dest );
       
   114                         //
       
   115                         ret = DoDecompressImage( pSource, aSource.Length, pDest, aDestination.Length, out aAmountOfSourceRead );
       
   116                     }
       
   117                 }
       
   118             }
       
   119             //
       
   120             return ret;
       
   121         }
       
   122         #endregion
       
   123 
       
   124         #region Properties
       
   125         #endregion
       
   126 
       
   127         #region Internal methods
       
   128         #endregion
       
   129 
       
   130         #region Data members
       
   131         #endregion
       
   132     }
       
   133 }