This commit is contained in:
Igor Pavlov
2005-05-30 00:00:00 +00:00
committed by Kornel Lesiński
parent 8c1b5c7b7e
commit 3c510ba80b
926 changed files with 40559 additions and 23519 deletions

View File

@@ -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;
}

View File

@@ -14,38 +14,24 @@ DEFINE_GUID(CLSID_CCompressConvertByteSwap2,
DEFINE_GUID(CLSID_CCompressConvertByteSwap4,
0x23170F69, 0x40C1, 0x278B, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00);
class CBuffer
{
protected:
BYTE *_buffer;
public:
CBuffer();
~CBuffer();
};
class CByteSwap2 :
public ICompressCoder,
public CBuffer,
class CByteSwap2:
public ICompressFilter,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP
STDMETHOD(Code)(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
ICompressProgressInfo *progress);
STDMETHOD(Init)();
STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
};
class CByteSwap4 :
public ICompressCoder,
public CBuffer,
class CByteSwap4:
public ICompressFilter,
public CMyUnknownImp
{
public:
MY_UNKNOWN_IMP
STDMETHOD(Code)(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
ICompressProgressInfo *progress);
STDMETHOD(Init)();
STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
};
#endif
#endif

View File

@@ -2,8 +2,7 @@
#include "StdAfx.h"
#define INITGUID
#include "Common/MyInitGuid.h"
#include "Common/ComTry.h"
#include "ByteSwap.h"
#include "../../ICoder.h"
@@ -18,19 +17,19 @@ STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)
{
COM_TRY_BEGIN
*outObject = 0;
int correctInterface = (*iid == IID_ICompressCoder);
CMyComPtr<ICompressCoder> coder;
int correctInterface = (*iid == IID_ICompressFilter);
CMyComPtr<ICompressFilter> coder;
if (*clsid == CLSID_CCompressConvertByteSwap2)
{
if (!correctInterface)
return E_NOINTERFACE;
coder = (ICompressCoder *)new CByteSwap2();
coder = (ICompressFilter *)new CByteSwap2();
}
else if (*clsid == CLSID_CCompressConvertByteSwap4)
{
if (!correctInterface)
return E_NOINTERFACE;
coder = (ICompressCoder *)new CByteSwap4();
coder = (ICompressFilter *)new CByteSwap4();
}
else
return CLASS_E_CLASSNOTAVAILABLE;

View File

@@ -1,3 +1,3 @@
// StdAfx.cpp
#include "stdafx.h"
#include "StdAfx.h"

View File

@@ -1,8 +1,8 @@
// stdafx.h
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include <windows.h>
#include "../../../Common/MyWindows.h"
#endif
#endif

View File

@@ -66,8 +66,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,9,2,0
PRODUCTVERSION 3,9,2,0
FILEVERSION 4,7,0,0
PRODUCTVERSION 4,7,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@@ -84,15 +84,15 @@ BEGIN
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", "Igor Pavlov\0"
VALUE "FileDescription", "Byte Swap converter \0"
VALUE "FileVersion", "3, 9, 2, 0\0"
VALUE "FileDescription", "Byte Swap filter\0"
VALUE "FileVersion", "4, 7, 0, 0\0"
VALUE "InternalName", "Swap\0"
VALUE "LegalCopyright", "Copyright (C) 1999-2003 Igor Pavlov\0"
VALUE "LegalCopyright", "Copyright (C) 1999-2004 Igor Pavlov\0"
VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", "Swap.dll\0"
VALUE "PrivateBuild", "\0"
VALUE "ProductName", "7-Zip\0"
VALUE "ProductVersion", "3, 9, 2, 0\0"
VALUE "ProductVersion", "4, 7, 0, 0\0"
VALUE "SpecialBuild", "\0"
END
END