mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-07 16:07:05 -06:00
4.63
This commit is contained in:
committed by
Kornel Lesiński
parent
c1f1243a70
commit
3a524e5ba2
@@ -1,27 +0,0 @@
|
||||
// Stream/LSBFDecoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "LSBFDecoder.h"
|
||||
|
||||
namespace NStream {
|
||||
namespace NLSBF {
|
||||
|
||||
Byte kInvertTable[256];
|
||||
|
||||
class CInverterTableInitializer
|
||||
{
|
||||
public:
|
||||
CInverterTableInitializer()
|
||||
{
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
int x = ((i & 0x55) << 1) | ((i & 0xAA) >> 1);
|
||||
x = ((x & 0x33) << 2) | ((x & 0xCC) >> 2);
|
||||
kInvertTable[i] = (Byte)(((x & 0x0F) << 4) | ((x & 0xF0) >> 4));
|
||||
}
|
||||
}
|
||||
} g_InverterTableInitializer;
|
||||
|
||||
|
||||
}}
|
||||
@@ -1,127 +0,0 @@
|
||||
// LSBFDecoder.h
|
||||
|
||||
#ifndef __STREAM_LSBFDECODER_H
|
||||
#define __STREAM_LSBFDECODER_H
|
||||
|
||||
#include "../IStream.h"
|
||||
|
||||
namespace NStream {
|
||||
namespace NLSBF {
|
||||
|
||||
const int kNumBigValueBits = 8 * 4;
|
||||
|
||||
const int kNumValueBytes = 3;
|
||||
const int kNumValueBits = 8 * kNumValueBytes;
|
||||
|
||||
const UInt32 kMask = (1 << kNumValueBits) - 1;
|
||||
|
||||
extern Byte kInvertTable[256];
|
||||
// the Least Significant Bit of byte is First
|
||||
|
||||
template<class TInByte>
|
||||
class CBaseDecoder
|
||||
{
|
||||
protected:
|
||||
int m_BitPos;
|
||||
UInt32 m_Value;
|
||||
TInByte m_Stream;
|
||||
public:
|
||||
UInt32 NumExtraBytes;
|
||||
bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
|
||||
void SetStream(ISequentialInStream *inStream) { m_Stream.SetStream(inStream); }
|
||||
void ReleaseStream() { m_Stream.ReleaseStream(); }
|
||||
void Init()
|
||||
{
|
||||
m_Stream.Init();
|
||||
m_BitPos = kNumBigValueBits;
|
||||
m_Value = 0;
|
||||
NumExtraBytes = 0;
|
||||
}
|
||||
UInt64 GetProcessedSize() const
|
||||
{ return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; }
|
||||
UInt64 GetProcessedBitsSize() const
|
||||
{ return (m_Stream.GetProcessedSize() << 3) - (kNumBigValueBits - m_BitPos); }
|
||||
int GetBitPosition() const { return (m_BitPos & 7); }
|
||||
|
||||
void Normalize()
|
||||
{
|
||||
for (;m_BitPos >= 8; m_BitPos -= 8)
|
||||
{
|
||||
Byte b = 0;
|
||||
if (!m_Stream.ReadByte(b))
|
||||
{
|
||||
b = 0xFF; // check it
|
||||
NumExtraBytes++;
|
||||
}
|
||||
m_Value = (b << (kNumBigValueBits - m_BitPos)) | m_Value;
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 ReadBits(int numBits)
|
||||
{
|
||||
Normalize();
|
||||
UInt32 res = m_Value & ((1 << numBits) - 1);
|
||||
m_BitPos += numBits;
|
||||
m_Value >>= numBits;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool ExtraBitsWereRead() const
|
||||
{
|
||||
if (NumExtraBytes == 0)
|
||||
return false;
|
||||
return ((UInt32)(kNumBigValueBits - m_BitPos) < (NumExtraBytes << 3));
|
||||
}
|
||||
};
|
||||
|
||||
template<class TInByte>
|
||||
class CDecoder: public CBaseDecoder<TInByte>
|
||||
{
|
||||
UInt32 m_NormalValue;
|
||||
|
||||
public:
|
||||
void Init()
|
||||
{
|
||||
CBaseDecoder<TInByte>::Init();
|
||||
m_NormalValue = 0;
|
||||
}
|
||||
|
||||
void Normalize()
|
||||
{
|
||||
for (; this->m_BitPos >= 8; this->m_BitPos -= 8)
|
||||
{
|
||||
Byte b = 0;
|
||||
if (!this->m_Stream.ReadByte(b))
|
||||
{
|
||||
b = 0xFF; // check it
|
||||
this->NumExtraBytes++;
|
||||
}
|
||||
m_NormalValue = (b << (kNumBigValueBits - this->m_BitPos)) | m_NormalValue;
|
||||
this->m_Value = (this->m_Value << 8) | kInvertTable[b];
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 GetValue(int numBits)
|
||||
{
|
||||
Normalize();
|
||||
return ((this->m_Value >> (8 - this->m_BitPos)) & kMask) >> (kNumValueBits - numBits);
|
||||
}
|
||||
|
||||
void MovePos(int numBits)
|
||||
{
|
||||
this->m_BitPos += numBits;
|
||||
m_NormalValue >>= numBits;
|
||||
}
|
||||
|
||||
UInt32 ReadBits(int numBits)
|
||||
{
|
||||
Normalize();
|
||||
UInt32 res = m_NormalValue & ( (1 << numBits) - 1);
|
||||
MovePos(numBits);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
// LSBFEncoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "LSBFEncoder.h"
|
||||
#include "Common/Defs.h"
|
||||
|
||||
namespace NStream {
|
||||
namespace NLSBF {
|
||||
|
||||
}}
|
||||
@@ -1,67 +0,0 @@
|
||||
// Stream/LSBFEncoder.h
|
||||
|
||||
#ifndef __STREAM_LSBFENCODER_H
|
||||
#define __STREAM_LSBFENCODER_H
|
||||
|
||||
#include "../IStream.h"
|
||||
#include "OutBuffer.h"
|
||||
|
||||
namespace NStream {
|
||||
namespace NLSBF {
|
||||
|
||||
class CEncoder
|
||||
{
|
||||
COutBuffer m_Stream;
|
||||
int m_BitPos;
|
||||
Byte m_CurByte;
|
||||
public:
|
||||
bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
|
||||
void SetStream(ISequentialOutStream *outStream) { m_Stream.SetStream(outStream); }
|
||||
void ReleaseStream() { m_Stream.ReleaseStream(); }
|
||||
void Init()
|
||||
{
|
||||
m_Stream.Init();
|
||||
m_BitPos = 8;
|
||||
m_CurByte = 0;
|
||||
}
|
||||
HRESULT Flush()
|
||||
{
|
||||
FlushByte();
|
||||
return m_Stream.Flush();
|
||||
}
|
||||
|
||||
void FlushByte()
|
||||
{
|
||||
if(m_BitPos < 8)
|
||||
m_Stream.WriteByte(m_CurByte);
|
||||
m_BitPos = 8;
|
||||
m_CurByte = 0;
|
||||
}
|
||||
|
||||
void WriteBits(UInt32 value, int numBits)
|
||||
{
|
||||
while(numBits > 0)
|
||||
{
|
||||
if (numBits < m_BitPos)
|
||||
{
|
||||
m_CurByte |= (value & ((1 << numBits) - 1)) << (8 - m_BitPos);
|
||||
m_BitPos -= numBits;
|
||||
return;
|
||||
}
|
||||
numBits -= m_BitPos;
|
||||
m_Stream.WriteByte((Byte)(m_CurByte | (value << (8 - m_BitPos))));
|
||||
value >>= m_BitPos;
|
||||
m_BitPos = 8;
|
||||
m_CurByte = 0;
|
||||
}
|
||||
}
|
||||
UInt32 GetBitPosition() const { return (8 - m_BitPos); }
|
||||
UInt64 GetProcessedSize() const {
|
||||
return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) /8; }
|
||||
void WriteByte(Byte b) { m_Stream.WriteByte(b);}
|
||||
};
|
||||
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -1,69 +0,0 @@
|
||||
// MSBFDecoder.h
|
||||
// the Most Significant Bit of byte is First
|
||||
|
||||
#ifndef __STREAM_MSBFDECODER_H
|
||||
#define __STREAM_MSBFDECODER_H
|
||||
|
||||
#include "../../Common/Types.h"
|
||||
#include "../IStream.h"
|
||||
|
||||
namespace NStream {
|
||||
namespace NMSBF {
|
||||
|
||||
const int kNumBigValueBits = 8 * 4;
|
||||
const int kNumValueBytes = 3;
|
||||
const int kNumValueBits = 8 * kNumValueBytes;
|
||||
|
||||
const UInt32 kMask = (1 << kNumValueBits) - 1;
|
||||
|
||||
template<class TInByte>
|
||||
class CDecoder
|
||||
{
|
||||
UInt32 m_BitPos;
|
||||
UInt32 m_Value;
|
||||
public:
|
||||
TInByte m_Stream;
|
||||
bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
|
||||
void SetStream(ISequentialInStream *inStream) { m_Stream.SetStream(inStream);}
|
||||
void ReleaseStream() { m_Stream.ReleaseStream();}
|
||||
|
||||
void Init()
|
||||
{
|
||||
m_Stream.Init();
|
||||
m_BitPos = kNumBigValueBits;
|
||||
Normalize();
|
||||
}
|
||||
|
||||
UInt64 GetProcessedSize() const
|
||||
{ return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; }
|
||||
UInt32 GetBitPosition() const { return (m_BitPos & 7); }
|
||||
|
||||
void Normalize()
|
||||
{
|
||||
for (;m_BitPos >= 8; m_BitPos -= 8)
|
||||
m_Value = (m_Value << 8) | m_Stream.ReadByte();
|
||||
}
|
||||
|
||||
UInt32 GetValue(UInt32 numBits) const
|
||||
{
|
||||
// return (m_Value << m_BitPos) >> (kNumBigValueBits - numBits);
|
||||
return ((m_Value >> (8 - m_BitPos)) & kMask) >> (kNumValueBits - numBits);
|
||||
}
|
||||
|
||||
void MovePos(UInt32 numBits)
|
||||
{
|
||||
m_BitPos += numBits;
|
||||
Normalize();
|
||||
}
|
||||
|
||||
UInt32 ReadBits(UInt32 numBits)
|
||||
{
|
||||
UInt32 res = GetValue(numBits);
|
||||
MovePos(numBits);
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -1,59 +0,0 @@
|
||||
// Stream/MSBFEncoder.h
|
||||
|
||||
#ifndef __STREAM_MSBFENCODER_H
|
||||
#define __STREAM_MSBFENCODER_H
|
||||
|
||||
#include "Common/Defs.h"
|
||||
#include "../IStream.h"
|
||||
#include "OutBuffer.h"
|
||||
|
||||
namespace NStream {
|
||||
namespace NMSBF {
|
||||
|
||||
template<class TOutByte>
|
||||
class CEncoder
|
||||
{
|
||||
TOutByte m_Stream;
|
||||
int m_BitPos;
|
||||
Byte m_CurByte;
|
||||
public:
|
||||
bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
|
||||
void SetStream(ISequentialOutStream *outStream) { m_Stream.SetStream(outStream);}
|
||||
void ReleaseStream() { m_Stream.ReleaseStream(); }
|
||||
void Init()
|
||||
{
|
||||
m_Stream.Init();
|
||||
m_BitPos = 8;
|
||||
m_CurByte = 0;
|
||||
}
|
||||
HRESULT Flush()
|
||||
{
|
||||
if(m_BitPos < 8)
|
||||
WriteBits(0, m_BitPos);
|
||||
return m_Stream.Flush();
|
||||
}
|
||||
|
||||
void WriteBits(UInt32 value, int numBits)
|
||||
{
|
||||
while(numBits > 0)
|
||||
{
|
||||
if (numBits < m_BitPos)
|
||||
{
|
||||
m_CurByte |= ((Byte)value << (m_BitPos -= numBits));
|
||||
return;
|
||||
}
|
||||
numBits -= m_BitPos;
|
||||
UInt32 newBits = (value >> numBits);
|
||||
value -= (newBits << numBits);
|
||||
m_Stream.WriteByte((Byte)(m_CurByte | newBits));
|
||||
m_BitPos = 8;
|
||||
m_CurByte = 0;
|
||||
}
|
||||
}
|
||||
UInt64 GetProcessedSize() const {
|
||||
return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) / 8; }
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -2,9 +2,12 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "MethodProps.h"
|
||||
#include "../../Common/MyCom.h"
|
||||
|
||||
#include "../ICoder.h"
|
||||
|
||||
#include "MethodProps.h"
|
||||
|
||||
static UInt64 k_LZMA = 0x030101;
|
||||
// static UInt64 k_LZMA2 = 0x030102;
|
||||
|
||||
@@ -35,24 +38,24 @@ HRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce
|
||||
}
|
||||
|
||||
{
|
||||
int numProperties = method.Properties.Size();
|
||||
int numProps = method.Props.Size();
|
||||
CMyComPtr<ICompressSetCoderProperties> setCoderProperties;
|
||||
coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);
|
||||
if (setCoderProperties == NULL)
|
||||
{
|
||||
if (numProperties != 0)
|
||||
if (numProps != 0)
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
else
|
||||
{
|
||||
CRecordVector<PROPID> propIDs;
|
||||
NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProperties];
|
||||
NWindows::NCOM::CPropVariant *values = new NWindows::NCOM::CPropVariant[numProps];
|
||||
HRESULT res = S_OK;
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < numProperties; i++)
|
||||
for (int i = 0; i < numProps; i++)
|
||||
{
|
||||
const CProp &prop = method.Properties[i];
|
||||
const CProp &prop = method.Props[i];
|
||||
propIDs.Add(prop.Id);
|
||||
NWindows::NCOM::CPropVariant &value = values[i];
|
||||
value = prop.Value;
|
||||
@@ -65,7 +68,7 @@ HRESULT SetMethodProperties(const CMethod &method, const UInt64 *inSizeForReduce
|
||||
}
|
||||
CMyComPtr<ICompressSetCoderProperties> setCoderProperties;
|
||||
coder->QueryInterface(IID_ICompressSetCoderProperties, (void **)&setCoderProperties);
|
||||
res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProperties);
|
||||
res = setCoderProperties->SetCoderProperties(&propIDs.Front(), values, numProps);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
#ifndef __7Z_METHOD_PROPS_H
|
||||
#define __7Z_METHOD_PROPS_H
|
||||
|
||||
#include "MethodId.h"
|
||||
#include "../../Common/MyVector.h"
|
||||
|
||||
#include "../../Windows/PropVariant.h"
|
||||
#include "../../Common/MyVector.h"
|
||||
#include "../ICoder.h"
|
||||
|
||||
#include "MethodId.h"
|
||||
|
||||
struct CProp
|
||||
{
|
||||
@@ -18,7 +18,7 @@ struct CProp
|
||||
struct CMethod
|
||||
{
|
||||
CMethodId Id;
|
||||
CObjectVector<CProp> Properties;
|
||||
CObjectVector<CProp> Props;
|
||||
};
|
||||
|
||||
struct CMethodsMode
|
||||
|
||||
Reference in New Issue
Block a user