mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-09 06:07:05 -06:00
3.13
This commit is contained in:
317
7zip/Compress/Arj/Decoder1.cpp
Executable file
317
7zip/Compress/Arj/Decoder1.cpp
Executable file
@@ -0,0 +1,317 @@
|
||||
// Arj/Decoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Decoder1.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
namespace NCompress{
|
||||
namespace NArj {
|
||||
namespace NDecoder1 {
|
||||
|
||||
static const UINT32 kHistorySize = 26624;
|
||||
static const UINT32 kMatchMaxLen = 256;
|
||||
static const UINT32 kMatchMinLen = 3;
|
||||
|
||||
static const UINT32 kNC = 255 + kMatchMaxLen + 2 - kMatchMinLen;
|
||||
|
||||
CCoder::CCoder()
|
||||
{}
|
||||
|
||||
void CCoder::make_table(int nchar, BYTE *bitlen, int tablebits,
|
||||
UINT32 *table, int tablesize)
|
||||
{
|
||||
UINT32 count[17], weight[17], start[18], *p;
|
||||
UINT32 i, k, len, ch, jutbits, avail, nextcode, mask;
|
||||
|
||||
for (i = 1; i <= 16; i++)
|
||||
count[i] = 0;
|
||||
for (i = 0; (int)i < nchar; i++)
|
||||
count[bitlen[i]]++;
|
||||
|
||||
start[1] = 0;
|
||||
for (i = 1; i <= 16; i++)
|
||||
start[i + 1] = start[i] + (count[i] << (16 - i));
|
||||
if (start[17] != (UINT32) (1 << 16))
|
||||
throw "Data error";
|
||||
|
||||
jutbits = 16 - tablebits;
|
||||
for (i = 1; (int)i <= tablebits; i++)
|
||||
{
|
||||
start[i] >>= jutbits;
|
||||
weight[i] = 1 << (tablebits - i);
|
||||
}
|
||||
while (i <= 16)
|
||||
{
|
||||
weight[i] = 1 << (16 - i);
|
||||
i++;
|
||||
}
|
||||
|
||||
i = start[tablebits + 1] >> jutbits;
|
||||
if (i != (UINT32) (1 << 16))
|
||||
{
|
||||
k = 1 << tablebits;
|
||||
while (i != k)
|
||||
table[i++] = 0;
|
||||
}
|
||||
|
||||
avail = nchar;
|
||||
mask = 1 << (15 - tablebits);
|
||||
for (ch = 0; (int)ch < nchar; ch++)
|
||||
{
|
||||
if ((len = bitlen[ch]) == 0)
|
||||
continue;
|
||||
k = start[len];
|
||||
nextcode = k + weight[len];
|
||||
if ((int)len <= tablebits)
|
||||
{
|
||||
if (nextcode > (UINT32)tablesize)
|
||||
throw "Data error";
|
||||
for (i = start[len]; i < nextcode; i++)
|
||||
table[i] = ch;
|
||||
}
|
||||
else
|
||||
{
|
||||
p = &table[k >> jutbits];
|
||||
i = len - tablebits;
|
||||
while (i != 0)
|
||||
{
|
||||
if (*p == 0)
|
||||
{
|
||||
right[avail] = left[avail] = 0;
|
||||
*p = avail++;
|
||||
}
|
||||
if (k & mask)
|
||||
p = &right[*p];
|
||||
else
|
||||
p = &left[*p];
|
||||
k <<= 1;
|
||||
i--;
|
||||
}
|
||||
*p = ch;
|
||||
}
|
||||
start[len] = nextcode;
|
||||
}
|
||||
}
|
||||
|
||||
void CCoder::read_pt_len(int nn, int nbit, int i_special)
|
||||
{
|
||||
UINT32 n = m_InBitStream.ReadBits(nbit);
|
||||
if (n == 0)
|
||||
{
|
||||
UINT32 c = m_InBitStream.ReadBits(nbit);
|
||||
int i;
|
||||
for (i = 0; i < nn; i++)
|
||||
pt_len[i] = 0;
|
||||
for (i = 0; i < 256; i++)
|
||||
pt_table[i] = c;
|
||||
}
|
||||
else
|
||||
{
|
||||
UINT32 i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
UINT32 bitBuf = m_InBitStream.GetValue(16);
|
||||
int c = bitBuf >> 13;
|
||||
if (c == 7)
|
||||
{
|
||||
UINT32 mask = 1 << (12);
|
||||
while (mask & bitBuf)
|
||||
{
|
||||
mask >>= 1;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
m_InBitStream.MovePos((c < 7) ? 3 : (int)(c - 3));
|
||||
pt_len[i++] = (BYTE)c;
|
||||
if (i == (UINT32)i_special)
|
||||
{
|
||||
c = m_InBitStream.ReadBits(2);
|
||||
while (--c >= 0)
|
||||
pt_len[i++] = 0;
|
||||
}
|
||||
}
|
||||
while (i < (UINT32)nn)
|
||||
pt_len[i++] = 0;
|
||||
make_table(nn, pt_len, 8, pt_table, PTABLESIZE);
|
||||
}
|
||||
}
|
||||
|
||||
void CCoder::read_c_len()
|
||||
{
|
||||
int i, c, n;
|
||||
UINT32 mask;
|
||||
|
||||
n = m_InBitStream.ReadBits(CBIT);
|
||||
if (n == 0)
|
||||
{
|
||||
c = m_InBitStream.ReadBits(CBIT);
|
||||
for (i = 0; i < NC; i++)
|
||||
c_len[i] = 0;
|
||||
for (i = 0; i < CTABLESIZE; i++)
|
||||
c_table[i] = c;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
UINT32 bitBuf = m_InBitStream.GetValue(16);
|
||||
c = pt_table[bitBuf >> (8)];
|
||||
if (c >= NT)
|
||||
{
|
||||
mask = 1 << (7);
|
||||
do
|
||||
{
|
||||
if (bitBuf & mask)
|
||||
c = right[c];
|
||||
else
|
||||
c = left[c];
|
||||
mask >>= 1;
|
||||
} while (c >= NT);
|
||||
}
|
||||
m_InBitStream.MovePos((int)(pt_len[c]));
|
||||
if (c <= 2)
|
||||
{
|
||||
if (c == 0)
|
||||
c = 1;
|
||||
else if (c == 1)
|
||||
c = m_InBitStream.ReadBits(4) + 3;
|
||||
else
|
||||
c = m_InBitStream.ReadBits(CBIT) + 20;
|
||||
while (--c >= 0)
|
||||
c_len[i++] = 0;
|
||||
}
|
||||
else
|
||||
c_len[i++] = (BYTE)(c - 2);
|
||||
}
|
||||
while (i < NC)
|
||||
c_len[i++] = 0;
|
||||
make_table(NC, c_len, 12, c_table, CTABLESIZE);
|
||||
}
|
||||
}
|
||||
|
||||
UINT32 CCoder::decode_c()
|
||||
{
|
||||
UINT32 j, mask;
|
||||
UINT32 bitbuf = m_InBitStream.GetValue(16);
|
||||
j = c_table[bitbuf >> 4];
|
||||
if (j >= NC)
|
||||
{
|
||||
mask = 1 << (3);
|
||||
do
|
||||
{
|
||||
if (bitbuf & mask)
|
||||
j = right[j];
|
||||
else
|
||||
j = left[j];
|
||||
mask >>= 1;
|
||||
} while (j >= NC);
|
||||
}
|
||||
m_InBitStream.MovePos((int)(c_len[j]));
|
||||
return j;
|
||||
}
|
||||
|
||||
UINT32 CCoder::decode_p()
|
||||
{
|
||||
UINT32 j, mask;
|
||||
UINT32 bitbuf = m_InBitStream.GetValue(16);
|
||||
j = pt_table[bitbuf >> (8)];
|
||||
if (j >= NP)
|
||||
{
|
||||
mask = 1 << (7);
|
||||
do
|
||||
{
|
||||
if (bitbuf & mask)
|
||||
j = right[j];
|
||||
else
|
||||
j = left[j];
|
||||
mask >>= 1;
|
||||
} while (j >= NP);
|
||||
}
|
||||
m_InBitStream.MovePos((int)(pt_len[j]));
|
||||
if (j != 0)
|
||||
{
|
||||
j--;
|
||||
j = (1 << j) + m_InBitStream.ReadBits((int)j);
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
int size1 = sizeof(c_table) / sizeof(c_table[0]);
|
||||
for (int i = 0; i < size1; i++)
|
||||
{
|
||||
if (i % 100 == 0)
|
||||
c_table[i] = 0;
|
||||
|
||||
c_table[i] = 0;
|
||||
}
|
||||
|
||||
if (outSize == NULL)
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (!m_OutWindowStream.IsCreated())
|
||||
{
|
||||
try { m_OutWindowStream.Create(kHistorySize); }
|
||||
catch(...) { return E_OUTOFMEMORY; }
|
||||
}
|
||||
UINT64 pos = 0;
|
||||
m_OutWindowStream.Init(outStream, false);
|
||||
m_InBitStream.Init(inStream);
|
||||
CCoderReleaser coderReleaser(this);
|
||||
|
||||
UINT32 blockSize = 0;
|
||||
|
||||
while(pos < *outSize)
|
||||
{
|
||||
if (blockSize == 0)
|
||||
{
|
||||
if (progress != NULL)
|
||||
{
|
||||
UINT64 packSize = m_InBitStream.GetProcessedSize();
|
||||
RINOK(progress->SetRatioInfo(&packSize, &pos));
|
||||
}
|
||||
blockSize = m_InBitStream.ReadBits(16);
|
||||
read_pt_len(NT, TBIT, 3);
|
||||
read_c_len();
|
||||
read_pt_len(NP, PBIT, -1);
|
||||
}
|
||||
blockSize--;
|
||||
|
||||
UINT32 number = decode_c();
|
||||
if (number < 256)
|
||||
{
|
||||
m_OutWindowStream.PutOneByte(number);
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
UINT32 len = number - 256 + kMatchMinLen;
|
||||
UINT32 distance = decode_p();
|
||||
if (distance >= pos)
|
||||
throw "data error";
|
||||
m_OutWindowStream.CopyBackBlock(distance, len);
|
||||
pos += len;
|
||||
}
|
||||
}
|
||||
return m_OutWindowStream.Flush();
|
||||
}
|
||||
|
||||
STDMETHODIMP CCoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
try { return CodeReal(inStream, outStream, inSize, outSize, progress);}
|
||||
catch(const CInBufferException &e) { return e.ErrorCode; }
|
||||
catch(const CLZOutWindowException &e) { return e.ErrorCode; }
|
||||
catch(...) { return S_FALSE; }
|
||||
}
|
||||
|
||||
}}}
|
||||
110
7zip/Compress/Arj/Decoder1.h
Executable file
110
7zip/Compress/Arj/Decoder1.h
Executable file
@@ -0,0 +1,110 @@
|
||||
// Arj/Decoder1.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __COMPRESS_ARJ_DECODER1_H
|
||||
#define __COMPRESS_ARJ_DECODER1_H
|
||||
|
||||
#include "Common/MyCom.h"
|
||||
#include "../../ICoder.h"
|
||||
#include "../../Common/MSBFDecoder.h"
|
||||
#include "../../Common/InBuffer.h"
|
||||
#include "../LZ/LZOutWindow.h"
|
||||
|
||||
/*
|
||||
// {23170F69-40C1-278B-0404-010000000000}
|
||||
DEFINE_GUID(CLSID_CCompressArjDecoder,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x04, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
*/
|
||||
|
||||
namespace NCompress {
|
||||
namespace NArj {
|
||||
namespace NDecoder1 {
|
||||
|
||||
#define CODE_BIT 16
|
||||
|
||||
#define THRESHOLD 3
|
||||
#define DDICSIZ 26624
|
||||
#define MAXDICBIT 16
|
||||
#define MATCHBIT 8
|
||||
#define MAXMATCH 256
|
||||
#define NC (UCHAR_MAX + MAXMATCH + 2 - THRESHOLD)
|
||||
#define NP (MAXDICBIT + 1)
|
||||
#define CBIT 9
|
||||
#define NT (CODE_BIT + 3)
|
||||
#define PBIT 5
|
||||
#define TBIT 5
|
||||
|
||||
#if NT > NP
|
||||
#define NPT NT
|
||||
#else
|
||||
#define NPT NP
|
||||
#endif
|
||||
|
||||
#define CTABLESIZE 4096
|
||||
#define PTABLESIZE 256
|
||||
|
||||
|
||||
class CCoder :
|
||||
public ICompressCoder,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CLZOutWindow m_OutWindowStream;
|
||||
NStream::NMSBF::CDecoder<CInBuffer> m_InBitStream;
|
||||
|
||||
UINT32 left[2 * NC - 1];
|
||||
UINT32 right[2 * NC - 1];
|
||||
BYTE c_len[NC];
|
||||
BYTE pt_len[NPT];
|
||||
|
||||
UINT32 c_table[CTABLESIZE];
|
||||
UINT32 pt_table[PTABLESIZE];
|
||||
|
||||
|
||||
/*
|
||||
void CCoder::ReleaseStreams()
|
||||
{
|
||||
m_OutWindowStream.ReleaseStream();
|
||||
m_InBitStream.ReleaseStream();
|
||||
}
|
||||
*/
|
||||
class CCoderReleaser
|
||||
{
|
||||
CCoder *m_Coder;
|
||||
public:
|
||||
CCoderReleaser(CCoder *aCoder): m_Coder(aCoder) {}
|
||||
~CCoderReleaser()
|
||||
{
|
||||
m_Coder->m_OutWindowStream.Flush();
|
||||
// m_Coder->ReleaseStreams();
|
||||
}
|
||||
};
|
||||
friend class CCoderReleaser;
|
||||
|
||||
void make_table(int nchar, BYTE *bitlen, int tablebits,
|
||||
UINT32 *table, int tablesize);
|
||||
|
||||
void read_c_len();
|
||||
void read_pt_len(int nn, int nbit, int i_special);
|
||||
UINT32 decode_c();
|
||||
UINT32 decode_p();
|
||||
|
||||
|
||||
public:
|
||||
CCoder();
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(CodeReal)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
95
7zip/Compress/Arj/Decoder2.cpp
Executable file
95
7zip/Compress/Arj/Decoder2.cpp
Executable file
@@ -0,0 +1,95 @@
|
||||
// Arj/Decoder2.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Decoder2.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
namespace NCompress{
|
||||
namespace NArj {
|
||||
namespace NDecoder2 {
|
||||
|
||||
static const UINT32 kHistorySize = 26624;
|
||||
static const UINT32 kMatchMaxLen = 256;
|
||||
static const UINT32 kMatchMinLen = 3;
|
||||
|
||||
CCoder::CCoder()
|
||||
{}
|
||||
|
||||
STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
if (outSize == NULL)
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (!m_OutWindowStream.IsCreated())
|
||||
{
|
||||
try { m_OutWindowStream.Create(kHistorySize); }
|
||||
catch(...) { return E_OUTOFMEMORY; }
|
||||
}
|
||||
UINT64 pos = 0;
|
||||
m_OutWindowStream.Init(outStream, false);
|
||||
m_InBitStream.Init(inStream);
|
||||
CCoderReleaser coderReleaser(this);
|
||||
|
||||
while(pos < *outSize)
|
||||
{
|
||||
const UINT32 kStartWidth = 0;
|
||||
const UINT32 kStopWidth = 7;
|
||||
UINT32 power = 1 << kStartWidth;
|
||||
UINT32 width;
|
||||
UINT32 len = 0;
|
||||
for (width = kStartWidth; width < kStopWidth; width++)
|
||||
{
|
||||
if (m_InBitStream.ReadBits(1) == 0)
|
||||
break;
|
||||
len += power;
|
||||
power <<= 1;
|
||||
}
|
||||
if (width != 0)
|
||||
len += m_InBitStream.ReadBits(width);
|
||||
if (len == 0)
|
||||
{
|
||||
m_OutWindowStream.PutOneByte(m_InBitStream.ReadBits(8));
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
len = len - 1 + kMatchMinLen;
|
||||
const UINT32 kStartWidth = 9;
|
||||
const UINT32 kStopWidth = 13;
|
||||
UINT32 power = 1 << kStartWidth;
|
||||
UINT32 width;
|
||||
UINT32 distance = 0;
|
||||
for (width = kStartWidth; width < kStopWidth; width++)
|
||||
{
|
||||
if (m_InBitStream.ReadBits(1) == 0)
|
||||
break;
|
||||
distance += power;
|
||||
power <<= 1;
|
||||
}
|
||||
if (width != 0)
|
||||
distance += m_InBitStream.ReadBits(width);
|
||||
if (distance >= pos)
|
||||
throw "data error";
|
||||
m_OutWindowStream.CopyBackBlock(distance, len);
|
||||
pos += len;
|
||||
}
|
||||
}
|
||||
return m_OutWindowStream.Flush();
|
||||
}
|
||||
|
||||
STDMETHODIMP CCoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
try { return CodeReal(inStream, outStream, inSize, outSize, progress);}
|
||||
catch(const CInBufferException &e) { return e.ErrorCode; }
|
||||
catch(const CLZOutWindowException &e) { return e.ErrorCode; }
|
||||
catch(...) { return S_FALSE; }
|
||||
}
|
||||
|
||||
}}}
|
||||
69
7zip/Compress/Arj/Decoder2.h
Executable file
69
7zip/Compress/Arj/Decoder2.h
Executable file
@@ -0,0 +1,69 @@
|
||||
// Arj/Decoder2.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __COMPRESS_ARJ_DECODER2_H
|
||||
#define __COMPRESS_ARJ_DECODER2_H
|
||||
|
||||
#include "Common/MyCom.h"
|
||||
#include "../../ICoder.h"
|
||||
#include "../../Common/MSBFDecoder.h"
|
||||
#include "../../Common/InBuffer.h"
|
||||
#include "../LZ/LZOutWindow.h"
|
||||
|
||||
/*
|
||||
// {23170F69-40C1-278B-0404-020000000000}
|
||||
DEFINE_GUID(CLSID_CCompressArj2Decoder,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x04, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
*/
|
||||
|
||||
namespace NCompress {
|
||||
namespace NArj {
|
||||
namespace NDecoder2 {
|
||||
|
||||
class CCoder :
|
||||
public ICompressCoder,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CLZOutWindow m_OutWindowStream;
|
||||
NStream::NMSBF::CDecoder<CInBuffer> m_InBitStream;
|
||||
|
||||
/*
|
||||
void CCoder::ReleaseStreams()
|
||||
{
|
||||
m_OutWindowStream.ReleaseStream();
|
||||
m_InBitStream.ReleaseStream();
|
||||
}
|
||||
*/
|
||||
|
||||
class CCoderReleaser
|
||||
{
|
||||
CCoder *m_Coder;
|
||||
public:
|
||||
CCoderReleaser(CCoder *aCoder): m_Coder(aCoder) {}
|
||||
~CCoderReleaser()
|
||||
{
|
||||
m_Coder->m_OutWindowStream.Flush();
|
||||
// m_Coder->ReleaseStreams();
|
||||
}
|
||||
};
|
||||
friend class CCoderReleaser;
|
||||
|
||||
public:
|
||||
CCoder();
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(CodeReal)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
9
7zip/Compress/BZip2/BZip2.def
Executable file
9
7zip/Compress/BZip2/BZip2.def
Executable file
@@ -0,0 +1,9 @@
|
||||
; BZip2.def
|
||||
|
||||
LIBRARY BZip2.dll
|
||||
|
||||
EXPORTS
|
||||
CreateObject PRIVATE
|
||||
GetNumberOfMethods PRIVATE
|
||||
GetMethodProperty PRIVATE
|
||||
|
||||
297
7zip/Compress/BZip2/BZip2.dsp
Executable file
297
7zip/Compress/BZip2/BZip2.dsp
Executable file
@@ -0,0 +1,297 @@
|
||||
# Microsoft Developer Studio Project File - Name="BZip2" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=BZip2 - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "BZip2.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "BZip2.mak" CFG="BZip2 - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "BZip2 - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "BZip2 - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "BZip2 - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BZIP2_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BZIP2_EXPORTS" /D "BZ_NO_STDIO" /Yu"StdAfx.h" /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "NDEBUG"
|
||||
# ADD RSC /l 0x419 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\BZip2.dll" /opt:NOWIN98
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BZIP2_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BZIP2_EXPORTS" /Yu"StdAfx.h" /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "_DEBUG"
|
||||
# ADD RSC /l 0x419 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\BZip2.dll" /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "BZip2 - Win32 Release"
|
||||
# Name "BZip2 - Win32 Debug"
|
||||
# Begin Group "Spec"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BZip2.def
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\DllExports.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\resource.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\resource.rc
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.cpp
|
||||
# ADD CPP /Yc"StdAfx.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Origianl"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Original\blocksort.c
|
||||
|
||||
!IF "$(CFG)" == "BZip2 - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug"
|
||||
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Original\bzlib.c
|
||||
|
||||
!IF "$(CFG)" == "BZip2 - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug"
|
||||
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Original\bzlib.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Original\bzlib_private.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Original\compress.c
|
||||
|
||||
!IF "$(CFG)" == "BZip2 - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug"
|
||||
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Original\crctable.c
|
||||
|
||||
!IF "$(CFG)" == "BZip2 - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug"
|
||||
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Original\decompress.c
|
||||
|
||||
!IF "$(CFG)" == "BZip2 - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug"
|
||||
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Original\huffman.c
|
||||
|
||||
!IF "$(CFG)" == "BZip2 - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug"
|
||||
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Original\randtable.c
|
||||
|
||||
!IF "$(CFG)" == "BZip2 - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug"
|
||||
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Common"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\NewHandler.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\NewHandler.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BZip2Decoder.cpp
|
||||
|
||||
!IF "$(CFG)" == "BZip2 - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BZip2Decoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BZip2Encoder.cpp
|
||||
|
||||
!IF "$(CFG)" == "BZip2 - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BZip2Encoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BZip2Error.cpp
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
29
7zip/Compress/BZip2/BZip2.dsw
Executable file
29
7zip/Compress/BZip2/BZip2.dsw
Executable file
@@ -0,0 +1,29 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "BZip2"=.\BZip2.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
125
7zip/Compress/BZip2/BZip2Decoder.cpp
Executable file
125
7zip/Compress/BZip2/BZip2Decoder.cpp
Executable file
@@ -0,0 +1,125 @@
|
||||
// BZip2Decoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "BZip2Decoder.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
#include "Original/bzlib.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NBZip2 {
|
||||
|
||||
static const UINT32 kBufferSize = (1 << 20);
|
||||
|
||||
CDecoder::CDecoder()
|
||||
{
|
||||
m_InBuffer = new BYTE[kBufferSize];
|
||||
m_OutBuffer = new BYTE[kBufferSize];
|
||||
}
|
||||
|
||||
CDecoder::~CDecoder()
|
||||
{
|
||||
delete []m_OutBuffer;
|
||||
delete []m_InBuffer;
|
||||
}
|
||||
|
||||
struct CBZip2Decompressor: public bz_stream
|
||||
{
|
||||
// bz_stream m_Object;
|
||||
public:
|
||||
int Init(int verbosity, int small) { return BZ2_bzDecompressInit(this, verbosity, small); }
|
||||
int Decompress() { return BZ2_bzDecompress(this); }
|
||||
int End() { return BZ2_bzDecompressEnd(this); }
|
||||
UINT64 GetTotalIn() const { return (UINT64(total_in_hi32) << 32) + total_in_lo32; }
|
||||
UINT64 GetTotalOut() const { return (UINT64(total_out_hi32) << 32) + total_out_lo32; }
|
||||
};
|
||||
|
||||
class CBZip2DecompressorReleaser
|
||||
{
|
||||
CBZip2Decompressor *m_Decompressor;
|
||||
public:
|
||||
CBZip2DecompressorReleaser(CBZip2Decompressor *aDecompressor): m_Decompressor(aDecompressor) {}
|
||||
void Diable() { m_Decompressor = NULL; }
|
||||
~CBZip2DecompressorReleaser() { if (m_Decompressor != NULL) m_Decompressor->End(); }
|
||||
};
|
||||
|
||||
STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
CBZip2Decompressor bzStream;
|
||||
bzStream.bzalloc = NULL;
|
||||
bzStream.bzfree = NULL;
|
||||
bzStream.opaque = NULL;
|
||||
|
||||
|
||||
int result = bzStream.Init(0, 0);
|
||||
switch(result)
|
||||
{
|
||||
case BZ_OK:
|
||||
break;
|
||||
case BZ_MEM_ERROR:
|
||||
return E_OUTOFMEMORY;
|
||||
default:
|
||||
return E_FAIL;
|
||||
}
|
||||
CBZip2DecompressorReleaser releaser(&bzStream);
|
||||
bzStream.avail_in = 0;
|
||||
while (true)
|
||||
{
|
||||
if (bzStream.avail_in == 0)
|
||||
{
|
||||
bzStream.next_in = (char *)m_InBuffer;
|
||||
UINT32 processedSize;
|
||||
RINOK(inStream->Read(m_InBuffer, kBufferSize, &processedSize));
|
||||
bzStream.avail_in = processedSize;
|
||||
}
|
||||
|
||||
bzStream.next_out = (char *)m_OutBuffer;
|
||||
bzStream.avail_out = kBufferSize;
|
||||
result = bzStream.Decompress();
|
||||
UINT32 numBytesToWrite = kBufferSize - bzStream.avail_out;
|
||||
if (numBytesToWrite > 0)
|
||||
{
|
||||
UINT32 processedSize;
|
||||
RINOK(outStream->Write(m_OutBuffer, numBytesToWrite, &processedSize));
|
||||
if (numBytesToWrite != processedSize)
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (result == BZ_STREAM_END)
|
||||
break;
|
||||
switch(result)
|
||||
{
|
||||
case BZ_DATA_ERROR:
|
||||
case BZ_DATA_ERROR_MAGIC:
|
||||
return S_FALSE;
|
||||
case BZ_OK:
|
||||
break;
|
||||
case BZ_MEM_ERROR:
|
||||
return E_OUTOFMEMORY;
|
||||
default:
|
||||
return E_FAIL;
|
||||
}
|
||||
if (progress != NULL)
|
||||
{
|
||||
UINT64 totalIn = bzStream.GetTotalIn();
|
||||
UINT64 totalOut = bzStream.GetTotalOut();
|
||||
RINOK(progress->SetRatioInfo(&totalIn, &totalOut));
|
||||
}
|
||||
}
|
||||
// result = bzStream.End();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
try { return CodeReal(inStream, outStream, inSize, outSize, progress); }
|
||||
catch(...) { return S_FALSE; }
|
||||
}
|
||||
|
||||
}}
|
||||
41
7zip/Compress/BZip2/BZip2Decoder.h
Executable file
41
7zip/Compress/BZip2/BZip2Decoder.h
Executable file
@@ -0,0 +1,41 @@
|
||||
// Compress/BZip2/Decoder.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __COMPRESS_BZIP2_DECODER_H
|
||||
#define __COMPRESS_BZIP2_DECODER_H
|
||||
|
||||
#include "../../ICoder.h"
|
||||
// #include "../../Interface/CompressInterface.h"
|
||||
#include "Common/MyCom.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NBZip2 {
|
||||
|
||||
class CDecoder :
|
||||
public ICompressCoder,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
BYTE *m_InBuffer;
|
||||
BYTE *m_OutBuffer;
|
||||
public:
|
||||
CDecoder();
|
||||
~CDecoder();
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
HRESULT Flush();
|
||||
// void (ReleaseStreams)();
|
||||
|
||||
STDMETHOD(CodeReal)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
120
7zip/Compress/BZip2/BZip2Encoder.cpp
Executable file
120
7zip/Compress/BZip2/BZip2Encoder.cpp
Executable file
@@ -0,0 +1,120 @@
|
||||
// BZip2Encoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
#include "BZip2Encoder.h"
|
||||
#include "Original/bzlib.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NBZip2 {
|
||||
|
||||
static const UINT32 kBufferSize = (1 << 20);
|
||||
|
||||
CEncoder::CEncoder()
|
||||
{
|
||||
m_InBuffer = new BYTE[kBufferSize];
|
||||
m_OutBuffer = new BYTE[kBufferSize];
|
||||
}
|
||||
|
||||
CEncoder::~CEncoder()
|
||||
{
|
||||
delete []m_OutBuffer;
|
||||
delete []m_InBuffer;
|
||||
}
|
||||
|
||||
struct CBZip2Compressor: public bz_stream
|
||||
{
|
||||
public:
|
||||
int Init(int blockSize100k, int verbosity, int small)
|
||||
{ return BZ2_bzCompressInit(this, blockSize100k, verbosity, small); }
|
||||
int Compress(int action ) { return BZ2_bzCompress(this, action ); }
|
||||
int End() { return BZ2_bzCompressEnd(this); }
|
||||
UINT64 GetTotalIn() const { return (UINT64(total_in_hi32) << 32) + total_in_lo32; }
|
||||
UINT64 GetTotalOut() const { return (UINT64(total_out_hi32) << 32) + total_out_lo32; }
|
||||
};
|
||||
|
||||
class CBZip2CompressorReleaser
|
||||
{
|
||||
CBZip2Compressor *m_Compressor;
|
||||
public:
|
||||
CBZip2CompressorReleaser(CBZip2Compressor *compressor): m_Compressor(compressor) {}
|
||||
void Disable() { m_Compressor = NULL; }
|
||||
~CBZip2CompressorReleaser() { if (m_Compressor != NULL) m_Compressor->End(); }
|
||||
};
|
||||
|
||||
|
||||
STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
CBZip2Compressor bzStream;
|
||||
bzStream.bzalloc = NULL;
|
||||
bzStream.bzfree = NULL;
|
||||
bzStream.opaque = NULL;
|
||||
|
||||
int result = bzStream.Init(9, 0, 0);
|
||||
switch(result)
|
||||
{
|
||||
case BZ_OK:
|
||||
break;
|
||||
case BZ_MEM_ERROR:
|
||||
return E_OUTOFMEMORY;
|
||||
default:
|
||||
return E_FAIL;
|
||||
}
|
||||
CBZip2CompressorReleaser releaser(&bzStream);
|
||||
bzStream.avail_in = 0;
|
||||
while (true)
|
||||
{
|
||||
if (bzStream.avail_in == 0)
|
||||
{
|
||||
bzStream.next_in = (char *)m_InBuffer;
|
||||
UINT32 processedSize;
|
||||
RINOK(inStream->Read(m_InBuffer, kBufferSize, &processedSize));
|
||||
bzStream.avail_in = processedSize;
|
||||
}
|
||||
|
||||
bzStream.next_out = (char *)m_OutBuffer;
|
||||
bzStream.avail_out = kBufferSize;
|
||||
bool askFinish = (bzStream.avail_in == 0);
|
||||
result = bzStream.Compress(askFinish ? BZ_FINISH : BZ_RUN);
|
||||
UINT32 numBytesToWrite = kBufferSize - bzStream.avail_out;
|
||||
if (numBytesToWrite > 0)
|
||||
{
|
||||
UINT32 processedSize;
|
||||
RINOK(outStream->Write(m_OutBuffer, numBytesToWrite, &processedSize));
|
||||
if (numBytesToWrite != processedSize)
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
if (result == BZ_STREAM_END)
|
||||
break;
|
||||
switch(result)
|
||||
{
|
||||
case BZ_RUN_OK:
|
||||
if (!askFinish)
|
||||
break;
|
||||
return E_FAIL;
|
||||
case BZ_FINISH_OK:
|
||||
if (askFinish)
|
||||
break;
|
||||
return E_FAIL;
|
||||
case BZ_MEM_ERROR:
|
||||
return E_OUTOFMEMORY;
|
||||
default:
|
||||
return E_FAIL;
|
||||
}
|
||||
if (progress != NULL)
|
||||
{
|
||||
UINT64 totalIn = bzStream.GetTotalIn();
|
||||
UINT64 totalOut = bzStream.GetTotalOut();
|
||||
RINOK(progress->SetRatioInfo(&totalIn, &totalOut));
|
||||
}
|
||||
}
|
||||
// result = bzStream.End();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
36
7zip/Compress/BZip2/BZip2Encoder.h
Executable file
36
7zip/Compress/BZip2/BZip2Encoder.h
Executable file
@@ -0,0 +1,36 @@
|
||||
// Compress/BZip2/Encoder.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __COMPRESS_BZIP2_ENCODER_H
|
||||
#define __COMPRESS_BZIP2_ENCODER_H
|
||||
|
||||
#include "Common/MyCom.h"
|
||||
#include "../../ICoder.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NBZip2 {
|
||||
|
||||
class CEncoder :
|
||||
public ICompressCoder,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
BYTE *m_InBuffer;
|
||||
BYTE *m_OutBuffer;
|
||||
|
||||
public:
|
||||
CEncoder();
|
||||
~CEncoder();
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
// STDMETHOD(ReleaseStreams)();
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
10
7zip/Compress/BZip2/BZip2Error.cpp
Executable file
10
7zip/Compress/BZip2/BZip2Error.cpp
Executable file
@@ -0,0 +1,10 @@
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Original/bzlib.h"
|
||||
|
||||
extern "C"
|
||||
|
||||
void bz_internal_error (int errcode)
|
||||
{
|
||||
throw "error";
|
||||
}
|
||||
86
7zip/Compress/BZip2/DllExports.cpp
Executable file
86
7zip/Compress/BZip2/DllExports.cpp
Executable file
@@ -0,0 +1,86 @@
|
||||
// DLLExports.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#define INITGUID
|
||||
|
||||
#include "BZip2Encoder.h"
|
||||
#include "BZip2Decoder.h"
|
||||
#include "Common/ComTry.h"
|
||||
|
||||
// {23170F69-40C1-278B-0402-020000000000}
|
||||
DEFINE_GUID(CLSID_CCompressBZip2Decoder,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
// {23170F69-40C1-278B-0402-020000000100}
|
||||
DEFINE_GUID(CLSID_CCompressBZip2Encoder,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x04, 0x02, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00);
|
||||
|
||||
extern "C"
|
||||
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
*outObject = 0;
|
||||
int correctInterface = (*iid == IID_ICompressCoder);
|
||||
CMyComPtr<ICompressCoder> coder;
|
||||
if (*clsid == CLSID_CCompressBZip2Decoder)
|
||||
{
|
||||
if (!correctInterface)
|
||||
return E_NOINTERFACE;
|
||||
coder = (ICompressCoder *)new NCompress::NBZip2::CDecoder;
|
||||
}
|
||||
else if (*clsid == CLSID_CCompressBZip2Encoder)
|
||||
{
|
||||
if (!correctInterface)
|
||||
return E_NOINTERFACE;
|
||||
coder = (ICompressCoder *)new NCompress::NBZip2::CEncoder;
|
||||
}
|
||||
else
|
||||
return CLASS_E_CLASSNOTAVAILABLE;
|
||||
*outObject = coder.Detach();
|
||||
COM_TRY_END
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDAPI GetNumberOfMethods(UINT32 *numMethods)
|
||||
{
|
||||
*numMethods = 1;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDAPI GetMethodProperty(UINT32 index, PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
if (index != 0)
|
||||
return E_INVALIDARG;
|
||||
::VariantClear((tagVARIANT *)value);
|
||||
switch(propID)
|
||||
{
|
||||
case NMethodPropID::kID:
|
||||
{
|
||||
const char id[] = { 0x04, 0x02, 0x02 };
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(id, sizeof(id))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
}
|
||||
case NMethodPropID::kName:
|
||||
if ((value->bstrVal = ::SysAllocString(L"BZip2")) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
case NMethodPropID::kDecoder:
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(
|
||||
(const char *)&CLSID_CCompressBZip2Decoder, sizeof(GUID))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
case NMethodPropID::kEncoder:
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(
|
||||
(const char *)&CLSID_CCompressBZip2Encoder, sizeof(GUID))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
3
7zip/Compress/BZip2/StdAfx.cpp
Executable file
3
7zip/Compress/BZip2/StdAfx.cpp
Executable file
@@ -0,0 +1,3 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "stdafx.h"
|
||||
8
7zip/Compress/BZip2/StdAfx.h
Executable file
8
7zip/Compress/BZip2/StdAfx.h
Executable file
@@ -0,0 +1,8 @@
|
||||
// stdafx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#endif
|
||||
15
7zip/Compress/BZip2/resource.h
Executable file
15
7zip/Compress/BZip2/resource.h
Executable file
@@ -0,0 +1,15 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by resource.rc
|
||||
//
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 101
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
121
7zip/Compress/BZip2/resource.rc
Executable file
121
7zip/Compress/BZip2/resource.rc
Executable file
@@ -0,0 +1,121 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Russian resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
|
||||
#pragma code_page(1251)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // Russian resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifndef _MAC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 3,8,1,0
|
||||
PRODUCTVERSION 3,8,1,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "\0"
|
||||
VALUE "CompanyName", " \0"
|
||||
VALUE "FileDescription", "BZip2 Coder\0"
|
||||
VALUE "FileVersion", "3, 8, 1, 0\0"
|
||||
VALUE "InternalName", "BZip2\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 1999-2003 Igor Pavlov\0"
|
||||
VALUE "LegalTrademarks", "\0"
|
||||
VALUE "OriginalFilename", "BZip2.dll\0"
|
||||
VALUE "PrivateBuild", "\0"
|
||||
VALUE "ProductName", "7-Zip\0"
|
||||
VALUE "ProductVersion", "3, 8, 1, 0\0"
|
||||
VALUE "SpecialBuild", "\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // !_MAC
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
69
7zip/Compress/Branch/ARM.cpp
Executable file
69
7zip/Compress/Branch/ARM.cpp
Executable file
@@ -0,0 +1,69 @@
|
||||
// ARM.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "ARM.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
static HRESULT BC_ARM_Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress, BYTE *buffer, bool encoding)
|
||||
{
|
||||
UINT32 nowPos = 0;
|
||||
UINT64 nowPos64 = 0;
|
||||
UINT32 bufferPos = 0;
|
||||
while(true)
|
||||
{
|
||||
UINT32 processedSize;
|
||||
UINT32 size = kBufferSize - bufferPos;
|
||||
RINOK(inStream->Read(buffer + bufferPos, size, &processedSize));
|
||||
UINT32 endPos = bufferPos + processedSize;
|
||||
if (endPos < 4)
|
||||
{
|
||||
if (endPos > 0)
|
||||
{
|
||||
RINOK(outStream->Write(buffer, endPos, &processedSize));
|
||||
if (endPos != processedSize)
|
||||
return E_FAIL;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
for (bufferPos = 0; bufferPos <= endPos - 4; bufferPos += 4)
|
||||
{
|
||||
if (buffer[bufferPos + 3] == 0xeb)
|
||||
{
|
||||
UINT32 src =
|
||||
(buffer[bufferPos + 2] << 16) |
|
||||
(buffer[bufferPos + 1] << 8) |
|
||||
(buffer[bufferPos + 0]);
|
||||
|
||||
src <<= 2;
|
||||
UINT32 dest;
|
||||
if (encoding)
|
||||
dest = nowPos + bufferPos + 8 + src;
|
||||
else
|
||||
dest = src - (nowPos + bufferPos + 8);
|
||||
dest >>= 2;
|
||||
buffer[bufferPos + 2] = (dest >> 16);
|
||||
buffer[bufferPos + 1] = (dest >> 8);
|
||||
buffer[bufferPos + 0] = dest;
|
||||
}
|
||||
}
|
||||
nowPos += bufferPos;
|
||||
nowPos64 += bufferPos;
|
||||
RINOK(outStream->Write(buffer, bufferPos, &processedSize));
|
||||
if (bufferPos != processedSize)
|
||||
return E_FAIL;
|
||||
if (progress != NULL)
|
||||
{
|
||||
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
|
||||
}
|
||||
|
||||
UINT32 i = 0;
|
||||
while(bufferPos < endPos)
|
||||
buffer[i++] = buffer[bufferPos++];
|
||||
bufferPos = i;
|
||||
}
|
||||
}
|
||||
|
||||
MyClassImp(BC_ARM)
|
||||
12
7zip/Compress/Branch/ARM.h
Executable file
12
7zip/Compress/Branch/ARM.h
Executable file
@@ -0,0 +1,12 @@
|
||||
// ARM.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __ARM_H
|
||||
#define __ARM_H
|
||||
|
||||
#include "Coder.h"
|
||||
|
||||
MyClass(BC_ARM, 0x05, 1)
|
||||
|
||||
#endif
|
||||
76
7zip/Compress/Branch/ARMThumb.cpp
Executable file
76
7zip/Compress/Branch/ARMThumb.cpp
Executable file
@@ -0,0 +1,76 @@
|
||||
// ARMThumb.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "ARMThumb.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
static HRESULT BC_ARMThumb_Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress, BYTE *buffer, bool encoding)
|
||||
{
|
||||
UINT32 nowPos = 0;
|
||||
UINT64 nowPos64 = 0;
|
||||
UINT32 bufferPos = 0;
|
||||
while(true)
|
||||
{
|
||||
UINT32 processedSize;
|
||||
UINT32 size = kBufferSize - bufferPos;
|
||||
RINOK(inStream->Read(buffer + bufferPos, size, &processedSize));
|
||||
UINT32 endPos = bufferPos + processedSize;
|
||||
if (endPos < 4)
|
||||
{
|
||||
if (endPos > 0)
|
||||
{
|
||||
RINOK(outStream->Write(buffer, endPos, &processedSize));
|
||||
if (endPos != processedSize)
|
||||
return E_FAIL;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
for (bufferPos = 0; bufferPos <= endPos - 4; bufferPos += 2)
|
||||
{
|
||||
if ((buffer[bufferPos + 1] & 0xF8) == 0xF0 &&
|
||||
(buffer[bufferPos + 3] & 0xF8) == 0xF8)
|
||||
{
|
||||
UINT32 src =
|
||||
((buffer[bufferPos + 1] & 0x7) << 19) |
|
||||
(buffer[bufferPos + 0] << 11) |
|
||||
((buffer[bufferPos + 3] & 0x7) << 8) |
|
||||
(buffer[bufferPos + 2]);
|
||||
|
||||
src <<= 1;
|
||||
UINT32 dest;
|
||||
if (encoding)
|
||||
dest = nowPos + bufferPos + 4 + src;
|
||||
else
|
||||
dest = src - (nowPos + bufferPos + 4);
|
||||
dest >>= 1;
|
||||
|
||||
buffer[bufferPos + 1] = 0xF0 | ((dest >> 19) & 0x7);
|
||||
buffer[bufferPos + 0] = (dest >> 11);
|
||||
buffer[bufferPos + 3] = 0xF8 | ((dest >> 8) & 0x7);
|
||||
buffer[bufferPos + 2] = (dest);
|
||||
bufferPos += 2;
|
||||
}
|
||||
}
|
||||
nowPos += bufferPos;
|
||||
nowPos64 += bufferPos;
|
||||
RINOK(outStream->Write(buffer, bufferPos, &processedSize));
|
||||
if (bufferPos != processedSize)
|
||||
return E_FAIL;
|
||||
if (progress != NULL)
|
||||
{
|
||||
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
|
||||
}
|
||||
|
||||
UINT32 i = 0;
|
||||
while(bufferPos < endPos)
|
||||
buffer[i++] = buffer[bufferPos++];
|
||||
bufferPos = i;
|
||||
}
|
||||
}
|
||||
|
||||
MyClassImp(BC_ARMThumb)
|
||||
|
||||
|
||||
12
7zip/Compress/Branch/ARMThumb.h
Executable file
12
7zip/Compress/Branch/ARMThumb.h
Executable file
@@ -0,0 +1,12 @@
|
||||
// ARMThumb.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __ARMTHUMB_H
|
||||
#define __ARMTHUMB_H
|
||||
|
||||
#include "Coder.h"
|
||||
|
||||
MyClass(BC_ARMThumb, 0x07, 1)
|
||||
|
||||
#endif
|
||||
75
7zip/Compress/Branch/Alpha.cpp
Executable file
75
7zip/Compress/Branch/Alpha.cpp
Executable file
@@ -0,0 +1,75 @@
|
||||
// Alpha.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "Alpha.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
static HRESULT BC_Alpha_Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress, BYTE *buffer, bool encoding)
|
||||
{
|
||||
UINT32 nowPos = 0;
|
||||
UINT64 nowPos64 = 0;
|
||||
UINT32 bufferPos = 0;
|
||||
while(true)
|
||||
{
|
||||
UINT32 processedSize;
|
||||
UINT32 size = kBufferSize - bufferPos;
|
||||
RINOK(inStream->Read(buffer + bufferPos, size, &processedSize));
|
||||
UINT32 endPos = bufferPos + processedSize;
|
||||
if (endPos < 4)
|
||||
{
|
||||
if (endPos > 0)
|
||||
{
|
||||
RINOK(outStream->Write(buffer, endPos, &processedSize));
|
||||
if (endPos != processedSize)
|
||||
return E_FAIL;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
for (bufferPos = 0; bufferPos <= endPos - 4; bufferPos += 4)
|
||||
{
|
||||
// if (buffer[bufferPos + 3] == 0xc3 && (buffer[bufferPos + 2] >> 5) == 7) // its jump
|
||||
// if (buffer[bufferPos + 3] == 0xd3 && (buffer[bufferPos + 2] >> 5) == 2)
|
||||
// if (buffer[bufferPos + 3] == 0xd3)
|
||||
if ((buffer[bufferPos + 3] >> 2) == 0x34)
|
||||
{
|
||||
UINT32 src =
|
||||
((buffer[bufferPos + 2] & 0x1F) << 16) |
|
||||
(buffer[bufferPos + 1] << 8) |
|
||||
(buffer[bufferPos + 0]);
|
||||
|
||||
src <<= 2;
|
||||
|
||||
UINT32 dest;
|
||||
if (encoding)
|
||||
dest = (nowPos + bufferPos + 4) + src;
|
||||
else
|
||||
dest = src - (nowPos + bufferPos + 4);
|
||||
dest >>= 2;
|
||||
dest &= 0x1FFFFF;
|
||||
buffer[bufferPos + 2] &= (~0x1F);
|
||||
buffer[bufferPos + 2] |= (dest >> 16);
|
||||
buffer[bufferPos + 1] = (dest >> 8);
|
||||
buffer[bufferPos + 0] = dest;
|
||||
}
|
||||
}
|
||||
nowPos += bufferPos;
|
||||
nowPos64 += bufferPos;
|
||||
RINOK(outStream->Write(buffer, bufferPos, &processedSize));
|
||||
if (bufferPos != processedSize)
|
||||
return E_FAIL;
|
||||
if (progress != NULL)
|
||||
{
|
||||
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
|
||||
}
|
||||
|
||||
UINT32 i = 0;
|
||||
while(bufferPos < endPos)
|
||||
buffer[i++] = buffer[bufferPos++];
|
||||
bufferPos = i;
|
||||
}
|
||||
}
|
||||
|
||||
MyClassImp(BC_Alpha)
|
||||
12
7zip/Compress/Branch/Alpha.h
Executable file
12
7zip/Compress/Branch/Alpha.h
Executable file
@@ -0,0 +1,12 @@
|
||||
// Alpha.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __ALPHA_H
|
||||
#define __ALPHA_H
|
||||
|
||||
#include "Coder.h"
|
||||
|
||||
MyClass(BC_Alpha, 0x03, 1)
|
||||
|
||||
#endif
|
||||
9
7zip/Compress/Branch/Branch.def
Executable file
9
7zip/Compress/Branch/Branch.def
Executable file
@@ -0,0 +1,9 @@
|
||||
; Branch.def
|
||||
|
||||
LIBRARY Branch.dll
|
||||
|
||||
EXPORTS
|
||||
CreateObject PRIVATE
|
||||
GetNumberOfMethods PRIVATE
|
||||
GetMethodProperty PRIVATE
|
||||
|
||||
310
7zip/Compress/Branch/Branch.dsp
Executable file
310
7zip/Compress/Branch/Branch.dsp
Executable file
@@ -0,0 +1,310 @@
|
||||
# Microsoft Developer Studio Project File - Name="Branch" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=Branch - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "Branch.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "Branch.mak" CFG="Branch - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "Branch - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "Branch - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "Branch - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BRANCH_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /Gz /MD /W3 /GX /O2 /I "..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BRANCH_EXPORTS" /FD /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "NDEBUG"
|
||||
# ADD RSC /l 0x419 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\Branch.dll" /opt:NOWIN98
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BRANCH_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BRANCH_EXPORTS" /Yu"StdAfx.h" /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "_DEBUG"
|
||||
# ADD RSC /l 0x419 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\Branch.dll" /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "Branch - Win32 Release"
|
||||
# Name "Branch - Win32 Debug"
|
||||
# Begin Group "Spec"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Branch.def
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\DllExports.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\resource.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\resource.rc
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.cpp
|
||||
# ADD CPP /Yc"StdAfx.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Methods"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Alpha.cpp
|
||||
|
||||
!IF "$(CFG)" == "Branch - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Alpha.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ARM.cpp
|
||||
|
||||
!IF "$(CFG)" == "Branch - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ARM.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ARMThumb.cpp
|
||||
|
||||
!IF "$(CFG)" == "Branch - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ARMThumb.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Coder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\IA64.cpp
|
||||
|
||||
!IF "$(CFG)" == "Branch - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\IA64.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\M68.cpp
|
||||
|
||||
!IF "$(CFG)" == "Branch - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\M68.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\PPC.cpp
|
||||
|
||||
!IF "$(CFG)" == "Branch - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\PPC.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\x86.cpp
|
||||
|
||||
!IF "$(CFG)" == "Branch - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\x86.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\x86_2.cpp
|
||||
|
||||
!IF "$(CFG)" == "Branch - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\x86_2.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Stream"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\InBuffer.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\InBuffer.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\OutBuffer.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\OutBuffer.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "RangeCoder"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\RangeCoder\RangeCoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\RangeCoder\RangeCoderBit.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Common"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
29
7zip/Compress/Branch/Branch.dsw
Executable file
29
7zip/Compress/Branch/Branch.dsw
Executable file
@@ -0,0 +1,29 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "Branch"=.\Branch.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
66
7zip/Compress/Branch/Coder.h
Executable file
66
7zip/Compress/Branch/Coder.h
Executable file
@@ -0,0 +1,66 @@
|
||||
// Branch/Coder.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __CallPowerPC_CODER_H
|
||||
#define __CallPowerPC_CODER_H
|
||||
|
||||
#include "Common/MyCom.h"
|
||||
#include "Common/Types.h"
|
||||
|
||||
#include "../../ICoder.h"
|
||||
|
||||
const int kBufferSize = 1 << 17;
|
||||
|
||||
class CDataBuffer
|
||||
{
|
||||
protected:
|
||||
BYTE *_buffer;
|
||||
public:
|
||||
CDataBuffer()
|
||||
{ _buffer = new BYTE[kBufferSize]; }
|
||||
~CDataBuffer()
|
||||
{ delete []_buffer; }
|
||||
};
|
||||
|
||||
#define MyClass3(Name) \
|
||||
class C ## Name: \
|
||||
public ICompressCoder, \
|
||||
public CDataBuffer, \
|
||||
public CMyUnknownImp \
|
||||
{ \
|
||||
public: \
|
||||
MY_UNKNOWN_IMP \
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream, \
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize, \
|
||||
ICompressProgressInfo *progress); \
|
||||
};
|
||||
|
||||
// {23170F69-40C1-278B-0303-010100000100}
|
||||
#define MyClass2(Name, id, subId, encodingId) \
|
||||
DEFINE_GUID(CLSID_CCompressConvert ## Name, \
|
||||
0x23170F69, 0x40C1, 0x278B, 0x03, 0x03, id, subId, 0x00, 0x00, encodingId, 0x00); \
|
||||
MyClass3(Name) \
|
||||
|
||||
|
||||
#define MyClass(Name, id, subId) \
|
||||
MyClass2(Name ## _Encoder, id, subId, 0x01) \
|
||||
MyClass2(Name ## _Decoder, id, subId, 0x00)
|
||||
|
||||
#define MyClassImp(Name) \
|
||||
STDMETHODIMP C ## Name ## _Encoder::Code(ISequentialInStream *inStream, \
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize, \
|
||||
ICompressProgressInfo *progress) \
|
||||
{ \
|
||||
return Name ## _Code(inStream, outStream, inSize, outSize, \
|
||||
progress, _buffer, true); \
|
||||
} \
|
||||
STDMETHODIMP C ## Name ## _Decoder::Code(ISequentialInStream *inStream, \
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize, \
|
||||
ICompressProgressInfo *progress) \
|
||||
{ \
|
||||
return Name ## _Code(inStream, outStream, inSize, outSize, \
|
||||
progress, _buffer, false); \
|
||||
}
|
||||
|
||||
#endif
|
||||
178
7zip/Compress/Branch/DllExports.cpp
Executable file
178
7zip/Compress/Branch/DllExports.cpp
Executable file
@@ -0,0 +1,178 @@
|
||||
// DLLExports.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#define INITGUID
|
||||
|
||||
#include "Common/ComTry.h"
|
||||
|
||||
#include "Coder.h"
|
||||
#include "x86.h"
|
||||
#include "PPC.h"
|
||||
#include "Alpha.h"
|
||||
#include "IA64.h"
|
||||
#include "ARM.h"
|
||||
#include "ARMThumb.h"
|
||||
#include "M68.h"
|
||||
#include "x86_2.h"
|
||||
|
||||
#include "../../ICoder.h"
|
||||
|
||||
|
||||
#define MY_CreateClass(n) \
|
||||
if (*clsid == CLSID_CCompressConvert ## n ## _Encoder) { \
|
||||
if (!correctInterface) \
|
||||
return E_NOINTERFACE; \
|
||||
coder = (ICompressCoder *)new C ## n ## _Encoder(); \
|
||||
} else if (*clsid == CLSID_CCompressConvert ## n ## _Decoder){ \
|
||||
if (!correctInterface) \
|
||||
return E_NOINTERFACE; \
|
||||
coder = (ICompressCoder *)new C ## n ## _Decoder(); \
|
||||
}
|
||||
|
||||
/*
|
||||
#define MyOBJECT_ENTRY(Name) \
|
||||
OBJECT_ENTRY(CLSID_CCompressConvert ## Name ## _Encoder, C ## Name ## _Encoder) \
|
||||
OBJECT_ENTRY(CLSID_CCompressConvert ## Name ## _Decoder, C ## Name ## _Decoder) \
|
||||
|
||||
|
||||
BEGIN_OBJECT_MAP(ObjectMap)
|
||||
MyOBJECT_ENTRY(BCJ_x86)
|
||||
MyOBJECT_ENTRY(BCJ2_x86)
|
||||
MyOBJECT_ENTRY(BC_PPC_B)
|
||||
MyOBJECT_ENTRY(BC_Alpha)
|
||||
MyOBJECT_ENTRY(BC_IA64)
|
||||
MyOBJECT_ENTRY(BC_ARM)
|
||||
MyOBJECT_ENTRY(BC_ARMThumb)
|
||||
MyOBJECT_ENTRY(BC_M68_B)
|
||||
END_OBJECT_MAP()
|
||||
*/
|
||||
|
||||
extern "C"
|
||||
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
STDAPI CreateObject(
|
||||
const GUID *clsid,
|
||||
const GUID *interfaceID,
|
||||
void **outObject)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
*outObject = 0;
|
||||
int correctInterface = (*interfaceID == IID_ICompressCoder);
|
||||
CMyComPtr<ICompressCoder> coder;
|
||||
|
||||
MY_CreateClass(BCJ_x86)
|
||||
else
|
||||
MY_CreateClass(BC_PPC_B)
|
||||
else
|
||||
MY_CreateClass(BC_Alpha)
|
||||
else
|
||||
MY_CreateClass(BC_IA64)
|
||||
else
|
||||
MY_CreateClass(BC_ARM)
|
||||
else
|
||||
MY_CreateClass(BC_ARMThumb)
|
||||
else
|
||||
MY_CreateClass(BC_M68_B)
|
||||
else
|
||||
{
|
||||
CMyComPtr<ICompressCoder2> coder2;
|
||||
correctInterface = (*interfaceID == IID_ICompressCoder2);
|
||||
if (*clsid == CLSID_CCompressConvertBCJ2_x86_Encoder)
|
||||
{
|
||||
if (!correctInterface)
|
||||
return E_NOINTERFACE;
|
||||
coder2 = (ICompressCoder2 *)new CBCJ2_x86_Encoder();
|
||||
}
|
||||
else if (*clsid == CLSID_CCompressConvertBCJ2_x86_Decoder)
|
||||
{
|
||||
if (!correctInterface)
|
||||
return E_NOINTERFACE;
|
||||
coder2 = (ICompressCoder2 *)new CBCJ2_x86_Decoder();
|
||||
}
|
||||
else
|
||||
return CLASS_E_CLASSNOTAVAILABLE;
|
||||
*outObject = coder2.Detach();
|
||||
return S_OK;
|
||||
}
|
||||
*outObject = coder.Detach();
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
struct CBranchMethodItem
|
||||
{
|
||||
char ID[4];
|
||||
const wchar_t *UserName;
|
||||
const GUID *Decoder;
|
||||
const GUID *Encoder;
|
||||
UINT32 NumInStreams;
|
||||
};
|
||||
|
||||
#define METHOD_ITEM(Name, id, subId, UserName, NumInStreams) \
|
||||
{ { 0x03, 0x03, id, subId }, UserName, \
|
||||
&CLSID_CCompressConvert ## Name ## _Decoder, \
|
||||
&CLSID_CCompressConvert ## Name ## _Encoder, NumInStreams }
|
||||
|
||||
|
||||
static CBranchMethodItem g_Methods[] =
|
||||
{
|
||||
METHOD_ITEM(BCJ_x86, 0x01, 0x03, L"BCJ", 1),
|
||||
METHOD_ITEM(BCJ2_x86, 0x01, 0x1B, L"BCJ2", 4),
|
||||
METHOD_ITEM(BC_PPC_B, 0x02, 0x05, L"BC_PPC_B", 1),
|
||||
METHOD_ITEM(BC_Alpha, 0x03, 1, L"BC_Alpha", 1),
|
||||
METHOD_ITEM(BC_IA64, 0x04, 1, L"BC_IA64", 1),
|
||||
METHOD_ITEM(BC_ARM, 0x05, 1, L"BC_ARM", 1),
|
||||
METHOD_ITEM(BC_M68_B, 0x06, 5, L"BC_M68_B", 1),
|
||||
METHOD_ITEM(BC_ARMThumb, 0x07, 1, L"BC_ARMThumb", 1)
|
||||
};
|
||||
|
||||
STDAPI GetNumberOfMethods(UINT32 *numMethods)
|
||||
{
|
||||
*numMethods = sizeof(g_Methods) / sizeof(g_Methods[1]);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDAPI GetMethodProperty(UINT32 index, PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
if (index > sizeof(g_Methods) / sizeof(g_Methods[1]))
|
||||
return E_INVALIDARG;
|
||||
VariantClear((tagVARIANT *)value);
|
||||
const CBranchMethodItem &method = g_Methods[index];
|
||||
switch(propID)
|
||||
{
|
||||
case NMethodPropID::kID:
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(method.ID,
|
||||
sizeof(method.ID))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
case NMethodPropID::kName:
|
||||
if ((value->bstrVal = ::SysAllocString(method.UserName)) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
case NMethodPropID::kDecoder:
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(
|
||||
(const char *)method.Decoder, sizeof(GUID))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
case NMethodPropID::kEncoder:
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(
|
||||
(const char *)method.Encoder, sizeof(GUID))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
case NMethodPropID::kInStreams:
|
||||
{
|
||||
if (method.NumInStreams != 1)
|
||||
{
|
||||
value->vt = VT_UI4;
|
||||
value->ulVal = method.NumInStreams;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
103
7zip/Compress/Branch/IA64.cpp
Executable file
103
7zip/Compress/Branch/IA64.cpp
Executable file
@@ -0,0 +1,103 @@
|
||||
// IA64.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "IA64.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
const BYTE kBranchTable[32] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
4, 4, 6, 6, 0, 0, 7, 7,
|
||||
4, 4, 0, 0, 4, 4, 0, 0
|
||||
};
|
||||
|
||||
|
||||
static HRESULT BC_IA64_Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress, BYTE *buffer, bool encoding)
|
||||
{
|
||||
UINT32 nowPos = 0;
|
||||
UINT64 nowPos64 = 0;
|
||||
UINT32 bufferPos = 0;
|
||||
while(true)
|
||||
{
|
||||
UINT32 processedSize;
|
||||
UINT32 size = kBufferSize - bufferPos;
|
||||
RINOK(inStream->Read(buffer + bufferPos, size, &processedSize));
|
||||
UINT32 endPos = bufferPos + processedSize;
|
||||
if (endPos < 16)
|
||||
{
|
||||
if (endPos > 0)
|
||||
{
|
||||
RINOK(outStream->Write(buffer, endPos, &processedSize));
|
||||
if (endPos != processedSize)
|
||||
return E_FAIL;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
for (bufferPos = 0; bufferPos <= endPos - 16; bufferPos += 16)
|
||||
{
|
||||
UINT32 instrTemplate = buffer[bufferPos] & 0x1F;
|
||||
// ofs << hex << setw(4) << instrTemplate << endl;
|
||||
UINT32 mask = kBranchTable[instrTemplate];
|
||||
UINT32 bitPos = 5;
|
||||
for (int slot = 0; slot < 3; slot++, bitPos += 41)
|
||||
{
|
||||
if (((mask >> slot) & 1) == 0)
|
||||
continue;
|
||||
UINT32 bytePos = (bitPos >> 3);
|
||||
UINT32 bitRes = bitPos & 0x7;
|
||||
UINT64 instruction = *(UINT64 *)(buffer + bufferPos + bytePos);
|
||||
UINT64 instNorm = instruction >> bitRes;
|
||||
if (((instNorm >> 37) & 0xF) == 0x5
|
||||
&& ((instNorm >> 9) & 0x7) == 0
|
||||
// && (instNorm & 0x3F)== 0
|
||||
)
|
||||
{
|
||||
UINT32 src = UINT32((instNorm >> 13) & 0xFFFFF);
|
||||
src |= ((instNorm >> 36) & 1) << 20;
|
||||
|
||||
src <<= 4;
|
||||
|
||||
UINT32 dest;
|
||||
if (encoding)
|
||||
dest = nowPos + bufferPos + src;
|
||||
else
|
||||
dest = src - (nowPos + bufferPos);
|
||||
|
||||
dest >>= 4;
|
||||
|
||||
UINT64 instNorm2 = instNorm;
|
||||
|
||||
instNorm &= ~(UINT64(0x8FFFFF) << 13);
|
||||
instNorm |= (UINT64(dest & 0xFFFFF) << 13);
|
||||
instNorm |= (UINT64(dest & 0x100000) << (36 - 20));
|
||||
|
||||
instruction &= (1 << bitRes) - 1;
|
||||
instruction |= (instNorm << bitRes);
|
||||
*(UINT64 *)(buffer + bufferPos + bytePos) = instruction;
|
||||
}
|
||||
}
|
||||
}
|
||||
nowPos += bufferPos;
|
||||
nowPos64 += bufferPos;
|
||||
RINOK(outStream->Write(buffer, bufferPos, &processedSize));
|
||||
if (bufferPos != processedSize)
|
||||
return E_FAIL;
|
||||
if (progress != NULL)
|
||||
{
|
||||
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
|
||||
}
|
||||
|
||||
UINT32 i = 0;
|
||||
while(bufferPos < endPos)
|
||||
buffer[i++] = buffer[bufferPos++];
|
||||
bufferPos = i;
|
||||
}
|
||||
}
|
||||
|
||||
MyClassImp(BC_IA64)
|
||||
|
||||
|
||||
14
7zip/Compress/Branch/IA64.h
Executable file
14
7zip/Compress/Branch/IA64.h
Executable file
@@ -0,0 +1,14 @@
|
||||
// IA64.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __IA64_H
|
||||
#define __IA64_H
|
||||
|
||||
#include "Coder.h"
|
||||
|
||||
MyClass(BC_IA64, 0x04, 1)
|
||||
|
||||
// MyClass(IA64_Parse, 0x08, 1)
|
||||
|
||||
#endif
|
||||
69
7zip/Compress/Branch/M68.cpp
Executable file
69
7zip/Compress/Branch/M68.cpp
Executable file
@@ -0,0 +1,69 @@
|
||||
// M68.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "M68.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
static HRESULT BC_M68_B_Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress, BYTE *buffer, bool encoding)
|
||||
{
|
||||
UINT32 nowPos = 0;
|
||||
UINT64 nowPos64 = 0;
|
||||
UINT32 bufferPos = 0;
|
||||
while(true)
|
||||
{
|
||||
UINT32 processedSize;
|
||||
UINT32 size = kBufferSize - bufferPos;
|
||||
RINOK(inStream->Read(buffer + bufferPos, size, &processedSize));
|
||||
UINT32 endPos = bufferPos + processedSize;
|
||||
if (endPos < 4)
|
||||
{
|
||||
if (endPos > 0)
|
||||
{
|
||||
RINOK(outStream->Write(buffer, endPos, &processedSize));
|
||||
if (endPos != processedSize)
|
||||
return E_FAIL;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
for (bufferPos = 0; bufferPos <= endPos - 4;)
|
||||
{
|
||||
if (buffer[bufferPos] == 0x61 && buffer[bufferPos + 1] == 0x00)
|
||||
{
|
||||
UINT32 src =
|
||||
(buffer[bufferPos + 2] << 8) |
|
||||
(buffer[bufferPos + 3]);
|
||||
|
||||
UINT32 dest;
|
||||
if (encoding)
|
||||
dest = nowPos + bufferPos + 2 + src;
|
||||
else
|
||||
dest = src - (nowPos + bufferPos + 2);
|
||||
buffer[bufferPos + 2] = (dest >> 8);
|
||||
buffer[bufferPos + 3] = dest;
|
||||
bufferPos += 4;
|
||||
}
|
||||
else
|
||||
bufferPos += 2;
|
||||
}
|
||||
nowPos += bufferPos;
|
||||
nowPos64 += bufferPos;
|
||||
RINOK(outStream->Write(buffer, bufferPos, &processedSize));
|
||||
if (bufferPos != processedSize)
|
||||
return E_FAIL;
|
||||
if (progress != NULL)
|
||||
{
|
||||
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
|
||||
}
|
||||
|
||||
UINT32 i = 0;
|
||||
while(bufferPos < endPos)
|
||||
buffer[i++] = buffer[bufferPos++];
|
||||
bufferPos = i;
|
||||
}
|
||||
}
|
||||
|
||||
MyClassImp(BC_M68_B)
|
||||
|
||||
12
7zip/Compress/Branch/M68.h
Executable file
12
7zip/Compress/Branch/M68.h
Executable file
@@ -0,0 +1,12 @@
|
||||
// M68.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __M68_H
|
||||
#define __M68_H
|
||||
|
||||
#include "Coder.h"
|
||||
|
||||
MyClass(BC_M68_B, 0x06, 5)
|
||||
|
||||
#endif
|
||||
76
7zip/Compress/Branch/PPC.cpp
Executable file
76
7zip/Compress/Branch/PPC.cpp
Executable file
@@ -0,0 +1,76 @@
|
||||
// PPC.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "PPC.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
static HRESULT BC_PPC_B_Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress, BYTE *buffer, bool encoding)
|
||||
{
|
||||
UINT32 nowPos = 0;
|
||||
UINT64 nowPos64 = 0;
|
||||
UINT32 bufferPos = 0;
|
||||
while(true)
|
||||
{
|
||||
UINT32 processedSize;
|
||||
UINT32 size = kBufferSize - bufferPos;
|
||||
RINOK(inStream->Read(buffer + bufferPos, size, &processedSize));
|
||||
UINT32 endPos = bufferPos + processedSize;
|
||||
if (endPos < 4)
|
||||
{
|
||||
if (endPos > 0)
|
||||
{
|
||||
RINOK(outStream->Write(buffer, endPos, &processedSize));
|
||||
if (endPos != processedSize)
|
||||
return E_FAIL;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
for (bufferPos = 0; bufferPos <= endPos - 4; bufferPos += 4)
|
||||
{
|
||||
// PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link)
|
||||
if ((buffer[bufferPos] >> 2) == 0x12 &&
|
||||
(
|
||||
(buffer[bufferPos + 3] & 3) == 1
|
||||
// || (buffer[bufferPos+3] & 3) == 3
|
||||
)
|
||||
)
|
||||
{
|
||||
UINT32 src = ((buffer[bufferPos + 0] & 3) << 24) |
|
||||
(buffer[bufferPos + 1] << 16) |
|
||||
(buffer[bufferPos + 2] << 8) |
|
||||
(buffer[bufferPos + 3] & (~3));
|
||||
|
||||
UINT32 dest;
|
||||
if (encoding)
|
||||
dest = nowPos + bufferPos + src;
|
||||
else
|
||||
dest = src - (nowPos + bufferPos);
|
||||
buffer[bufferPos + 0] = 0x48 | ((dest >> 24) & 0x3);
|
||||
buffer[bufferPos + 1] = (dest >> 16);
|
||||
buffer[bufferPos + 2] = (dest >> 8);
|
||||
buffer[bufferPos + 3] &= 0x3;
|
||||
buffer[bufferPos + 3] |= dest;
|
||||
}
|
||||
}
|
||||
nowPos += bufferPos;
|
||||
nowPos64 += bufferPos;
|
||||
RINOK(outStream->Write(buffer, bufferPos, &processedSize));
|
||||
if (bufferPos != processedSize)
|
||||
return E_FAIL;
|
||||
if (progress != NULL)
|
||||
{
|
||||
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
|
||||
}
|
||||
|
||||
UINT32 i = 0;
|
||||
while(bufferPos < endPos)
|
||||
buffer[i++] = buffer[bufferPos++];
|
||||
bufferPos = i;
|
||||
}
|
||||
}
|
||||
|
||||
MyClassImp(BC_PPC_B)
|
||||
|
||||
12
7zip/Compress/Branch/PPC.h
Executable file
12
7zip/Compress/Branch/PPC.h
Executable file
@@ -0,0 +1,12 @@
|
||||
// PPC.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __PPC_H
|
||||
#define __PPC_H
|
||||
|
||||
#include "Coder.h"
|
||||
|
||||
MyClass(BC_PPC_B, 0x02, 5)
|
||||
|
||||
#endif
|
||||
3
7zip/Compress/Branch/StdAfx.cpp
Executable file
3
7zip/Compress/Branch/StdAfx.cpp
Executable file
@@ -0,0 +1,3 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "stdafx.h"
|
||||
8
7zip/Compress/Branch/StdAfx.h
Executable file
8
7zip/Compress/Branch/StdAfx.h
Executable file
@@ -0,0 +1,8 @@
|
||||
// stdafx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#endif
|
||||
15
7zip/Compress/Branch/resource.h
Executable file
15
7zip/Compress/Branch/resource.h
Executable file
@@ -0,0 +1,15 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by resource.rc
|
||||
//
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 101
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
121
7zip/Compress/Branch/resource.rc
Executable file
121
7zip/Compress/Branch/resource.rc
Executable file
@@ -0,0 +1,121 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Russian resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
|
||||
#pragma code_page(1251)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // Russian resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifndef _MAC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 3,9,2,0
|
||||
PRODUCTVERSION 3,9,2,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "\0"
|
||||
VALUE "CompanyName", "Igor Pavlov\0"
|
||||
VALUE "FileDescription", "Branch converter\0"
|
||||
VALUE "FileVersion", "3, 9, 2, 0\0"
|
||||
VALUE "InternalName", "Branch\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 1999-2003 Igor Pavlov\0"
|
||||
VALUE "LegalTrademarks", "\0"
|
||||
VALUE "OriginalFilename", "Branch.dll\0"
|
||||
VALUE "PrivateBuild", "\0"
|
||||
VALUE "ProductName", "7-Zip\0"
|
||||
VALUE "ProductVersion", "3, 9, 2, 0\0"
|
||||
VALUE "SpecialBuild", "\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // !_MAC
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
124
7zip/Compress/Branch/x86.cpp
Executable file
124
7zip/Compress/Branch/x86.cpp
Executable file
@@ -0,0 +1,124 @@
|
||||
// x86.h
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "x86.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
static bool inline Test86MSByte(BYTE b)
|
||||
{
|
||||
return (b == 0 || b == 0xFF);
|
||||
}
|
||||
|
||||
const bool kMaskToAllowedStatus[8] = {true, true, true, false, true, false, false, false};
|
||||
const BYTE kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};
|
||||
|
||||
static HRESULT BCJ_x86_Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress, BYTE *buffer, bool encoding)
|
||||
{
|
||||
UINT64 nowPos64 = 0;
|
||||
UINT32 nowPos = 0;
|
||||
UINT32 bufferPos = 0;
|
||||
UINT32 prevMask = 0;
|
||||
UINT32 prevPos = (- 5);
|
||||
|
||||
while(true)
|
||||
{
|
||||
UINT32 processedSize;
|
||||
UINT32 size = kBufferSize - bufferPos;
|
||||
RINOK(inStream->Read(buffer + bufferPos, size, &processedSize));
|
||||
UINT32 endPos = bufferPos + processedSize;
|
||||
if (endPos < 5)
|
||||
{
|
||||
if (endPos > 0)
|
||||
{
|
||||
RINOK(outStream->Write(buffer, endPos, &processedSize));
|
||||
if (endPos != processedSize)
|
||||
return E_FAIL;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
bufferPos = 0;
|
||||
if (nowPos - prevPos > 5)
|
||||
prevPos = nowPos - 5;
|
||||
|
||||
UINT32 limit = endPos - 5;
|
||||
while(bufferPos <= limit)
|
||||
{
|
||||
if (buffer[bufferPos] != 0xE8 && buffer[bufferPos] != 0xE9)
|
||||
{
|
||||
bufferPos++;
|
||||
continue;
|
||||
}
|
||||
UINT32 offset = (nowPos + bufferPos - prevPos);
|
||||
prevPos = (nowPos + bufferPos);
|
||||
if (offset > 5)
|
||||
prevMask = 0;
|
||||
else
|
||||
{
|
||||
for (UINT32 i = 0; i < offset; i++)
|
||||
{
|
||||
prevMask &= 0x77;
|
||||
prevMask <<= 1;
|
||||
}
|
||||
}
|
||||
BYTE &nextByte = buffer[bufferPos + 4];
|
||||
if (Test86MSByte(nextByte) && kMaskToAllowedStatus[(prevMask >> 1) & 0x7] &&
|
||||
(prevMask >> 1) < 0x10)
|
||||
{
|
||||
UINT32 src =
|
||||
(UINT32(nextByte) << 24) |
|
||||
(UINT32(buffer[bufferPos + 3]) << 16) |
|
||||
(UINT32(buffer[bufferPos + 2]) << 8) |
|
||||
(buffer[bufferPos + 1]);
|
||||
|
||||
UINT32 dest;
|
||||
while(true)
|
||||
{
|
||||
if (encoding)
|
||||
dest = (nowPos + bufferPos + 5) + src;
|
||||
else
|
||||
dest = src - (nowPos + bufferPos + 5);
|
||||
if (prevMask == 0)
|
||||
break;
|
||||
UINT32 index = kMaskToBitNumber[prevMask >> 1];
|
||||
if (!Test86MSByte(dest >> (24 - index * 8)))
|
||||
break;
|
||||
src = dest ^ ((1 << (32 - index * 8)) - 1);
|
||||
// src = dest;
|
||||
}
|
||||
nextByte = ~(((dest >> 24) & 1) - 1);
|
||||
buffer[bufferPos + 3] = (dest >> 16);
|
||||
buffer[bufferPos + 2] = (dest >> 8);
|
||||
buffer[bufferPos + 1] = dest;
|
||||
bufferPos += 5;
|
||||
prevMask = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
bufferPos++;
|
||||
prevMask |= 1;
|
||||
if (Test86MSByte(nextByte))
|
||||
prevMask |= 0x10;
|
||||
}
|
||||
}
|
||||
nowPos += bufferPos;
|
||||
nowPos64 += bufferPos;
|
||||
RINOK(outStream->Write(buffer, bufferPos, &processedSize));
|
||||
if (bufferPos != processedSize)
|
||||
return E_FAIL;
|
||||
if (progress != NULL)
|
||||
{
|
||||
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
|
||||
}
|
||||
|
||||
UINT32 i = 0;
|
||||
while(bufferPos < endPos)
|
||||
buffer[i++] = buffer[bufferPos++];
|
||||
bufferPos = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MyClassImp(BCJ_x86)
|
||||
13
7zip/Compress/Branch/x86.h
Executable file
13
7zip/Compress/Branch/x86.h
Executable file
@@ -0,0 +1,13 @@
|
||||
// x86.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __X86_H
|
||||
#define __X86_H
|
||||
|
||||
#include "Coder.h"
|
||||
|
||||
MyClass(BCJ_x86, 0x01, 3)
|
||||
// MyClass(x86_J, 0x01, 2)
|
||||
|
||||
#endif
|
||||
331
7zip/Compress/Branch/x86_2.cpp
Executable file
331
7zip/Compress/Branch/x86_2.cpp
Executable file
@@ -0,0 +1,331 @@
|
||||
// x86_2.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "x86_2.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
#include "../../ICoder.h"
|
||||
|
||||
inline UINT32 Swap4(UINT32 value)
|
||||
{
|
||||
return (value << 24) | (value >> 24) |
|
||||
( (value >> 8) & 0xFF00) | ( (value << 8) & 0xFF0000);
|
||||
}
|
||||
|
||||
inline bool IsJcc(BYTE b0, BYTE b1)
|
||||
{
|
||||
return (b0 == 0x0F && (b1 & 0xF0) == 0x80);
|
||||
}
|
||||
|
||||
#ifndef EXTRACT_ONLY
|
||||
|
||||
static bool inline Test86MSByte(BYTE b)
|
||||
{
|
||||
return (b == 0 || b == 0xFF);
|
||||
}
|
||||
|
||||
HRESULT CBCJ2_x86_Encoder::Flush()
|
||||
{
|
||||
RINOK(_mainStream.Flush());
|
||||
RINOK(_callStream.Flush());
|
||||
RINOK(_jumpStream.Flush());
|
||||
_rangeEncoder.FlushData();
|
||||
return _rangeEncoder.FlushStream();
|
||||
}
|
||||
|
||||
const UINT32 kDefaultLimit = (1 << 24);
|
||||
|
||||
HRESULT CBCJ2_x86_Encoder::CodeReal(ISequentialInStream **inStreams,
|
||||
const UINT64 **inSizes,
|
||||
UINT32 numInStreams,
|
||||
ISequentialOutStream **outStreams,
|
||||
const UINT64 **outSizes,
|
||||
UINT32 numOutStreams,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
if (numInStreams != 1 || numOutStreams != 4)
|
||||
return E_INVALIDARG;
|
||||
|
||||
bool sizeIsDefined = false;
|
||||
UINT64 inSize;
|
||||
if (inSizes != NULL)
|
||||
if (inSizes[0] != NULL)
|
||||
{
|
||||
inSize = *inSizes[0];
|
||||
if (inSize <= kDefaultLimit)
|
||||
sizeIsDefined = true;
|
||||
}
|
||||
|
||||
|
||||
ISequentialInStream *inStream = inStreams[0];
|
||||
|
||||
_mainStream.Init(outStreams[0]);
|
||||
_callStream.Init(outStreams[1]);
|
||||
_jumpStream.Init(outStreams[2]);
|
||||
_rangeEncoder.Init(outStreams[3]);
|
||||
for (int i = 0; i < 256; i++)
|
||||
_statusE8Encoder[i].Init();
|
||||
_statusE9Encoder.Init();
|
||||
_statusJccEncoder.Init();
|
||||
// CCoderReleaser releaser(this);
|
||||
|
||||
CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;
|
||||
{
|
||||
inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);
|
||||
}
|
||||
|
||||
|
||||
UINT32 nowPos = 0;
|
||||
UINT64 nowPos64 = 0;
|
||||
UINT32 bufferPos = 0;
|
||||
UINT32 processedSize;
|
||||
|
||||
BYTE prevByte = 0;
|
||||
|
||||
UINT64 subStreamIndex = 0;
|
||||
UINT64 subStreamStartPos = 0;
|
||||
UINT64 subStreamEndPos = 0;
|
||||
|
||||
while(true)
|
||||
{
|
||||
UINT32 size = kBufferSize - bufferPos;
|
||||
RINOK(inStream->Read(_buffer + bufferPos, size, &processedSize));
|
||||
UINT32 endPos = bufferPos + processedSize;
|
||||
|
||||
if (endPos < 5)
|
||||
{
|
||||
// change it
|
||||
for (bufferPos = 0; bufferPos < endPos; bufferPos++)
|
||||
{
|
||||
BYTE b = _buffer[bufferPos];
|
||||
_mainStream.WriteByte(b);
|
||||
if (b == 0xE8)
|
||||
_statusE8Encoder[prevByte].Encode(&_rangeEncoder, 0);
|
||||
else if (b == 0xE9)
|
||||
_statusE9Encoder.Encode(&_rangeEncoder, 0);
|
||||
else if (IsJcc(prevByte, b))
|
||||
_statusJccEncoder.Encode(&_rangeEncoder, 0);
|
||||
prevByte = b;
|
||||
}
|
||||
return Flush();
|
||||
}
|
||||
|
||||
bufferPos = 0;
|
||||
|
||||
UINT32 limit = endPos - 5;
|
||||
while(bufferPos <= limit)
|
||||
{
|
||||
BYTE b = _buffer[bufferPos];
|
||||
_mainStream.WriteByte(b);
|
||||
if (b != 0xE8 && b != 0xE9 && !IsJcc(prevByte, b))
|
||||
{
|
||||
bufferPos++;
|
||||
prevByte = b;
|
||||
continue;
|
||||
}
|
||||
BYTE nextByte = _buffer[bufferPos + 4];
|
||||
UINT32 src =
|
||||
(UINT32(nextByte) << 24) |
|
||||
(UINT32(_buffer[bufferPos + 3]) << 16) |
|
||||
(UINT32(_buffer[bufferPos + 2]) << 8) |
|
||||
(_buffer[bufferPos + 1]);
|
||||
UINT32 dest = (nowPos + bufferPos + 5) + src;
|
||||
// if (Test86MSByte(nextByte))
|
||||
bool convert;
|
||||
if (getSubStreamSize != NULL)
|
||||
{
|
||||
UINT64 currentPos = (nowPos64 + bufferPos);
|
||||
while (subStreamEndPos < currentPos)
|
||||
{
|
||||
UINT64 subStreamSize;
|
||||
HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);
|
||||
if (result == S_OK)
|
||||
{
|
||||
subStreamStartPos = subStreamEndPos;
|
||||
subStreamEndPos += subStreamSize;
|
||||
subStreamIndex++;
|
||||
}
|
||||
else if (result == S_FALSE || result == E_NOTIMPL)
|
||||
{
|
||||
getSubStreamSize.Release();
|
||||
subStreamStartPos = 0;
|
||||
subStreamEndPos = subStreamStartPos - 1;
|
||||
}
|
||||
else
|
||||
return result;
|
||||
}
|
||||
if (getSubStreamSize == NULL)
|
||||
{
|
||||
if (sizeIsDefined)
|
||||
convert = (dest < inSize);
|
||||
else
|
||||
convert = Test86MSByte(nextByte);
|
||||
}
|
||||
else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)
|
||||
convert = Test86MSByte(nextByte);
|
||||
else
|
||||
{
|
||||
UINT64 dest64 = (currentPos + 5) + INT64(INT32(src));
|
||||
convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);
|
||||
}
|
||||
}
|
||||
else if (sizeIsDefined)
|
||||
convert = (dest < inSize);
|
||||
else
|
||||
convert = Test86MSByte(nextByte);
|
||||
if (convert)
|
||||
{
|
||||
if (b == 0xE8)
|
||||
_statusE8Encoder[prevByte].Encode(&_rangeEncoder, 1);
|
||||
else if (b == 0xE9)
|
||||
_statusE9Encoder.Encode(&_rangeEncoder, 1);
|
||||
else
|
||||
_statusJccEncoder.Encode(&_rangeEncoder, 1);
|
||||
|
||||
dest = Swap4(dest);
|
||||
|
||||
bufferPos += 5;
|
||||
if (b == 0xE8)
|
||||
_callStream.WriteBytes(&dest, sizeof(dest));
|
||||
else
|
||||
_jumpStream.WriteBytes(&dest, sizeof(dest));
|
||||
prevByte = nextByte;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (b == 0xE8)
|
||||
_statusE8Encoder[prevByte].Encode(&_rangeEncoder, 0);
|
||||
else if (b == 0xE9)
|
||||
_statusE9Encoder.Encode(&_rangeEncoder, 0);
|
||||
else
|
||||
_statusJccEncoder.Encode(&_rangeEncoder, 0);
|
||||
bufferPos++;
|
||||
prevByte = b;
|
||||
}
|
||||
}
|
||||
nowPos += bufferPos;
|
||||
nowPos64 += bufferPos;
|
||||
|
||||
if (progress != NULL)
|
||||
{
|
||||
RINOK(progress->SetRatioInfo(&nowPos64, NULL));
|
||||
}
|
||||
|
||||
|
||||
UINT32 i = 0;
|
||||
while(bufferPos < endPos)
|
||||
_buffer[i++] = _buffer[bufferPos++];
|
||||
bufferPos = i;
|
||||
}
|
||||
}
|
||||
|
||||
STDMETHODIMP CBCJ2_x86_Encoder::Code(ISequentialInStream **inStreams,
|
||||
const UINT64 **inSizes,
|
||||
UINT32 numInStreams,
|
||||
ISequentialOutStream **outStreams,
|
||||
const UINT64 **outSizes,
|
||||
UINT32 numOutStreams,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
try
|
||||
{
|
||||
return CodeReal(inStreams, inSizes, numInStreams,
|
||||
outStreams, outSizes,numOutStreams, progress);
|
||||
}
|
||||
catch(const COutBufferException &e) { return e.ErrorCode; }
|
||||
catch(...) { return S_FALSE; }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
HRESULT CBCJ2_x86_Decoder::CodeReal(ISequentialInStream **inStreams,
|
||||
const UINT64 **inSizes,
|
||||
UINT32 numInStreams,
|
||||
ISequentialOutStream **outStreams,
|
||||
const UINT64 **outSizes,
|
||||
UINT32 numOutStreams,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
if (numInStreams != 4 || numOutStreams != 1)
|
||||
return E_INVALIDARG;
|
||||
|
||||
_mainInStream.Init(inStreams[0]);
|
||||
_callStream.Init(inStreams[1]);
|
||||
_jumpStream.Init(inStreams[2]);
|
||||
_rangeDecoder.Init(inStreams[3]);
|
||||
for (int i = 0; i < 256; i++)
|
||||
_statusE8Decoder[i].Init();
|
||||
_statusE9Decoder.Init();
|
||||
_statusJccDecoder.Init();
|
||||
|
||||
_outStream.Init(outStreams[0]);
|
||||
|
||||
// CCoderReleaser releaser(this);
|
||||
|
||||
BYTE prevByte = 0;
|
||||
UINT32 processedBytes = 0;
|
||||
while(true)
|
||||
{
|
||||
if (processedBytes > (1 << 20) && progress != NULL)
|
||||
{
|
||||
UINT64 nowPos64 = _outStream.GetProcessedSize();
|
||||
RINOK(progress->SetRatioInfo(NULL, &nowPos64));
|
||||
processedBytes = 0;
|
||||
}
|
||||
processedBytes++;
|
||||
BYTE b;
|
||||
if (!_mainInStream.ReadByte(b))
|
||||
return Flush();
|
||||
_outStream.WriteByte(b);
|
||||
if (b != 0xE8 && b != 0xE9 && !IsJcc(prevByte, b))
|
||||
{
|
||||
prevByte = b;
|
||||
continue;
|
||||
}
|
||||
bool status;
|
||||
if (b == 0xE8)
|
||||
status = (_statusE8Decoder[prevByte].Decode(&_rangeDecoder) == 1);
|
||||
else if (b == 0xE9)
|
||||
status = (_statusE9Decoder.Decode(&_rangeDecoder) == 1);
|
||||
else
|
||||
status = (_statusJccDecoder.Decode(&_rangeDecoder) == 1);
|
||||
if (status)
|
||||
{
|
||||
UINT32 src;
|
||||
if (b == 0xE8)
|
||||
{
|
||||
if (!_callStream.ReadBytes(&src, sizeof(src)))
|
||||
return S_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_jumpStream.ReadBytes(&src, sizeof(src)))
|
||||
return S_FALSE;
|
||||
}
|
||||
src = Swap4(src);
|
||||
UINT32 dest = src - (UINT32(_outStream.GetProcessedSize()) + 4) ;
|
||||
_outStream.WriteBytes(&dest, sizeof(dest));
|
||||
prevByte = (dest >> 24);
|
||||
processedBytes += 4;
|
||||
}
|
||||
else
|
||||
prevByte = b;
|
||||
}
|
||||
}
|
||||
|
||||
STDMETHODIMP CBCJ2_x86_Decoder::Code(ISequentialInStream **inStreams,
|
||||
const UINT64 **inSizes,
|
||||
UINT32 numInStreams,
|
||||
ISequentialOutStream **outStreams,
|
||||
const UINT64 **outSizes,
|
||||
UINT32 numOutStreams,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
try
|
||||
{
|
||||
return CodeReal(inStreams, inSizes, numInStreams,
|
||||
outStreams, outSizes,numOutStreams, progress);
|
||||
}
|
||||
catch(const COutBufferException &e) { return e.ErrorCode; }
|
||||
catch(...) { return S_FALSE; }
|
||||
}
|
||||
147
7zip/Compress/Branch/x86_2.h
Executable file
147
7zip/Compress/Branch/x86_2.h
Executable file
@@ -0,0 +1,147 @@
|
||||
// x86_2.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __X86_2_H
|
||||
#define __X86_2_H
|
||||
|
||||
#include "Common/MyCom.h"
|
||||
#include "Coder.h"
|
||||
#include "../RangeCoder/RangeCoderBit.h"
|
||||
// #include "../../Common/InBuffer.h"
|
||||
|
||||
// {23170F69-40C1-278B-0303-010100000100}
|
||||
#define MyClass2_a(Name, id, subId, encodingId) \
|
||||
DEFINE_GUID(CLSID_CCompressConvert ## Name, \
|
||||
0x23170F69, 0x40C1, 0x278B, 0x03, 0x03, id, subId, 0x00, 0x00, encodingId, 0x00);
|
||||
|
||||
#define MyClass_a(Name, id, subId) \
|
||||
MyClass2_a(Name ## _Encoder, id, subId, 0x01) \
|
||||
MyClass2_a(Name ## _Decoder, id, subId, 0x00)
|
||||
|
||||
MyClass_a(BCJ2_x86, 0x01, 0x1B)
|
||||
|
||||
const int kNumMoveBits = 5;
|
||||
|
||||
#ifndef EXTRACT_ONLY
|
||||
|
||||
class CBCJ2_x86_Encoder:
|
||||
public ICompressCoder2,
|
||||
public CDataBuffer,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
CBCJ2_x86_Encoder(): _mainStream(1 << 16) {}
|
||||
|
||||
COutBuffer _mainStream;
|
||||
COutBuffer _callStream;
|
||||
COutBuffer _jumpStream;
|
||||
NCompress::NRangeCoder::CEncoder _rangeEncoder;
|
||||
NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusE8Encoder[256];
|
||||
NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusE9Encoder;
|
||||
NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusJccEncoder;
|
||||
|
||||
HRESULT Flush();
|
||||
/*
|
||||
void ReleaseStreams()
|
||||
{
|
||||
_mainStream.ReleaseStream();
|
||||
_callStream.ReleaseStream();
|
||||
_jumpStream.ReleaseStream();
|
||||
_rangeEncoder.ReleaseStream();
|
||||
}
|
||||
|
||||
class CCoderReleaser
|
||||
{
|
||||
CBCJ2_x86_Encoder *_coder;
|
||||
public:
|
||||
CCoderReleaser(CBCJ2_x86_Encoder *aCoder): _coder(aCoder) {}
|
||||
~CCoderReleaser()
|
||||
{
|
||||
_coder->ReleaseStreams();
|
||||
}
|
||||
};
|
||||
friend class CCoderReleaser;
|
||||
*/
|
||||
|
||||
public:
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
HRESULT CodeReal(ISequentialInStream **inStreams,
|
||||
const UINT64 **inSizes,
|
||||
UINT32 numInStreams,
|
||||
ISequentialOutStream **outStreams,
|
||||
const UINT64 **outSizes,
|
||||
UINT32 numOutStreams,
|
||||
ICompressProgressInfo *progress);
|
||||
STDMETHOD(Code)(ISequentialInStream **inStreams,
|
||||
const UINT64 **inSizes,
|
||||
UINT32 numInStreams,
|
||||
ISequentialOutStream **outStreams,
|
||||
const UINT64 **outSizes,
|
||||
UINT32 numOutStreams,
|
||||
ICompressProgressInfo *progress);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
class CBCJ2_x86_Decoder:
|
||||
public ICompressCoder2,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
CBCJ2_x86_Decoder(): _outStream(1 << 16), _mainInStream(1 << 16) {}
|
||||
|
||||
CInBuffer _mainInStream;
|
||||
CInBuffer _callStream;
|
||||
CInBuffer _jumpStream;
|
||||
NCompress::NRangeCoder::CDecoder _rangeDecoder;
|
||||
NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusE8Decoder[256];
|
||||
NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusE9Decoder;
|
||||
NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusJccDecoder;
|
||||
|
||||
COutBuffer _outStream;
|
||||
|
||||
/*
|
||||
void ReleaseStreams()
|
||||
{
|
||||
_mainInStream.ReleaseStream();
|
||||
_callStream.ReleaseStream();
|
||||
_jumpStream.ReleaseStream();
|
||||
_rangeDecoder.ReleaseStream();
|
||||
_outStream.ReleaseStream();
|
||||
}
|
||||
*/
|
||||
|
||||
HRESULT Flush() { return _outStream.Flush(); }
|
||||
/*
|
||||
class CCoderReleaser
|
||||
{
|
||||
CBCJ2_x86_Decoder *_coder;
|
||||
public:
|
||||
CCoderReleaser(CBCJ2_x86_Decoder *aCoder): _coder(aCoder) {}
|
||||
~CCoderReleaser() { _coder->ReleaseStreams(); }
|
||||
};
|
||||
friend class CCoderReleaser;
|
||||
*/
|
||||
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
HRESULT CodeReal(ISequentialInStream **inStreams,
|
||||
const UINT64 **inSizes,
|
||||
UINT32 numInStreams,
|
||||
ISequentialOutStream **outStreams,
|
||||
const UINT64 **outSizes,
|
||||
UINT32 numOutStreams,
|
||||
ICompressProgressInfo *progress);
|
||||
STDMETHOD(Code)(ISequentialInStream **inStreams,
|
||||
const UINT64 **inSizes,
|
||||
UINT32 numInStreams,
|
||||
ISequentialOutStream **outStreams,
|
||||
const UINT64 **outSizes,
|
||||
UINT32 numOutStreams,
|
||||
ICompressProgressInfo *progress);
|
||||
};
|
||||
|
||||
#endif
|
||||
100
7zip/Compress/ByteSwap/ByteSwap.cpp
Executable file
100
7zip/Compress/ByteSwap/ByteSwap.cpp
Executable file
@@ -0,0 +1,100 @@
|
||||
// Coder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ByteSwap.h"
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
const int kBufferSize = 1 << 17;
|
||||
|
||||
CBuffer::CBuffer():
|
||||
_buffer(0)
|
||||
{
|
||||
_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)
|
||||
{
|
||||
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++];
|
||||
}
|
||||
}
|
||||
|
||||
STDMETHODIMP CByteSwap4::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
const UINT32 kStep = 4;
|
||||
UINT32 bufferPos = 0;
|
||||
UINT64 nowPos64 = 0;
|
||||
while(true)
|
||||
{
|
||||
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++];
|
||||
}
|
||||
}
|
||||
|
||||
9
7zip/Compress/ByteSwap/ByteSwap.def
Executable file
9
7zip/Compress/ByteSwap/ByteSwap.def
Executable file
@@ -0,0 +1,9 @@
|
||||
; Swap.def
|
||||
|
||||
LIBRARY Swap.dll
|
||||
|
||||
EXPORTS
|
||||
CreateObject PRIVATE
|
||||
GetNumberOfMethods PRIVATE
|
||||
GetMethodProperty PRIVATE
|
||||
|
||||
125
7zip/Compress/ByteSwap/ByteSwap.dsp
Executable file
125
7zip/Compress/ByteSwap/ByteSwap.dsp
Executable file
@@ -0,0 +1,125 @@
|
||||
# Microsoft Developer Studio Project File - Name="ByteSwap" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=ByteSwap - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "ByteSwap.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "ByteSwap.mak" CFG="ByteSwap - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "ByteSwap - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "ByteSwap - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "ByteSwap - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BYTESWAP_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BYTESWAP_EXPORTS" /Yu"StdAfx.h" /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "NDEBUG"
|
||||
# ADD RSC /l 0x419 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\Swap.dll" /opt:NOWIN98
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "ByteSwap - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BYTESWAP_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BYTESWAP_EXPORTS" /Yu"StdAfx.h" /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "_DEBUG"
|
||||
# ADD RSC /l 0x419 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\Swap.dll" /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "ByteSwap - Win32 Release"
|
||||
# Name "ByteSwap - Win32 Debug"
|
||||
# Begin Group "Spec"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ByteSwap.def
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\DllExports.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\resource.rc
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.cpp
|
||||
# ADD CPP /Yc"StdAfx.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ByteSwap.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ByteSwap.h
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
29
7zip/Compress/ByteSwap/ByteSwap.dsw
Executable file
29
7zip/Compress/ByteSwap/ByteSwap.dsw
Executable file
@@ -0,0 +1,29 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "ByteSwap"=.\ByteSwap.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
51
7zip/Compress/ByteSwap/ByteSwap.h
Executable file
51
7zip/Compress/ByteSwap/ByteSwap.h
Executable file
@@ -0,0 +1,51 @@
|
||||
// ByteSwap.h
|
||||
|
||||
#ifndef __BYTESWAP_H
|
||||
#define __BYTESWAP_H
|
||||
|
||||
#include "../../ICoder.h"
|
||||
#include "Common/MyCom.h"
|
||||
|
||||
// {23170F69-40C1-278B-0203-020000000000}
|
||||
DEFINE_GUID(CLSID_CCompressConvertByteSwap2,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x02, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
// {23170F69-40C1-278B-0203-040000000000}
|
||||
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,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
};
|
||||
|
||||
class CByteSwap4 :
|
||||
public ICompressCoder,
|
||||
public CBuffer,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
92
7zip/Compress/ByteSwap/DllExports.cpp
Executable file
92
7zip/Compress/ByteSwap/DllExports.cpp
Executable file
@@ -0,0 +1,92 @@
|
||||
// DLLExports.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#define INITGUID
|
||||
|
||||
#include "Common/ComTry.h"
|
||||
#include "ByteSwap.h"
|
||||
#include "../../ICoder.h"
|
||||
|
||||
extern "C"
|
||||
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
*outObject = 0;
|
||||
int correctInterface = (*iid == IID_ICompressCoder);
|
||||
CMyComPtr<ICompressCoder> coder;
|
||||
if (*clsid == CLSID_CCompressConvertByteSwap2)
|
||||
{
|
||||
if (!correctInterface)
|
||||
return E_NOINTERFACE;
|
||||
coder = (ICompressCoder *)new CByteSwap2();
|
||||
}
|
||||
else if (*clsid == CLSID_CCompressConvertByteSwap4)
|
||||
{
|
||||
if (!correctInterface)
|
||||
return E_NOINTERFACE;
|
||||
coder = (ICompressCoder *)new CByteSwap4();
|
||||
}
|
||||
else
|
||||
return CLASS_E_CLASSNOTAVAILABLE;
|
||||
*outObject = coder.Detach();
|
||||
COM_TRY_END
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
struct CSwapMethodInfo
|
||||
{
|
||||
char ID[3];
|
||||
const wchar_t *Name;
|
||||
const GUID *clsid;
|
||||
};
|
||||
|
||||
static CSwapMethodInfo g_Methods[] =
|
||||
{
|
||||
{ { 0x2, 0x03, 0x02 }, L"Swap2", &CLSID_CCompressConvertByteSwap2 },
|
||||
{ { 0x2, 0x03, 0x04 }, L"Swap4", &CLSID_CCompressConvertByteSwap4 }
|
||||
};
|
||||
|
||||
STDAPI GetNumberOfMethods(UINT32 *numMethods)
|
||||
{
|
||||
*numMethods = sizeof(g_Methods) / sizeof(g_Methods[1]);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDAPI GetMethodProperty(UINT32 index, PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
if (index > sizeof(g_Methods) / sizeof(g_Methods[1]))
|
||||
return E_INVALIDARG;
|
||||
::VariantClear((tagVARIANT *)value);
|
||||
const CSwapMethodInfo &method = g_Methods[index];
|
||||
switch(propID)
|
||||
{
|
||||
case NMethodPropID::kID:
|
||||
{
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(method.ID,
|
||||
sizeof(method.ID))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
}
|
||||
case NMethodPropID::kName:
|
||||
{
|
||||
if ((value->bstrVal = ::SysAllocString(method.Name)) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
}
|
||||
case NMethodPropID::kDecoder:
|
||||
case NMethodPropID::kEncoder:
|
||||
{
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(
|
||||
(const char *)method.clsid, sizeof(GUID))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
3
7zip/Compress/ByteSwap/StdAfx.cpp
Executable file
3
7zip/Compress/ByteSwap/StdAfx.cpp
Executable file
@@ -0,0 +1,3 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "stdafx.h"
|
||||
8
7zip/Compress/ByteSwap/StdAfx.h
Executable file
8
7zip/Compress/ByteSwap/StdAfx.h
Executable file
@@ -0,0 +1,8 @@
|
||||
// stdafx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#endif
|
||||
15
7zip/Compress/ByteSwap/resource.h
Executable file
15
7zip/Compress/ByteSwap/resource.h
Executable file
@@ -0,0 +1,15 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by resource.rc
|
||||
//
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 101
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
121
7zip/Compress/ByteSwap/resource.rc
Executable file
121
7zip/Compress/ByteSwap/resource.rc
Executable file
@@ -0,0 +1,121 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Russian resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
|
||||
#pragma code_page(1251)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // Russian resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifndef _MAC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 3,9,2,0
|
||||
PRODUCTVERSION 3,9,2,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "\0"
|
||||
VALUE "CompanyName", "Igor Pavlov\0"
|
||||
VALUE "FileDescription", "Byte Swap converter \0"
|
||||
VALUE "FileVersion", "3, 9, 2, 0\0"
|
||||
VALUE "InternalName", "Swap\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 1999-2003 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 "SpecialBuild", "\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // !_MAC
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
4
7zip/Compress/Copy/Copy.def
Executable file
4
7zip/Compress/Copy/Copy.def
Executable file
@@ -0,0 +1,4 @@
|
||||
EXPORTS
|
||||
CreateObject PRIVATE
|
||||
GetNumberOfMethods PRIVATE
|
||||
GetMethodProperty PRIVATE
|
||||
125
7zip/Compress/Copy/Copy.dsp
Executable file
125
7zip/Compress/Copy/Copy.dsp
Executable file
@@ -0,0 +1,125 @@
|
||||
# Microsoft Developer Studio Project File - Name="Copy" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=Copy - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "Copy.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "Copy.mak" CFG="Copy - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "Copy - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "Copy - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "Copy - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COPY_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COPY_EXPORTS" /Yu"StdAfx.h" /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-zip\Codecs\Copy.dll" /opt:NOWIN98
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "Copy - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COPY_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COPY_EXPORTS" /Yu"StdAfx.h" /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-zip\Codecs\Copy.dll" /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "Copy - Win32 Release"
|
||||
# Name "Copy - Win32 Debug"
|
||||
# Begin Group "Spec"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Copy.def
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\DllExports.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\resource.rc
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.cpp
|
||||
# ADD CPP /Yc"StdAfx.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CopyCoder.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CopyCoder.h
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
29
7zip/Compress/Copy/Copy.dsw
Executable file
29
7zip/Compress/Copy/Copy.dsw
Executable file
@@ -0,0 +1,29 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "Copy"=".\Copy.dsp" - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
45
7zip/Compress/Copy/CopyCoder.cpp
Executable file
45
7zip/Compress/Copy/CopyCoder.cpp
Executable file
@@ -0,0 +1,45 @@
|
||||
// Compress/CopyCoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "CopyCoder.h"
|
||||
|
||||
namespace NCompress {
|
||||
|
||||
static const UINT32 kBufferSize = 1 << 17;
|
||||
|
||||
CCopyCoder::CCopyCoder():
|
||||
TotalSize(0)
|
||||
{
|
||||
_buffer = new BYTE[kBufferSize];
|
||||
}
|
||||
|
||||
CCopyCoder::~CCopyCoder()
|
||||
{
|
||||
delete []_buffer;
|
||||
}
|
||||
|
||||
STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
TotalSize = 0;
|
||||
while(true)
|
||||
{
|
||||
UINT32 realProcessedSize;
|
||||
RINOK(inStream->ReadPart(_buffer, kBufferSize, &realProcessedSize));
|
||||
if(realProcessedSize == 0)
|
||||
break;
|
||||
RINOK(outStream->Write(_buffer, realProcessedSize, NULL));
|
||||
TotalSize += realProcessedSize;
|
||||
if (progress != NULL)
|
||||
{
|
||||
RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
34
7zip/Compress/Copy/CopyCoder.h
Executable file
34
7zip/Compress/Copy/CopyCoder.h
Executable file
@@ -0,0 +1,34 @@
|
||||
// Compress/CopyCoder.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __COMPRESS_COPYCODER_H
|
||||
#define __COMPRESS_COPYCODER_H
|
||||
|
||||
#include "../../ICoder.h"
|
||||
#include "../../../Common/MyCom.h"
|
||||
|
||||
|
||||
namespace NCompress {
|
||||
|
||||
class CCopyCoder:
|
||||
public ICompressCoder,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
BYTE *_buffer;
|
||||
public:
|
||||
UINT64 TotalSize;
|
||||
CCopyCoder();
|
||||
~CCopyCoder();
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
70
7zip/Compress/Copy/DllExports.cpp
Executable file
70
7zip/Compress/Copy/DllExports.cpp
Executable file
@@ -0,0 +1,70 @@
|
||||
// DLLExports.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include <initguid.h>
|
||||
|
||||
#include "CopyCoder.h"
|
||||
#include "../../../Common/ComTry.h"
|
||||
|
||||
// {23170F69-40C1-278B-0000-000000000000}
|
||||
DEFINE_GUID(CLSID_CCompressCopyCoder,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
extern "C"
|
||||
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
*outObject = 0;
|
||||
if (*clsid != CLSID_CCompressCopyCoder)
|
||||
return CLASS_E_CLASSNOTAVAILABLE;
|
||||
if (*iid != IID_ICompressCoder)
|
||||
return E_NOINTERFACE;
|
||||
CMyComPtr<ICompressCoder> coder = (ICompressCoder *)new NCompress::CCopyCoder();
|
||||
*outObject = coder.Detach();
|
||||
COM_TRY_END
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDAPI GetNumberOfMethods(UINT32 *numMethods)
|
||||
{
|
||||
*numMethods = 1;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDAPI GetMethodProperty(UINT32 index, PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
if (index != 0)
|
||||
return E_INVALIDARG;
|
||||
// ::VariantClear((tagVARIANT *)value);
|
||||
switch(propID)
|
||||
{
|
||||
case NMethodPropID::kID:
|
||||
{
|
||||
const char id[] = { 0x0 };
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(id, sizeof(id))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
}
|
||||
case NMethodPropID::kName:
|
||||
{
|
||||
if ((value->bstrVal = ::SysAllocString(L"Copy")) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
}
|
||||
case NMethodPropID::kDecoder:
|
||||
case NMethodPropID::kEncoder:
|
||||
{
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(
|
||||
(const char *)&CLSID_CCompressCopyCoder, sizeof(GUID))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
3
7zip/Compress/Copy/StdAfx.cpp
Executable file
3
7zip/Compress/Copy/StdAfx.cpp
Executable file
@@ -0,0 +1,3 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "stdafx.h"
|
||||
8
7zip/Compress/Copy/StdAfx.h
Executable file
8
7zip/Compress/Copy/StdAfx.h
Executable file
@@ -0,0 +1,8 @@
|
||||
// stdafx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#endif
|
||||
15
7zip/Compress/Copy/resource.h
Executable file
15
7zip/Compress/Copy/resource.h
Executable file
@@ -0,0 +1,15 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by resource.rc
|
||||
//
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 101
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
121
7zip/Compress/Copy/resource.rc
Executable file
121
7zip/Compress/Copy/resource.rc
Executable file
@@ -0,0 +1,121 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Russian resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
|
||||
#pragma code_page(1251)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // Russian resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifndef _MAC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 3,8,1,0
|
||||
PRODUCTVERSION 3,8,1,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "\0"
|
||||
VALUE "CompanyName", "Igor Pavlov\0"
|
||||
VALUE "FileDescription", "Copy Coder\0"
|
||||
VALUE "FileVersion", "3, 8, 1, 0\0"
|
||||
VALUE "InternalName", "Copy\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 1999-2003 Igor Pavlov\0"
|
||||
VALUE "LegalTrademarks", "\0"
|
||||
VALUE "OriginalFilename", "Copy.dll\0"
|
||||
VALUE "PrivateBuild", "\0"
|
||||
VALUE "ProductName", "7-Zip\0"
|
||||
VALUE "ProductVersion", "3, 8, 1, 0\0"
|
||||
VALUE "SpecialBuild", "\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // !_MAC
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
8
7zip/Compress/Deflate/Deflate.def
Executable file
8
7zip/Compress/Deflate/Deflate.def
Executable file
@@ -0,0 +1,8 @@
|
||||
; Deflate.def
|
||||
|
||||
LIBRARY Deflate.dll
|
||||
|
||||
EXPORTS
|
||||
CreateObject PRIVATE
|
||||
GetNumberOfMethods PRIVATE
|
||||
GetMethodProperty PRIVATE
|
||||
275
7zip/Compress/Deflate/Deflate.dsp
Executable file
275
7zip/Compress/Deflate/Deflate.dsp
Executable file
@@ -0,0 +1,275 @@
|
||||
# Microsoft Developer Studio Project File - Name="Deflate" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=Deflate - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "Deflate.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "Deflate.mak" CFG="Deflate - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "Deflate - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "Deflate - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "Deflate - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "DEFLATE_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "DEFLATE_EXPORTS" /Yu"StdAfx.h" /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\Deflate.dll" /opt:NOWIN98
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "Deflate - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "DEFLATE_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "DEFLATE_EXPORTS" /Yu"StdAfx.h" /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\Deflate.dll" /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "Deflate - Win32 Release"
|
||||
# Name "Deflate - Win32 Debug"
|
||||
# Begin Group "Spec"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Deflate.def
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\DllExports.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\resource.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\resource.rc
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.cpp
|
||||
# ADD CPP /Yc"StdAfx.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Huffman"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Huffman\HuffmanDecoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Huffman\HuffmanEncoder.cpp
|
||||
|
||||
!IF "$(CFG)" == "Deflate - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "Deflate - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Huffman\HuffmanEncoder.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Interface"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# End Group
|
||||
# Begin Group "7zip Common"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\InBuffer.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\InBuffer.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\LSBFDecoder.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\LSBFDecoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\LSBFEncoder.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\LSBFEncoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\OutBuffer.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\OutBuffer.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Common"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\CRC.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\CRC.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\NewHandler.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\NewHandler.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Windows"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# End Group
|
||||
# Begin Group "LZ"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\LZInWindow.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\LZInWindow.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\LZOutWindow.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\LZOutWindow.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\DeflateConst.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\DeflateDecoder.cpp
|
||||
|
||||
!IF "$(CFG)" == "Deflate - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "Deflate - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\DeflateDecoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\DeflateEncoder.cpp
|
||||
|
||||
!IF "$(CFG)" == "Deflate - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "Deflate - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\DeflateEncoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\DeflateExtConst.h
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
29
7zip/Compress/Deflate/Deflate.dsw
Executable file
29
7zip/Compress/Deflate/Deflate.dsw
Executable file
@@ -0,0 +1,29 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "Deflate"=.\Deflate.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
106
7zip/Compress/Deflate/DeflateConst.h
Executable file
106
7zip/Compress/Deflate/DeflateConst.h
Executable file
@@ -0,0 +1,106 @@
|
||||
// DeflateConst.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __DEFLATE_CONST_H
|
||||
#define __DEFLATE_CONST_H
|
||||
|
||||
#include "DeflateExtConst.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NDeflate {
|
||||
|
||||
const UINT32 kLenTableSize = 29;
|
||||
|
||||
const UINT32 kStaticDistTableSize = 32;
|
||||
const UINT32 kStaticLenTableSize = 31;
|
||||
|
||||
const UINT32 kReadTableNumber = 0x100;
|
||||
const UINT32 kMatchNumber = kReadTableNumber + 1;
|
||||
|
||||
const UINT32 kMainTableSize = kMatchNumber + kLenTableSize; //298;
|
||||
const UINT32 kStaticMainTableSize = kMatchNumber + kStaticLenTableSize; //298;
|
||||
|
||||
const UINT32 kDistTableStart = kMainTableSize;
|
||||
|
||||
const UINT32 kHeapTablesSizesSum32 = kMainTableSize + kDistTableSize32;
|
||||
const UINT32 kHeapTablesSizesSum64 = kMainTableSize + kDistTableSize64;
|
||||
|
||||
const UINT32 kLevelTableSize = 19;
|
||||
|
||||
const UINT32 kMaxTableSize32 = kHeapTablesSizesSum32; // test it
|
||||
const UINT32 kMaxTableSize64 = kHeapTablesSizesSum64; // test it
|
||||
|
||||
const UINT32 kStaticMaxTableSize = kStaticMainTableSize + kStaticDistTableSize;
|
||||
|
||||
const UINT32 kTableDirectLevels = 16;
|
||||
const UINT32 kTableLevelRepNumber = kTableDirectLevels;
|
||||
const UINT32 kTableLevel0Number = kTableLevelRepNumber + 1;
|
||||
const UINT32 kTableLevel0Number2 = kTableLevel0Number + 1;
|
||||
|
||||
const UINT32 kLevelMask = 0xF;
|
||||
|
||||
const BYTE kLenStart32[kLenTableSize] =
|
||||
{0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224, 255};
|
||||
const BYTE kLenStart64[kLenTableSize] =
|
||||
{0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224, 0};
|
||||
|
||||
const BYTE kLenDirectBits32[kLenTableSize] =
|
||||
{0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
|
||||
const BYTE kLenDirectBits64[kLenTableSize] =
|
||||
{0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 16};
|
||||
|
||||
const UINT32 kDistStart[kDistTableSize64] =
|
||||
{0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,512,768,
|
||||
1024,1536,2048,3072,4096,6144,8192,12288,16384,24576, 32768, 49152};
|
||||
const BYTE kDistDirectBits[kDistTableSize64] =
|
||||
{0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14};
|
||||
|
||||
const BYTE kLevelDirectBits[kLevelTableSize] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7};
|
||||
|
||||
const BYTE kCodeLengthAlphabetOrder[kLevelTableSize] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
|
||||
|
||||
const UINT32 kMatchMinLen = 3;
|
||||
const UINT32 kMatchMaxLen32 = kNumLenCombinations32 + kMatchMinLen - 1; //256 + 2; test it
|
||||
const UINT32 kMatchMaxLen64 = kNumLenCombinations64 + kMatchMinLen - 1; //255 + 2; test it
|
||||
|
||||
const int kFinalBlockFieldSize = 1;
|
||||
|
||||
namespace NFinalBlockField
|
||||
{
|
||||
enum
|
||||
{
|
||||
kNotFinalBlock = 0,
|
||||
kFinalBlock = 1
|
||||
};
|
||||
}
|
||||
|
||||
const int kBlockTypeFieldSize = 2;
|
||||
|
||||
namespace NBlockType
|
||||
{
|
||||
enum
|
||||
{
|
||||
kStored = 0,
|
||||
kFixedHuffman = 1,
|
||||
kDynamicHuffman = 2,
|
||||
kReserved = 3
|
||||
};
|
||||
}
|
||||
|
||||
const UINT32 kDeflateNumberOfLengthCodesFieldSize = 5;
|
||||
const UINT32 kDeflateNumberOfDistanceCodesFieldSize = 5;
|
||||
const UINT32 kDeflateNumberOfLevelCodesFieldSize = 4;
|
||||
|
||||
const UINT32 kDeflateNumberOfLitLenCodesMin = 257;
|
||||
|
||||
const UINT32 kDeflateNumberOfDistanceCodesMin = 1;
|
||||
const UINT32 kDeflateNumberOfLevelCodesMin = 4;
|
||||
|
||||
const UINT32 kDeflateLevelCodeFieldSize = 3;
|
||||
|
||||
const UINT32 kDeflateStoredBlockLengthFieldSizeSize = 16;
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
291
7zip/Compress/Deflate/DeflateDecoder.cpp
Executable file
291
7zip/Compress/Deflate/DeflateDecoder.cpp
Executable file
@@ -0,0 +1,291 @@
|
||||
// DeflateDecoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "DeflateDecoder.h"
|
||||
#include "DeflateConst.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NDeflate {
|
||||
namespace NDecoder {
|
||||
|
||||
CCoder::CCoder(bool deflate64Mode):
|
||||
m_MainDecoder(kStaticMainTableSize),
|
||||
m_DistDecoder(kStaticDistTableSize),
|
||||
m_LevelDecoder(kLevelTableSize),
|
||||
_deflate64Mode(deflate64Mode)
|
||||
{}
|
||||
|
||||
void CCoder::DeCodeLevelTable(BYTE *newLevels, int numLevels)
|
||||
{
|
||||
int i = 0;
|
||||
while (i < numLevels)
|
||||
{
|
||||
UINT32 number = m_LevelDecoder.DecodeSymbol(&m_InBitStream);
|
||||
if (number < kTableDirectLevels)
|
||||
newLevels[i++] = BYTE(number);
|
||||
else
|
||||
{
|
||||
if (number == kTableLevelRepNumber)
|
||||
{
|
||||
int t = m_InBitStream.ReadBits(2) + 3;
|
||||
for (int reps = t; reps > 0 && i < numLevels ; reps--, i++)
|
||||
newLevels[i] = newLevels[i - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
int num;
|
||||
if (number == kTableLevel0Number)
|
||||
num = m_InBitStream.ReadBits(3) + 3;
|
||||
else
|
||||
num = m_InBitStream.ReadBits(7) + 11;
|
||||
for (;num > 0 && i < numLevels; num--)
|
||||
newLevels[i++] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCoder::ReadTables(void)
|
||||
{
|
||||
if(m_FinalBlock) // test it
|
||||
throw CException(CException::kData);
|
||||
|
||||
m_FinalBlock = (m_InBitStream.ReadBits(kFinalBlockFieldSize) == NFinalBlockField::kFinalBlock);
|
||||
|
||||
int blockType = m_InBitStream.ReadBits(kBlockTypeFieldSize);
|
||||
|
||||
switch(blockType)
|
||||
{
|
||||
case NBlockType::kStored:
|
||||
{
|
||||
m_StoredMode = true;
|
||||
UINT32 currentBitPosition = m_InBitStream.GetBitPosition();
|
||||
UINT32 numBitsForAlign = currentBitPosition > 0 ? (8 - currentBitPosition): 0;
|
||||
if (numBitsForAlign > 0)
|
||||
m_InBitStream.ReadBits(numBitsForAlign);
|
||||
m_StoredBlockSize = m_InBitStream.ReadBits(kDeflateStoredBlockLengthFieldSizeSize);
|
||||
WORD onesComplementReverse = ~WORD(m_InBitStream.ReadBits(kDeflateStoredBlockLengthFieldSizeSize));
|
||||
if (m_StoredBlockSize != onesComplementReverse)
|
||||
throw CException(CException::kData);
|
||||
break;
|
||||
}
|
||||
case NBlockType::kFixedHuffman:
|
||||
case NBlockType::kDynamicHuffman:
|
||||
{
|
||||
m_StoredMode = false;
|
||||
BYTE litLenLevels[kStaticMainTableSize];
|
||||
BYTE distLevels[kStaticDistTableSize];
|
||||
if (blockType == NBlockType::kFixedHuffman)
|
||||
{
|
||||
int i;
|
||||
|
||||
// Leteral / length levels
|
||||
for (i = 0; i < 144; i++)
|
||||
litLenLevels[i] = 8;
|
||||
for (; i < 256; i++)
|
||||
litLenLevels[i] = 9;
|
||||
for (; i < 280; i++)
|
||||
litLenLevels[i] = 7;
|
||||
for (; i < 288; i++) /* make a complete, but wrong code set */
|
||||
litLenLevels[i] = 8;
|
||||
|
||||
// Distance levels
|
||||
for (i = 0; i < kStaticDistTableSize; i++) // test it: infozip only use kDistTableSize
|
||||
distLevels[i] = 5;
|
||||
}
|
||||
else // in case when (blockType == kDeflateBlockTypeFixedHuffman)
|
||||
{
|
||||
int numLitLenLevels = m_InBitStream.ReadBits(kDeflateNumberOfLengthCodesFieldSize) +
|
||||
kDeflateNumberOfLitLenCodesMin;
|
||||
int numDistLevels = m_InBitStream.ReadBits(kDeflateNumberOfDistanceCodesFieldSize) +
|
||||
kDeflateNumberOfDistanceCodesMin;
|
||||
int numLevelCodes = m_InBitStream.ReadBits(kDeflateNumberOfLevelCodesFieldSize) +
|
||||
kDeflateNumberOfLevelCodesMin;
|
||||
|
||||
int numLevels = _deflate64Mode ? kHeapTablesSizesSum64 :
|
||||
kHeapTablesSizesSum32;
|
||||
|
||||
BYTE levelLevels[kLevelTableSize];
|
||||
int i;
|
||||
for (i = 0; i < kLevelTableSize; i++)
|
||||
{
|
||||
int position = kCodeLengthAlphabetOrder[i];
|
||||
if(i < numLevelCodes)
|
||||
levelLevels[position] = BYTE(m_InBitStream.ReadBits(kDeflateLevelCodeFieldSize));
|
||||
else
|
||||
levelLevels[position] = 0;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
m_LevelDecoder.SetCodeLengths(levelLevels);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
throw CException(CException::kData);
|
||||
}
|
||||
|
||||
BYTE tmpLevels[kStaticMaxTableSize];
|
||||
DeCodeLevelTable(tmpLevels, numLitLenLevels + numDistLevels);
|
||||
|
||||
memmove(litLenLevels, tmpLevels, numLitLenLevels);
|
||||
memset(litLenLevels + numLitLenLevels, 0,
|
||||
kStaticMainTableSize - numLitLenLevels);
|
||||
|
||||
memmove(distLevels, tmpLevels + numLitLenLevels, numDistLevels);
|
||||
memset(distLevels + numDistLevels, 0, kStaticDistTableSize - numDistLevels);
|
||||
}
|
||||
try
|
||||
{
|
||||
m_MainDecoder.SetCodeLengths(litLenLevels);
|
||||
m_DistDecoder.SetCodeLengths(distLevels);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
throw CException(CException::kData);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw CException(CException::kData);
|
||||
}
|
||||
}
|
||||
|
||||
HRESULT CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
{
|
||||
try
|
||||
{
|
||||
m_OutWindowStream.Create(_deflate64Mode ? kHistorySize64: kHistorySize32 /* , kMatchMaxLen */);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
}
|
||||
UINT64 pos = 0;
|
||||
m_OutWindowStream.Init(outStream, false);
|
||||
m_InBitStream.Init(inStream);
|
||||
// CCoderReleaser coderReleaser(this);
|
||||
|
||||
m_FinalBlock = false;
|
||||
|
||||
while(!m_FinalBlock)
|
||||
{
|
||||
if (progress != NULL)
|
||||
{
|
||||
UINT64 packSize = m_InBitStream.GetProcessedSize();
|
||||
RINOK(progress->SetRatioInfo(&packSize, &pos));
|
||||
}
|
||||
ReadTables();
|
||||
if(m_StoredMode)
|
||||
{
|
||||
for (UINT32 i = 0; i < m_StoredBlockSize; i++)
|
||||
m_OutWindowStream.PutOneByte(BYTE(m_InBitStream.ReadBits(8)));
|
||||
pos += m_StoredBlockSize;
|
||||
continue;
|
||||
}
|
||||
while(true)
|
||||
{
|
||||
if (m_InBitStream.NumExtraBytes > 4)
|
||||
throw CException(CException::kData);
|
||||
|
||||
UINT32 number = m_MainDecoder.DecodeSymbol(&m_InBitStream);
|
||||
if (number < 256)
|
||||
{
|
||||
if (outSize != NULL)
|
||||
if (pos >= *outSize)
|
||||
throw CException(CException::kData);
|
||||
m_OutWindowStream.PutOneByte(BYTE(number));
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
else if (number >= kMatchNumber)
|
||||
{
|
||||
if (outSize != NULL)
|
||||
if (pos >= *outSize)
|
||||
throw CException(CException::kData);
|
||||
number -= kMatchNumber;
|
||||
|
||||
UINT32 length;
|
||||
if (_deflate64Mode)
|
||||
{
|
||||
length = UINT32(kLenStart64[number]) + kMatchMinLen;
|
||||
UINT32 numBits = kLenDirectBits64[number];
|
||||
if (numBits > 0)
|
||||
length += m_InBitStream.ReadBits(numBits);
|
||||
}
|
||||
else
|
||||
{
|
||||
length = UINT32(kLenStart32[number]) + kMatchMinLen;
|
||||
UINT32 numBits = kLenDirectBits32[number];
|
||||
if (numBits > 0)
|
||||
length += m_InBitStream.ReadBits(numBits);
|
||||
}
|
||||
|
||||
|
||||
number = m_DistDecoder.DecodeSymbol(&m_InBitStream);
|
||||
UINT32 distance = kDistStart[number] + m_InBitStream.ReadBits(kDistDirectBits[number]);
|
||||
if (distance >= pos)
|
||||
throw "data error";
|
||||
m_OutWindowStream.CopyBackBlock(distance, length);
|
||||
pos += length;
|
||||
}
|
||||
else if (number == kReadTableNumber)
|
||||
break;
|
||||
else
|
||||
throw CException(CException::kData);
|
||||
}
|
||||
}
|
||||
return m_OutWindowStream.Flush();
|
||||
}
|
||||
|
||||
HRESULT CCoder::BaseCode(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
try { return CodeReal(inStream, outStream, inSize, outSize, progress); }
|
||||
catch(const CInBufferException &e) { return e.ErrorCode; }
|
||||
catch(const CLZOutWindowException &e) { return e.ErrorCode; }
|
||||
catch(...) { return S_FALSE; }
|
||||
}
|
||||
|
||||
HRESULT CCoder::BaseGetInStreamProcessedSize(UINT64 *value)
|
||||
{
|
||||
if (value == NULL)
|
||||
return E_INVALIDARG;
|
||||
*value = m_InBitStream.GetProcessedSize();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CCOMCoder::GetInStreamProcessedSize(UINT64 *value)
|
||||
{
|
||||
return BaseGetInStreamProcessedSize(value);
|
||||
}
|
||||
|
||||
HRESULT CCOMCoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
return BaseCode(inStream, outStream, inSize, outSize, progress);
|
||||
}
|
||||
|
||||
STDMETHODIMP CCOMCoder64::GetInStreamProcessedSize(UINT64 *value)
|
||||
{
|
||||
return BaseGetInStreamProcessedSize(value);
|
||||
}
|
||||
|
||||
HRESULT CCOMCoder64::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
return BaseCode(inStream, outStream, inSize, outSize, progress);
|
||||
}
|
||||
|
||||
|
||||
}}}
|
||||
128
7zip/Compress/Deflate/DeflateDecoder.h
Executable file
128
7zip/Compress/Deflate/DeflateDecoder.h
Executable file
@@ -0,0 +1,128 @@
|
||||
// DeflateDecoder.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __DEFLATE_DECODER_H
|
||||
#define __DEFLATE_DECODER_H
|
||||
|
||||
#include "Common/MyCom.h"
|
||||
|
||||
#include "../../ICoder.h"
|
||||
#include "../../Common/LSBFDecoder.h"
|
||||
#include "../../Common/InBuffer.h"
|
||||
#include "../LZ/LZOutWindow.h"
|
||||
#include "../Huffman/HuffmanDecoder.h"
|
||||
|
||||
#include "DeflateExtConst.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NDeflate {
|
||||
namespace NDecoder {
|
||||
|
||||
class CException
|
||||
{
|
||||
public:
|
||||
enum ECauseType
|
||||
{
|
||||
kData
|
||||
} m_Cause;
|
||||
CException(ECauseType aCause): m_Cause(aCause) {}
|
||||
};
|
||||
|
||||
typedef NStream::NLSBF::CDecoder<CInBuffer> CInBit;
|
||||
typedef NCompress::NHuffman::CDecoder<kNumHuffmanBits> CHuffmanDecoder;
|
||||
|
||||
class CCoder
|
||||
{
|
||||
CLZOutWindow m_OutWindowStream;
|
||||
CInBit m_InBitStream;
|
||||
CHuffmanDecoder m_MainDecoder;
|
||||
CHuffmanDecoder m_DistDecoder;
|
||||
CHuffmanDecoder m_LevelDecoder; // table for decoding other tables;
|
||||
|
||||
bool m_FinalBlock;
|
||||
bool m_StoredMode;
|
||||
UINT32 m_StoredBlockSize;
|
||||
|
||||
bool _deflate64Mode;
|
||||
|
||||
void DeCodeLevelTable(BYTE *newLevels, int numLevels);
|
||||
void ReadTables();
|
||||
|
||||
/*
|
||||
void CCoder::ReleaseStreams()
|
||||
{
|
||||
m_OutWindowStream.ReleaseStream();
|
||||
m_InBitStream.ReleaseStream();
|
||||
}
|
||||
class CCoderReleaser
|
||||
{
|
||||
CCoder *m_Coder;
|
||||
public:
|
||||
CCoderReleaser(CCoder *coder): m_Coder(coder) {}
|
||||
~CCoderReleaser()
|
||||
{
|
||||
m_Coder->m_OutWindowStream.Flush();
|
||||
m_Coder->ReleaseStreams();
|
||||
}
|
||||
};
|
||||
friend class CCoderReleaser;
|
||||
*/
|
||||
|
||||
public:
|
||||
CCoder(bool deflate64Mode = false);
|
||||
|
||||
HRESULT CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
HRESULT BaseCode(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
// IGetInStreamProcessedSize
|
||||
HRESULT BaseGetInStreamProcessedSize(UINT64 *aValue);
|
||||
};
|
||||
|
||||
class CCOMCoder :
|
||||
public ICompressCoder,
|
||||
public ICompressGetInStreamProcessedSize,
|
||||
public CMyUnknownImp,
|
||||
public CCoder
|
||||
{
|
||||
public:
|
||||
|
||||
MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
// IGetInStreamProcessedSize
|
||||
STDMETHOD(GetInStreamProcessedSize)(UINT64 *aValue);
|
||||
|
||||
CCOMCoder(): CCoder(false) {}
|
||||
};
|
||||
|
||||
class CCOMCoder64 :
|
||||
public ICompressCoder,
|
||||
public ICompressGetInStreamProcessedSize,
|
||||
public CMyUnknownImp,
|
||||
public CCoder
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
// IGetInStreamProcessedSize
|
||||
STDMETHOD(GetInStreamProcessedSize)(UINT64 *aValue);
|
||||
|
||||
CCOMCoder64(): CCoder(true) {}
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
785
7zip/Compress/Deflate/DeflateEncoder.cpp
Executable file
785
7zip/Compress/Deflate/DeflateEncoder.cpp
Executable file
@@ -0,0 +1,785 @@
|
||||
// DeflateEncoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "DeflateEncoder.h"
|
||||
#include "DeflateConst.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
#include "Common/ComTry.h"
|
||||
#include "../LZ/BinTree/BinTree3ZMain.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NDeflate {
|
||||
namespace NEncoder {
|
||||
|
||||
class CMatchFinderException
|
||||
{
|
||||
public:
|
||||
HRESULT m_Result;
|
||||
CMatchFinderException(HRESULT result): m_Result (result) {}
|
||||
};
|
||||
|
||||
static const int kValueBlockSize = 0x2000;
|
||||
|
||||
static const int kMaxCodeBitLength = 15;
|
||||
static const int kMaxLevelBitLength = 7;
|
||||
|
||||
static const BYTE kFlagImm = 0;
|
||||
static const BYTE kFlagLenPos = 4;
|
||||
|
||||
static const UINT32 kMaxUncompressedBlockSize = 0xFFFF; // test it !!!
|
||||
|
||||
static const UINT32 kBlockUncompressedSizeThreshold =
|
||||
kMaxUncompressedBlockSize - kMatchMaxLen32 - kNumOpts;
|
||||
|
||||
static const int kNumGoodBacks = 0x10000;
|
||||
|
||||
static BYTE kNoLiteralDummy = 13;
|
||||
static BYTE kNoLenDummy = 13;
|
||||
static BYTE kNoPosDummy = 6;
|
||||
|
||||
static BYTE g_LenSlots[kNumLenCombinations32];
|
||||
static BYTE g_FastPos[1 << 9];
|
||||
|
||||
class CFastPosInit
|
||||
{
|
||||
public:
|
||||
CFastPosInit()
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < kLenTableSize; i++)
|
||||
{
|
||||
int c = kLenStart32[i];
|
||||
int j = 1 << kLenDirectBits32[i];
|
||||
for(int k = 0; k < j; k++, c++)
|
||||
g_LenSlots[c] = i;
|
||||
}
|
||||
|
||||
const int kFastSlots = 18;
|
||||
int c = 0;
|
||||
for (BYTE slotFast = 0; slotFast < kFastSlots; slotFast++)
|
||||
{
|
||||
UINT32 k = (1 << kDistDirectBits[slotFast]);
|
||||
for (UINT32 j = 0; j < k; j++, c++)
|
||||
g_FastPos[c] = slotFast;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static CFastPosInit g_FastPosInit;
|
||||
|
||||
|
||||
inline UINT32 GetPosSlot(UINT32 pos)
|
||||
{
|
||||
// for (UINT32 i = 1; pos >= kDistStart[i]; i++);
|
||||
// return i - 1;
|
||||
if (pos < 0x200)
|
||||
return g_FastPos[pos];
|
||||
return g_FastPos[pos >> 8] + 16;
|
||||
}
|
||||
|
||||
CCoder::CCoder(bool deflate64Mode):
|
||||
_deflate64Mode(deflate64Mode),
|
||||
m_MainCoder(kMainTableSize,
|
||||
deflate64Mode ? kLenDirectBits64 : kLenDirectBits32,
|
||||
kMatchNumber, kMaxCodeBitLength),
|
||||
m_DistCoder(deflate64Mode ? kDistTableSize64 : kDistTableSize32, kDistDirectBits, 0, kMaxCodeBitLength),
|
||||
m_LevelCoder(kLevelTableSize, kLevelDirectBits, 0, kMaxLevelBitLength),
|
||||
m_NumPasses(1),
|
||||
m_NumFastBytes(32),
|
||||
m_OnePosMatchesMemory(0),
|
||||
m_OnePosMatchesArray(0),
|
||||
m_MatchDistances(0),
|
||||
m_Created(false),
|
||||
m_Values(0)
|
||||
{
|
||||
m_MatchMaxLen = deflate64Mode ? kMatchMaxLen64 : kMatchMaxLen32;
|
||||
m_NumLenCombinations = deflate64Mode ? kNumLenCombinations64 :
|
||||
kNumLenCombinations32;
|
||||
m_LenStart = deflate64Mode ? kLenStart64 : kLenStart32;
|
||||
m_LenDirectBits = deflate64Mode ? kLenDirectBits64 : kLenDirectBits32;
|
||||
|
||||
m_Values = new CCodeValue[kValueBlockSize + kNumOpts];
|
||||
}
|
||||
|
||||
HRESULT CCoder::Create()
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
m_MatchFinder.Create(
|
||||
_deflate64Mode ? kHistorySize64 : kHistorySize32,
|
||||
kNumOpts + kNumGoodBacks, m_NumFastBytes,
|
||||
m_MatchMaxLen - m_NumFastBytes);
|
||||
m_MatchLengthEdge = m_NumFastBytes + 1;
|
||||
|
||||
if (m_NumPasses > 1)
|
||||
{
|
||||
m_OnePosMatchesMemory = new UINT16[kNumGoodBacks * (m_NumFastBytes + 1)];
|
||||
try
|
||||
{
|
||||
m_OnePosMatchesArray = new COnePosMatches[kNumGoodBacks];
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
delete []m_OnePosMatchesMemory;
|
||||
m_OnePosMatchesMemory = 0;
|
||||
throw;
|
||||
}
|
||||
UINT16 *goodBacksWordsCurrent = m_OnePosMatchesMemory;
|
||||
for(int i = 0; i < kNumGoodBacks; i++, goodBacksWordsCurrent += (m_NumFastBytes + 1))
|
||||
m_OnePosMatchesArray[i].Init(goodBacksWordsCurrent);
|
||||
}
|
||||
else
|
||||
m_MatchDistances = new UINT16[m_NumFastBytes + 1];
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
// ICompressSetEncoderProperties2
|
||||
HRESULT CCoder::BaseSetEncoderProperties2(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UINT32 numProperties)
|
||||
{
|
||||
for(UINT32 i = 0; i < numProperties; i++)
|
||||
{
|
||||
const PROPVARIANT &property = properties[i];
|
||||
switch(propIDs[i])
|
||||
{
|
||||
case NCoderPropID::kNumPasses:
|
||||
if (property.vt != VT_UI4)
|
||||
return E_INVALIDARG;
|
||||
m_NumPasses = property.ulVal;
|
||||
if(m_NumPasses == 0 || m_NumPasses > 255)
|
||||
return E_INVALIDARG;
|
||||
break;
|
||||
case NCoderPropID::kNumFastBytes:
|
||||
if (property.vt != VT_UI4)
|
||||
return E_INVALIDARG;
|
||||
m_NumFastBytes = property.ulVal;
|
||||
if(m_NumFastBytes < 3 || m_NumFastBytes > m_MatchMaxLen)
|
||||
return E_INVALIDARG;
|
||||
break;
|
||||
default:
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void CCoder::Free()
|
||||
{
|
||||
if(m_NumPasses > 0)
|
||||
{
|
||||
if (m_NumPasses > 1)
|
||||
{
|
||||
delete []m_OnePosMatchesMemory;
|
||||
delete []m_OnePosMatchesArray;
|
||||
}
|
||||
else
|
||||
delete []m_MatchDistances;
|
||||
}
|
||||
}
|
||||
|
||||
CCoder::~CCoder()
|
||||
{
|
||||
Free();
|
||||
delete []m_Values;
|
||||
}
|
||||
|
||||
void CCoder::ReadGoodBacks()
|
||||
{
|
||||
UINT32 goodIndex;
|
||||
if (m_NumPasses > 1)
|
||||
{
|
||||
goodIndex = m_FinderPos % kNumGoodBacks;
|
||||
m_MatchDistances = m_OnePosMatchesArray[goodIndex].MatchDistances;
|
||||
}
|
||||
UINT32 distanceTmp[kMatchMaxLen32 + 1];
|
||||
UINT32 len = m_MatchFinder.GetLongestMatch(distanceTmp);
|
||||
for(UINT32 i = kMatchMinLen; i <= len; i++)
|
||||
m_MatchDistances[i] = distanceTmp[i];
|
||||
|
||||
m_LongestMatchDistance = m_MatchDistances[len];
|
||||
if (len == m_NumFastBytes && m_NumFastBytes != m_MatchMaxLen)
|
||||
m_LongestMatchLength = len + m_MatchFinder.GetMatchLen(len,
|
||||
m_LongestMatchDistance, m_MatchMaxLen - len);
|
||||
else
|
||||
m_LongestMatchLength = len;
|
||||
if (m_NumPasses > 1)
|
||||
{
|
||||
m_OnePosMatchesArray[goodIndex].LongestMatchDistance = UINT16(m_LongestMatchDistance);
|
||||
m_OnePosMatchesArray[goodIndex].LongestMatchLength = UINT16(m_LongestMatchLength);
|
||||
}
|
||||
HRESULT result = m_MatchFinder.MovePos();
|
||||
if (result != S_OK)
|
||||
throw CMatchFinderException(result);
|
||||
m_FinderPos++;
|
||||
m_AdditionalOffset++;
|
||||
}
|
||||
|
||||
void CCoder::GetBacks(UINT32 pos)
|
||||
{
|
||||
if(pos == m_FinderPos)
|
||||
ReadGoodBacks();
|
||||
else
|
||||
{
|
||||
if (m_NumPasses == 1)
|
||||
{
|
||||
if(pos + 1 == m_FinderPos)
|
||||
return;
|
||||
throw 1932;
|
||||
}
|
||||
else
|
||||
{
|
||||
UINT32 goodIndex = pos % kNumGoodBacks;
|
||||
m_MatchDistances = m_OnePosMatchesArray[goodIndex].MatchDistances;
|
||||
m_LongestMatchDistance = m_OnePosMatchesArray[goodIndex].LongestMatchDistance;
|
||||
m_LongestMatchLength = m_OnePosMatchesArray[goodIndex].LongestMatchLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CCoder::MovePos(UINT32 num)
|
||||
{
|
||||
if (m_NumPasses > 1)
|
||||
{
|
||||
for(UINT32 i = 0; i < num; i++)
|
||||
GetBacks(UINT32(m_BlockStartPostion + m_CurrentBlockUncompressedSize + i + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (;num > 0; num--)
|
||||
{
|
||||
m_MatchFinder.DummyLongestMatch();
|
||||
HRESULT result = m_MatchFinder.MovePos();
|
||||
if (result != S_OK)
|
||||
throw CMatchFinderException(result);
|
||||
m_FinderPos++;
|
||||
m_AdditionalOffset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const UINT32 kIfinityPrice = 0xFFFFFFF;
|
||||
|
||||
UINT32 CCoder::Backward(UINT32 &backRes, UINT32 cur)
|
||||
{
|
||||
m_OptimumEndIndex = cur;
|
||||
UINT32 posMem = m_Optimum[cur].PosPrev;
|
||||
UINT16 backMem = m_Optimum[cur].BackPrev;
|
||||
do
|
||||
{
|
||||
UINT32 posPrev = posMem;
|
||||
UINT16 backCur = backMem;
|
||||
backMem = m_Optimum[posPrev].BackPrev;
|
||||
posMem = m_Optimum[posPrev].PosPrev;
|
||||
m_Optimum[posPrev].BackPrev = backCur;
|
||||
m_Optimum[posPrev].PosPrev = cur;
|
||||
cur = posPrev;
|
||||
}
|
||||
while(cur > 0);
|
||||
backRes = m_Optimum[0].BackPrev;
|
||||
m_OptimumCurrentIndex = m_Optimum[0].PosPrev;
|
||||
return m_OptimumCurrentIndex;
|
||||
}
|
||||
|
||||
UINT32 CCoder::GetOptimal(UINT32 &backRes)
|
||||
{
|
||||
if(m_OptimumEndIndex != m_OptimumCurrentIndex)
|
||||
{
|
||||
UINT32 len = m_Optimum[m_OptimumCurrentIndex].PosPrev - m_OptimumCurrentIndex;
|
||||
backRes = m_Optimum[m_OptimumCurrentIndex].BackPrev;
|
||||
m_OptimumCurrentIndex = m_Optimum[m_OptimumCurrentIndex].PosPrev;
|
||||
return len;
|
||||
}
|
||||
m_OptimumCurrentIndex = 0;
|
||||
m_OptimumEndIndex = 0;
|
||||
|
||||
GetBacks(UINT32(m_BlockStartPostion + m_CurrentBlockUncompressedSize));
|
||||
|
||||
UINT32 lenMain = m_LongestMatchLength;
|
||||
UINT32 backMain = m_LongestMatchDistance;
|
||||
|
||||
if(lenMain < kMatchMinLen)
|
||||
return 1;
|
||||
if(lenMain >= m_MatchLengthEdge)
|
||||
{
|
||||
backRes = backMain;
|
||||
MovePos(lenMain - 1);
|
||||
return lenMain;
|
||||
}
|
||||
m_Optimum[1].Price = m_LiteralPrices[m_MatchFinder.GetIndexByte(0 - m_AdditionalOffset)];
|
||||
m_Optimum[1].PosPrev = 0;
|
||||
|
||||
m_Optimum[2].Price = kIfinityPrice;
|
||||
m_Optimum[2].PosPrev = 1;
|
||||
|
||||
for(UINT32 i = kMatchMinLen; i <= lenMain; i++)
|
||||
{
|
||||
m_Optimum[i].PosPrev = 0;
|
||||
m_Optimum[i].BackPrev = m_MatchDistances[i];
|
||||
m_Optimum[i].Price = m_LenPrices[i - kMatchMinLen] + m_PosPrices[GetPosSlot(m_MatchDistances[i])];
|
||||
}
|
||||
|
||||
|
||||
UINT32 cur = 0;
|
||||
UINT32 lenEnd = lenMain;
|
||||
while(true)
|
||||
{
|
||||
cur++;
|
||||
if(cur == lenEnd)
|
||||
return Backward(backRes, cur);
|
||||
GetBacks(UINT32(m_BlockStartPostion + m_CurrentBlockUncompressedSize + cur));
|
||||
UINT32 newLen = m_LongestMatchLength;
|
||||
if(newLen >= m_MatchLengthEdge)
|
||||
return Backward(backRes, cur);
|
||||
|
||||
UINT32 curPrice = m_Optimum[cur].Price;
|
||||
UINT32 curAnd1Price = curPrice +
|
||||
m_LiteralPrices[m_MatchFinder.GetIndexByte(cur - m_AdditionalOffset)];
|
||||
COptimal &optimum = m_Optimum[cur + 1];
|
||||
if (curAnd1Price < optimum.Price)
|
||||
{
|
||||
optimum.Price = curAnd1Price;
|
||||
optimum.PosPrev = cur;
|
||||
}
|
||||
if (newLen < kMatchMinLen)
|
||||
continue;
|
||||
if(cur + newLen > lenEnd)
|
||||
{
|
||||
if (cur + newLen > kNumOpts - 1)
|
||||
newLen = kNumOpts - 1 - cur;
|
||||
UINT32 lenEndNew = cur + newLen;
|
||||
if (lenEnd < lenEndNew)
|
||||
{
|
||||
for(UINT32 i = lenEnd + 1; i <= lenEndNew; i++)
|
||||
m_Optimum[i].Price = kIfinityPrice;
|
||||
lenEnd = lenEndNew;
|
||||
}
|
||||
}
|
||||
for(UINT32 lenTest = kMatchMinLen; lenTest <= newLen; lenTest++)
|
||||
{
|
||||
UINT16 curBack = m_MatchDistances[lenTest];
|
||||
UINT32 curAndLenPrice = curPrice +
|
||||
m_LenPrices[lenTest - kMatchMinLen] + m_PosPrices[GetPosSlot(curBack)];
|
||||
COptimal &optimum = m_Optimum[cur + lenTest];
|
||||
if (curAndLenPrice < optimum.Price)
|
||||
{
|
||||
optimum.Price = curAndLenPrice;
|
||||
optimum.PosPrev = cur;
|
||||
optimum.BackPrev = curBack;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CCoder::InitStructures()
|
||||
{
|
||||
memset(m_LastLevels, 0, kMaxTableSize64);
|
||||
|
||||
m_ValueIndex = 0;
|
||||
m_OptimumEndIndex = 0;
|
||||
m_OptimumCurrentIndex = 0;
|
||||
m_AdditionalOffset = 0;
|
||||
|
||||
m_BlockStartPostion = 0;
|
||||
m_CurrentBlockUncompressedSize = 0;
|
||||
|
||||
m_MainCoder.StartNewBlock();
|
||||
m_DistCoder.StartNewBlock();
|
||||
|
||||
UINT32 i;
|
||||
for(i = 0; i < 256; i++)
|
||||
m_LiteralPrices[i] = 8;
|
||||
for(i = 0; i < m_NumLenCombinations; i++)
|
||||
m_LenPrices[i] = 5 + m_LenDirectBits[g_LenSlots[i]]; // test it
|
||||
for(i = 0; i < kDistTableSize64; i++)
|
||||
m_PosPrices[i] = 5 + kDistDirectBits[i];
|
||||
}
|
||||
|
||||
void CCoder::WriteBlockData(bool writeMode, bool finalBlock)
|
||||
{
|
||||
m_MainCoder.AddSymbol(kReadTableNumber);
|
||||
int method = WriteTables(writeMode, finalBlock);
|
||||
|
||||
if (writeMode)
|
||||
{
|
||||
if(method == NBlockType::kStored)
|
||||
{
|
||||
for(UINT32 i = 0; i < m_CurrentBlockUncompressedSize; i++)
|
||||
{
|
||||
BYTE b = m_MatchFinder.GetIndexByte(i - m_AdditionalOffset -
|
||||
m_CurrentBlockUncompressedSize);
|
||||
m_OutStream.WriteBits(b, 8);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (UINT32 i = 0; i < m_ValueIndex; i++)
|
||||
{
|
||||
if (m_Values[i].Flag == kFlagImm)
|
||||
m_MainCoder.CodeOneValue(&m_ReverseOutStream, m_Values[i].Imm);
|
||||
else if (m_Values[i].Flag == kFlagLenPos)
|
||||
{
|
||||
UINT32 len = m_Values[i].Len;
|
||||
UINT32 lenSlot = g_LenSlots[len];
|
||||
m_MainCoder.CodeOneValue(&m_ReverseOutStream, kMatchNumber + lenSlot);
|
||||
m_OutStream.WriteBits(len - m_LenStart[lenSlot], m_LenDirectBits[lenSlot]);
|
||||
UINT32 dist = m_Values[i].Pos;
|
||||
UINT32 posSlot = GetPosSlot(dist);
|
||||
m_DistCoder.CodeOneValue(&m_ReverseOutStream, posSlot);
|
||||
m_OutStream.WriteBits(dist - kDistStart[posSlot], kDistDirectBits[posSlot]);
|
||||
}
|
||||
}
|
||||
m_MainCoder.CodeOneValue(&m_ReverseOutStream, kReadTableNumber);
|
||||
}
|
||||
}
|
||||
m_MainCoder.StartNewBlock();
|
||||
m_DistCoder.StartNewBlock();
|
||||
m_ValueIndex = 0;
|
||||
UINT32 i;
|
||||
for(i = 0; i < 256; i++)
|
||||
if(m_LastLevels[i] != 0)
|
||||
m_LiteralPrices[i] = m_LastLevels[i];
|
||||
else
|
||||
m_LiteralPrices[i] = kNoLiteralDummy;
|
||||
|
||||
// -------------- Normal match -----------------------------
|
||||
|
||||
for(i = 0; i < m_NumLenCombinations; i++)
|
||||
{
|
||||
UINT32 slot = g_LenSlots[i];
|
||||
BYTE dummy = m_LastLevels[kMatchNumber + slot];
|
||||
if (dummy != 0)
|
||||
m_LenPrices[i] = dummy;
|
||||
else
|
||||
m_LenPrices[i] = kNoLenDummy;
|
||||
m_LenPrices[i] += m_LenDirectBits[slot];
|
||||
}
|
||||
for(i = 0; i < kDistTableSize64; i++)
|
||||
{
|
||||
BYTE dummy = m_LastLevels[kDistTableStart + i];
|
||||
if (dummy != 0)
|
||||
m_PosPrices[i] = dummy;
|
||||
else
|
||||
m_PosPrices[i] = kNoPosDummy;
|
||||
m_PosPrices[i] += kDistDirectBits[i];
|
||||
}
|
||||
}
|
||||
|
||||
void CCoder::CodeLevelTable(BYTE *newLevels, int numLevels, bool codeMode)
|
||||
{
|
||||
int prevLen = 0xFF; // last emitted length
|
||||
int nextLen = newLevels[0]; // length of next code
|
||||
int count = 0; // repeat count of the current code
|
||||
int maxCount = 7; // max repeat count
|
||||
int minCount = 4; // min repeat count
|
||||
if (nextLen == 0)
|
||||
{
|
||||
maxCount = 138;
|
||||
minCount = 3;
|
||||
}
|
||||
BYTE oldValueInGuardElement = newLevels[numLevels]; // push guard value
|
||||
try
|
||||
{
|
||||
newLevels[numLevels] = 0xFF; // guard already set
|
||||
for (int n = 0; n < numLevels; n++)
|
||||
{
|
||||
int curLen = nextLen;
|
||||
nextLen = newLevels[n + 1];
|
||||
count++;
|
||||
if (count < maxCount && curLen == nextLen)
|
||||
continue;
|
||||
else if (count < minCount)
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
int codeLen = curLen;
|
||||
if (codeMode)
|
||||
m_LevelCoder.CodeOneValue(&m_ReverseOutStream, codeLen);
|
||||
else
|
||||
m_LevelCoder.AddSymbol(codeLen);
|
||||
}
|
||||
else if (curLen != 0)
|
||||
{
|
||||
if (curLen != prevLen)
|
||||
{
|
||||
int codeLen = curLen;
|
||||
if (codeMode)
|
||||
m_LevelCoder.CodeOneValue(&m_ReverseOutStream, codeLen);
|
||||
else
|
||||
m_LevelCoder.AddSymbol(codeLen);
|
||||
count--;
|
||||
}
|
||||
if (codeMode)
|
||||
{
|
||||
m_LevelCoder.CodeOneValue(&m_ReverseOutStream, kTableLevelRepNumber);
|
||||
m_OutStream.WriteBits(count - 3, 2);
|
||||
}
|
||||
else
|
||||
m_LevelCoder.AddSymbol(kTableLevelRepNumber);
|
||||
}
|
||||
else if (count <= 10)
|
||||
{
|
||||
if (codeMode)
|
||||
{
|
||||
m_LevelCoder.CodeOneValue(&m_ReverseOutStream, kTableLevel0Number);
|
||||
m_OutStream.WriteBits(count - 3, 3);
|
||||
}
|
||||
else
|
||||
m_LevelCoder.AddSymbol(kTableLevel0Number);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (codeMode)
|
||||
{
|
||||
m_LevelCoder.CodeOneValue(&m_ReverseOutStream, kTableLevel0Number2);
|
||||
m_OutStream.WriteBits(count - 11, 7);
|
||||
}
|
||||
else
|
||||
m_LevelCoder.AddSymbol(kTableLevel0Number2);
|
||||
}
|
||||
count = 0;
|
||||
prevLen = curLen;
|
||||
if (nextLen == 0)
|
||||
{
|
||||
maxCount = 138;
|
||||
minCount = 3;
|
||||
}
|
||||
else if (curLen == nextLen)
|
||||
{
|
||||
maxCount = 6;
|
||||
minCount = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
maxCount = 7;
|
||||
minCount = 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
newLevels[numLevels] = oldValueInGuardElement; // old guard
|
||||
throw;
|
||||
}
|
||||
newLevels[numLevels] = oldValueInGuardElement; // old guard
|
||||
}
|
||||
|
||||
int CCoder::WriteTables(bool writeMode, bool finalBlock)
|
||||
{
|
||||
BYTE newLevels[kMaxTableSize64 + 1]; // (+ 1) for guard
|
||||
|
||||
m_MainCoder.BuildTree(&newLevels[0]);
|
||||
m_DistCoder.BuildTree(&newLevels[kDistTableStart]);
|
||||
|
||||
|
||||
memset(m_LastLevels, 0, kMaxTableSize64);
|
||||
|
||||
if (writeMode)
|
||||
{
|
||||
if(finalBlock)
|
||||
m_OutStream.WriteBits(NFinalBlockField::kFinalBlock, kFinalBlockFieldSize);
|
||||
else
|
||||
m_OutStream.WriteBits(NFinalBlockField::kNotFinalBlock, kFinalBlockFieldSize);
|
||||
|
||||
m_LevelCoder.StartNewBlock();
|
||||
|
||||
int numLitLenLevels = kMainTableSize;
|
||||
while(numLitLenLevels > kDeflateNumberOfLitLenCodesMin && newLevels[numLitLenLevels - 1] == 0)
|
||||
numLitLenLevels--;
|
||||
|
||||
int numDistLevels = _deflate64Mode ? kDistTableSize64 : kDistTableSize32;
|
||||
while(numDistLevels > kDeflateNumberOfDistanceCodesMin &&
|
||||
newLevels[kDistTableStart + numDistLevels - 1] == 0)
|
||||
numDistLevels--;
|
||||
|
||||
|
||||
/////////////////////////
|
||||
// First Pass
|
||||
|
||||
CodeLevelTable(newLevels, numLitLenLevels, false);
|
||||
CodeLevelTable(&newLevels[kDistTableStart], numDistLevels, false);
|
||||
|
||||
memcpy(m_LastLevels, newLevels, kMaxTableSize64);
|
||||
|
||||
|
||||
BYTE levelLevels[kLevelTableSize];
|
||||
m_LevelCoder.BuildTree(levelLevels);
|
||||
|
||||
BYTE levelLevelsStream[kLevelTableSize];
|
||||
int numLevelCodes = kDeflateNumberOfLevelCodesMin;
|
||||
int i;
|
||||
for (i = 0; i < kLevelTableSize; i++)
|
||||
{
|
||||
int streamPos = kCodeLengthAlphabetOrder[i];
|
||||
int level = levelLevels[streamPos];
|
||||
if (level > 0 && i >= numLevelCodes)
|
||||
numLevelCodes = i + 1;
|
||||
levelLevelsStream[i] = level;
|
||||
}
|
||||
|
||||
UINT32 numLZHuffmanBits = m_MainCoder.GetBlockBitLength();
|
||||
numLZHuffmanBits += m_DistCoder.GetBlockBitLength();
|
||||
numLZHuffmanBits += m_LevelCoder.GetBlockBitLength();
|
||||
numLZHuffmanBits += kDeflateNumberOfLengthCodesFieldSize +
|
||||
kDeflateNumberOfDistanceCodesFieldSize +
|
||||
kDeflateNumberOfLevelCodesFieldSize;
|
||||
numLZHuffmanBits += numLevelCodes * kDeflateLevelCodeFieldSize;
|
||||
|
||||
UINT32 nextBitPosition =
|
||||
(m_OutStream.GetBitPosition() + kBlockTypeFieldSize) % 8;
|
||||
UINT32 numBitsForAlign = nextBitPosition > 0 ? (8 - nextBitPosition): 0;
|
||||
|
||||
UINT32 numStoreBits = numBitsForAlign + (2 * sizeof(UINT16)) * 8;
|
||||
numStoreBits += m_CurrentBlockUncompressedSize * 8;
|
||||
if(numStoreBits < numLZHuffmanBits)
|
||||
{
|
||||
m_OutStream.WriteBits(NBlockType::kStored, kBlockTypeFieldSize); // test it
|
||||
m_OutStream.WriteBits(0, numBitsForAlign); // test it
|
||||
UINT16 currentBlockUncompressedSize = UINT16(m_CurrentBlockUncompressedSize);
|
||||
UINT16 currentBlockUncompressedSizeNot = ~currentBlockUncompressedSize;
|
||||
m_OutStream.WriteBits(currentBlockUncompressedSize, kDeflateStoredBlockLengthFieldSizeSize);
|
||||
m_OutStream.WriteBits(currentBlockUncompressedSizeNot, kDeflateStoredBlockLengthFieldSizeSize);
|
||||
return NBlockType::kStored;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_OutStream.WriteBits(NBlockType::kDynamicHuffman, kBlockTypeFieldSize);
|
||||
m_OutStream.WriteBits(numLitLenLevels - kDeflateNumberOfLitLenCodesMin, kDeflateNumberOfLengthCodesFieldSize);
|
||||
m_OutStream.WriteBits(numDistLevels - kDeflateNumberOfDistanceCodesMin,
|
||||
kDeflateNumberOfDistanceCodesFieldSize);
|
||||
m_OutStream.WriteBits(numLevelCodes - kDeflateNumberOfLevelCodesMin,
|
||||
kDeflateNumberOfLevelCodesFieldSize);
|
||||
|
||||
for (i = 0; i < numLevelCodes; i++)
|
||||
m_OutStream.WriteBits(levelLevelsStream[i], kDeflateLevelCodeFieldSize);
|
||||
|
||||
/////////////////////////
|
||||
// Second Pass
|
||||
|
||||
CodeLevelTable(newLevels, numLitLenLevels, true);
|
||||
CodeLevelTable(&newLevels[kDistTableStart], numDistLevels, true);
|
||||
return NBlockType::kDynamicHuffman;
|
||||
}
|
||||
}
|
||||
else
|
||||
memcpy(m_LastLevels, newLevels, kMaxTableSize64);
|
||||
return -1;
|
||||
}
|
||||
|
||||
HRESULT CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
if (!m_Created)
|
||||
{
|
||||
RINOK(Create());
|
||||
m_Created = true;
|
||||
}
|
||||
|
||||
UINT64 nowPos = 0;
|
||||
m_FinderPos = 0;
|
||||
|
||||
RINOK(m_MatchFinder.Init(inStream));
|
||||
m_OutStream.Init(outStream);
|
||||
m_ReverseOutStream.Init(&m_OutStream);
|
||||
|
||||
// CCoderReleaser coderReleaser(this);
|
||||
InitStructures();
|
||||
|
||||
while(true)
|
||||
{
|
||||
int currentPassIndex = 0;
|
||||
bool noMoreBytes;
|
||||
while (true)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
noMoreBytes = (m_AdditionalOffset == 0 && m_MatchFinder.GetNumAvailableBytes() == 0);
|
||||
|
||||
if (((m_CurrentBlockUncompressedSize >= kBlockUncompressedSizeThreshold ||
|
||||
m_ValueIndex >= kValueBlockSize) &&
|
||||
(m_OptimumEndIndex == m_OptimumCurrentIndex))
|
||||
|| noMoreBytes)
|
||||
break;
|
||||
UINT32 pos;
|
||||
UINT32 len = GetOptimal(pos);
|
||||
if (len >= kMatchMinLen)
|
||||
{
|
||||
UINT32 newLen = len - kMatchMinLen;
|
||||
m_Values[m_ValueIndex].Flag = kFlagLenPos;
|
||||
m_Values[m_ValueIndex].Len = BYTE(newLen);
|
||||
UINT32 lenSlot = g_LenSlots[newLen];
|
||||
m_MainCoder.AddSymbol(kMatchNumber + lenSlot);
|
||||
m_Values[m_ValueIndex].Pos = UINT16(pos);
|
||||
UINT32 posSlot = GetPosSlot(pos);
|
||||
m_DistCoder.AddSymbol(posSlot);
|
||||
}
|
||||
else if (len == 1)
|
||||
{
|
||||
BYTE b = m_MatchFinder.GetIndexByte(0 - m_AdditionalOffset);
|
||||
len = 1;
|
||||
m_MainCoder.AddSymbol(b);
|
||||
m_Values[m_ValueIndex].Flag = kFlagImm;
|
||||
m_Values[m_ValueIndex].Imm = b;
|
||||
}
|
||||
else
|
||||
throw 12112342;
|
||||
m_ValueIndex++;
|
||||
m_AdditionalOffset -= len;
|
||||
nowPos += len;
|
||||
m_CurrentBlockUncompressedSize += len;
|
||||
|
||||
}
|
||||
currentPassIndex++;
|
||||
bool writeMode = (currentPassIndex == m_NumPasses);
|
||||
WriteBlockData(writeMode, noMoreBytes);
|
||||
if (writeMode)
|
||||
break;
|
||||
nowPos = m_BlockStartPostion;
|
||||
m_AdditionalOffset = UINT32(m_FinderPos - m_BlockStartPostion);
|
||||
m_CurrentBlockUncompressedSize = 0;
|
||||
}
|
||||
m_BlockStartPostion += m_CurrentBlockUncompressedSize;
|
||||
m_CurrentBlockUncompressedSize = 0;
|
||||
if (progress != NULL)
|
||||
{
|
||||
UINT64 packSize = m_OutStream.GetProcessedSize();
|
||||
RINOK(progress->SetRatioInfo(&nowPos, &packSize));
|
||||
}
|
||||
if (noMoreBytes)
|
||||
break;
|
||||
}
|
||||
return m_OutStream.Flush();
|
||||
}
|
||||
|
||||
HRESULT CCoder::BaseCode(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
try { return CodeReal(inStream, outStream, inSize, outSize, progress); }
|
||||
catch(CMatchFinderException &e) { return e.m_Result; }
|
||||
catch(const COutBufferException &e) { return e.ErrorCode; }
|
||||
catch(...) { return E_FAIL; }
|
||||
}
|
||||
|
||||
STDMETHODIMP CCOMCoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{ return BaseCode(inStream, outStream, inSize, outSize, progress); }
|
||||
|
||||
STDMETHODIMP CCOMCoder::SetCoderProperties(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UINT32 numProperties)
|
||||
{ return BaseSetEncoderProperties2(propIDs, properties, numProperties); }
|
||||
|
||||
STDMETHODIMP CCOMCoder64::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{ return BaseCode(inStream, outStream, inSize, outSize, progress); }
|
||||
|
||||
STDMETHODIMP CCOMCoder64::SetCoderProperties(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UINT32 numProperties)
|
||||
{ return BaseSetEncoderProperties2(propIDs, properties, numProperties); }
|
||||
|
||||
}}}
|
||||
197
7zip/Compress/Deflate/DeflateEncoder.h
Executable file
197
7zip/Compress/Deflate/DeflateEncoder.h
Executable file
@@ -0,0 +1,197 @@
|
||||
// DeflateEncoder.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __DEFLATE_ENCODER_H
|
||||
#define __DEFLATE_ENCODER_H
|
||||
|
||||
#include "Common/MyCom.h"
|
||||
|
||||
#include "../../ICoder.h"
|
||||
#include "../../Common/LSBFEncoder.h"
|
||||
#include "../LZ/BinTree/BinTree3Z.h"
|
||||
#include "../Huffman/HuffmanEncoder.h"
|
||||
|
||||
#include "DeflateConst.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NDeflate {
|
||||
namespace NEncoder {
|
||||
|
||||
struct CCodeValue
|
||||
{
|
||||
BYTE Flag;
|
||||
union
|
||||
{
|
||||
BYTE Imm;
|
||||
BYTE Len;
|
||||
};
|
||||
UINT16 Pos;
|
||||
};
|
||||
|
||||
class COnePosMatches
|
||||
{
|
||||
public:
|
||||
UINT16 *MatchDistances;
|
||||
UINT16 LongestMatchLength;
|
||||
UINT16 LongestMatchDistance;
|
||||
void Init(UINT16 *matchDistances)
|
||||
{
|
||||
MatchDistances = matchDistances;
|
||||
};
|
||||
};
|
||||
|
||||
struct COptimal
|
||||
{
|
||||
UINT32 Price;
|
||||
UINT16 PosPrev;
|
||||
UINT16 BackPrev;
|
||||
};
|
||||
|
||||
const int kNumOpts = 0x1000;
|
||||
|
||||
class CCoder
|
||||
{
|
||||
UINT32 m_FinderPos;
|
||||
|
||||
COptimal m_Optimum[kNumOpts];
|
||||
|
||||
// CComPtr<IInWindowStreamMatch> m_MatchFinder;
|
||||
NBT3Z::CInTree m_MatchFinder;
|
||||
|
||||
NStream::NLSBF::CEncoder m_OutStream;
|
||||
NStream::NLSBF::CReverseEncoder m_ReverseOutStream;
|
||||
|
||||
NCompression::NHuffman::CEncoder m_MainCoder;
|
||||
NCompression::NHuffman::CEncoder m_DistCoder;
|
||||
NCompression::NHuffman::CEncoder m_LevelCoder;
|
||||
|
||||
BYTE m_LastLevels[kMaxTableSize64];
|
||||
|
||||
UINT32 m_ValueIndex;
|
||||
CCodeValue *m_Values;
|
||||
|
||||
UINT32 m_OptimumEndIndex;
|
||||
UINT32 m_OptimumCurrentIndex;
|
||||
UINT32 m_AdditionalOffset;
|
||||
|
||||
UINT32 m_LongestMatchLength;
|
||||
UINT32 m_LongestMatchDistance;
|
||||
UINT16 *m_MatchDistances;
|
||||
|
||||
UINT32 m_NumFastBytes;
|
||||
UINT32 m_MatchLengthEdge;
|
||||
|
||||
BYTE m_LiteralPrices[256];
|
||||
|
||||
BYTE m_LenPrices[kNumLenCombinations32];
|
||||
BYTE m_PosPrices[kDistTableSize64];
|
||||
|
||||
UINT32 m_CurrentBlockUncompressedSize;
|
||||
|
||||
COnePosMatches *m_OnePosMatchesArray;
|
||||
UINT16 *m_OnePosMatchesMemory;
|
||||
|
||||
UINT64 m_BlockStartPostion;
|
||||
int m_NumPasses;
|
||||
|
||||
bool m_Created;
|
||||
|
||||
bool _deflate64Mode;
|
||||
UINT32 m_NumLenCombinations;
|
||||
UINT32 m_MatchMaxLen;
|
||||
const BYTE *m_LenStart;
|
||||
const BYTE *m_LenDirectBits;
|
||||
|
||||
HRESULT Create();
|
||||
void Free();
|
||||
|
||||
void GetBacks(UINT32 aPos);
|
||||
|
||||
void ReadGoodBacks();
|
||||
void MovePos(UINT32 num);
|
||||
UINT32 Backward(UINT32 &backRes, UINT32 cur);
|
||||
UINT32 GetOptimal(UINT32 &backRes);
|
||||
|
||||
void InitStructures();
|
||||
void CodeLevelTable(BYTE *newLevels, int numLevels, bool codeMode);
|
||||
int WriteTables(bool writeMode, bool finalBlock);
|
||||
void CopyBackBlockOp(UINT32 distance, UINT32 length);
|
||||
void WriteBlockData(bool writeMode, bool finalBlock);
|
||||
|
||||
/*
|
||||
void CCoder::ReleaseStreams()
|
||||
{
|
||||
m_MatchFinder.ReleaseStream();
|
||||
m_OutStream.ReleaseStream();
|
||||
}
|
||||
class CCoderReleaser
|
||||
{
|
||||
CCoder *m_Coder;
|
||||
public:
|
||||
CCoderReleaser(CCoder *aCoder): m_Coder(aCoder) {}
|
||||
~CCoderReleaser()
|
||||
{
|
||||
m_Coder->ReleaseStreams();
|
||||
}
|
||||
};
|
||||
friend class CCoderReleaser;
|
||||
*/
|
||||
|
||||
public:
|
||||
CCoder(bool deflate64Mode = false);
|
||||
~CCoder();
|
||||
|
||||
HRESULT CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
HRESULT BaseCode(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
// ICompressSetCoderProperties
|
||||
HRESULT BaseSetEncoderProperties2(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UINT32 numProperties);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
class CCOMCoder :
|
||||
public ICompressCoder,
|
||||
public ICompressSetCoderProperties,
|
||||
public CMyUnknownImp,
|
||||
public CCoder
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP1(ICompressSetCoderProperties)
|
||||
CCOMCoder(): CCoder(false) {};
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
// ICompressSetCoderProperties
|
||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UINT32 numProperties);
|
||||
};
|
||||
|
||||
class CCOMCoder64 :
|
||||
public ICompressCoder,
|
||||
public ICompressSetCoderProperties,
|
||||
public CMyUnknownImp,
|
||||
public CCoder
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP1(ICompressSetCoderProperties)
|
||||
CCOMCoder64(): CCoder(true) {};
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
// ICompressSetCoderProperties
|
||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UINT32 numProperties);
|
||||
};
|
||||
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
27
7zip/Compress/Deflate/DeflateExtConst.h
Executable file
27
7zip/Compress/Deflate/DeflateExtConst.h
Executable file
@@ -0,0 +1,27 @@
|
||||
// DeflateExtConst.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __DEFLATE_EXTCONST_H
|
||||
#define __DEFLATE_EXTCONST_H
|
||||
|
||||
#include "Common/Types.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NDeflate {
|
||||
|
||||
// const UINT32 kDistTableSize = 30;
|
||||
const UINT32 kDistTableSize32 = 30;
|
||||
const UINT32 kDistTableSize64 = 32;
|
||||
|
||||
const UINT32 kHistorySize32 = 0x8000;
|
||||
const UINT32 kHistorySize64 = 0x10000;
|
||||
const UINT32 kNumLenCombinations32 = 256;
|
||||
const UINT32 kNumLenCombinations64 = 255;
|
||||
// don't change kNumLenCombinations64. It must be less than 255.
|
||||
|
||||
const UINT32 kNumHuffmanBits = 15;
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
126
7zip/Compress/Deflate/DllExports.cpp
Executable file
126
7zip/Compress/Deflate/DllExports.cpp
Executable file
@@ -0,0 +1,126 @@
|
||||
// DLLExports.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#define INITGUID
|
||||
|
||||
#include "DeflateEncoder.h"
|
||||
#include "DeflateDecoder.h"
|
||||
#include "Common/ComTry.h"
|
||||
|
||||
|
||||
// {23170F69-40C1-278B-0401-080000000000}
|
||||
DEFINE_GUID(CLSID_CCompressDeflateDecoder,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x04, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
// {23170F69-40C1-278B-0401-090000000000}
|
||||
DEFINE_GUID(CLSID_CCompressDeflate64Decoder,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x04, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
// {23170F69-40C1-278B-0401-080000000100}
|
||||
DEFINE_GUID(CLSID_CCompressDeflateEncoder,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x04, 0x01, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00);
|
||||
|
||||
// {23170F69-40C1-278B-0401-090000000100}
|
||||
DEFINE_GUID(CLSID_CCompressDeflate64Encoder,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x04, 0x01, 0x09, 0x00, 0x00, 0x00, 0x01, 0x00);
|
||||
|
||||
extern "C"
|
||||
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
*outObject = 0;
|
||||
int correctInterface = (*iid == IID_ICompressCoder);
|
||||
CMyComPtr<ICompressCoder> coder;
|
||||
if (*clsid == CLSID_CCompressDeflateDecoder)
|
||||
{
|
||||
if (!correctInterface)
|
||||
return E_NOINTERFACE;
|
||||
coder = (ICompressCoder *)new NCompress::NDeflate::NDecoder::CCOMCoder();
|
||||
}
|
||||
else if (*clsid == CLSID_CCompressDeflateEncoder)
|
||||
{
|
||||
if (!correctInterface)
|
||||
return E_NOINTERFACE;
|
||||
coder = (ICompressCoder *)new NCompress::NDeflate::NEncoder::CCOMCoder();
|
||||
}
|
||||
else if (*clsid == CLSID_CCompressDeflate64Decoder)
|
||||
{
|
||||
if (!correctInterface)
|
||||
return E_NOINTERFACE;
|
||||
coder = (ICompressCoder *)new NCompress::NDeflate::NDecoder::CCOMCoder64();
|
||||
}
|
||||
else if (*clsid == CLSID_CCompressDeflate64Encoder)
|
||||
{
|
||||
if (!correctInterface)
|
||||
return E_NOINTERFACE;
|
||||
coder = (ICompressCoder *)new NCompress::NDeflate::NEncoder::CCOMCoder64();
|
||||
}
|
||||
else
|
||||
return CLASS_E_CLASSNOTAVAILABLE;
|
||||
*outObject = coder.Detach();
|
||||
COM_TRY_END
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
struct CDeflateMethodItem
|
||||
{
|
||||
char ID[3];
|
||||
const wchar_t *UserName;
|
||||
const GUID *Decoder;
|
||||
const GUID *Encoder;
|
||||
};
|
||||
|
||||
#define METHOD_ITEM(Name, id, UserName) \
|
||||
{ { 0x04, 0x01, id }, UserName, \
|
||||
&CLSID_CCompress ## Name ## Decoder, \
|
||||
&CLSID_CCompress ## Name ## Encoder }
|
||||
|
||||
|
||||
static CDeflateMethodItem g_Methods[] =
|
||||
{
|
||||
METHOD_ITEM(Deflate, 0x08, L"Deflate"),
|
||||
METHOD_ITEM(Deflate64, 0x09, L"Deflate64")
|
||||
};
|
||||
|
||||
STDAPI GetNumberOfMethods(UINT32 *numMethods)
|
||||
{
|
||||
*numMethods = sizeof(g_Methods) / sizeof(g_Methods[0]);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDAPI GetMethodProperty(UINT32 index, PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
if (index > sizeof(g_Methods) / sizeof(g_Methods[0]))
|
||||
return E_INVALIDARG;
|
||||
VariantClear((tagVARIANT *)value);
|
||||
const CDeflateMethodItem &method = g_Methods[index];
|
||||
switch(propID)
|
||||
{
|
||||
case NMethodPropID::kID:
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(method.ID,
|
||||
sizeof(method.ID))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
case NMethodPropID::kName:
|
||||
if ((value->bstrVal = ::SysAllocString(method.UserName)) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
case NMethodPropID::kDecoder:
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(
|
||||
(const char *)method.Decoder, sizeof(GUID))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
case NMethodPropID::kEncoder:
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(
|
||||
(const char *)method.Encoder, sizeof(GUID))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
3
7zip/Compress/Deflate/StdAfx.cpp
Executable file
3
7zip/Compress/Deflate/StdAfx.cpp
Executable file
@@ -0,0 +1,3 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "stdafx.h"
|
||||
8
7zip/Compress/Deflate/StdAfx.h
Executable file
8
7zip/Compress/Deflate/StdAfx.h
Executable file
@@ -0,0 +1,8 @@
|
||||
// stdafx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#endif
|
||||
15
7zip/Compress/Deflate/resource.h
Executable file
15
7zip/Compress/Deflate/resource.h
Executable file
@@ -0,0 +1,15 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by resource.rc
|
||||
//
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 101
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
121
7zip/Compress/Deflate/resource.rc
Executable file
121
7zip/Compress/Deflate/resource.rc
Executable file
@@ -0,0 +1,121 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Russian resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
|
||||
#pragma code_page(1251)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // Russian resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifndef _MAC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 3,9,2,0
|
||||
PRODUCTVERSION 3,9,2,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "\0"
|
||||
VALUE "CompanyName", " \0"
|
||||
VALUE "FileDescription", "Deflate Coder\0"
|
||||
VALUE "FileVersion", "3, 9, 2, 0\0"
|
||||
VALUE "InternalName", "Deflate\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 1999-2003 Igor Pavlov\0"
|
||||
VALUE "LegalTrademarks", "\0"
|
||||
VALUE "OriginalFilename", "Deflate.dll\0"
|
||||
VALUE "PrivateBuild", "\0"
|
||||
VALUE "ProductName", "7-Zip\0"
|
||||
VALUE "ProductVersion", "3, 9, 2, 0\0"
|
||||
VALUE "SpecialBuild", "\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // !_MAC
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
113
7zip/Compress/Huffman/HuffmanDecoder.h
Executable file
113
7zip/Compress/Huffman/HuffmanDecoder.h
Executable file
@@ -0,0 +1,113 @@
|
||||
// Compress/HuffmanDecoder.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __COMPRESS_HUFFMANDECODER_H
|
||||
#define __COMPRESS_HUFFMANDECODER_H
|
||||
|
||||
namespace NCompress {
|
||||
namespace NHuffman {
|
||||
|
||||
class CDecoderException{};
|
||||
|
||||
const UINT32 kValueTableBits = 8;
|
||||
|
||||
template <int kNumBitsInLongestCode>
|
||||
class CDecoder
|
||||
{
|
||||
UINT32 m_Limitits[kNumBitsInLongestCode + 1]; // m_Limitits[i] = value limit for symbols with length = i
|
||||
UINT32 m_Positions[kNumBitsInLongestCode + 1]; // m_Positions[i] = index in m_Symbols[] of first symbol with length = i
|
||||
UINT32 m_NumSymbols;
|
||||
UINT32 *m_Symbols; // symbols: at first with len = 1 then 2, ... 15.
|
||||
BYTE m_Lengths[1 << kValueTableBits];
|
||||
public:
|
||||
CDecoder(UINT32 numSymbols):
|
||||
m_NumSymbols(numSymbols)
|
||||
{ m_Symbols = new UINT32[m_NumSymbols]; }
|
||||
|
||||
~CDecoder()
|
||||
{ delete []m_Symbols; }
|
||||
|
||||
void SetNumSymbols(UINT32 numSymbols)
|
||||
{ m_NumSymbols = numSymbols; }
|
||||
void SetCodeLengths(const BYTE *codeLengths);
|
||||
template <class TBitDecoder>
|
||||
UINT32 DecodeSymbol(TBitDecoder *bitStream)
|
||||
{
|
||||
UINT32 numBits;
|
||||
|
||||
UINT32 value = bitStream->GetValue(kNumBitsInLongestCode);
|
||||
|
||||
if (value < m_Limitits[kValueTableBits])
|
||||
numBits = m_Lengths[value >> (kNumBitsInLongestCode - kValueTableBits)];
|
||||
else if (value < m_Limitits[10])
|
||||
if (value < m_Limitits[9])
|
||||
numBits = 9;
|
||||
else
|
||||
numBits = 10;
|
||||
else if (value < m_Limitits[11])
|
||||
numBits = 11;
|
||||
else if (value < m_Limitits[12])
|
||||
numBits = 12;
|
||||
else
|
||||
for (numBits = 13; numBits < kNumBitsInLongestCode; numBits++)
|
||||
if (value < m_Limitits[numBits])
|
||||
break;
|
||||
bitStream->MovePos(numBits);
|
||||
UINT32 index = m_Positions[numBits] +
|
||||
((value - m_Limitits[numBits - 1]) >> (kNumBitsInLongestCode - numBits));
|
||||
if (index >= m_NumSymbols)
|
||||
throw CDecoderException(); // test it
|
||||
return m_Symbols[index];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <int kNumBitsInLongestCode>
|
||||
void CDecoder<kNumBitsInLongestCode>::SetCodeLengths(const BYTE *codeLengths)
|
||||
{
|
||||
int lenCounts[kNumBitsInLongestCode + 1], tmpPositions[kNumBitsInLongestCode + 1];
|
||||
int i;
|
||||
for(i = 1; i <= kNumBitsInLongestCode; i++)
|
||||
lenCounts[i] = 0;
|
||||
UINT32 symbol;
|
||||
for (symbol = 0; symbol < m_NumSymbols; symbol++)
|
||||
{
|
||||
BYTE codeLength = codeLengths[symbol];
|
||||
if (codeLength > kNumBitsInLongestCode)
|
||||
throw CDecoderException();
|
||||
lenCounts[codeLength]++;
|
||||
}
|
||||
lenCounts[0] = 0;
|
||||
tmpPositions[0] = m_Positions[0] = m_Limitits[0] = 0;
|
||||
UINT32 startPos = 0;
|
||||
UINT32 index = 0;
|
||||
const UINT32 kMaxValue = (1 << kNumBitsInLongestCode);
|
||||
for (i = 1; i <= kNumBitsInLongestCode; i++)
|
||||
{
|
||||
startPos += lenCounts[i] << (kNumBitsInLongestCode - i);
|
||||
if (startPos > kMaxValue)
|
||||
throw CDecoderException();
|
||||
m_Limitits[i] = startPos;
|
||||
m_Positions[i] = m_Positions[i - 1] + lenCounts[i - 1];
|
||||
tmpPositions[i] = m_Positions[i];
|
||||
|
||||
if(i <= kValueTableBits)
|
||||
{
|
||||
UINT32 limit = (m_Limitits[i] >> (kNumBitsInLongestCode - kValueTableBits)); // change it
|
||||
memset(m_Lengths + index, BYTE(i), limit - index);
|
||||
index = limit;
|
||||
}
|
||||
}
|
||||
|
||||
// if (startPos != kMaxValue)
|
||||
// throw CDecoderException();
|
||||
|
||||
for (symbol = 0; symbol < m_NumSymbols; symbol++)
|
||||
if (codeLengths[symbol] != 0)
|
||||
m_Symbols[tmpPositions[codeLengths[symbol]]++] = symbol;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
296
7zip/Compress/Huffman/HuffmanEncoder.cpp
Executable file
296
7zip/Compress/Huffman/HuffmanEncoder.cpp
Executable file
@@ -0,0 +1,296 @@
|
||||
// Compression/HuffmanEncoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "HuffmanEncoder.h"
|
||||
#include "Common/Defs.h"
|
||||
|
||||
namespace NCompression {
|
||||
namespace NHuffman {
|
||||
|
||||
static const char *kIncorrectBitLenCountsMessage = "Incorrect bit len counts";
|
||||
|
||||
CEncoder::CEncoder(UINT32 numSymbols,
|
||||
const BYTE *extraBits, UINT32 extraBase, UINT32 maxLength):
|
||||
m_NumSymbols(numSymbols),
|
||||
m_ExtraBits(extraBits),
|
||||
m_ExtraBase(extraBase),
|
||||
m_MaxLength(maxLength),
|
||||
m_HeapSize(numSymbols * 2+ 1)
|
||||
{
|
||||
m_Items = new CItem[m_HeapSize];
|
||||
m_Heap = new UINT32[m_HeapSize];
|
||||
m_Depth = new BYTE[m_HeapSize];
|
||||
}
|
||||
|
||||
CEncoder::~CEncoder()
|
||||
{
|
||||
delete []m_Depth;
|
||||
delete []m_Heap;
|
||||
delete []m_Items;
|
||||
}
|
||||
|
||||
void CEncoder::StartNewBlock()
|
||||
{
|
||||
for (UINT32 i = 0; i < m_NumSymbols; i++)
|
||||
m_Items[i].Freq = 0;
|
||||
}
|
||||
|
||||
void CEncoder::SetFreqs(const UINT32 *freqs)
|
||||
{
|
||||
for (UINT32 i = 0; i < m_NumSymbols; i++)
|
||||
m_Items[i].Freq = freqs[i];
|
||||
}
|
||||
|
||||
static const int kSmallest = 1;
|
||||
|
||||
// ===========================================================================
|
||||
// Remove the smallest element from the heap and recreate the heap with
|
||||
// one less element. Updates heap and m_HeapLength.
|
||||
|
||||
UINT32 CEncoder::RemoveSmallest()
|
||||
{
|
||||
UINT32 top = m_Heap[kSmallest];
|
||||
m_Heap[kSmallest] = m_Heap[m_HeapLength--];
|
||||
DownHeap(kSmallest);
|
||||
return top;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// Compares to subtrees, using the tree m_Depth as tie breaker when
|
||||
// the subtrees have equal frequency. This minimizes the worst case length.
|
||||
|
||||
bool CEncoder::Smaller(int n, int m)
|
||||
{
|
||||
return (m_Items[n].Freq < m_Items[m].Freq ||
|
||||
(m_Items[n].Freq == m_Items[m].Freq && m_Depth[n] <= m_Depth[m]));
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// Restore the m_Heap property by moving down the tree starting at node k,
|
||||
// exchanging a node with the smallest of its two sons if necessary, stopping
|
||||
// when the m_Heap property is re-established (each father CompareFreqs than its
|
||||
// two sons).
|
||||
|
||||
void CEncoder::DownHeap(UINT32 k)
|
||||
{
|
||||
UINT32 symbol = m_Heap[k];
|
||||
for (UINT32 j = k << 1; j <= m_HeapLength;) // j: left son of k
|
||||
{
|
||||
// Set j to the smallest of the two sons:
|
||||
if (j < m_HeapLength && Smaller(m_Heap[j+1], m_Heap[j]))
|
||||
j++;
|
||||
UINT32 htemp = m_Heap[j]; // htemp required because of bug in SASC compiler
|
||||
if (Smaller(symbol, htemp)) // Exit if v is smaller than both sons
|
||||
break;
|
||||
m_Heap[k] = htemp; // Exchange v with the smallest son
|
||||
k = j;
|
||||
j <<= 1; // And continue down the tree, setting j to the left son of k
|
||||
}
|
||||
m_Heap[k] = symbol;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// Compute the optimal bit lengths for a tree and update the total bit length
|
||||
// for the current block.
|
||||
// IN assertion: the fields freq and dad are set, heap[heapMax] and
|
||||
// above are the tree nodes sorted by increasing frequency.
|
||||
// OUT assertions: the field len is set to the optimal bit length, the
|
||||
// array m_BitLenCounters contains the frequencies for each bit length.
|
||||
// The length m_BlockBitLength is updated; static_len is also updated if stree is
|
||||
// not null.
|
||||
|
||||
void CEncoder::GenerateBitLen(UINT32 maxCode, UINT32 heapMax)
|
||||
{
|
||||
int overflow = 0; // number of elements with bit length too large
|
||||
|
||||
for (UINT32 i = 0; i <= kNumBitsInLongestCode; i++)
|
||||
m_BitLenCounters[i] = 0;
|
||||
|
||||
/* In a first pass, compute the optimal bit lengths (which may
|
||||
* overflow in the case of the bit length tree).
|
||||
*/
|
||||
m_Items[m_Heap[heapMax]].Len = 0; /* root of the heap */
|
||||
UINT32 h; /* heap index */
|
||||
for (h = heapMax+1; h < m_HeapSize; h++)
|
||||
{
|
||||
UINT32 symbol = m_Heap[h];
|
||||
UINT32 len = m_Items[m_Items[symbol].Dad].Len + 1;
|
||||
if (len > m_MaxLength)
|
||||
{
|
||||
len = m_MaxLength;
|
||||
overflow++;
|
||||
}
|
||||
m_Items[symbol].Len = len; // We overwrite m_Items[symbol].Dad which is no longer needed
|
||||
if (symbol > maxCode)
|
||||
continue; // not a leaf node
|
||||
m_BitLenCounters[len]++;
|
||||
UINT32 extraBits;
|
||||
if (m_ExtraBits != 0 && symbol >= m_ExtraBase)
|
||||
extraBits = m_ExtraBits[symbol - m_ExtraBase];
|
||||
else
|
||||
extraBits = 0;
|
||||
m_BlockBitLength += (m_Items[symbol].Freq * (len + extraBits));
|
||||
}
|
||||
if (overflow == 0)
|
||||
return;
|
||||
|
||||
// This happens for example on obj2 and pic of the Calgary corpus
|
||||
// Find the first bit length which could increase:
|
||||
do
|
||||
{
|
||||
UINT32 bits = m_MaxLength-1;
|
||||
while (m_BitLenCounters[bits] == 0)
|
||||
bits--;
|
||||
m_BitLenCounters[bits]--; // move one leaf down the m_Items
|
||||
m_BitLenCounters[bits + 1] += 2; // move one overflow item as its brother
|
||||
m_BitLenCounters[m_MaxLength]--;
|
||||
// The brother of the overflow item also moves one step up,
|
||||
// but this does not affect m_BitLenCounters[m_MaxLength]
|
||||
overflow -= 2;
|
||||
}
|
||||
while (overflow > 0);
|
||||
|
||||
// Now recompute all bit lengths, scanning in increasing frequency.
|
||||
// h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
|
||||
// lengths instead of fixing only the wrong ones. This idea is taken
|
||||
// from 'ar' written by Haruhiko Okumura.)
|
||||
for (UINT32 bits = m_MaxLength; bits != 0; bits--)
|
||||
{
|
||||
UINT32 numNodes = m_BitLenCounters[bits];
|
||||
while (numNodes != 0)
|
||||
{
|
||||
UINT32 m = m_Heap[--h];
|
||||
if (m > maxCode)
|
||||
continue;
|
||||
if (m_Items[m].Len != (unsigned) bits)
|
||||
{
|
||||
m_BlockBitLength += ((long)bits - (long)m_Items[m].Len) * (long)m_Items[m].Freq;
|
||||
m_Items[m].Len = bits;
|
||||
}
|
||||
numNodes--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ===========================================================================
|
||||
// Generate the codes for a given tree and bit counts (which need not be
|
||||
// optimal).
|
||||
// IN assertion: the array m_BitLenCounters contains the bit length statistics for
|
||||
// the given tree and the field len is set for all tree elements.
|
||||
// OUT assertion: the field code is set for all tree elements of non
|
||||
// zero code length.
|
||||
|
||||
// UINT32 maxCode = largest code with non zero frequency
|
||||
|
||||
|
||||
void CEncoder::GenerateCodes(UINT32 maxCode)
|
||||
{
|
||||
UINT32 nextCodes[kNumBitsInLongestCode + 1]; // next code value for each bit length
|
||||
UINT32 code = 0; // running code value
|
||||
// The distribution counts are first used to generate the code values
|
||||
// without bit reversal.
|
||||
for (UINT32 bits = 1; bits <= kNumBitsInLongestCode; bits++)
|
||||
nextCodes[bits] = code = (code + m_BitLenCounters[bits - 1]) << 1;
|
||||
// Check that the bit counts in m_BitLenCounters are consistent. The last code
|
||||
// must be all ones.
|
||||
if (code + m_BitLenCounters[kNumBitsInLongestCode] - 1 != (1 << kNumBitsInLongestCode) - 1)
|
||||
throw kIncorrectBitLenCountsMessage;
|
||||
for (UINT32 n = 0; n <= maxCode; n++)
|
||||
{
|
||||
int len = m_Items[n].Len;
|
||||
if (len == 0)
|
||||
continue;
|
||||
m_Items[n].Code = nextCodes[len]++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ===========================================================================
|
||||
// Construct one Huffman tree and assigns the code bit strings and lengths.
|
||||
// Update the total bit length for the current block.
|
||||
// IN assertion: the field freq is set for all tree elements.
|
||||
// OUT assertions: the fields len and code are set to the optimal bit length
|
||||
// and corresponding code. The length m_BlockBitLength is updated; static_len is
|
||||
// also updated if stree is not null. The field max_code is set.
|
||||
|
||||
void CEncoder::BuildTree(BYTE *levels)
|
||||
{
|
||||
m_BlockBitLength = 0;
|
||||
int maxCode = -1; // WAS = -1; largest code with non zero frequency */
|
||||
|
||||
// Construct the initial m_Heap, with least frequent element in
|
||||
// m_Heap[kSmallest]. The sons of m_Heap[n] are m_Heap[2*n] and m_Heap[2*n+1].
|
||||
// m_Heap[0] is not used.
|
||||
//
|
||||
|
||||
m_HeapLength = 0;
|
||||
UINT32 n; // iterate over m_Heap elements
|
||||
for (n = 0; n < m_NumSymbols; n++)
|
||||
{
|
||||
if (m_Items[n].Freq != 0)
|
||||
{
|
||||
m_Heap[++m_HeapLength] = maxCode = n;
|
||||
m_Depth[n] = 0;
|
||||
}
|
||||
else
|
||||
m_Items[n].Len = 0;
|
||||
}
|
||||
|
||||
// The pkzip format requires that at least one distance code exists,
|
||||
// and that at least one bit should be sent even if there is only one
|
||||
// possible code. So to avoid special checks later on we force at least
|
||||
// two codes of non zero frequency.
|
||||
while (m_HeapLength < 2)
|
||||
{
|
||||
int aNewNode = m_Heap[++m_HeapLength] = (maxCode < 2 ? ++maxCode : 0);
|
||||
m_Items[aNewNode].Freq = 1;
|
||||
m_Depth[aNewNode] = 0;
|
||||
m_BlockBitLength--;
|
||||
// if (stree) static_len -= stree[aNewNode].Len;
|
||||
// aNewNode is 0 or 1 so it does not have m_ExtraBits bits
|
||||
}
|
||||
|
||||
// The elements m_Heap[m_HeapLength/2+1 .. m_HeapLength] are leaves of the m_Items,
|
||||
// establish sub-heaps of increasing lengths:
|
||||
for (n = m_HeapLength / 2; n >= 1; n--)
|
||||
DownHeap(n);
|
||||
|
||||
// Construct the Huffman tree by repeatedly combining the least two
|
||||
// frequent nodes.
|
||||
int node = m_NumSymbols; // next internal node of the tree
|
||||
UINT32 heapMax = m_NumSymbols * 2+ 1;
|
||||
do
|
||||
{
|
||||
n = RemoveSmallest(); /* n = node of least frequency */
|
||||
UINT32 m = m_Heap[kSmallest]; /* m = node of next least frequency */
|
||||
|
||||
m_Heap[--heapMax] = n; /* keep the nodes sorted by frequency */
|
||||
m_Heap[--heapMax] = m;
|
||||
|
||||
// Create a new node father of n and m
|
||||
m_Items[node].Freq = m_Items[n].Freq + m_Items[m].Freq;
|
||||
m_Depth[node] = (BYTE) (MyMax(m_Depth[n], m_Depth[m]) + 1);
|
||||
m_Items[n].Dad = m_Items[m].Dad = node;
|
||||
// and insert the new node in the m_Heap
|
||||
m_Heap[kSmallest] = node++;
|
||||
DownHeap(kSmallest);
|
||||
|
||||
}
|
||||
while (m_HeapLength >= 2);
|
||||
|
||||
m_Heap[--heapMax] = m_Heap[kSmallest];
|
||||
|
||||
// At this point, the fields freq and dad are set. We can now
|
||||
// generate the bit lengths.
|
||||
GenerateBitLen(maxCode, heapMax);
|
||||
|
||||
// The field len is now set, we can generate the bit codes
|
||||
GenerateCodes (maxCode);
|
||||
|
||||
for (n = 0; n < m_NumSymbols; n++)
|
||||
levels[n] = BYTE(m_Items[n].Len);
|
||||
}
|
||||
|
||||
}}
|
||||
66
7zip/Compress/Huffman/HuffmanEncoder.h
Executable file
66
7zip/Compress/Huffman/HuffmanEncoder.h
Executable file
@@ -0,0 +1,66 @@
|
||||
// Compression/HuffmanEncoder.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __COMPRESSION_HUFFMANENCODER_H
|
||||
#define __COMPRESSION_HUFFMANENCODER_H
|
||||
|
||||
#include "../../../Common/Types.h"
|
||||
|
||||
namespace NCompression {
|
||||
namespace NHuffman {
|
||||
|
||||
const int kNumBitsInLongestCode = 15;
|
||||
|
||||
struct CItem
|
||||
{
|
||||
UINT32 Freq;
|
||||
UINT32 Code;
|
||||
UINT32 Dad;
|
||||
UINT32 Len;
|
||||
};
|
||||
|
||||
class CEncoder
|
||||
{
|
||||
UINT32 m_NumSymbols; // number of symbols in adwSymbol
|
||||
|
||||
CItem *m_Items;
|
||||
UINT32 *m_Heap;
|
||||
UINT32 m_HeapSize;
|
||||
BYTE *m_Depth;
|
||||
const BYTE *m_ExtraBits;
|
||||
UINT32 m_ExtraBase;
|
||||
UINT32 m_MaxLength;
|
||||
|
||||
UINT32 m_HeapLength;
|
||||
UINT32 m_BitLenCounters[kNumBitsInLongestCode + 1];
|
||||
|
||||
UINT32 RemoveSmallest();
|
||||
bool Smaller(int n, int m);
|
||||
void DownHeap(UINT32 k);
|
||||
void GenerateBitLen(UINT32 maxCode, UINT32 heapMax);
|
||||
void GenerateCodes(UINT32 maxCode);
|
||||
|
||||
UINT32 m_BlockBitLength;
|
||||
public:
|
||||
|
||||
CEncoder(UINT32 numSymbols, const BYTE *extraBits,
|
||||
UINT32 extraBase, UINT32 maxLength);
|
||||
~CEncoder();
|
||||
void StartNewBlock();
|
||||
|
||||
void AddSymbol(UINT32 symbol)
|
||||
{ m_Items[symbol].Freq++; }
|
||||
|
||||
void SetFreqs(const UINT32 *freqs);
|
||||
void BuildTree(BYTE *levels);
|
||||
UINT32 GetBlockBitLength() const { return m_BlockBitLength; }
|
||||
|
||||
template <class TBitEncoder>
|
||||
void CodeOneValue(TBitEncoder *bitEncoder, UINT32 symbol)
|
||||
{ bitEncoder->WriteBits(m_Items[symbol].Code, m_Items[symbol].Len); }
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
6
7zip/Compress/Huffman/StdAfx.h
Executable file
6
7zip/Compress/Huffman/StdAfx.h
Executable file
@@ -0,0 +1,6 @@
|
||||
// stdafx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#endif
|
||||
66
7zip/Compress/Implode/DllExports.cpp
Executable file
66
7zip/Compress/Implode/DllExports.cpp
Executable file
@@ -0,0 +1,66 @@
|
||||
// DLLExports.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#define INITGUID
|
||||
|
||||
#include "Common/ComTry.h"
|
||||
#include "ImplodeDecoder.h"
|
||||
|
||||
// {23170F69-40C1-278B-0401-060000000000}
|
||||
DEFINE_GUID(CLSID_CCompressImplodeDecoder,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x04, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
extern "C"
|
||||
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
*outObject = 0;
|
||||
if (*clsid != CLSID_CCompressImplodeDecoder)
|
||||
return CLASS_E_CLASSNOTAVAILABLE;
|
||||
if (*iid != IID_ICompressCoder)
|
||||
return E_NOINTERFACE;
|
||||
CMyComPtr<ICompressCoder> coder = (ICompressCoder *)new
|
||||
NCompress::NImplode::NDecoder::CCoder;
|
||||
*outObject = coder.Detach();
|
||||
COM_TRY_END
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDAPI GetNumberOfMethods(UINT32 *numMethods)
|
||||
{
|
||||
*numMethods = 1;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDAPI GetMethodProperty(UINT32 index, PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
if (index != 0)
|
||||
return E_INVALIDARG;
|
||||
::VariantClear((tagVARIANT *)value);
|
||||
switch(propID)
|
||||
{
|
||||
case NMethodPropID::kID:
|
||||
{
|
||||
const char id[] = { 0x04, 0x01, 0x06 };
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(id, sizeof(id))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
}
|
||||
case NMethodPropID::kName:
|
||||
if ((value->bstrVal = ::SysAllocString(L"Implode")) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
case NMethodPropID::kDecoder:
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(
|
||||
(const char *)&CLSID_CCompressImplodeDecoder, sizeof(GUID))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
9
7zip/Compress/Implode/Implode.def
Executable file
9
7zip/Compress/Implode/Implode.def
Executable file
@@ -0,0 +1,9 @@
|
||||
; Implode.def
|
||||
|
||||
LIBRARY Implode.dll
|
||||
|
||||
EXPORTS
|
||||
CreateObject PRIVATE
|
||||
GetNumberOfMethods PRIVATE
|
||||
GetMethodProperty PRIVATE
|
||||
|
||||
181
7zip/Compress/Implode/Implode.dsp
Executable file
181
7zip/Compress/Implode/Implode.dsp
Executable file
@@ -0,0 +1,181 @@
|
||||
# Microsoft Developer Studio Project File - Name="Implode" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=Implode - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "Implode.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "Implode.mak" CFG="Implode - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "Implode - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "Implode - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "Implode - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "IMPLODE_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "IMPLODE_EXPORTS" /Yu"StdAfx.h" /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "NDEBUG"
|
||||
# ADD RSC /l 0x419 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\Implode.dll" /opt:NOWIN98
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "Implode - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "IMPLODE_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "IMPLODE_EXPORTS" /Yu"StdAfx.h" /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "_DEBUG"
|
||||
# ADD RSC /l 0x419 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\Implode.dll" /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "Implode - Win32 Release"
|
||||
# Name "Implode - Win32 Debug"
|
||||
# Begin Group "Spec"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\DllExports.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Implode.def
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\resource.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\resource.rc
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.cpp
|
||||
# ADD CPP /Yc"StdAfx.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "7zip Common"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\InBuffer.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\InBuffer.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\LSBFDecoder.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\LSBFDecoder.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Common"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\NewHandler.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\NewHandler.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "LZ"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\LZOutWindow.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\LZOutWindow.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ImplodeDecoder.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ImplodeDecoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ImplodeHuffmanDecoder.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ImplodeHuffmanDecoder.h
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
29
7zip/Compress/Implode/Implode.dsw
Executable file
29
7zip/Compress/Implode/Implode.dsw
Executable file
@@ -0,0 +1,29 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "Implode"=.\Implode.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
210
7zip/Compress/Implode/ImplodeDecoder.cpp
Executable file
210
7zip/Compress/Implode/ImplodeDecoder.cpp
Executable file
@@ -0,0 +1,210 @@
|
||||
// Implode/Decoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ImplodeDecoder.h"
|
||||
#include "Common/Defs.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NImplode {
|
||||
namespace NDecoder {
|
||||
|
||||
static const int kNumDistanceLowDirectBitsForBigDict = 7;
|
||||
static const int kNumDistanceLowDirectBitsForSmallDict = 6;
|
||||
|
||||
static const int kNumBitsInByte = 8;
|
||||
|
||||
static const int kLevelStructuresNumberFieldSize = kNumBitsInByte;
|
||||
static const int kLevelStructuresNumberAdditionalValue = 1;
|
||||
|
||||
static const int kNumLevelStructureLevelBits = 4;
|
||||
static const int kLevelStructureLevelAdditionalValue = 1;
|
||||
|
||||
static const int kNumLevelStructureRepNumberBits = 4;
|
||||
static const int kLevelStructureRepNumberAdditionalValue = 1;
|
||||
|
||||
|
||||
static const int kLiteralTableSize = (1 << kNumBitsInByte);
|
||||
static const int kDistanceTableSize = 64;
|
||||
static const int kLengthTableSize = 64;
|
||||
|
||||
static const UINT32 kHistorySize =
|
||||
(1 << MyMax(kNumDistanceLowDirectBitsForBigDict,
|
||||
kNumDistanceLowDirectBitsForSmallDict)) *
|
||||
kDistanceTableSize; // = 8 KB;
|
||||
|
||||
static const int kNumAdditionalLengthBits = 8;
|
||||
|
||||
static const UINT32 kMatchMinLenWhenLiteralsOn = 3;
|
||||
static const UINT32 kMatchMinLenWhenLiteralsOff = 2;
|
||||
|
||||
static const UINT32 kMatchMinLenMax = MyMax(kMatchMinLenWhenLiteralsOn,
|
||||
kMatchMinLenWhenLiteralsOff); // 3
|
||||
|
||||
static const UINT32 kMatchMaxLenMax = kMatchMinLenMax +
|
||||
(kLengthTableSize - 1) + (1 << kNumAdditionalLengthBits) - 1; // or 2
|
||||
|
||||
enum
|
||||
{
|
||||
kMatchId = 0,
|
||||
kLiteralId = 1
|
||||
};
|
||||
|
||||
|
||||
CCoder::CCoder():
|
||||
m_LiteralDecoder(kLiteralTableSize),
|
||||
m_LengthDecoder(kLengthTableSize),
|
||||
m_DistanceDecoder(kDistanceTableSize)
|
||||
{
|
||||
m_OutWindowStream.Create(kHistorySize/*, kMatchMaxLenMax*/);
|
||||
}
|
||||
|
||||
/*
|
||||
STDMETHODIMP CCoder::ReleaseStreams()
|
||||
{
|
||||
m_OutWindowStream.ReleaseStream();
|
||||
m_InBitStream.ReleaseStream();
|
||||
return S_OK;
|
||||
}
|
||||
*/
|
||||
|
||||
void CCoder::ReadLevelItems(NImplode::NHuffman::CDecoder &decoder,
|
||||
BYTE *levels, int numLevelItems)
|
||||
{
|
||||
int numCodedStructures = m_InBitStream.ReadBits(kNumBitsInByte) +
|
||||
kLevelStructuresNumberAdditionalValue;
|
||||
int currentIndex = 0;
|
||||
for(int i = 0; i < numCodedStructures; i++)
|
||||
{
|
||||
int level = m_InBitStream.ReadBits(kNumLevelStructureLevelBits) +
|
||||
kLevelStructureLevelAdditionalValue;
|
||||
int rep = m_InBitStream.ReadBits(kNumLevelStructureRepNumberBits) +
|
||||
kLevelStructureRepNumberAdditionalValue;
|
||||
if (currentIndex + rep > numLevelItems)
|
||||
throw CException(CException::kData);
|
||||
for(int j = 0; j < rep; j++)
|
||||
levels[currentIndex++] = level;
|
||||
}
|
||||
if (currentIndex != numLevelItems)
|
||||
throw CException(CException::kData);
|
||||
try
|
||||
{
|
||||
decoder.SetCodeLengths(levels);
|
||||
}
|
||||
catch(const NImplode::NHuffman::CDecoderException &)
|
||||
{
|
||||
throw CException(CException::kData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CCoder::ReadTables(void)
|
||||
{
|
||||
if (m_LiteralsOn)
|
||||
{
|
||||
BYTE literalLevels[kLiteralTableSize];
|
||||
ReadLevelItems(m_LiteralDecoder, literalLevels, kLiteralTableSize);
|
||||
}
|
||||
|
||||
BYTE lengthLevels[kLengthTableSize];
|
||||
ReadLevelItems(m_LengthDecoder, lengthLevels, kLengthTableSize);
|
||||
|
||||
BYTE distanceLevels[kDistanceTableSize];
|
||||
ReadLevelItems(m_DistanceDecoder, distanceLevels, kDistanceTableSize);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
class CCoderReleaser
|
||||
{
|
||||
CCoder *m_Coder;
|
||||
public:
|
||||
CCoderReleaser(CCoder *coder): m_Coder(coder) {}
|
||||
~CCoderReleaser() { m_Coder->ReleaseStreams(); }
|
||||
};
|
||||
*/
|
||||
|
||||
STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
if (outSize == NULL)
|
||||
return E_INVALIDARG;
|
||||
UINT64 pos = 0, unPackSize = *outSize;
|
||||
|
||||
m_OutWindowStream.Init(outStream, false);
|
||||
m_InBitStream.Init(inStream);
|
||||
// CCoderReleaser coderReleaser(this);
|
||||
|
||||
ReadTables();
|
||||
|
||||
while(pos < unPackSize)
|
||||
{
|
||||
if (progress != NULL && pos % (1 << 16) == 0)
|
||||
{
|
||||
UINT64 packSize = m_InBitStream.GetProcessedSize();
|
||||
RINOK(progress->SetRatioInfo(&packSize, &pos));
|
||||
}
|
||||
if(m_InBitStream.ReadBits(1) == kMatchId) // match
|
||||
{
|
||||
UINT32 lowDistBits = m_InBitStream.ReadBits(m_NumDistanceLowDirectBits);
|
||||
UINT32 distance = (m_DistanceDecoder.DecodeSymbol(&m_InBitStream) <<
|
||||
m_NumDistanceLowDirectBits) + lowDistBits;
|
||||
|
||||
UINT32 lengthSymbol = m_LengthDecoder.DecodeSymbol(&m_InBitStream);
|
||||
UINT32 length = lengthSymbol + m_MinMatchLength;
|
||||
if (lengthSymbol == kLengthTableSize - 1) // special symbol = 63
|
||||
length += m_InBitStream.ReadBits(kNumAdditionalLengthBits);
|
||||
while(distance >= pos && length > 0)
|
||||
{
|
||||
m_OutWindowStream.PutOneByte(0);
|
||||
pos++;
|
||||
length--;
|
||||
}
|
||||
if (length > 0)
|
||||
m_OutWindowStream.CopyBackBlock(distance, length);
|
||||
pos += length;
|
||||
}
|
||||
else
|
||||
{
|
||||
BYTE b = BYTE(m_LiteralsOn ? m_LiteralDecoder.DecodeSymbol(&m_InBitStream) :
|
||||
m_InBitStream.ReadBits(kNumBitsInByte));
|
||||
m_OutWindowStream.PutOneByte(b);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
if (pos > unPackSize)
|
||||
throw CException(CException::kData);
|
||||
return m_OutWindowStream.Flush();
|
||||
}
|
||||
|
||||
STDMETHODIMP CCoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
try { return CodeReal(inStream, outStream, inSize, outSize, progress); }
|
||||
catch(const CLZOutWindowException &e) { return e.ErrorCode; }
|
||||
catch(...) { return S_FALSE; }
|
||||
}
|
||||
|
||||
STDMETHODIMP CCoder::SetDecoderProperties(ISequentialInStream *inStream)
|
||||
{
|
||||
BYTE flag;
|
||||
UINT32 processedSize;
|
||||
RINOK(inStream->Read(&flag, sizeof(flag), &processedSize));
|
||||
if (processedSize != sizeof(flag))
|
||||
return E_INVALIDARG;
|
||||
m_BigDictionaryOn = ((flag & 2) != 0);
|
||||
m_NumDistanceLowDirectBits = m_BigDictionaryOn ?
|
||||
kNumDistanceLowDirectBitsForBigDict:
|
||||
kNumDistanceLowDirectBitsForSmallDict;
|
||||
m_LiteralsOn = ((flag & 4) != 0);
|
||||
m_MinMatchLength = m_LiteralsOn ?
|
||||
kMatchMinLenWhenLiteralsOn :
|
||||
kMatchMinLenWhenLiteralsOff;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
}}}
|
||||
77
7zip/Compress/Implode/ImplodeDecoder.h
Executable file
77
7zip/Compress/Implode/ImplodeDecoder.h
Executable file
@@ -0,0 +1,77 @@
|
||||
// ImplodeDecoder.h
|
||||
|
||||
#ifndef __IMPLODE_DECODER_H
|
||||
#define __IMPLODE_DECODER_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Common/MyCom.h"
|
||||
|
||||
#include "../../ICoder.h"
|
||||
#include "../LZ/LZOutWindow.h"
|
||||
|
||||
#include "ImplodeHuffmanDecoder.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NImplode {
|
||||
namespace NDecoder {
|
||||
|
||||
class CException
|
||||
{
|
||||
public:
|
||||
enum ECauseType
|
||||
{
|
||||
kData
|
||||
} m_Cause;
|
||||
CException(ECauseType cause): m_Cause(cause) {}
|
||||
};
|
||||
|
||||
class CCoder :
|
||||
public ICompressCoder,
|
||||
public ICompressSetDecoderProperties,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CLZOutWindow m_OutWindowStream;
|
||||
NStream::NLSBF::CDecoder<CInBuffer> m_InBitStream;
|
||||
|
||||
NImplode::NHuffman::CDecoder m_LiteralDecoder;
|
||||
NImplode::NHuffman::CDecoder m_LengthDecoder;
|
||||
NImplode::NHuffman::CDecoder m_DistanceDecoder;
|
||||
|
||||
|
||||
bool m_BigDictionaryOn;
|
||||
bool m_LiteralsOn;
|
||||
|
||||
int m_NumDistanceLowDirectBits;
|
||||
UINT32 m_MinMatchLength;
|
||||
|
||||
void ReadLevelItems(NImplode::NHuffman::CDecoder &table,
|
||||
BYTE *levels, int numLevelItems);
|
||||
void ReadTables();
|
||||
void DeCodeLevelTable(BYTE *newLevels, int numLevels);
|
||||
public:
|
||||
CCoder();
|
||||
|
||||
MY_UNKNOWN_IMP1(ICompressSetDecoderProperties)
|
||||
|
||||
// STDMETHOD(ReleaseStreams)();
|
||||
// STDMETHOD(Code)(UINT32 aSize, UINT32 &aProcessedSize);
|
||||
HRESULT (Flush)() { return m_OutWindowStream.Flush(); }
|
||||
|
||||
|
||||
STDMETHOD(CodeReal)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
// ICompressSetDecoderProperties
|
||||
// STDMETHOD(SetCoderProperties)(PROPVARIANT *aProperties, UINT32 aNumProperties);
|
||||
STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream);
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
88
7zip/Compress/Implode/ImplodeHuffmanDecoder.cpp
Executable file
88
7zip/Compress/Implode/ImplodeHuffmanDecoder.cpp
Executable file
@@ -0,0 +1,88 @@
|
||||
// ImplodeHuffmanDecoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ImplodeHuffmanDecoder.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NImplode {
|
||||
namespace NHuffman {
|
||||
|
||||
CDecoder::CDecoder(UINT32 numSymbols):
|
||||
m_NumSymbols(numSymbols)
|
||||
{
|
||||
m_Symbols = new UINT32[m_NumSymbols];
|
||||
}
|
||||
|
||||
CDecoder::~CDecoder()
|
||||
{
|
||||
delete []m_Symbols;
|
||||
}
|
||||
|
||||
void CDecoder::SetCodeLengths(const BYTE *codeLengths)
|
||||
{
|
||||
// int lenCounts[kNumBitsInLongestCode + 1], tmpPositions[kNumBitsInLongestCode + 1];
|
||||
int lenCounts[kNumBitsInLongestCode + 2], tmpPositions[kNumBitsInLongestCode + 1];
|
||||
int i;
|
||||
for(i = 0; i <= kNumBitsInLongestCode; i++)
|
||||
lenCounts[i] = 0;
|
||||
UINT32 symbolIndex;
|
||||
for (symbolIndex = 0; symbolIndex < m_NumSymbols; symbolIndex++)
|
||||
lenCounts[codeLengths[symbolIndex]]++;
|
||||
// lenCounts[0] = 0;
|
||||
|
||||
// tmpPositions[0] = m_Positions[0] = m_Limitits[0] = 0;
|
||||
m_Limitits[kNumBitsInLongestCode + 1] = 0;
|
||||
m_Positions[kNumBitsInLongestCode + 1] = 0;
|
||||
lenCounts[kNumBitsInLongestCode + 1] = 0;
|
||||
|
||||
|
||||
UINT32 startPos = 0;
|
||||
static const UINT32 kMaxValue = (1 << kNumBitsInLongestCode);
|
||||
|
||||
for (i = kNumBitsInLongestCode; i > 0; i--)
|
||||
{
|
||||
startPos += lenCounts[i] << (kNumBitsInLongestCode - i);
|
||||
if (startPos > kMaxValue)
|
||||
throw CDecoderException();
|
||||
m_Limitits[i] = startPos;
|
||||
m_Positions[i] = m_Positions[i + 1] + lenCounts[i + 1];
|
||||
tmpPositions[i] = m_Positions[i] + lenCounts[i];
|
||||
|
||||
}
|
||||
|
||||
// if _ZIP_MODE do not throw exception for trees containing only one node
|
||||
// #ifndef _ZIP_MODE
|
||||
if (startPos != kMaxValue)
|
||||
throw CDecoderException();
|
||||
// #endif
|
||||
|
||||
for (symbolIndex = 0; symbolIndex < m_NumSymbols; symbolIndex++)
|
||||
if (codeLengths[symbolIndex] != 0)
|
||||
m_Symbols[--tmpPositions[codeLengths[symbolIndex]]] = symbolIndex;
|
||||
}
|
||||
|
||||
UINT32 CDecoder::DecodeSymbol(CInBit *inStream)
|
||||
{
|
||||
UINT32 numBits;
|
||||
UINT32 value = inStream->GetValue(kNumBitsInLongestCode);
|
||||
int i;
|
||||
for(i = kNumBitsInLongestCode; i > 0; i--)
|
||||
{
|
||||
if (value < m_Limitits[i])
|
||||
{
|
||||
numBits = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == 0)
|
||||
throw CDecoderException();
|
||||
inStream->MovePos(numBits);
|
||||
UINT32 index = m_Positions[numBits] +
|
||||
((value - m_Limitits[numBits + 1]) >> (kNumBitsInLongestCode - numBits));
|
||||
if (index >= m_NumSymbols)
|
||||
throw CDecoderException(); // test it
|
||||
return m_Symbols[index];
|
||||
}
|
||||
|
||||
}}}
|
||||
36
7zip/Compress/Implode/ImplodeHuffmanDecoder.h
Executable file
36
7zip/Compress/Implode/ImplodeHuffmanDecoder.h
Executable file
@@ -0,0 +1,36 @@
|
||||
// ImplodeHuffmanDecoder.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __IMPLODE_HUFFMAN_DECODER_H
|
||||
#define __IMPLODE_HUFFMAN_DECODER_H
|
||||
|
||||
#include "../../Common/LSBFDecoder.h"
|
||||
#include "../../Common/InBuffer.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NImplode {
|
||||
namespace NHuffman {
|
||||
|
||||
const int kNumBitsInLongestCode = 16;
|
||||
class CDecoderException{};
|
||||
|
||||
typedef NStream::NLSBF::CDecoder<CInBuffer> CInBit;
|
||||
|
||||
class CDecoder
|
||||
{
|
||||
UINT32 m_Limitits[kNumBitsInLongestCode + 2]; // m_Limitits[i] = value limit for symbols with length = i
|
||||
UINT32 m_Positions[kNumBitsInLongestCode + 2]; // m_Positions[i] = index in m_Symbols[] of first symbol with length = i
|
||||
UINT32 m_NumSymbols; // number of symbols in m_Symbols
|
||||
UINT32 *m_Symbols; // symbols: at first with len=1 then 2, ... 15.
|
||||
public:
|
||||
CDecoder(UINT32 numSymbols);
|
||||
~CDecoder();
|
||||
|
||||
void SetCodeLengths(const BYTE *codeLengths);
|
||||
UINT32 DecodeSymbol(CInBit *inStream);
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
3
7zip/Compress/Implode/StdAfx.cpp
Executable file
3
7zip/Compress/Implode/StdAfx.cpp
Executable file
@@ -0,0 +1,3 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "stdafx.h"
|
||||
8
7zip/Compress/Implode/StdAfx.h
Executable file
8
7zip/Compress/Implode/StdAfx.h
Executable file
@@ -0,0 +1,8 @@
|
||||
// stdafx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#endif
|
||||
15
7zip/Compress/Implode/resource.h
Executable file
15
7zip/Compress/Implode/resource.h
Executable file
@@ -0,0 +1,15 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by resource.rc
|
||||
//
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 101
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
121
7zip/Compress/Implode/resource.rc
Executable file
121
7zip/Compress/Implode/resource.rc
Executable file
@@ -0,0 +1,121 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Russian resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
|
||||
#pragma code_page(1251)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // Russian resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifndef _MAC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 3,9,2,0
|
||||
PRODUCTVERSION 3,9,2,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "\0"
|
||||
VALUE "CompanyName", "Igor Pavlov\0"
|
||||
VALUE "FileDescription", "Implode Decoder\0"
|
||||
VALUE "FileVersion", "3, 9, 2, 0\0"
|
||||
VALUE "InternalName", "Implode\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 1999-2003 Igor Pavlov\0"
|
||||
VALUE "LegalTrademarks", "\0"
|
||||
VALUE "OriginalFilename", "Implode.dll\0"
|
||||
VALUE "PrivateBuild", "\0"
|
||||
VALUE "ProductName", "7-Zip\0"
|
||||
VALUE "ProductVersion", "3, 9, 2, 0\0"
|
||||
VALUE "SpecialBuild", "\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // !_MAC
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
116
7zip/Compress/LZ/BinTree/BinTree.h
Executable file
116
7zip/Compress/LZ/BinTree/BinTree.h
Executable file
@@ -0,0 +1,116 @@
|
||||
// BinTree.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
// #ifndef __BINTREE_H
|
||||
// #define __BINTREE_H
|
||||
|
||||
#include "../LZInWindow.h"
|
||||
// #include "Common/Types.h"
|
||||
// #include "Windows/Defs.h"
|
||||
|
||||
namespace BT_NAMESPACE {
|
||||
|
||||
// #define __USE_3_BYTES
|
||||
|
||||
#ifdef __USE_3_BYTES
|
||||
|
||||
#pragma pack(push, PragmaBinTree, 1)
|
||||
|
||||
struct CIndex
|
||||
{
|
||||
BYTE Data[3];
|
||||
CIndex(){}
|
||||
CIndex(UINT32 value)
|
||||
{
|
||||
Data[0] = value & 0xFF;
|
||||
Data[1] = (value >> 8) & 0xFF;
|
||||
Data[2] = (value >> 16) & 0xFF;
|
||||
}
|
||||
operator UINT32() const { return (*((const UINT32 *)Data)) & 0xFFFFFF; }
|
||||
};
|
||||
const UINT32 kMaxValForNormalize = CIndex(-1);
|
||||
|
||||
#pragma pack(pop, PragmaBinTree)
|
||||
|
||||
#else
|
||||
|
||||
typedef UINT32 CIndex;
|
||||
const UINT32 kMaxValForNormalize = (UINT32(1) << 31) - 1;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// #define HASH_ARRAY_2
|
||||
|
||||
// #ifdef HASH_ARRAY_2
|
||||
|
||||
// #define HASH_ARRAY_3
|
||||
|
||||
// #else
|
||||
|
||||
// #define HASH_ZIP
|
||||
|
||||
// #endif
|
||||
|
||||
#pragma pack(push, PragmaBinTreePair, 1)
|
||||
// #pragma pack(push, 1)
|
||||
|
||||
struct CPair
|
||||
{
|
||||
CIndex Left;
|
||||
CIndex Right;
|
||||
};
|
||||
|
||||
// #pragma pack(pop)
|
||||
#pragma pack(pop, PragmaBinTreePair)
|
||||
|
||||
class CInTree: public CLZInWindow
|
||||
{
|
||||
UINT32 _cyclicBufferPos;
|
||||
UINT32 _cyclicBufferSize;
|
||||
UINT32 _historySize;
|
||||
UINT32 _matchMaxLen;
|
||||
|
||||
CIndex *_hash;
|
||||
|
||||
#ifdef HASH_ARRAY_2
|
||||
CIndex *_hash2;
|
||||
#ifdef HASH_ARRAY_3
|
||||
CIndex *_hash3;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
CPair *_son;
|
||||
|
||||
UINT32 _cutValue;
|
||||
|
||||
void NormalizeLinks(CIndex *array, UINT32 numItems, UINT32 subValue);
|
||||
void Normalize();
|
||||
void FreeMemory();
|
||||
|
||||
public:
|
||||
CInTree();
|
||||
~CInTree();
|
||||
HRESULT Create(UINT32 sizeHistory, UINT32 keepAddBufferBefore, UINT32 matchMaxLen,
|
||||
UINT32 keepAddBufferAfter, UINT32 sizeReserv = (1<<17));
|
||||
HRESULT Init(ISequentialInStream *stream);
|
||||
void SetCutValue(UINT32 cutValue) { _cutValue = cutValue; }
|
||||
UINT32 GetLongestMatch(UINT32 *distances);
|
||||
void DummyLongestMatch();
|
||||
HRESULT MovePos()
|
||||
{
|
||||
_cyclicBufferPos++;
|
||||
if (_cyclicBufferPos >= _cyclicBufferSize)
|
||||
_cyclicBufferPos = 0;
|
||||
RINOK(CLZInWindow::MovePos());
|
||||
if (_pos == kMaxValForNormalize)
|
||||
Normalize();
|
||||
return S_OK;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// #endif
|
||||
18
7zip/Compress/LZ/BinTree/BinTree2.h
Executable file
18
7zip/Compress/LZ/BinTree/BinTree2.h
Executable file
@@ -0,0 +1,18 @@
|
||||
// BinTree2.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __BINTREE2__H
|
||||
#define __BINTREE2__H
|
||||
|
||||
#undef BT_CLSID
|
||||
#define BT_CLSID CLSID_CMatchFinderBT2
|
||||
|
||||
#undef BT_NAMESPACE
|
||||
#define BT_NAMESPACE NBT2
|
||||
|
||||
#include "BinTreeMF.h"
|
||||
#include "BinTreeMFMain.h"
|
||||
|
||||
#endif
|
||||
|
||||
22
7zip/Compress/LZ/BinTree/BinTree3.h
Executable file
22
7zip/Compress/LZ/BinTree/BinTree3.h
Executable file
@@ -0,0 +1,22 @@
|
||||
// BinTree3.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __BINTREE3__H
|
||||
#define __BINTREE3__H
|
||||
|
||||
#undef BT_CLSID
|
||||
#define BT_CLSID CLSID_CMatchFinderBT3
|
||||
|
||||
#undef BT_NAMESPACE
|
||||
#define BT_NAMESPACE NBT3
|
||||
|
||||
#define HASH_ARRAY_2
|
||||
|
||||
#include "BinTreeMF.h"
|
||||
#include "BinTreeMFMain.h"
|
||||
|
||||
#undef HASH_ARRAY_2
|
||||
|
||||
#endif
|
||||
|
||||
19
7zip/Compress/LZ/BinTree/BinTree3Z.h
Executable file
19
7zip/Compress/LZ/BinTree/BinTree3Z.h
Executable file
@@ -0,0 +1,19 @@
|
||||
// BinTree3Z.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __BINTREE3Z__H
|
||||
#define __BINTREE3Z__H
|
||||
|
||||
#undef BT_NAMESPACE
|
||||
#define BT_NAMESPACE NBT3Z
|
||||
|
||||
#define HASH_ZIP
|
||||
|
||||
#include "BinTree.h"
|
||||
// #include "BinTreeMain.h"
|
||||
|
||||
#undef HASH_ZIP
|
||||
|
||||
#endif
|
||||
|
||||
18
7zip/Compress/LZ/BinTree/BinTree3ZMain.h
Executable file
18
7zip/Compress/LZ/BinTree/BinTree3ZMain.h
Executable file
@@ -0,0 +1,18 @@
|
||||
// BinTree3ZMain.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __BINTREE3ZMAIN__H
|
||||
#define __BINTREE3ZMAIN__H
|
||||
|
||||
#undef BT_NAMESPACE
|
||||
#define BT_NAMESPACE NBT3Z
|
||||
|
||||
#define HASH_ZIP
|
||||
|
||||
#include "BinTreeMain.h"
|
||||
|
||||
#undef HASH_ZIP
|
||||
|
||||
#endif
|
||||
|
||||
24
7zip/Compress/LZ/BinTree/BinTree4.h
Executable file
24
7zip/Compress/LZ/BinTree/BinTree4.h
Executable file
@@ -0,0 +1,24 @@
|
||||
// BinTree4.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __BINTREE4__H
|
||||
#define __BINTREE4__H
|
||||
|
||||
#undef BT_CLSID
|
||||
#define BT_CLSID CLSID_CMatchFinderBT4
|
||||
|
||||
#undef BT_NAMESPACE
|
||||
#define BT_NAMESPACE NBT4
|
||||
|
||||
#define HASH_ARRAY_2
|
||||
#define HASH_ARRAY_3
|
||||
|
||||
#include "BinTreeMF.h"
|
||||
#include "BinTreeMFMain.h"
|
||||
|
||||
#undef HASH_ARRAY_2
|
||||
#undef HASH_ARRAY_3
|
||||
|
||||
#endif
|
||||
|
||||
26
7zip/Compress/LZ/BinTree/BinTree4b.h
Executable file
26
7zip/Compress/LZ/BinTree/BinTree4b.h
Executable file
@@ -0,0 +1,26 @@
|
||||
// BinTree4b.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __BINTREE4B__H
|
||||
#define __BINTREE4B__H
|
||||
|
||||
#undef BT_CLSID
|
||||
#define BT_CLSID CLSID_CMatchFinderBT4b
|
||||
|
||||
#undef BT_NAMESPACE
|
||||
#define BT_NAMESPACE NBT4B
|
||||
|
||||
#define HASH_ARRAY_2
|
||||
#define HASH_ARRAY_3
|
||||
#define HASH_BIG
|
||||
|
||||
#include "BinTreeMF.h"
|
||||
#include "BinTreeMFMain.h"
|
||||
|
||||
#undef HASH_ARRAY_2
|
||||
#undef HASH_ARRAY_3
|
||||
#undef HASH_BIG
|
||||
|
||||
#endif
|
||||
|
||||
110
7zip/Compress/LZ/BinTree/BinTreeMF.h
Executable file
110
7zip/Compress/LZ/BinTree/BinTreeMF.h
Executable file
@@ -0,0 +1,110 @@
|
||||
// BinTreeMF.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
// #ifndef __BINTREEMF_H
|
||||
// #define __BINTREEMF_H
|
||||
|
||||
#include "../../../ICoder.h"
|
||||
#include "BinTree.h"
|
||||
|
||||
namespace BT_NAMESPACE {
|
||||
|
||||
#undef kIDByte
|
||||
#undef kIDString
|
||||
|
||||
#ifdef HASH_ARRAY_2
|
||||
#ifdef HASH_ARRAY_3
|
||||
#ifdef HASH_BIG
|
||||
#define kIDByte 0x4
|
||||
#define kIDString TEXT("4b")
|
||||
#else
|
||||
#define kIDByte 0x3
|
||||
#define kIDString TEXT("4")
|
||||
#endif
|
||||
#else
|
||||
#define kIDByte 0x2
|
||||
#define kIDString TEXT("3")
|
||||
#endif
|
||||
#else
|
||||
#ifdef HASH_ZIP
|
||||
#define kIDByte 0x0
|
||||
#define kIDString TEXT("3Z")
|
||||
#else
|
||||
#define kIDByte 0x1
|
||||
#define kIDString TEXT("2")
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#undef kIDUse3BytesByte
|
||||
#undef kIDUse3BytesString
|
||||
|
||||
#ifdef __USE_3_BYTES
|
||||
#define kIDUse3BytesByte 0x80
|
||||
#define kIDUse3BytesString TEXT("T")
|
||||
#else
|
||||
#define kIDUse3BytesByte 0x00
|
||||
#define kIDUse3BytesString TEXT("")
|
||||
#endif
|
||||
|
||||
// #undef kIDStringFull
|
||||
|
||||
// #define kIDStringFull TEXT("Compress.MatchFinderBT") kIDString kIDUse3BytesString
|
||||
|
||||
// {23170F69-40C1-278C-02XX-0000000000}
|
||||
DEFINE_GUID(BT_CLSID,
|
||||
0x23170F69, 0x40C1, 0x278C, 0x02, kIDByte | kIDUse3BytesByte,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
class CInTree2: public CInTree
|
||||
{
|
||||
CMyComPtr<IMatchFinderCallback> _callback;
|
||||
virtual void BeforeMoveBlock();
|
||||
virtual void AfterMoveBlock();
|
||||
public:
|
||||
void SetCallback(IMatchFinderCallback *callback)
|
||||
{
|
||||
_callback = callback;
|
||||
}
|
||||
};
|
||||
|
||||
class CMatchFinderBinTree:
|
||||
public IMatchFinder,
|
||||
public IMatchFinderSetCallback,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
MY_UNKNOWN_IMP1(IMatchFinderSetCallback)
|
||||
|
||||
STDMETHOD(Init)(ISequentialInStream *stream);
|
||||
STDMETHOD_(void, ReleaseStream)();
|
||||
STDMETHOD(MovePos)();
|
||||
STDMETHOD_(BYTE, GetIndexByte)(UINT32 index);
|
||||
STDMETHOD_(UINT32, GetMatchLen)(UINT32 index, UINT32 back, UINT32 limit);
|
||||
STDMETHOD_(UINT32, GetNumAvailableBytes)();
|
||||
STDMETHOD_(const BYTE *, GetPointerToCurrentPos)();
|
||||
STDMETHOD(Create)(UINT32 sizeHistory,
|
||||
UINT32 keepAddBufferBefore, UINT32 matchMaxLen,
|
||||
UINT32 keepAddBufferAfter);
|
||||
STDMETHOD_(UINT32, GetLongestMatch)(UINT32 *distances);
|
||||
STDMETHOD_(void, DummyLongestMatch)();
|
||||
|
||||
// IMatchFinderSetCallback
|
||||
STDMETHOD(SetCallback)(IMatchFinderCallback *callback);
|
||||
|
||||
private:
|
||||
// UINT32 m_WindowReservSize;
|
||||
CInTree2 _matchFinder;
|
||||
public:
|
||||
// CMatchFinderBinTree(): m_WindowReservSize((1 << 19) + 256) {};
|
||||
void SetCutValue(UINT32 cutValue)
|
||||
{ _matchFinder.SetCutValue(cutValue); }
|
||||
/*
|
||||
void SetWindowReservSize(UINT32 reservWindowSize)
|
||||
{ m_WindowReservSize = reservWindowSize; }
|
||||
*/
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// #endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user