misc/libphysfs/lzma/CPP/7zip/Compress/ByteSwap/ByteSwap.cpp
changeset 13904 99b265e0d1d0
parent 13903 5f819b90d479
child 13905 b172a5d40eee
equal deleted inserted replaced
13903:5f819b90d479 13904:99b265e0d1d0
     1 // ByteSwap.cpp
       
     2 
       
     3 #include "StdAfx.h"
       
     4 
       
     5 #include "ByteSwap.h"
       
     6 
       
     7 STDMETHODIMP CByteSwap2::Init() { return S_OK; }
       
     8 
       
     9 STDMETHODIMP_(UInt32) CByteSwap2::Filter(Byte *data, UInt32 size)
       
    10 {
       
    11   const UInt32 kStep = 2;
       
    12   UInt32 i;
       
    13   for (i = 0; i + kStep <= size; i += kStep)
       
    14   {
       
    15     Byte b = data[i];
       
    16     data[i] = data[i + 1];
       
    17     data[i + 1] = b;
       
    18   }
       
    19   return i;
       
    20 }
       
    21 
       
    22 STDMETHODIMP CByteSwap4::Init() { return S_OK; }
       
    23 
       
    24 STDMETHODIMP_(UInt32) CByteSwap4::Filter(Byte *data, UInt32 size)
       
    25 {
       
    26   const UInt32 kStep = 4;
       
    27   UInt32 i;
       
    28   for (i = 0; i + kStep <= size; i += kStep)
       
    29   {
       
    30     Byte b0 = data[i];
       
    31     Byte b1 = data[i + 1];
       
    32     data[i] = data[i + 3];
       
    33     data[i + 1] = data[i + 2];
       
    34     data[i + 2] = b1;
       
    35     data[i + 3] = b0;
       
    36   }
       
    37   return i;
       
    38 }