mirror of
https://github.com/Xevion/easy7zip.git
synced 2026-02-01 06:24:12 -06:00
4.20
This commit is contained in:
committed by
Kornel Lesiński
parent
8c1b5c7b7e
commit
3c510ba80b
@@ -1,100 +1,38 @@
|
||||
// Coder.cpp
|
||||
// ByteSwap.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ByteSwap.h"
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
const int kBufferSize = 1 << 17;
|
||||
STDMETHODIMP CByteSwap2::Init() { return S_OK; }
|
||||
|
||||
CBuffer::CBuffer():
|
||||
_buffer(0)
|
||||
STDMETHODIMP_(UInt32) CByteSwap2::Filter(Byte *data, UInt32 size)
|
||||
{
|
||||
_buffer = new BYTE[kBufferSize];
|
||||
}
|
||||
|
||||
CBuffer::~CBuffer()
|
||||
{
|
||||
delete []_buffer;
|
||||
}
|
||||
|
||||
STDMETHODIMP CByteSwap2::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
const UINT32 kStep = 2;
|
||||
UINT32 bufferPos = 0;
|
||||
UINT64 nowPos64 = 0;
|
||||
while(true)
|
||||
const UInt32 kStep = 2;
|
||||
UInt32 i;
|
||||
for (i = 0; i + kStep <= size; i += kStep)
|
||||
{
|
||||
UINT32 processedSize;
|
||||
UINT32 size = kBufferSize - bufferPos;
|
||||
RINOK(inStream->Read(_buffer + bufferPos, size, &processedSize));
|
||||
if (processedSize == 0)
|
||||
return outStream->Write(_buffer, bufferPos, NULL);
|
||||
|
||||
UINT32 endPos = bufferPos + processedSize;
|
||||
for (UINT32 curPos = 0; curPos + kStep <= endPos; curPos += kStep)
|
||||
{
|
||||
BYTE data[kStep];
|
||||
data[0] = _buffer[curPos + 0];
|
||||
data[1] = _buffer[curPos + 1];
|
||||
_buffer[curPos + 0] = data[1];
|
||||
_buffer[curPos + 1] = data[0];
|
||||
}
|
||||
RINOK(outStream->Write(_buffer, curPos, &processedSize));
|
||||
if (curPos != processedSize)
|
||||
return E_FAIL;
|
||||
nowPos64 += curPos;
|
||||
if (progress != NULL)
|
||||
{
|
||||
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
|
||||
}
|
||||
bufferPos = 0;
|
||||
while(curPos < endPos)
|
||||
_buffer[bufferPos++] = _buffer[curPos++];
|
||||
Byte b = data[i];
|
||||
data[i] = data[i + 1];
|
||||
data[i + 1] = b;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
STDMETHODIMP CByteSwap4::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
STDMETHODIMP CByteSwap4::Init() { return S_OK; }
|
||||
|
||||
STDMETHODIMP_(UInt32) CByteSwap4::Filter(Byte *data, UInt32 size)
|
||||
{
|
||||
const UINT32 kStep = 4;
|
||||
UINT32 bufferPos = 0;
|
||||
UINT64 nowPos64 = 0;
|
||||
while(true)
|
||||
const UInt32 kStep = 4;
|
||||
UInt32 i;
|
||||
for (i = 0; i + kStep <= size; i += kStep)
|
||||
{
|
||||
UINT32 processedSize;
|
||||
UINT32 size = kBufferSize - bufferPos;
|
||||
RINOK(inStream->Read(_buffer + bufferPos, size, &processedSize));
|
||||
if (processedSize == 0)
|
||||
return outStream->Write(_buffer, bufferPos, NULL);
|
||||
|
||||
UINT32 endPos = bufferPos + processedSize;
|
||||
for (UINT32 curPos = 0; curPos + kStep <= endPos; curPos += kStep)
|
||||
{
|
||||
BYTE data[kStep];
|
||||
data[0] = _buffer[curPos + 0];
|
||||
data[1] = _buffer[curPos + 1];
|
||||
data[2] = _buffer[curPos + 2];
|
||||
data[3] = _buffer[curPos + 3];
|
||||
_buffer[curPos + 0] = data[3];
|
||||
_buffer[curPos + 1] = data[2];
|
||||
_buffer[curPos + 2] = data[1];
|
||||
_buffer[curPos + 3] = data[0];
|
||||
}
|
||||
RINOK(outStream->Write(_buffer, curPos, &processedSize));
|
||||
if (curPos != processedSize)
|
||||
return E_FAIL;
|
||||
nowPos64 += curPos;
|
||||
if (progress != NULL)
|
||||
{
|
||||
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
|
||||
}
|
||||
bufferPos = 0;
|
||||
while(curPos < endPos)
|
||||
_buffer[bufferPos++] = _buffer[curPos++];
|
||||
Byte b0 = data[i];
|
||||
Byte b1 = data[i + 1];
|
||||
data[i] = data[i + 3];
|
||||
data[i + 1] = data[i + 2];
|
||||
data[i + 2] = b1;
|
||||
data[i + 3] = b0;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user