Compiler warning fixes and code style cleanup. No Functional changes.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37269 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -47,7 +47,8 @@ const uint32 CRC32_TABLE[256] = {0u,1996959894u,3993919788u,2567524794u,
|
|||||||
1567103746u,711928724u,3020668471u,3272380065u,1510334235u,755167117u};
|
1567103746u,711928724u,3020668471u,3272380065u,1510334235u,755167117u};
|
||||||
|
|
||||||
|
|
||||||
int CPrepare::Prepare(const unsigned char* pRawData, int nBytes,
|
int
|
||||||
|
CPrepare::Prepare(const unsigned char* pRawData, int nBytes,
|
||||||
const WAVEFORMATEX* pWaveFormatEx, int* pOutputX, int* pOutputY,
|
const WAVEFORMATEX* pWaveFormatEx, int* pOutputX, int* pOutputY,
|
||||||
unsigned int* pCRC, int* pSpecialCodes, int* pPeakLevel)
|
unsigned int* pCRC, int* pSpecialCodes, int* pPeakLevel)
|
||||||
{
|
{
|
||||||
@@ -255,7 +256,8 @@ int CPrepare::Prepare(const unsigned char* pRawData, int nBytes,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CPrepare::Unprepare(int X, int Y, const WAVEFORMATEX* pWaveFormatEx,
|
void
|
||||||
|
CPrepare::Unprepare(int X, int Y, const WAVEFORMATEX* pWaveFormatEx,
|
||||||
unsigned char* pOutput, unsigned int* pCRC)
|
unsigned char* pOutput, unsigned int* pCRC)
|
||||||
{
|
{
|
||||||
#define CALCULATE_CRC_BYTE *pCRC = (*pCRC >> 8) ^ CRC32_TABLE[(*pCRC & 0xFF) ^ *pOutput++];
|
#define CALCULATE_CRC_BYTE *pCRC = (*pCRC >> 8) ^ CRC32_TABLE[(*pCRC & 0xFF) ^ *pOutput++];
|
||||||
@@ -352,7 +354,8 @@ void CPrepare::Unprepare(int X, int Y, const WAVEFORMATEX* pWaveFormatEx,
|
|||||||
|
|
||||||
|
|
||||||
#ifdef BACKWARDS_COMPATIBILITY
|
#ifdef BACKWARDS_COMPATIBILITY
|
||||||
int CPrepare::UnprepareOld(int* pInputX, int* pInputY, int nBlocks,
|
int
|
||||||
|
CPrepare::UnprepareOld(int* pInputX, int* pInputY, int nBlocks,
|
||||||
const WAVEFORMATEX* pWaveFormatEx, unsigned char* pRawData,
|
const WAVEFORMATEX* pWaveFormatEx, unsigned char* pRawData,
|
||||||
unsigned int* pCRC, int* pSpecialCodes, int nFileVersion)
|
unsigned int* pCRC, int* pSpecialCodes, int nFileVersion)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef APE_PREPARE_H
|
#ifndef APE_PREPARE_H
|
||||||
#define APE_PREPARE_H
|
#define APE_PREPARE_H
|
||||||
|
|
||||||
|
#include "NoWindows.h"
|
||||||
|
|
||||||
#define SPECIAL_FRAME_MONO_SILENCE 1
|
#define SPECIAL_FRAME_MONO_SILENCE 1
|
||||||
#define SPECIAL_FRAME_LEFT_SILENCE 1
|
#define SPECIAL_FRAME_LEFT_SILENCE 1
|
||||||
#define SPECIAL_FRAME_RIGHT_SILENCE 2
|
#define SPECIAL_FRAME_RIGHT_SILENCE 2
|
||||||
|
|||||||
@@ -6,296 +6,343 @@
|
|||||||
#include "BitArray.h"
|
#include "BitArray.h"
|
||||||
|
|
||||||
|
|
||||||
const uint32 POWERS_OF_TWO_MINUS_ONE_REVERSED[33] = {4294967295,2147483647,1073741823,536870911,268435455,134217727,67108863,33554431,16777215,8388607,4194303,2097151,1048575,524287,262143,131071,65535,32767,16383,8191,4095,2047,1023,511,255,127,63,31,15,7,3,1,0};
|
const uint32 POWERS_OF_TWO_MINUS_ONE_REVERSED[33] = {4294967295u,2147483647u,
|
||||||
|
1073741823u,536870911u,268435455u,134217727u,67108863u,33554431u,16777215u,
|
||||||
|
8388607u,4194303u,2097151u,1048575u,524287u,262143u,131071u,65535u,32767u,
|
||||||
|
16383u,8191u,4095u,2047u,1023u,511u,255u,127u,63u,31u,15u,7u,3u,1u,0u};
|
||||||
|
|
||||||
const uint32 K_SUM_MIN_BOUNDARY[32] = {0,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,0,0,0,0};
|
const uint32 K_SUM_MIN_BOUNDARY[32] = {0u,32u,64u,128u,256u,512u,1024u,2048u,
|
||||||
|
4096u,8192u,16384u,32768u,65536u,131072u,262144u,524288u,1048576u,2097152u,
|
||||||
|
4194304u,8388608u,16777216u,33554432u,67108864u,134217728u,268435456u,
|
||||||
|
536870912u,1073741824u,2147483648u,0u,0u,0u,0u};
|
||||||
|
|
||||||
const uint32 RANGE_TOTAL_1[65] = {0,14824,28224,39348,47855,53994,58171,60926,62682,63786,64463,64878,65126,65276,65365,65419,65450,65469,65480,65487,65491,65493,65494,65495,65496,65497,65498,65499,65500,65501,65502,65503,65504,65505,65506,65507,65508,65509,65510,65511,65512,65513,65514,65515,65516,65517,65518,65519,65520,65521,65522,65523,65524,65525,65526,65527,65528,65529,65530,65531,65532,65533,65534,65535,65536};
|
const uint32 RANGE_TOTAL_1[65] = {0u,14824u,28224u,39348u,47855u,53994u,58171u,
|
||||||
const uint32 RANGE_WIDTH_1[64] = {14824,13400,11124,8507,6139,4177,2755,1756,1104,677,415,248,150,89,54,31,19,11,7,4,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
|
60926u,62682u,63786u,64463u,64878u,65126u,65276u,65365u,65419u,65450u,
|
||||||
|
65469u,65480u,65487u,65491u,65493u,65494u,65495u,65496u,65497u,65498u,
|
||||||
|
65499u,65500u,65501u,65502u,65503u,65504u,65505u,65506u,65507u,65508u,
|
||||||
|
65509u,65510u,65511u,65512u,65513u,65514u,65515u,65516u,65517u,65518u,
|
||||||
|
65519u,65520u,65521u,65522u,65523u,65524u,65525u,65526u,65527u,65528u,
|
||||||
|
65529u,65530u,65531u,65532u,65533u,65534u,65535u,65536u};
|
||||||
|
|
||||||
|
const uint32 RANGE_WIDTH_1[64] = {14824u,13400u,11124u,8507u,6139u,4177u,2755u,
|
||||||
|
1756u,1104u,677u,415u,248u,150u,89u,54u,31u,19u,11u,7u,4u,2u,1u,1u,1u,1u,1u,
|
||||||
|
1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,
|
||||||
|
1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u};
|
||||||
|
|
||||||
const uint32 RANGE_TOTAL_2[65] = {0,19578,36160,48417,56323,60899,63265,64435,64971,65232,65351,65416,65447,65466,65476,65482,65485,65488,65490,65491,65492,65493,65494,65495,65496,65497,65498,65499,65500,65501,65502,65503,65504,65505,65506,65507,65508,65509,65510,65511,65512,65513,65514,65515,65516,65517,65518,65519,65520,65521,65522,65523,65524,65525,65526,65527,65528,65529,65530,65531,65532,65533,65534,65535,65536};
|
const uint32 RANGE_TOTAL_2[65] = {0u,19578u,36160u,48417u,56323u,60899u,63265u,
|
||||||
const uint32 RANGE_WIDTH_2[64] = {19578,16582,12257,7906,4576,2366,1170,536,261,119,65,31,19,10,6,3,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,};
|
64435u,64971u,65232u,65351u,65416u,65447u,65466u,65476u,65482u,65485u,
|
||||||
|
65488u,65490u,65491u,65492u,65493u,65494u,65495u,65496u,65497u,65498u,
|
||||||
|
65499u,65500u,65501u,65502u,65503u,65504u,65505u,65506u,65507u,65508u,
|
||||||
|
65509u,65510u,65511u,65512u,65513u,65514u,65515u,65516u,65517u,65518u,
|
||||||
|
65519u,65520u,65521u,65522u,65523u,65524u,65525u,65526u,65527u,65528u,
|
||||||
|
65529u,65530u,65531u,65532u,65533u,65534u,65535u,65536u};
|
||||||
|
|
||||||
#define RANGE_OVERFLOW_TOTAL_WIDTH 65536
|
const uint32 RANGE_WIDTH_2[64] = {19578u,16582u,12257u,7906u,4576u,2366u,1170u,
|
||||||
#define RANGE_OVERFLOW_SHIFT 16
|
536u,261u,119u,65u,31u,19u,10u,6u,3u,3u,2u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,
|
||||||
|
1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,1u,
|
||||||
|
1u,1u,1u,1u,1u,1u,1u,1u,1u,1u};
|
||||||
|
|
||||||
#define CODE_BITS 32
|
|
||||||
#define TOP_VALUE ((unsigned int ) 1 << (CODE_BITS - 1))
|
|
||||||
#define SHIFT_BITS (CODE_BITS - 9)
|
|
||||||
#define EXTRA_BITS ((CODE_BITS - 2) % 8 + 1)
|
|
||||||
#define BOTTOM_VALUE (TOP_VALUE >> 8)
|
|
||||||
|
|
||||||
#define MODEL_ELEMENTS 64
|
#define RANGE_OVERFLOW_TOTAL_WIDTH 65536
|
||||||
|
#define RANGE_OVERFLOW_SHIFT 16
|
||||||
|
|
||||||
|
#define CODE_BITS 32
|
||||||
|
#define TOP_VALUE ((unsigned int ) 1 << (CODE_BITS - 1))
|
||||||
|
#define SHIFT_BITS (CODE_BITS - 9)
|
||||||
|
#define EXTRA_BITS ((CODE_BITS - 2) % 8 + 1)
|
||||||
|
#define BOTTOM_VALUE (TOP_VALUE >> 8)
|
||||||
|
|
||||||
|
#define MODEL_ELEMENTS 64
|
||||||
|
|
||||||
#if __GNUC__ != 2
|
#if __GNUC__ != 2
|
||||||
using std::min;
|
using std::min;
|
||||||
using std::max;
|
using std::max;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/***********************************************************************************
|
|
||||||
Construction
|
|
||||||
***********************************************************************************/
|
|
||||||
CUnBitArray::CUnBitArray(CIO * pIO, int nVersion)
|
CUnBitArray::CUnBitArray(CIO * pIO, int nVersion)
|
||||||
{
|
{
|
||||||
CreateHelper(pIO, 16384, nVersion);
|
CreateHelper(pIO, 16384, nVersion);
|
||||||
m_nFlushCounter = 0;
|
m_nFlushCounter = 0;
|
||||||
m_nFinalizeCounter = 0;
|
m_nFinalizeCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CUnBitArray::~CUnBitArray()
|
CUnBitArray::~CUnBitArray()
|
||||||
{
|
{
|
||||||
SAFE_ARRAY_DELETE(m_pBitArray)
|
SAFE_ARRAY_DELETE(m_pBitArray)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int CUnBitArray::DecodeValue(DECODE_VALUE_METHOD DecodeMethod, int nParam1, int nParam2)
|
|
||||||
|
unsigned int
|
||||||
|
CUnBitArray::DecodeValue(DECODE_VALUE_METHOD DecodeMethod, int nParam1,
|
||||||
|
int nParam2)
|
||||||
{
|
{
|
||||||
switch (DecodeMethod)
|
switch (DecodeMethod) {
|
||||||
{
|
case DECODE_VALUE_METHOD_UNSIGNED_INT:
|
||||||
case DECODE_VALUE_METHOD_UNSIGNED_INT:
|
return DecodeValueXBits(32);
|
||||||
return DecodeValueXBits(32);
|
case DECODE_VALUE_METHOD_UNSIGNED_RICE:
|
||||||
}
|
case DECODE_VALUE_METHOD_X_BITS:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUnBitArray::GenerateArray(int * pOutputArray, int nElements, int nBytesRequired)
|
|
||||||
|
void
|
||||||
|
CUnBitArray::GenerateArray(int * pOutputArray, int nElements,
|
||||||
|
int nBytesRequired)
|
||||||
{
|
{
|
||||||
GenerateArrayRange(pOutputArray, nElements);
|
GenerateArrayRange(pOutputArray, nElements);
|
||||||
}
|
}
|
||||||
|
|
||||||
__inline unsigned char CUnBitArray::GetC()
|
__inline unsigned char
|
||||||
|
CUnBitArray::GetC()
|
||||||
{
|
{
|
||||||
unsigned char nValue = (unsigned char) (m_pBitArray[m_nCurrentBitIndex >> 5] >> (24 - (m_nCurrentBitIndex & 31)));
|
uchar nValue = static_cast<uchar>(m_pBitArray[m_nCurrentBitIndex >> 5]
|
||||||
m_nCurrentBitIndex += 8;
|
>> (24 - (m_nCurrentBitIndex & 31)));
|
||||||
return nValue;
|
m_nCurrentBitIndex += 8;
|
||||||
|
return nValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
__inline int CUnBitArray::RangeDecodeFast(int nShift)
|
|
||||||
|
__inline int
|
||||||
|
CUnBitArray::RangeDecodeFast(int nShift)
|
||||||
{
|
{
|
||||||
while (m_RangeCoderInfo.range <= BOTTOM_VALUE)
|
while (m_RangeCoderInfo.range <= BOTTOM_VALUE) {
|
||||||
{
|
m_RangeCoderInfo.buffer = (m_RangeCoderInfo.buffer << 8)
|
||||||
m_RangeCoderInfo.buffer = (m_RangeCoderInfo.buffer << 8) | ((m_pBitArray[m_nCurrentBitIndex >> 5] >> (24 - (m_nCurrentBitIndex & 31))) & 0xFF);
|
| ((m_pBitArray[m_nCurrentBitIndex >> 5]
|
||||||
m_nCurrentBitIndex += 8;
|
>> (24 - (m_nCurrentBitIndex & 31))) & 0xFF);
|
||||||
m_RangeCoderInfo.low = (m_RangeCoderInfo.low << 8) | ((m_RangeCoderInfo.buffer >> 1) & 0xFF);
|
m_nCurrentBitIndex += 8;
|
||||||
m_RangeCoderInfo.range <<= 8;
|
m_RangeCoderInfo.low = (m_RangeCoderInfo.low << 8)
|
||||||
}
|
| ((m_RangeCoderInfo.buffer >> 1) & 0xFF);
|
||||||
|
m_RangeCoderInfo.range <<= 8;
|
||||||
|
}
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
m_RangeCoderInfo.range = m_RangeCoderInfo.range >> nShift;
|
m_RangeCoderInfo.range = m_RangeCoderInfo.range >> nShift;
|
||||||
return m_RangeCoderInfo.low / m_RangeCoderInfo.range;
|
return m_RangeCoderInfo.low / m_RangeCoderInfo.range;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
__inline int CUnBitArray::RangeDecodeFastWithUpdate(int nShift)
|
__inline int CUnBitArray::RangeDecodeFastWithUpdate(int nShift)
|
||||||
{
|
{
|
||||||
while (m_RangeCoderInfo.range <= BOTTOM_VALUE)
|
while (m_RangeCoderInfo.range <= BOTTOM_VALUE) {
|
||||||
{
|
m_RangeCoderInfo.buffer = (m_RangeCoderInfo.buffer << 8)
|
||||||
m_RangeCoderInfo.buffer = (m_RangeCoderInfo.buffer << 8) | ((m_pBitArray[m_nCurrentBitIndex >> 5] >> (24 - (m_nCurrentBitIndex & 31))) & 0xFF);
|
| ((m_pBitArray[m_nCurrentBitIndex >> 5]
|
||||||
m_nCurrentBitIndex += 8;
|
>> (24 - (m_nCurrentBitIndex & 31))) & 0xFF);
|
||||||
m_RangeCoderInfo.low = (m_RangeCoderInfo.low << 8) | ((m_RangeCoderInfo.buffer >> 1) & 0xFF);
|
m_nCurrentBitIndex += 8;
|
||||||
m_RangeCoderInfo.range <<= 8;
|
m_RangeCoderInfo.low = (m_RangeCoderInfo.low << 8)
|
||||||
}
|
| ((m_RangeCoderInfo.buffer >> 1) & 0xFF);
|
||||||
|
m_RangeCoderInfo.range <<= 8;
|
||||||
|
}
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
m_RangeCoderInfo.range = m_RangeCoderInfo.range >> nShift;
|
m_RangeCoderInfo.range = m_RangeCoderInfo.range >> nShift;
|
||||||
int nRetVal = m_RangeCoderInfo.low / m_RangeCoderInfo.range;
|
int nRetVal = m_RangeCoderInfo.low / m_RangeCoderInfo.range;
|
||||||
m_RangeCoderInfo.low -= m_RangeCoderInfo.range * nRetVal;
|
m_RangeCoderInfo.low -= m_RangeCoderInfo.range * nRetVal;
|
||||||
return nRetVal;
|
return nRetVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CUnBitArray::DecodeValueRange(UNBIT_ARRAY_STATE & BitArrayState)
|
|
||||||
|
int
|
||||||
|
CUnBitArray::DecodeValueRange(UNBIT_ARRAY_STATE & BitArrayState)
|
||||||
{
|
{
|
||||||
// make sure there is room for the data
|
// make sure there is room for the data
|
||||||
// this is a little slower than ensuring a huge block to start with, but it's safer
|
// this is a little slower than ensuring a huge block to start with,
|
||||||
if (m_nCurrentBitIndex > m_nRefillBitThreshold)
|
// but it's safer
|
||||||
{
|
if (m_nCurrentBitIndex > m_nRefillBitThreshold)
|
||||||
FillBitArray();
|
FillBitArray();
|
||||||
}
|
|
||||||
|
|
||||||
int nValue = 0;
|
int nValue = 0;
|
||||||
|
|
||||||
if (m_nVersion >= 3990)
|
if (m_nVersion >= 3990) {
|
||||||
{
|
// figure the pivot value
|
||||||
// figure the pivot value
|
int nPivotValue = max(BitArrayState.nKSum / 32, 1UL);
|
||||||
int nPivotValue = max(BitArrayState.nKSum / 32, 1UL);
|
|
||||||
|
|
||||||
// get the overflow
|
// get the overflow
|
||||||
int nOverflow = 0;
|
int nOverflow = 0;
|
||||||
{
|
|
||||||
// decode
|
|
||||||
int nRangeTotal = RangeDecodeFast(RANGE_OVERFLOW_SHIFT);
|
|
||||||
|
|
||||||
// lookup the symbol (must be a faster way than this)
|
// decode
|
||||||
while (nRangeTotal >= RANGE_TOTAL_2[nOverflow + 1]) { nOverflow++; }
|
uint32 nRangeTotal = RangeDecodeFast(RANGE_OVERFLOW_SHIFT);
|
||||||
|
|
||||||
// update
|
// lookup the symbol (must be a faster way than this)
|
||||||
m_RangeCoderInfo.low -= m_RangeCoderInfo.range * RANGE_TOTAL_2[nOverflow];
|
while (nRangeTotal >= RANGE_TOTAL_2[nOverflow + 1])
|
||||||
m_RangeCoderInfo.range = m_RangeCoderInfo.range * RANGE_WIDTH_2[nOverflow];
|
nOverflow++;
|
||||||
|
|
||||||
// get the working k
|
// update
|
||||||
if (nOverflow == (MODEL_ELEMENTS - 1))
|
m_RangeCoderInfo.low -= m_RangeCoderInfo.range
|
||||||
{
|
* RANGE_TOTAL_2[nOverflow];
|
||||||
nOverflow = RangeDecodeFastWithUpdate(16);
|
m_RangeCoderInfo.range = m_RangeCoderInfo.range
|
||||||
nOverflow <<= 16;
|
* RANGE_WIDTH_2[nOverflow];
|
||||||
nOverflow |= RangeDecodeFastWithUpdate(16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the value
|
// get the working k
|
||||||
int nBase = 0;
|
if (nOverflow == (MODEL_ELEMENTS - 1)) {
|
||||||
{
|
nOverflow = RangeDecodeFastWithUpdate(16);
|
||||||
int nShift = 0;
|
nOverflow <<= 16;
|
||||||
if (nPivotValue >= (1 << 16))
|
nOverflow |= RangeDecodeFastWithUpdate(16);
|
||||||
{
|
}
|
||||||
int nPivotValueBits = 0;
|
|
||||||
while ((nPivotValue >> nPivotValueBits) > 0) { nPivotValueBits++; }
|
|
||||||
int nSplitFactor = 1 << (nPivotValueBits - 16);
|
|
||||||
|
|
||||||
int nPivotValueA = (nPivotValue / nSplitFactor) + 1;
|
// get the value
|
||||||
int nPivotValueB = nSplitFactor;
|
int nBase = 0;
|
||||||
|
|
||||||
while (m_RangeCoderInfo.range <= BOTTOM_VALUE)
|
if (nPivotValue >= (1 << 16)) {
|
||||||
{
|
int nPivotValueBits = 0;
|
||||||
m_RangeCoderInfo.buffer = (m_RangeCoderInfo.buffer << 8) | ((m_pBitArray[m_nCurrentBitIndex >> 5] >> (24 - (m_nCurrentBitIndex & 31))) & 0xFF);
|
while ((nPivotValue >> nPivotValueBits) > 0)
|
||||||
m_nCurrentBitIndex += 8;
|
nPivotValueBits++;
|
||||||
m_RangeCoderInfo.low = (m_RangeCoderInfo.low << 8) | ((m_RangeCoderInfo.buffer >> 1) & 0xFF);
|
|
||||||
m_RangeCoderInfo.range <<= 8;
|
int nSplitFactor = 1 << (nPivotValueBits - 16);
|
||||||
}
|
int nPivotValueA = (nPivotValue / nSplitFactor) + 1;
|
||||||
m_RangeCoderInfo.range = m_RangeCoderInfo.range / nPivotValueA;
|
int nPivotValueB = nSplitFactor;
|
||||||
int nBaseA = m_RangeCoderInfo.low / m_RangeCoderInfo.range;
|
|
||||||
m_RangeCoderInfo.low -= m_RangeCoderInfo.range * nBaseA;
|
|
||||||
|
|
||||||
while (m_RangeCoderInfo.range <= BOTTOM_VALUE)
|
while (m_RangeCoderInfo.range <= BOTTOM_VALUE) {
|
||||||
{
|
m_RangeCoderInfo.buffer = (m_RangeCoderInfo.buffer << 8)
|
||||||
m_RangeCoderInfo.buffer = (m_RangeCoderInfo.buffer << 8) | ((m_pBitArray[m_nCurrentBitIndex >> 5] >> (24 - (m_nCurrentBitIndex & 31))) & 0xFF);
|
| ((m_pBitArray[m_nCurrentBitIndex >> 5]
|
||||||
m_nCurrentBitIndex += 8;
|
>> (24 - (m_nCurrentBitIndex & 31))) & 0xFF);
|
||||||
m_RangeCoderInfo.low = (m_RangeCoderInfo.low << 8) | ((m_RangeCoderInfo.buffer >> 1) & 0xFF);
|
m_nCurrentBitIndex += 8;
|
||||||
m_RangeCoderInfo.range <<= 8;
|
m_RangeCoderInfo.low = (m_RangeCoderInfo.low << 8)
|
||||||
}
|
| ((m_RangeCoderInfo.buffer >> 1) & 0xFF);
|
||||||
m_RangeCoderInfo.range = m_RangeCoderInfo.range / nPivotValueB;
|
m_RangeCoderInfo.range <<= 8;
|
||||||
int nBaseB = m_RangeCoderInfo.low / m_RangeCoderInfo.range;
|
}
|
||||||
m_RangeCoderInfo.low -= m_RangeCoderInfo.range * nBaseB;
|
m_RangeCoderInfo.range = m_RangeCoderInfo.range / nPivotValueA;
|
||||||
|
int nBaseA = m_RangeCoderInfo.low / m_RangeCoderInfo.range;
|
||||||
|
m_RangeCoderInfo.low -= m_RangeCoderInfo.range * nBaseA;
|
||||||
|
|
||||||
nBase = nBaseA * nSplitFactor + nBaseB;
|
while (m_RangeCoderInfo.range <= BOTTOM_VALUE) {
|
||||||
}
|
m_RangeCoderInfo.buffer = (m_RangeCoderInfo.buffer << 8)
|
||||||
else
|
| ((m_pBitArray[m_nCurrentBitIndex >> 5]
|
||||||
{
|
>> (24 - (m_nCurrentBitIndex & 31))) & 0xFF);
|
||||||
while (m_RangeCoderInfo.range <= BOTTOM_VALUE)
|
m_nCurrentBitIndex += 8;
|
||||||
{
|
m_RangeCoderInfo.low = (m_RangeCoderInfo.low << 8)
|
||||||
m_RangeCoderInfo.buffer = (m_RangeCoderInfo.buffer << 8) | ((m_pBitArray[m_nCurrentBitIndex >> 5] >> (24 - (m_nCurrentBitIndex & 31))) & 0xFF);
|
| ((m_RangeCoderInfo.buffer >> 1) & 0xFF);
|
||||||
m_nCurrentBitIndex += 8;
|
m_RangeCoderInfo.range <<= 8;
|
||||||
m_RangeCoderInfo.low = (m_RangeCoderInfo.low << 8) | ((m_RangeCoderInfo.buffer >> 1) & 0xFF);
|
}
|
||||||
m_RangeCoderInfo.range <<= 8;
|
m_RangeCoderInfo.range = m_RangeCoderInfo.range / nPivotValueB;
|
||||||
}
|
int nBaseB = m_RangeCoderInfo.low / m_RangeCoderInfo.range;
|
||||||
|
m_RangeCoderInfo.low -= m_RangeCoderInfo.range * nBaseB;
|
||||||
|
|
||||||
// decode
|
nBase = nBaseA * nSplitFactor + nBaseB;
|
||||||
m_RangeCoderInfo.range = m_RangeCoderInfo.range / nPivotValue;
|
} else {
|
||||||
int nBaseLower = m_RangeCoderInfo.low / m_RangeCoderInfo.range;
|
while (m_RangeCoderInfo.range <= BOTTOM_VALUE) {
|
||||||
m_RangeCoderInfo.low -= m_RangeCoderInfo.range * nBaseLower;
|
m_RangeCoderInfo.buffer = (m_RangeCoderInfo.buffer << 8)
|
||||||
|
| ((m_pBitArray[m_nCurrentBitIndex >> 5]
|
||||||
|
>> (24 - (m_nCurrentBitIndex & 31))) & 0xFF);
|
||||||
|
m_nCurrentBitIndex += 8;
|
||||||
|
m_RangeCoderInfo.low = (m_RangeCoderInfo.low << 8)
|
||||||
|
| ((m_RangeCoderInfo.buffer >> 1) & 0xFF);
|
||||||
|
m_RangeCoderInfo.range <<= 8;
|
||||||
|
}
|
||||||
|
|
||||||
nBase = nBaseLower;
|
// decode
|
||||||
}
|
m_RangeCoderInfo.range = m_RangeCoderInfo.range / nPivotValue;
|
||||||
}
|
int nBaseLower = m_RangeCoderInfo.low / m_RangeCoderInfo.range;
|
||||||
|
m_RangeCoderInfo.low -= m_RangeCoderInfo.range * nBaseLower;
|
||||||
|
|
||||||
// build the value
|
nBase = nBaseLower;
|
||||||
nValue = nBase + (nOverflow * nPivotValue);
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// decode
|
|
||||||
int nRangeTotal = RangeDecodeFast(RANGE_OVERFLOW_SHIFT);
|
|
||||||
|
|
||||||
// lookup the symbol (must be a faster way than this)
|
// build the value
|
||||||
int nOverflow = 0;
|
nValue = nBase + (nOverflow * nPivotValue);
|
||||||
while (nRangeTotal >= RANGE_TOTAL_1[nOverflow + 1]) { nOverflow++; }
|
} else {
|
||||||
|
// decode
|
||||||
|
uint32 nRangeTotal = RangeDecodeFast(RANGE_OVERFLOW_SHIFT);
|
||||||
|
|
||||||
// update
|
// lookup the symbol (must be a faster way than this)
|
||||||
m_RangeCoderInfo.low -= m_RangeCoderInfo.range * RANGE_TOTAL_1[nOverflow];
|
int nOverflow = 0;
|
||||||
m_RangeCoderInfo.range = m_RangeCoderInfo.range * RANGE_WIDTH_1[nOverflow];
|
while (nRangeTotal >= RANGE_TOTAL_1[nOverflow + 1])
|
||||||
|
nOverflow++;
|
||||||
|
|
||||||
// get the working k
|
// update
|
||||||
int nTempK;
|
m_RangeCoderInfo.low -= m_RangeCoderInfo.range
|
||||||
if (nOverflow == (MODEL_ELEMENTS - 1))
|
* RANGE_TOTAL_1[nOverflow];
|
||||||
{
|
m_RangeCoderInfo.range = m_RangeCoderInfo.range
|
||||||
nTempK = RangeDecodeFastWithUpdate(5);
|
* RANGE_WIDTH_1[nOverflow];
|
||||||
nOverflow = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
nTempK = (BitArrayState.k < 1) ? 0 : BitArrayState.k - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// figure the extra bits on the left and the left value
|
// get the working k
|
||||||
if (nTempK <= 16 || m_nVersion < 3910)
|
int nTempK;
|
||||||
{
|
if (nOverflow == (MODEL_ELEMENTS - 1)) {
|
||||||
nValue = RangeDecodeFastWithUpdate(nTempK);
|
nTempK = RangeDecodeFastWithUpdate(5);
|
||||||
}
|
nOverflow = 0;
|
||||||
else
|
} else
|
||||||
{
|
nTempK = (BitArrayState.k < 1) ? 0 : BitArrayState.k - 1;
|
||||||
int nX1 = RangeDecodeFastWithUpdate(16);
|
|
||||||
int nX2 = RangeDecodeFastWithUpdate(nTempK - 16);
|
|
||||||
nValue = nX1 | (nX2 << 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
// build the value and output it
|
// figure the extra bits on the left and the left value
|
||||||
nValue += (nOverflow << nTempK);
|
if (nTempK <= 16 || m_nVersion < 3910) {
|
||||||
}
|
nValue = RangeDecodeFastWithUpdate(nTempK);
|
||||||
|
} else {
|
||||||
|
int nX1 = RangeDecodeFastWithUpdate(16);
|
||||||
|
int nX2 = RangeDecodeFastWithUpdate(nTempK - 16);
|
||||||
|
nValue = nX1 | (nX2 << 16);
|
||||||
|
}
|
||||||
|
|
||||||
// update nKSum
|
// build the value and output it
|
||||||
BitArrayState.nKSum += ((nValue + 1) / 2) - ((BitArrayState.nKSum + 16) >> 5);
|
nValue += (nOverflow << nTempK);
|
||||||
|
}
|
||||||
|
|
||||||
// update k
|
// update nKSum
|
||||||
if (BitArrayState.nKSum < K_SUM_MIN_BOUNDARY[BitArrayState.k])
|
BitArrayState.nKSum += ((nValue + 1) / 2)
|
||||||
BitArrayState.k--;
|
- ((BitArrayState.nKSum + 16) >> 5);
|
||||||
else if (BitArrayState.nKSum >= K_SUM_MIN_BOUNDARY[BitArrayState.k + 1])
|
|
||||||
BitArrayState.k++;
|
|
||||||
|
|
||||||
// output the value (converted to signed)
|
// update k
|
||||||
return (nValue & 1) ? (nValue >> 1) + 1 : -(nValue >> 1);
|
if (BitArrayState.nKSum < K_SUM_MIN_BOUNDARY[BitArrayState.k])
|
||||||
|
BitArrayState.k--;
|
||||||
|
else if (BitArrayState.nKSum >= K_SUM_MIN_BOUNDARY[BitArrayState.k + 1])
|
||||||
|
BitArrayState.k++;
|
||||||
|
|
||||||
|
// output the value (converted to signed)
|
||||||
|
return (nValue & 1) ? (nValue >> 1) + 1 : -(nValue >> 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUnBitArray::FlushState(UNBIT_ARRAY_STATE & BitArrayState)
|
|
||||||
|
void
|
||||||
|
CUnBitArray::FlushState(UNBIT_ARRAY_STATE& BitArrayState)
|
||||||
{
|
{
|
||||||
BitArrayState.k = 10;
|
BitArrayState.k = 10;
|
||||||
BitArrayState.nKSum = (1 << BitArrayState.k) * 16;
|
BitArrayState.nKSum = (1 << BitArrayState.k) * 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUnBitArray::FlushBitArray()
|
void
|
||||||
|
CUnBitArray::FlushBitArray()
|
||||||
{
|
{
|
||||||
AdvanceToByteBoundary();
|
AdvanceToByteBoundary();
|
||||||
m_nCurrentBitIndex += 8; // ignore the first byte... (slows compression too much to not output this dummy byte)
|
m_nCurrentBitIndex += 8;
|
||||||
m_RangeCoderInfo.buffer = GetC();
|
// ignore the first byte... (slows compression too much to not
|
||||||
m_RangeCoderInfo.low = m_RangeCoderInfo.buffer >> (8 - EXTRA_BITS);
|
// output this dummy byte)
|
||||||
m_RangeCoderInfo.range = (unsigned int) 1 << EXTRA_BITS;
|
m_RangeCoderInfo.buffer = GetC();
|
||||||
|
m_RangeCoderInfo.low = m_RangeCoderInfo.buffer >> (8 - EXTRA_BITS);
|
||||||
|
m_RangeCoderInfo.range = (unsigned int) 1 << EXTRA_BITS;
|
||||||
|
|
||||||
m_nRefillBitThreshold = (m_nBits - 512);
|
m_nRefillBitThreshold = (m_nBits - 512);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUnBitArray::Finalize()
|
|
||||||
|
void
|
||||||
|
CUnBitArray::Finalize()
|
||||||
{
|
{
|
||||||
// normalize
|
// normalize
|
||||||
while (m_RangeCoderInfo.range <= BOTTOM_VALUE)
|
while (m_RangeCoderInfo.range <= BOTTOM_VALUE) {
|
||||||
{
|
m_nCurrentBitIndex += 8;
|
||||||
m_nCurrentBitIndex += 8;
|
m_RangeCoderInfo.range <<= 8;
|
||||||
m_RangeCoderInfo.range <<= 8;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// used to back-pedal the last two bytes out
|
// used to back-pedal the last two bytes out
|
||||||
// this should never have been a problem because we've outputted and normalized beforehand
|
// this should never have been a problem because we've outputted and normalized beforehand
|
||||||
// but stopped doing it as of 3.96 in case it accounted for rare decompression failures
|
// but stopped doing it as of 3.96 in case it accounted for rare decompression failures
|
||||||
if (m_nVersion <= 3950)
|
if (m_nVersion <= 3950)
|
||||||
m_nCurrentBitIndex -= 16;
|
m_nCurrentBitIndex -= 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUnBitArray::GenerateArrayRange(int * pOutputArray, int nElements)
|
|
||||||
|
void
|
||||||
|
CUnBitArray::GenerateArrayRange(int * pOutputArray, int nElements)
|
||||||
{
|
{
|
||||||
UNBIT_ARRAY_STATE BitArrayState;
|
UNBIT_ARRAY_STATE BitArrayState;
|
||||||
FlushState(BitArrayState);
|
FlushState(BitArrayState);
|
||||||
FlushBitArray();
|
FlushBitArray();
|
||||||
|
|
||||||
for (int z = 0; z < nElements; z++)
|
for (int z = 0; z < nElements; z++)
|
||||||
{
|
pOutputArray[z] = DecodeValueRange(BitArrayState);
|
||||||
pOutputArray[z] = DecodeValueRange(BitArrayState);
|
|
||||||
}
|
|
||||||
|
|
||||||
Finalize();
|
Finalize();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,51 +1,55 @@
|
|||||||
#ifndef APE_UNBITARRAY_H
|
#ifndef APE_UNBITARRAY_H
|
||||||
#define APE_UNBITARRAY_H
|
#define APE_UNBITARRAY_H
|
||||||
|
|
||||||
|
|
||||||
#include "UnBitArrayBase.h"
|
#include "UnBitArrayBase.h"
|
||||||
|
|
||||||
|
|
||||||
class IAPEDecompress;
|
class IAPEDecompress;
|
||||||
|
|
||||||
|
|
||||||
struct RANGE_CODER_STRUCT_DECOMPRESS
|
struct RANGE_CODER_STRUCT_DECOMPRESS
|
||||||
{
|
{
|
||||||
unsigned int low; // low end of interval
|
unsigned int low; // low end of interval
|
||||||
unsigned int range; // length of interval
|
unsigned int range; // length of interval
|
||||||
unsigned int buffer; // buffer for input/output
|
unsigned int buffer; // buffer for input/output
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class CUnBitArray : public CUnBitArrayBase
|
class CUnBitArray : public CUnBitArrayBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
CUnBitArray(CIO* pIO, int nVersion);
|
||||||
|
~CUnBitArray();
|
||||||
|
|
||||||
// construction/destruction
|
uint DecodeValue(DECODE_VALUE_METHOD DecodeMethod,
|
||||||
CUnBitArray(CIO * pIO, int nVersion);
|
int nParam1 = 0, int nParam2 = 0);
|
||||||
~CUnBitArray();
|
|
||||||
|
void GenerateArray(int * pOutputArray, int nElements,
|
||||||
|
int nBytesRequired = -1);
|
||||||
|
|
||||||
unsigned int DecodeValue(DECODE_VALUE_METHOD DecodeMethod, int nParam1 = 0, int nParam2 = 0);
|
int DecodeValueRange(UNBIT_ARRAY_STATE & BitArrayState);
|
||||||
|
|
||||||
void GenerateArray(int * pOutputArray, int nElements, int nBytesRequired = -1);
|
void FlushState(UNBIT_ARRAY_STATE & BitArrayState);
|
||||||
|
void FlushBitArray();
|
||||||
int DecodeValueRange(UNBIT_ARRAY_STATE & BitArrayState);
|
void Finalize();
|
||||||
|
|
||||||
void FlushState(UNBIT_ARRAY_STATE & BitArrayState);
|
|
||||||
void FlushBitArray();
|
|
||||||
void Finalize();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void GenerateArrayRange(int * pOutputArray, int nElements);
|
||||||
|
|
||||||
void GenerateArrayRange(int * pOutputArray, int nElements);
|
// data
|
||||||
|
int m_nFlushCounter;
|
||||||
// data
|
int m_nFinalizeCounter;
|
||||||
int m_nFlushCounter;
|
|
||||||
int m_nFinalizeCounter;
|
RANGE_CODER_STRUCT_DECOMPRESS m_RangeCoderInfo;
|
||||||
|
|
||||||
RANGE_CODER_STRUCT_DECOMPRESS m_RangeCoderInfo;
|
uint32 m_nRefillBitThreshold;
|
||||||
|
|
||||||
uint32 m_nRefillBitThreshold;
|
// functions
|
||||||
|
inline int RangeDecodeFast(int nShift);
|
||||||
// functions
|
inline int RangeDecodeFastWithUpdate(int nShift);
|
||||||
inline int RangeDecodeFast(int nShift);
|
inline uchar GetC();
|
||||||
inline int RangeDecodeFastWithUpdate(int nShift);
|
|
||||||
inline unsigned char GetC();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // #ifndef APE_UNBITARRAY_H
|
#endif // #ifndef APE_UNBITARRAY_H
|
||||||
|
|||||||
@@ -3,113 +3,135 @@
|
|||||||
#include "APEInfo.h"
|
#include "APEInfo.h"
|
||||||
#include "UnBitArray.h"
|
#include "UnBitArray.h"
|
||||||
|
|
||||||
|
|
||||||
#undef BACKWARDS_COMPATIBILITY
|
#undef BACKWARDS_COMPATIBILITY
|
||||||
|
|
||||||
#ifdef BACKWARDS_COMPATIBILITY
|
#ifdef BACKWARDS_COMPATIBILITY
|
||||||
#include "Old/APEDecompressOld.h"
|
#include "Old/APEDecompressOld.h"
|
||||||
#include "Old/UnBitArrayOld.h"
|
#include "Old/UnBitArrayOld.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const uint32 POWERS_OF_TWO_MINUS_ONE[33] = {0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535,131071,262143,524287,1048575,2097151,4194303,8388607,16777215,33554431,67108863,134217727,268435455,536870911,1073741823,2147483647,4294967295};
|
|
||||||
|
|
||||||
CUnBitArrayBase * CreateUnBitArray(IAPEDecompress * pAPEDecompress, int nVersion)
|
const uint32 POWERS_OF_TWO_MINUS_ONE[33] = {0u,1u,3u,7u,15u,31u,63u,127u,255u,
|
||||||
|
511u,1023u,2047u,4095u,8191u,16383u,32767u,65535u,131071u,262143u,524287u,
|
||||||
|
1048575u,2097151u,4194303u,8388607u,16777215u,33554431u,67108863u,
|
||||||
|
134217727u,268435455u,536870911u,1073741823u,2147483647u,4294967295u};
|
||||||
|
|
||||||
|
|
||||||
|
CUnBitArrayBase*
|
||||||
|
CreateUnBitArray(IAPEDecompress* pAPEDecompress, int nVersion)
|
||||||
{
|
{
|
||||||
#ifdef BACKWARDS_COMPATIBILITY
|
#ifdef BACKWARDS_COMPATIBILITY
|
||||||
if (nVersion >= 3900)
|
if (nVersion >= 3900)
|
||||||
return (CUnBitArrayBase * ) new CUnBitArray(GET_IO(pAPEDecompress), nVersion);
|
return static_cast<CUnBitArrayBase*>
|
||||||
else
|
(new CUnBitArray(GET_IO(pAPEDecompress), nVersion));
|
||||||
return (CUnBitArrayBase * ) new CUnBitArrayOld(pAPEDecompress, nVersion);
|
else
|
||||||
|
return static_cast<CUnBitArrayBase*>
|
||||||
|
(new CUnBitArrayOld(pAPEDecompress, nVersion));
|
||||||
#else
|
#else
|
||||||
return (CUnBitArrayBase * ) new CUnBitArray(GET_IO(pAPEDecompress), nVersion);
|
return static_cast<CUnBitArrayBase*>
|
||||||
|
(new CUnBitArray(GET_IO(pAPEDecompress), nVersion));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUnBitArrayBase::AdvanceToByteBoundary()
|
|
||||||
|
void
|
||||||
|
CUnBitArrayBase::AdvanceToByteBoundary()
|
||||||
{
|
{
|
||||||
int nMod = m_nCurrentBitIndex % 8;
|
int nMod = m_nCurrentBitIndex % 8;
|
||||||
if (nMod != 0) { m_nCurrentBitIndex += 8 - nMod; }
|
if (nMod != 0)
|
||||||
|
m_nCurrentBitIndex += 8 - nMod;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 CUnBitArrayBase::DecodeValueXBits(uint32 nBits)
|
|
||||||
{
|
|
||||||
// get more data if necessary
|
|
||||||
if ((m_nCurrentBitIndex + nBits) >= m_nBits)
|
|
||||||
FillBitArray();
|
|
||||||
|
|
||||||
// variable declares
|
uint32
|
||||||
uint32 nLeftBits = 32 - (m_nCurrentBitIndex & 31);
|
CUnBitArrayBase::DecodeValueXBits(uint32 nBits)
|
||||||
uint32 nBitArrayIndex = m_nCurrentBitIndex >> 5;
|
{
|
||||||
m_nCurrentBitIndex += nBits;
|
// get more data if necessary
|
||||||
|
if ((m_nCurrentBitIndex + nBits) >= m_nBits)
|
||||||
// if their isn't an overflow to the right value, get the value and exit
|
FillBitArray();
|
||||||
if (nLeftBits >= nBits)
|
|
||||||
return (m_pBitArray[nBitArrayIndex] & (POWERS_OF_TWO_MINUS_ONE[nLeftBits])) >> (nLeftBits - nBits);
|
// variable declares
|
||||||
|
uint32 nLeftBits = 32 - (m_nCurrentBitIndex & 31);
|
||||||
// must get the "split" value from left and right
|
uint32 nBitArrayIndex = m_nCurrentBitIndex >> 5;
|
||||||
int nRightBits = nBits - nLeftBits;
|
m_nCurrentBitIndex += nBits;
|
||||||
|
|
||||||
uint32 nLeftValue = ((m_pBitArray[nBitArrayIndex] & POWERS_OF_TWO_MINUS_ONE[nLeftBits]) << nRightBits);
|
// if there isn't an overflow to the right value, get the value and exit
|
||||||
uint32 nRightValue = (m_pBitArray[nBitArrayIndex + 1] >> (32 - nRightBits));
|
if (nLeftBits >= nBits)
|
||||||
return (nLeftValue | nRightValue);
|
return (m_pBitArray[nBitArrayIndex]
|
||||||
|
& (POWERS_OF_TWO_MINUS_ONE[nLeftBits])) >> (nLeftBits - nBits);
|
||||||
|
|
||||||
|
// must get the "split" value from left and right
|
||||||
|
int nRightBits = nBits - nLeftBits;
|
||||||
|
uint32 nLeftValue = ((m_pBitArray[nBitArrayIndex]
|
||||||
|
& POWERS_OF_TWO_MINUS_ONE[nLeftBits]) << nRightBits);
|
||||||
|
uint32 nRightValue = (m_pBitArray[nBitArrayIndex + 1] >> (32 - nRightBits));
|
||||||
|
return (nLeftValue | nRightValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CUnBitArrayBase::FillAndResetBitArray(int nFileLocation, int nNewBitIndex)
|
|
||||||
|
int
|
||||||
|
CUnBitArrayBase::FillAndResetBitArray(int nFileLocation, int nNewBitIndex)
|
||||||
{
|
{
|
||||||
// reset the bit index
|
// reset the bit index
|
||||||
m_nCurrentBitIndex = nNewBitIndex;
|
m_nCurrentBitIndex = nNewBitIndex;
|
||||||
|
|
||||||
// seek if necessary
|
// seek if necessary
|
||||||
if (nFileLocation != -1)
|
if (nFileLocation != -1 && m_pIO->Seek(nFileLocation, FILE_BEGIN) != 0)
|
||||||
{
|
return ERROR_IO_READ;
|
||||||
if (m_pIO->Seek(nFileLocation, FILE_BEGIN) != 0)
|
|
||||||
return ERROR_IO_READ;
|
|
||||||
}
|
|
||||||
|
|
||||||
// read the new data into the bit array
|
// read the new data into the bit array
|
||||||
unsigned int nBytesRead = 0;
|
unsigned int nBytesRead = 0;
|
||||||
if (m_pIO->Read(((unsigned char *) m_pBitArray), m_nBytes, &nBytesRead) != 0)
|
if (m_pIO->Read((unsigned char*)m_pBitArray, m_nBytes,
|
||||||
return ERROR_IO_READ;
|
&nBytesRead) != 0)
|
||||||
|
return ERROR_IO_READ;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CUnBitArrayBase::FillBitArray()
|
|
||||||
|
int
|
||||||
|
CUnBitArrayBase::FillBitArray()
|
||||||
{
|
{
|
||||||
// get the bit array index
|
// get the bit array index
|
||||||
uint32 nBitArrayIndex = m_nCurrentBitIndex >> 5;
|
uint32 nBitArrayIndex = m_nCurrentBitIndex >> 5;
|
||||||
|
|
||||||
// move the remaining data to the front
|
// move the remaining data to the front
|
||||||
memmove((void *) (m_pBitArray), (const void *) (m_pBitArray + nBitArrayIndex), m_nBytes - (nBitArrayIndex * 4));
|
memmove((void *) (m_pBitArray), static_cast<const void*>(m_pBitArray
|
||||||
|
+ nBitArrayIndex), m_nBytes - (nBitArrayIndex * 4));
|
||||||
// read the new data
|
|
||||||
int nBytesToRead = nBitArrayIndex * 4;
|
// read the new data
|
||||||
unsigned int nBytesRead = 0;
|
int nBytesToRead = nBitArrayIndex * 4;
|
||||||
int nRetVal = m_pIO->Read((unsigned char *) (m_pBitArray + m_nElements - nBitArrayIndex), nBytesToRead, &nBytesRead);
|
unsigned int nBytesRead = 0;
|
||||||
|
int nRetVal = m_pIO->Read((unsigned char*)(m_pBitArray + m_nElements
|
||||||
// adjust the m_Bit pointer
|
- nBitArrayIndex), nBytesToRead, &nBytesRead);
|
||||||
m_nCurrentBitIndex = m_nCurrentBitIndex & 31;
|
|
||||||
|
// adjust the m_Bit pointer
|
||||||
// return
|
m_nCurrentBitIndex = m_nCurrentBitIndex & 31;
|
||||||
return (nRetVal == 0) ? 0 : ERROR_IO_READ;
|
|
||||||
|
// return
|
||||||
|
return (nRetVal == 0) ? 0 : ERROR_IO_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CUnBitArrayBase::CreateHelper(CIO * pIO, int nBytes, int nVersion)
|
|
||||||
{
|
|
||||||
// check the parameters
|
|
||||||
if ((pIO == NULL) || (nBytes <= 0)) { return ERROR_BAD_PARAMETER; }
|
|
||||||
|
|
||||||
// save the size
|
int
|
||||||
m_nElements = nBytes / 4;
|
CUnBitArrayBase::CreateHelper(CIO * pIO, int nBytes, int nVersion)
|
||||||
m_nBytes = m_nElements * 4;
|
{
|
||||||
m_nBits = m_nBytes * 8;
|
// check the parameters
|
||||||
|
if ((pIO == NULL) || (nBytes <= 0))
|
||||||
// set the variables
|
return ERROR_BAD_PARAMETER;
|
||||||
m_pIO = pIO;
|
|
||||||
m_nVersion = nVersion;
|
// save the size
|
||||||
m_nCurrentBitIndex = 0;
|
m_nElements = nBytes / 4;
|
||||||
|
m_nBytes = m_nElements * 4;
|
||||||
// create the bitarray
|
m_nBits = m_nBytes * 8;
|
||||||
m_pBitArray = new uint32 [m_nElements];
|
|
||||||
|
// set the variables
|
||||||
return (m_pBitArray != NULL) ? 0 : ERROR_INSUFFICIENT_MEMORY;
|
m_pIO = pIO;
|
||||||
|
m_nVersion = nVersion;
|
||||||
|
m_nCurrentBitIndex = 0;
|
||||||
|
|
||||||
|
// create the bitarray
|
||||||
|
m_pBitArray = new uint32[m_nElements];
|
||||||
|
|
||||||
|
return (m_pBitArray != NULL) ? 0 : ERROR_INSUFFICIENT_MEMORY;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,59 +1,63 @@
|
|||||||
#ifndef APE_UNBITARRAYBASE_H
|
#ifndef APE_UNBITARRAYBASE_H
|
||||||
#define APE_UNBITARRAYBASE_H
|
#define APE_UNBITARRAYBASE_H
|
||||||
|
|
||||||
|
|
||||||
class IAPEDecompress;
|
class IAPEDecompress;
|
||||||
class CIO;
|
class CIO;
|
||||||
|
|
||||||
|
|
||||||
struct UNBIT_ARRAY_STATE
|
struct UNBIT_ARRAY_STATE
|
||||||
{
|
{
|
||||||
uint32 k;
|
uint32 k;
|
||||||
uint32 nKSum;
|
uint32 nKSum;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum DECODE_VALUE_METHOD
|
enum DECODE_VALUE_METHOD
|
||||||
{
|
{
|
||||||
DECODE_VALUE_METHOD_UNSIGNED_INT,
|
DECODE_VALUE_METHOD_UNSIGNED_INT,
|
||||||
DECODE_VALUE_METHOD_UNSIGNED_RICE,
|
DECODE_VALUE_METHOD_UNSIGNED_RICE,
|
||||||
DECODE_VALUE_METHOD_X_BITS
|
DECODE_VALUE_METHOD_X_BITS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class CUnBitArrayBase
|
class CUnBitArrayBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual ~CUnBitArrayBase() {}
|
||||||
|
|
||||||
// virtual destructor
|
virtual int FillBitArray();
|
||||||
virtual ~CUnBitArrayBase() {}
|
virtual int FillAndResetBitArray(int nFileLocation = -1,
|
||||||
|
int nNewBitIndex = 0);
|
||||||
|
|
||||||
// functions
|
virtual void GenerateArray(int * pOutputArray, int nElements,
|
||||||
virtual int FillBitArray();
|
int nBytesRequired = -1) {}
|
||||||
virtual int FillAndResetBitArray(int nFileLocation = -1, int nNewBitIndex = 0);
|
virtual uint DecodeValue(DECODE_VALUE_METHOD DecodeMethod,
|
||||||
|
int nParam1 = 0, int nParam2 = 0) { return 0; }
|
||||||
virtual void GenerateArray(int * pOutputArray, int nElements, int nBytesRequired = -1) {}
|
|
||||||
virtual unsigned int DecodeValue(DECODE_VALUE_METHOD DecodeMethod, int nParam1 = 0, int nParam2 = 0) { return 0; }
|
|
||||||
|
|
||||||
virtual void AdvanceToByteBoundary();
|
|
||||||
|
|
||||||
virtual int DecodeValueRange(UNBIT_ARRAY_STATE & BitArrayState) { return 0; }
|
virtual void AdvanceToByteBoundary();
|
||||||
virtual void FlushState(UNBIT_ARRAY_STATE & BitArrayState) {}
|
|
||||||
virtual void FlushBitArray() {}
|
virtual int DecodeValueRange(UNBIT_ARRAY_STATE& BitArrayState)
|
||||||
virtual void Finalize() {}
|
{ return 0; }
|
||||||
|
virtual void FlushState(UNBIT_ARRAY_STATE& BitArrayState) {}
|
||||||
|
virtual void FlushBitArray() {}
|
||||||
|
virtual void Finalize() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual int CreateHelper(CIO* pIO, int nBytes, int nVersion);
|
||||||
|
virtual uint32 DecodeValueXBits(uint32 nBits);
|
||||||
|
|
||||||
virtual int CreateHelper(CIO * pIO, int nBytes, int nVersion);
|
uint32 m_nElements;
|
||||||
virtual uint32 DecodeValueXBits(uint32 nBits);
|
uint32 m_nBytes;
|
||||||
|
uint32 m_nBits;
|
||||||
uint32 m_nElements;
|
|
||||||
uint32 m_nBytes;
|
|
||||||
uint32 m_nBits;
|
|
||||||
|
|
||||||
int m_nVersion;
|
|
||||||
CIO * m_pIO;
|
|
||||||
|
|
||||||
uint32 m_nCurrentBitIndex;
|
int m_nVersion;
|
||||||
uint32 * m_pBitArray;
|
CIO * m_pIO;
|
||||||
|
|
||||||
|
uint32 m_nCurrentBitIndex;
|
||||||
|
uint32 * m_pBitArray;
|
||||||
};
|
};
|
||||||
|
|
||||||
CUnBitArrayBase * CreateUnBitArray(IAPEDecompress * pAPEDecompress, int nVersion);
|
CUnBitArrayBase* CreateUnBitArray(IAPEDecompress* pAPEDecompress, int nVersion);
|
||||||
|
|
||||||
|
|
||||||
#endif // #ifndef APE_UNBITARRAYBASE_H
|
#endif // #ifndef APE_UNBITARRAYBASE_H
|
||||||
|
|||||||
Reference in New Issue
Block a user