mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
104 lines
2.7 KiB
C++
104 lines
2.7 KiB
C++
#ifndef _JARITHMETICDECODER_H
|
|
#define _JARITHMETICDECODER_H
|
|
|
|
class Stream;
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------------
|
|
// JArithmeticDecoderStats
|
|
//-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
class JArithmeticDecoderStats
|
|
{
|
|
public:
|
|
|
|
JArithmeticDecoderStats(int nContextSize);
|
|
~JArithmeticDecoderStats();
|
|
JArithmeticDecoderStats *Copy();
|
|
void Reset();
|
|
int GetContextSize()
|
|
{
|
|
return m_nContextSize;
|
|
}
|
|
void CopyFrom(JArithmeticDecoderStats *pStats);
|
|
void SetEntry(unsigned int unCx, int nIndex, int nMPS);
|
|
|
|
private:
|
|
|
|
unsigned char *m_pContextTable; // cxTab[cx] = (i[cx] << 1) + mps[cx]
|
|
int m_nContextSize;
|
|
|
|
friend class JArithmeticDecoder;
|
|
};
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------------
|
|
// JArithmeticDecoder
|
|
//-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
class JArithmeticDecoder
|
|
{
|
|
public:
|
|
|
|
JArithmeticDecoder();
|
|
~JArithmeticDecoder();
|
|
|
|
void SetStream(Stream *pStream)
|
|
{
|
|
m_pStream = pStream;
|
|
m_nDataSize = 0;
|
|
m_bLimitStream = FALSE;
|
|
}
|
|
void SetStream(Stream *pStream, int nDataSize)
|
|
{
|
|
m_pStream = pStream;
|
|
m_nDataSize = nDataSize;
|
|
m_bLimitStream = TRUE;
|
|
}
|
|
|
|
// Íà÷èíàåì äåêîäèðîâàòü íîâûé ïîòîê. Çàïîëíÿåì áóôôåð è çàïóñêàåì INITDEC.
|
|
void Start();
|
|
|
|
// Çàíîâî äåêîäèðóåì ïðåðâûííûé ïîòîê. Çàíîâî çàïîëíÿåì áóôôåð, íî íå çàïóñêàåì INITDEC. (Èñïîëüçóåòñÿ â ïîòîêàõ JPEG 2000, ãäå
|
|
// äàííûå ìîãóò áûòü ðàçäåëåíû íà áëîêè.)
|
|
void Restart(int nDataSize);
|
|
|
|
// ×èòàåì îñòàâøèåñÿ äàííûå â ïîòîêå.
|
|
void Cleanup();
|
|
|
|
// Äåêîäèðóåì îäèí áèò.
|
|
int DecodeBit(unsigned int unContext, JArithmeticDecoderStats *pStats);
|
|
|
|
// Äåêîäèðóåì îäèí áàéò.
|
|
int DecodeByte(unsigned int unContext, JArithmeticDecoderStats *pStats);
|
|
|
|
BOOL DecodeInt(int *pnValue, JArithmeticDecoderStats *pStats);
|
|
|
|
unsigned int DecodeIAID(unsigned int unCodeLen, JArithmeticDecoderStats *pStats);
|
|
|
|
private:
|
|
|
|
unsigned int ReadByte();
|
|
int DecodeIntBit(JArithmeticDecoderStats *pStats);
|
|
void ByteIn();
|
|
|
|
private:
|
|
|
|
static unsigned int arrunQeTable[47];
|
|
static int arrnNMPSTable[47];
|
|
static int arrnNLPSTable[47];
|
|
static int arrnSwitchTable[47];
|
|
|
|
unsigned int m_unBuffer0;
|
|
unsigned int m_unBuffer1;
|
|
unsigned int m_unC;
|
|
unsigned int m_unA;
|
|
int m_nCT;
|
|
|
|
unsigned int m_unPrev;
|
|
|
|
Stream *m_pStream;
|
|
int m_nDataSize;
|
|
BOOL m_bLimitStream;
|
|
};
|
|
|
|
#endif /* _JARITHMETICDECODER_H */
|