Fixed encoding in decoding.

This commit is contained in:
n-a-c-h
2004-11-21 01:54:40 +00:00
parent 95b03fc8da
commit e8884da95e
3 changed files with 24 additions and 186 deletions

View File

@@ -11,6 +11,29 @@ const UINT32 kBitModelTotal = (1 << kNumBitModelTotalBits);
const int kNumMoveReducingBits = 2; const int kNumMoveReducingBits = 2;
/////////////////////////////
// CBitModel
template <int aNumMoveBits>
class CBitModel
{
public:
UINT32 m_Probability;
void UpdateModel(UINT32 aSymbol)
{
/*
m_Probability -= (m_Probability + ((aSymbol - 1) & ((1 << aNumMoveBits) - 1))) >> aNumMoveBits;
m_Probability += (1 - aSymbol) << (kNumBitModelTotalBits - aNumMoveBits);
*/
if (aSymbol == 0)
m_Probability += (kBitModelTotal - m_Probability) >> aNumMoveBits;
else
m_Probability -= (m_Probability) >> aNumMoveBits;
}
public:
void Init() { m_Probability = kBitModelTotal / 2; }
};
template <int aNumMoveBits> template <int aNumMoveBits>
class CBitDecoder: public CBitModel<aNumMoveBits> class CBitDecoder: public CBitModel<aNumMoveBits>
{ {

View File

@@ -22,11 +22,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "aribitcd.h" #include "aribitcd.h"
typedef NCompression::NArithmetic::CRangeEncoder CMyRangeEncoder;
typedef NCompression::NArithmetic::CRangeDecoder CMyRangeDecoder;
template <int aNumMoveBits> class CMyBitEncoder: typedef NCompression::NArithmetic::CRangeDecoder CMyRangeDecoder;
public NCompression::NArithmetic::CBitEncoder<aNumMoveBits> {};
template <int aNumMoveBits> class CMyBitDecoder: template <int aNumMoveBits> class CMyBitDecoder:
public NCompression::NArithmetic::CBitDecoder<aNumMoveBits> {}; public NCompression::NArithmetic::CBitDecoder<aNumMoveBits> {};

View File

@@ -23,44 +23,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "aribitcd.h" #include "aribitcd.h"
#include "rcdefs.h" #include "rcdefs.h"
//////////////////////////
// CBitTreeEncoder
template <int aNumMoveBits, UINT32 m_NumBitLevels>
class CBitTreeEncoder
{
CMyBitEncoder<aNumMoveBits> m_Models[1 << m_NumBitLevels];
public:
void Init()
{
for(UINT32 i = 1; i < (1 << m_NumBitLevels); i++)
m_Models[i].Init();
}
void Encode(CMyRangeEncoder *aRangeEncoder, UINT32 aSymbol)
{
UINT32 aModelIndex = 1;
for (UINT32 aBitIndex = m_NumBitLevels; aBitIndex > 0 ;)
{
aBitIndex--;
UINT32 aBit = (aSymbol >> aBitIndex ) & 1;
m_Models[aModelIndex].Encode(aRangeEncoder, aBit);
aModelIndex = (aModelIndex << 1) | aBit;
}
};
UINT32 GetPrice(UINT32 aSymbol) const
{
UINT32 aPrice = 0;
UINT32 aModelIndex = 1;
for (UINT32 aBitIndex = m_NumBitLevels; aBitIndex > 0 ;)
{
aBitIndex--;
UINT32 aBit = (aSymbol >> aBitIndex ) & 1;
aPrice += m_Models[aModelIndex].GetPrice(aBit);
aModelIndex = (aModelIndex << 1) + aBit;
}
return aPrice;
}
};
////////////////////////// //////////////////////////
// CBitTreeDecoder // CBitTreeDecoder
@@ -89,66 +51,6 @@ public:
}; };
}; };
////////////////////////////////
// CReverseBitTreeEncoder
template <int aNumMoveBits>
class CReverseBitTreeEncoder2
{
CMyBitEncoder<aNumMoveBits> *m_Models;
UINT32 m_NumBitLevels;
public:
CReverseBitTreeEncoder2(): m_Models(0) { }
~CReverseBitTreeEncoder2() { delete []m_Models; }
bool Create(UINT32 aNumBitLevels)
{
m_NumBitLevels = aNumBitLevels;
m_Models = new CMyBitEncoder<aNumMoveBits>[1 << aNumBitLevels];
return (m_Models != 0);
}
void Init()
{
UINT32 aNumModels = 1 << m_NumBitLevels;
for(UINT32 i = 1; i < aNumModels; i++)
m_Models[i].Init();
}
void Encode(CMyRangeEncoder *aRangeEncoder, UINT32 aSymbol)
{
UINT32 aModelIndex = 1;
for (UINT32 i = 0; i < m_NumBitLevels; i++)
{
UINT32 aBit = aSymbol & 1;
m_Models[aModelIndex].Encode(aRangeEncoder, aBit);
aModelIndex = (aModelIndex << 1) | aBit;
aSymbol >>= 1;
}
}
UINT32 GetPrice(UINT32 aSymbol) const
{
UINT32 aPrice = 0;
UINT32 aModelIndex = 1;
for (UINT32 i = m_NumBitLevels; i > 0; i--)
{
UINT32 aBit = aSymbol & 1;
aSymbol >>= 1;
aPrice += m_Models[aModelIndex].GetPrice(aBit);
aModelIndex = (aModelIndex << 1) | aBit;
}
return aPrice;
}
};
/*
template <int aNumMoveBits, int aNumBitLevels>
class CReverseBitTreeEncoder: public CReverseBitTreeEncoder2<aNumMoveBits>
{
public:
CReverseBitTreeEncoder()
{ Create(aNumBitLevels); }
};
*/
//////////////////////////////// ////////////////////////////////
// CReverseBitTreeDecoder // CReverseBitTreeDecoder
@@ -220,90 +122,6 @@ public:
} }
}; };
/*
//////////////////////////
// CBitTreeEncoder2
template <int aNumMoveBits>
class CBitTreeEncoder2
{
NCompression::NArithmetic::CBitEncoder<aNumMoveBits> *m_Models;
UINT32 m_NumBitLevels;
public:
bool Create(UINT32 aNumBitLevels)
{
m_NumBitLevels = aNumBitLevels;
m_Models = new NCompression::NArithmetic::CBitEncoder<aNumMoveBits>[1 << aNumBitLevels];
return (m_Models != 0);
}
void Init()
{
UINT32 aNumModels = 1 << m_NumBitLevels;
for(UINT32 i = 1; i < aNumModels; i++)
m_Models[i].Init();
}
void Encode(CMyRangeEncoder *aRangeEncoder, UINT32 aSymbol)
{
UINT32 aModelIndex = 1;
for (UINT32 aBitIndex = m_NumBitLevels; aBitIndex > 0 ;)
{
aBitIndex--;
UINT32 aBit = (aSymbol >> aBitIndex ) & 1;
m_Models[aModelIndex].Encode(aRangeEncoder, aBit);
aModelIndex = (aModelIndex << 1) | aBit;
}
}
UINT32 GetPrice(UINT32 aSymbol) const
{
UINT32 aPrice = 0;
UINT32 aModelIndex = 1;
for (UINT32 aBitIndex = m_NumBitLevels; aBitIndex > 0 ;)
{
aBitIndex--;
UINT32 aBit = (aSymbol >> aBitIndex ) & 1;
aPrice += m_Models[aModelIndex].GetPrice(aBit);
aModelIndex = (aModelIndex << 1) + aBit;
}
return aPrice;
}
};
//////////////////////////
// CBitTreeDecoder2
template <int aNumMoveBits>
class CBitTreeDecoder2
{
NCompression::NArithmetic::CBitDecoder<aNumMoveBits> *m_Models;
UINT32 m_NumBitLevels;
public:
bool Create(UINT32 aNumBitLevels)
{
m_NumBitLevels = aNumBitLevels;
m_Models = new NCompression::NArithmetic::CBitDecoder<aNumMoveBits>[1 << aNumBitLevels];
return (m_Models != 0);
}
void Init()
{
UINT32 aNumModels = 1 << m_NumBitLevels;
for(UINT32 i = 1; i < aNumModels; i++)
m_Models[i].Init();
}
UINT32 Decode(CMyRangeDecoder *aRangeDecoder)
{
UINT32 aModelIndex = 1;
RC_INIT_VAR
for(UINT32 aBitIndex = m_NumBitLevels; aBitIndex > 0; aBitIndex--)
{
// aModelIndex = (aModelIndex << 1) + m_Models[aModelIndex].Decode(aRangeDecoder);
RC_GETBIT(aNumMoveBits, m_Models[aModelIndex].m_Probability, aModelIndex)
}
RC_FLUSH_VAR
return aModelIndex - (1 << m_NumBitLevels);
}
};
*/
#endif #endif