misc/libphysfs/lzma/CPP/7zip/Archive/Common/CoderMixer2.h
branchui-scaling
changeset 15283 c4fd2813b127
parent 13390 0135e64c6c66
parent 15279 7ab5cf405686
child 15663 d92eeb468dad
equal deleted inserted replaced
13390:0135e64c6c66 15283:c4fd2813b127
     1 // CoderMixer2.h
       
     2 
       
     3 #ifndef __CODER_MIXER2_H
       
     4 #define __CODER_MIXER2_H
       
     5 
       
     6 #include "../../../Common/MyVector.h"
       
     7 #include "../../../Common/Types.h"
       
     8 #include "../../../Common/MyCom.h"
       
     9 #include "../../ICoder.h"
       
    10 
       
    11 namespace NCoderMixer {
       
    12 
       
    13 struct CBindPair
       
    14 {
       
    15   UInt32 InIndex;
       
    16   UInt32 OutIndex;
       
    17 };
       
    18 
       
    19 struct CCoderStreamsInfo
       
    20 {
       
    21   UInt32 NumInStreams;
       
    22   UInt32 NumOutStreams;
       
    23 };
       
    24 
       
    25 struct CBindInfo
       
    26 {
       
    27   CRecordVector<CCoderStreamsInfo> Coders;
       
    28   CRecordVector<CBindPair> BindPairs;
       
    29   CRecordVector<UInt32> InStreams;
       
    30   CRecordVector<UInt32> OutStreams;
       
    31 
       
    32   void Clear()
       
    33   {
       
    34     Coders.Clear();
       
    35     BindPairs.Clear();
       
    36     InStreams.Clear();
       
    37     OutStreams.Clear();
       
    38   }
       
    39 
       
    40   /*
       
    41   UInt32 GetCoderStartOutStream(UInt32 coderIndex) const
       
    42   {
       
    43     UInt32 numOutStreams = 0;
       
    44     for (UInt32 i = 0; i < coderIndex; i++)
       
    45       numOutStreams += Coders[i].NumOutStreams;
       
    46     return numOutStreams;
       
    47   }
       
    48   */
       
    49 
       
    50 
       
    51   void GetNumStreams(UInt32 &numInStreams, UInt32 &numOutStreams) const
       
    52   {
       
    53     numInStreams = 0;
       
    54     numOutStreams = 0;
       
    55     for (int i = 0; i < Coders.Size(); i++)
       
    56     {
       
    57       const CCoderStreamsInfo &coderStreamsInfo = Coders[i];
       
    58       numInStreams += coderStreamsInfo.NumInStreams;
       
    59       numOutStreams += coderStreamsInfo.NumOutStreams;
       
    60     }
       
    61   }
       
    62 
       
    63   int FindBinderForInStream(UInt32 inStream) const
       
    64   {
       
    65     for (int i = 0; i < BindPairs.Size(); i++)
       
    66       if (BindPairs[i].InIndex == inStream)
       
    67         return i;
       
    68     return -1;
       
    69   }
       
    70   int FindBinderForOutStream(UInt32 outStream) const
       
    71   {
       
    72     for (int i = 0; i < BindPairs.Size(); i++)
       
    73       if (BindPairs[i].OutIndex == outStream)
       
    74         return i;
       
    75     return -1;
       
    76   }
       
    77 
       
    78   UInt32 GetCoderInStreamIndex(UInt32 coderIndex) const
       
    79   {
       
    80     UInt32 streamIndex = 0;
       
    81     for (UInt32 i = 0; i < coderIndex; i++)
       
    82       streamIndex += Coders[i].NumInStreams;
       
    83     return streamIndex;
       
    84   }
       
    85 
       
    86   UInt32 GetCoderOutStreamIndex(UInt32 coderIndex) const
       
    87   {
       
    88     UInt32 streamIndex = 0;
       
    89     for (UInt32 i = 0; i < coderIndex; i++)
       
    90       streamIndex += Coders[i].NumOutStreams;
       
    91     return streamIndex;
       
    92   }
       
    93 
       
    94 
       
    95   void FindInStream(UInt32 streamIndex, UInt32 &coderIndex, 
       
    96       UInt32 &coderStreamIndex) const
       
    97   {
       
    98     for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)
       
    99     {
       
   100       UInt32 curSize = Coders[coderIndex].NumInStreams;
       
   101       if (streamIndex < curSize)
       
   102       {
       
   103         coderStreamIndex = streamIndex;
       
   104         return;
       
   105       }
       
   106       streamIndex -= curSize;
       
   107     }
       
   108     throw 1;
       
   109   }
       
   110   void FindOutStream(UInt32 streamIndex, UInt32 &coderIndex, 
       
   111       UInt32 &coderStreamIndex) const
       
   112   {
       
   113     for (coderIndex = 0; coderIndex < (UInt32)Coders.Size(); coderIndex++)
       
   114     {
       
   115       UInt32 curSize = Coders[coderIndex].NumOutStreams;
       
   116       if (streamIndex < curSize)
       
   117       {
       
   118         coderStreamIndex = streamIndex;
       
   119         return;
       
   120       }
       
   121       streamIndex -= curSize;
       
   122     }
       
   123     throw 1;
       
   124   }
       
   125 };
       
   126 
       
   127 class CBindReverseConverter
       
   128 {
       
   129   UInt32 _numSrcOutStreams;
       
   130   NCoderMixer::CBindInfo _srcBindInfo;
       
   131   CRecordVector<UInt32> _srcInToDestOutMap;
       
   132   CRecordVector<UInt32> _srcOutToDestInMap;
       
   133   CRecordVector<UInt32> _destInToSrcOutMap;
       
   134 public:
       
   135   UInt32 NumSrcInStreams;
       
   136   CRecordVector<UInt32> DestOutToSrcInMap;
       
   137 
       
   138   CBindReverseConverter(const NCoderMixer::CBindInfo &srcBindInfo);
       
   139   void CreateReverseBindInfo(NCoderMixer::CBindInfo &destBindInfo);
       
   140 };
       
   141 
       
   142 struct CCoderInfo2
       
   143 {
       
   144   CMyComPtr<ICompressCoder> Coder;
       
   145   CMyComPtr<ICompressCoder2> Coder2;
       
   146   UInt32 NumInStreams;
       
   147   UInt32 NumOutStreams;
       
   148 
       
   149   CRecordVector<UInt64> InSizes;
       
   150   CRecordVector<UInt64> OutSizes;
       
   151   CRecordVector<const UInt64 *> InSizePointers;
       
   152   CRecordVector<const UInt64 *> OutSizePointers;
       
   153 
       
   154   CCoderInfo2(UInt32 numInStreams, UInt32 numOutStreams);
       
   155   void SetCoderInfo(const UInt64 **inSizes, const UInt64 **outSizes);
       
   156 
       
   157   HRESULT QueryInterface(REFGUID iid, void** pp) const
       
   158   {
       
   159     IUnknown *p = Coder ? (IUnknown *)Coder : (IUnknown *)Coder2;
       
   160     return p->QueryInterface(iid, pp);
       
   161   }
       
   162 };
       
   163 
       
   164 class CCoderMixer2
       
   165 {
       
   166 public:
       
   167   virtual HRESULT SetBindInfo(const CBindInfo &bindInfo) = 0;
       
   168   virtual void ReInit() = 0;
       
   169   virtual void SetCoderInfo(UInt32 coderIndex, const UInt64 **inSizes, const UInt64 **outSizes) = 0;
       
   170 };
       
   171 
       
   172 }
       
   173 #endif
       
   174