7#include "core/fxcodec/jbig2/JBig2_ArithIntDecoder.h"
12#include "core/fxcrt/fx_safe_types.h"
13#include "core/fxcrt/stl_util.h"
17int ShiftOr(
int val,
int bitwise_or_val) {
18 return (val << 1) | bitwise_or_val;
21struct ArithIntDecodeData {
26constexpr auto kArithIntDecodeData =
fxcrt::ToArray<ArithIntDecodeData>({
36 std::vector<JBig2ArithCtx>* context,
39 static const size_t kDepthEnd =
std::size(kArithIntDecodeData) - 1;
40 if (depth == kDepthEnd)
45 *prev = ShiftOr(*prev, D);
48 return RecursiveDecode(decoder, context, prev, depth + 1);
65 const int S = pArithDecoder->Decode(&m_IAx[PREV]);
66 PREV = ShiftOr(PREV, S);
68 const size_t nDecodeDataIndex =
69 RecursiveDecode(pArithDecoder, &m_IAx, &PREV, 0);
72 for (
int i = 0; i < kArithIntDecodeData[nDecodeDataIndex].nNeedBits; ++i) {
73 int D = pArithDecoder->Decode(&m_IAx[PREV]);
74 PREV = ShiftOr(PREV, D);
76 PREV = (PREV & 511) | 256;
77 nTemp = ShiftOr(nTemp, D);
79 FX_SAFE_INT32 safeValue = kArithIntDecodeData[nDecodeDataIndex].nValue;
83 if (!safeValue.IsValid()) {
88 int nValue = safeValue.ValueOrDie();
89 if (S == 1 && nValue > 0)
93 return S != 1 || nValue != 0;
97 : SBSYMCODELEN(SBSYMCODELENA) {
98 m_IAID.resize(
static_cast<size_t>(1) << SBSYMCODELEN);
106 for (
unsigned char i = 0; i < SBSYMCODELEN; ++i) {
109 PREV = ShiftOr(PREV, D);
111 *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()
pdfium::CheckedNumeric< int32_t > FX_SAFE_INT32