7#include "core/fxcodec/jbig2/JBig2_ArithIntDecoder.h"
11#include "core/fxcrt/fx_safe_types.h"
15int ShiftOr(
int val,
int bitwise_or_val) {
16 return (val << 1) | bitwise_or_val;
19struct ArithIntDecodeData {
24constexpr ArithIntDecodeData kArithIntDecodeData[] = {
25 {2, 0}, {4, 4}, {6, 20}, {8, 84}, {12, 340}, {32, 4436},
29 std::vector<JBig2ArithCtx>* context,
32 static const size_t kDepthEnd = std::size(kArithIntDecodeData) - 1;
33 if (depth == kDepthEnd)
38 *prev = ShiftOr(*prev, D);
41 return RecursiveDecode(decoder, context, prev, depth + 1);
58 const int S = pArithDecoder->Decode(&m_IAx[PREV]);
59 PREV = ShiftOr(PREV, S);
61 const size_t nDecodeDataIndex =
62 RecursiveDecode(pArithDecoder, &m_IAx, &PREV, 0);
65 for (
int i = 0; i < kArithIntDecodeData[nDecodeDataIndex].nNeedBits; ++i) {
66 int D = pArithDecoder->Decode(&m_IAx[PREV]);
67 PREV = ShiftOr(PREV, D);
69 PREV = (PREV & 511) | 256;
70 nTemp = ShiftOr(nTemp, D);
72 FX_SAFE_INT32 safeValue = kArithIntDecodeData[nDecodeDataIndex].nValue;
76 if (!safeValue.IsValid()) {
81 int nValue = safeValue.ValueOrDie();
82 if (S == 1 && nValue > 0)
86 return S != 1 || nValue != 0;
90 : SBSYMCODELEN(SBSYMCODELENA) {
91 m_IAID.resize(
static_cast<size_t>(1) << SBSYMCODELEN);
99 for (
unsigned char i = 0; i < SBSYMCODELEN; ++i) {
102 PREV = ShiftOr(PREV, D);
104 *nResult = PREV - (1 << SBSYMCODELEN);
int Decode(JBig2ArithCtx *pCX)
void Decode(CJBig2_ArithDecoder *pArithDecoder, uint32_t *nResult)
CJBig2_ArithIaidDecoder(unsigned char SBSYMCODELENA)
~CJBig2_ArithIaidDecoder()
bool Decode(CJBig2_ArithDecoder *pArithDecoder, int *nResult)
~CJBig2_ArithIntDecoder()