7#include "core/fxcodec/jbig2/JBig2_GrdProc.h"
14#include "core/fxcodec/fax/faxmodule.h"
15#include "core/fxcodec/jbig2/JBig2_ArithDecoder.h"
16#include "core/fxcodec/jbig2/JBig2_BitStream.h"
17#include "core/fxcodec/jbig2/JBig2_Image.h"
18#include "core/fxcrt/pauseindicator_iface.h"
23constexpr std::array<
const uint16_t, 3> kOptConstant1 = {
24 {0x9b25, 0x0795, 0x00e5}};
25constexpr std::array<
const uint16_t, 3> kOptConstant2 = {
26 {0x0006, 0x0004, 0x0001}};
27constexpr std::array<
const uint16_t, 3> kOptConstant3 = {
28 {0xf800, 0x1e00, 0x0380}};
29constexpr std::array<
const uint16_t, 3> kOptConstant4 = {
30 {0x0000, 0x0001, 0x0003}};
31constexpr std::array<
const uint16_t, 3> kOptConstant5 = {
32 {0x07f0, 0x01f8, 0x007c}};
33constexpr std::array<
const uint16_t, 3> kOptConstant6 = {
34 {0x7bf7, 0x0efb, 0x01bd}};
35constexpr std::array<
const uint16_t, 3> kOptConstant7 = {
36 {0x0800, 0x0200, 0x0080}};
37constexpr std::array<
const uint16_t, 3> kOptConstant8 = {
38 {0x0010, 0x0008, 0x0004}};
39constexpr std::array<
const uint16_t, 3> kOptConstant9 = {
40 {0x000c, 0x0009, 0x0007}};
41constexpr std::array<
const uint16_t, 3> kOptConstant10 = {
42 {0x0007, 0x000f, 0x0007}};
43constexpr std::array<
const uint16_t, 3> kOptConstant11 = {
44 {0x001f, 0x001f, 0x000f}};
45constexpr std::array<
const uint16_t, 3> kOptConstant12 = {
46 {0x000f, 0x0007, 0x0003}};
61 return (GBAT[0] == 3) && (GBAT[1] == -1) && (GBAT[2] == -3) &&
62 (GBAT[3] == -1) && (GBAT[4] == 2) && (GBAT[5] == -2) &&
63 (GBAT[6] == -2) && (GBAT[7] == -2);
67 return (GBAT[0] == 3) && (GBAT[1] == -1);
71 return (GBAT[0] == 2) && (GBAT[1] == -1);
76 pdfium::span<JBig2ArithCtx> gbContexts) {
82 return UseTemplate0Opt3()
83 ? DecodeArithOpt3(pArithDecoder, gbContexts, 0)
84 : DecodeArithTemplateUnopt(pArithDecoder, gbContexts, 0);
86 return UseTemplate1Opt3()
87 ? DecodeArithOpt3(pArithDecoder, gbContexts, 1)
88 : DecodeArithTemplateUnopt(pArithDecoder, gbContexts, 1);
90 return UseTemplate23Opt3()
91 ? DecodeArithOpt3(pArithDecoder, gbContexts, 2)
92 : DecodeArithTemplateUnopt(pArithDecoder, gbContexts, 2);
94 return UseTemplate23Opt3()
95 ? DecodeArithTemplate3Opt3(pArithDecoder, gbContexts)
96 : DecodeArithTemplate3Unopt(pArithDecoder, gbContexts);
102 pdfium::span<JBig2ArithCtx> gbContexts,
109 uint8_t* pLine = GBREG->data();
110 int32_t nStride = GBREG->stride();
111 int32_t nStride2 = nStride << 1;
112 int32_t nLineBytes = ((
GBW + 7) >> 3) - 1;
113 int32_t nBitsLeft =
GBW - (nLineBytes << 3);
115 uint32_t height = OPT == 0 ?
GBH & 0x7fffffff :
GBH;
117 for (uint32_t h = 0; h < height; ++h) {
123 LTP = LTP ^ pArithDecoder
->Decode(&gbContexts[kOptConstant1[OPT]]
);
126 GBREG->CopyLine(h, h - 1);
129 uint8_t* pLine1 = pLine - nStride2;
130 uint8_t* pLine2 = pLine - nStride;
131 uint32_t line1 = (*pLine1++) << kOptConstant2[OPT];
132 uint32_t line2 = *pLine2++;
134 (line1 & kOptConstant3[OPT]) |
135 ((line2 >> kOptConstant4[OPT]) & kOptConstant5[OPT]);
136 for (int32_t cc = 0; cc < nLineBytes; ++cc) {
137 line1 = (line1 << 8) | ((*pLine1++) << kOptConstant2[OPT]);
138 line2 = (line2 << 8) | (*pLine2++);
140 for (int32_t k = 7; k >= 0; --k) {
145 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
148 (((CONTEXT & kOptConstant6[OPT]) << 1) | bVal |
149 ((line1 >> k) & kOptConstant7[OPT]) |
150 ((line2 >> (k + kOptConstant4[OPT])) & kOptConstant8[OPT]));
157 for (int32_t k = 0; k < nBitsLeft; ++k) {
161 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
162 cVal1 |= bVal << (7 - k);
163 CONTEXT = (((CONTEXT & kOptConstant6[OPT]) << 1) | bVal |
164 ((line1 >> (7 - k)) & kOptConstant7[OPT]) |
165 ((line2 >> (7 + kOptConstant4[OPT] - k)) &
166 kOptConstant8[OPT]));
168 pLine[nLineBytes] = cVal1;
170 uint8_t* pLine2 = pLine - nStride;
171 uint32_t line2 = (h & 1) ? (*pLine2++) : 0;
173 ((line2 >> kOptConstant4[OPT]) & kOptConstant5[OPT]);
174 for (int32_t cc = 0; cc < nLineBytes; ++cc) {
176 line2 = (line2 << 8) | (*pLine2++);
179 for (int32_t k = 7; k >= 0; --k) {
184 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
187 (((CONTEXT & kOptConstant6[OPT]) << 1) | bVal |
188 ((line2 >> (k + kOptConstant4[OPT])) & kOptConstant8[OPT]));
194 for (int32_t k = 0; k < nBitsLeft; ++k) {
198 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
199 cVal1 |= bVal << (7 - k);
200 CONTEXT = (((CONTEXT & kOptConstant6[OPT]) << 1) | bVal |
201 (((line2 >> (7 + kOptConstant4[OPT] - k))) &
202 kOptConstant8[OPT]));
204 pLine[nLineBytes] = cVal1;
213std::unique_ptr<CJBig2_Image>
CJBig2_GRDProc::DecodeArithTemplateUnopt(
215 pdfium::span<JBig2ArithCtx> gbContexts,
223 uint8_t MOD2 = UNOPT % 2;
224 uint8_t DIV2 = UNOPT / 2;
225 uint8_t SHIFT = 4 - UNOPT;
226 for (uint32_t h = 0; h <
GBH; h++) {
231 LTP = LTP ^ pArithDecoder
->Decode(&gbContexts[kOptConstant1[UNOPT]]
);
234 GBREG->CopyLine(h, h - 1);
237 uint32_t line1 = GBREG->GetPixel(1 + MOD2, h - 2);
238 line1 |= GBREG->GetPixel(MOD2, h - 2) << 1;
240 line1 |= GBREG->GetPixel(0, h - 2) << 2;
241 uint32_t line2 = GBREG->GetPixel(2 - DIV2, h - 1);
242 line2 |= GBREG->GetPixel(1 - DIV2, h - 1) << 1;
244 line2 |= GBREG->GetPixel(0, h - 1) << 2;
246 for (uint32_t w = 0; w <
GBW; w++) {
248 if (!USESKIP || !SKIP->GetPixel(w, h)) {
252 uint32_t CONTEXT = line3;
253 CONTEXT |= GBREG->GetPixel(w + GBAT[0], h + GBAT[1]) << SHIFT;
254 CONTEXT |= line2 << (SHIFT + 1);
255 CONTEXT |= line1 << kOptConstant9[UNOPT];
257 CONTEXT |= GBREG->GetPixel(w + GBAT[2], h + GBAT[3]) << 10;
258 CONTEXT |= GBREG->GetPixel(w + GBAT[4], h + GBAT[5]) << 11;
259 CONTEXT |= GBREG->GetPixel(w + GBAT[6], h + GBAT[7]) << 15;
261 bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
263 GBREG->SetPixel(w, h, bVal);
265 line1 = ((line1 << 1) | GBREG->GetPixel(w + 2 + MOD2, h - 2)) &
266 kOptConstant10[UNOPT];
267 line2 = ((line2 << 1) | GBREG->GetPixel(w + 3 - DIV2, h - 1)) &
268 kOptConstant11[UNOPT];
269 line3 = ((line3 << 1) | bVal) & kOptConstant12[UNOPT];
275std::unique_ptr<CJBig2_Image>
CJBig2_GRDProc::DecodeArithTemplate3Opt3(
277 pdfium::span<JBig2ArithCtx> gbContexts) {
283 uint8_t* pLine = GBREG->data();
284 int32_t nStride = GBREG->stride();
285 int32_t nLineBytes = ((
GBW + 7) >> 3) - 1;
286 int32_t nBitsLeft =
GBW - (nLineBytes << 3);
289 for (uint32_t h = 0; h <
GBH; h++) {
295 LTP = LTP ^ pArithDecoder
->Decode(&gbContexts[0x0195]
);
299 GBREG->CopyLine(h, h - 1);
302 uint8_t* pLine1 = pLine - nStride;
303 uint32_t line1 = *pLine1++;
304 uint32_t CONTEXT = (line1 >> 1) & 0x03f0;
305 for (int32_t cc = 0; cc < nLineBytes; cc++) {
306 line1 = (line1 << 8) | (*pLine1++);
308 for (int32_t k = 7; k >= 0; k--) {
313 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
315 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal |
316 ((line1 >> (k + 1)) & 0x0010);
322 for (int32_t k = 0; k < nBitsLeft; k++) {
326 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
327 cVal1 |= bVal << (7 - k);
328 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal |
329 ((line1 >> (8 - k)) & 0x0010);
331 pLine[nLineBytes] = cVal1;
333 uint32_t CONTEXT = 0;
334 for (int32_t cc = 0; cc < nLineBytes; cc++) {
336 for (int32_t k = 7; k >= 0; k--) {
341 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
343 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal;
348 for (int32_t k = 0; k < nBitsLeft; k++) {
352 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
353 cVal1 |= bVal << (7 - k);
354 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal;
356 pLine[nLineBytes] = cVal1;
365std::unique_ptr<CJBig2_Image>
CJBig2_GRDProc::DecodeArithTemplate3Unopt(
367 pdfium::span<JBig2ArithCtx> gbContexts) {
374 for (uint32_t h = 0; h <
GBH; h++) {
379 LTP = LTP ^ pArithDecoder
->Decode(&gbContexts[0x0195]
);
382 GBREG->CopyLine(h, h - 1);
384 uint32_t line1 = GBREG->GetPixel(1, h - 1);
385 line1 |= GBREG->GetPixel(0, h - 1) << 1;
387 for (uint32_t w = 0; w <
GBW; w++) {
389 if (USESKIP && SKIP->GetPixel(w, h)) {
392 uint32_t CONTEXT = line2;
393 CONTEXT |= GBREG->GetPixel(w + GBAT[0], h + GBAT[1]) << 4;
394 CONTEXT |= line1 << 5;
398 bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
401 GBREG->SetPixel(w, h, bVal);
403 line1 = ((line1 << 1) | GBREG->GetPixel(w + 2, h - 1)) & 0x1f;
404 line2 = ((line2 << 1) | bVal) & 0x0f;
418 std::unique_ptr<CJBig2_Image>* pImage = pState->pImage;
421 if (!(*pImage)->data()) {
426 pImage->get()->Fill(
false);
431 return ProgressiveDecodeArith(pState);
436 int iline = m_loopIndex;
443 func = UseTemplate0Opt3()
448 func = UseTemplate1Opt3()
453 func = UseTemplate23Opt3()
458 func = UseTemplate23Opt3()
464 m_ProgressiveStatus = func(*
this, pState);
465 m_ReplaceRect
.left = 0;
467 m_ReplaceRect
.top = iline;
468 m_ReplaceRect
.bottom = m_loopIndex;
472 return m_ProgressiveStatus;
476 std::unique_ptr<CJBig2_Image>* pImage,
479 if (!image->data()) {
482 return m_ProgressiveStatus;
485 bitpos = FaxModule::FaxG4Decode(pStream->getBufSpan(), bitpos,
GBW,
GBH,
486 image->stride(), image->data());
488 for (uint32_t i = 0; i < image->stride() *
GBH; ++i) {
492 *pImage =
std::move(image);
493 return m_ProgressiveStatus;
499 return m_ProgressiveStatus;
501 if (m_DecodeType != 1) {
503 return m_ProgressiveStatus;
505 return ProgressiveDecodeArith(pState);
511 pdfium::span<JBig2ArithCtx> gbContexts = pState->gbContexts;
516 int32_t nStride2 = nStride << 1;
517 int32_t nLineBytes = ((
GBW + 7) >> 3) - 1;
518 int32_t nBitsLeft =
GBW - (nLineBytes << 3);
519 uint32_t height =
GBH & 0x7fffffff;
522 for (; m_loopIndex < height; m_loopIndex++) {
528 m_LTP = m_LTP ^ pArithDecoder
->Decode(&gbContexts[0x9b25]
);
533 if (m_loopIndex > 1) {
534 uint8_t* pLine1 = m_pLine - nStride2;
535 uint8_t* pLine2 = m_pLine - nStride;
536 uint32_t line1 = (*pLine1++) << 6;
537 uint32_t line2 = *pLine2++;
538 uint32_t CONTEXT = ((line1 & 0xf800) | (line2 & 0x07f0));
539 for (int32_t cc = 0; cc < nLineBytes; cc++) {
540 line1 = (line1 << 8) | ((*pLine1++) << 6);
541 line2 = (line2 << 8) | (*pLine2++);
543 for (int32_t k = 7; k >= 0; k--) {
548 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
550 CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal |
551 ((line1 >> k) & 0x0800) | ((line2 >> k) & 0x0010));
558 for (int32_t k = 0; k < nBitsLeft; k++) {
562 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
563 cVal1 |= bVal << (7 - k);
565 (((CONTEXT & 0x7bf7) << 1) | bVal |
566 ((line1 >> (7 - k)) & 0x0800) | ((line2 >> (7 - k)) & 0x0010));
568 m_pLine[nLineBytes] = cVal1;
570 uint8_t* pLine2 = m_pLine - nStride;
571 uint32_t line2 = (m_loopIndex & 1) ? (*pLine2++) : 0;
572 uint32_t CONTEXT = (line2 & 0x07f0);
573 for (int32_t cc = 0; cc < nLineBytes; cc++) {
574 if (m_loopIndex & 1) {
575 line2 = (line2 << 8) | (*pLine2++);
578 for (int32_t k = 7; k >= 0; k--) {
583 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
586 (((CONTEXT & 0x7bf7) << 1) | bVal | ((line2 >> k) & 0x0010));
592 for (int32_t k = 0; k < nBitsLeft; k++) {
597 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
598 cVal1 |= bVal << (7 - k);
599 CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal |
600 ((line2 >> (7 - k)) & 0x0010));
602 m_pLine[nLineBytes] = cVal1;
606 if (pState->pPause && pState->pPause->NeedToPauseNow()) {
620 pdfium::span<JBig2ArithCtx> gbContexts = pState->gbContexts;
622 for (; m_loopIndex <
GBH; m_loopIndex++) {
627 m_LTP = m_LTP ^ pArithDecoder
->Decode(&gbContexts[0x9b25]
);
638 for (uint32_t w = 0; w <
GBW; w++) {
640 if (USESKIP && SKIP->GetPixel(w, m_loopIndex)) {
643 uint32_t CONTEXT = line3;
644 CONTEXT |= pImage->GetPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 4;
645 CONTEXT |= line2 << 5;
646 CONTEXT |= pImage->GetPixel(w + GBAT[2], m_loopIndex + GBAT[3]) << 10;
647 CONTEXT |= pImage->GetPixel(w + GBAT[4], m_loopIndex + GBAT[5]) << 11;
648 CONTEXT |= line1 << 12;
649 CONTEXT |= pImage->GetPixel(w + GBAT[6], m_loopIndex + GBAT[7]) << 15;
653 bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
659 ((line1 << 1) | pImage
->GetPixel(w + 2
, m_loopIndex - 2
)) & 0x07;
661 ((line2 << 1) | pImage
->GetPixel(w + 3
, m_loopIndex - 1
)) & 0x1f;
662 line3 = ((line3 << 1) | bVal) & 0x0f;
665 if (pState->pPause && pState->pPause->NeedToPauseNow()) {
678 pdfium::span<JBig2ArithCtx> gbContexts = pState->gbContexts;
683 int32_t nStride2 = nStride << 1;
684 int32_t nLineBytes = ((
GBW + 7) >> 3) - 1;
685 int32_t nBitsLeft =
GBW - (nLineBytes << 3);
688 for (; m_loopIndex <
GBH; m_loopIndex++) {
694 m_LTP = m_LTP ^ pArithDecoder
->Decode(&gbContexts[0x0795]
);
699 if (m_loopIndex > 1) {
700 uint8_t* pLine1 = m_pLine - nStride2;
701 uint8_t* pLine2 = m_pLine - nStride;
702 uint32_t line1 = (*pLine1++) << 4;
703 uint32_t line2 = *pLine2++;
704 uint32_t CONTEXT = (line1 & 0x1e00) | ((line2 >> 1) & 0x01f8);
705 for (int32_t cc = 0; cc < nLineBytes; cc++) {
706 line1 = (line1 << 8) | ((*pLine1++) << 4);
707 line2 = (line2 << 8) | (*pLine2++);
709 for (int32_t k = 7; k >= 0; k--) {
714 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
716 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal |
717 ((line1 >> k) & 0x0200) | ((line2 >> (k + 1)) & 0x0008);
724 for (int32_t k = 0; k < nBitsLeft; k++) {
728 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
729 cVal1 |= bVal << (7 - k);
730 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal |
731 ((line1 >> (7 - k)) & 0x0200) |
732 ((line2 >> (8 - k)) & 0x0008);
734 m_pLine[nLineBytes] = cVal1;
736 uint8_t* pLine2 = m_pLine - nStride;
737 uint32_t line2 = (m_loopIndex & 1) ? (*pLine2++) : 0;
738 uint32_t CONTEXT = (line2 >> 1) & 0x01f8;
739 for (int32_t cc = 0; cc < nLineBytes; cc++) {
740 if (m_loopIndex & 1) {
741 line2 = (line2 << 8) | (*pLine2++);
744 for (int32_t k = 7; k >= 0; k--) {
749 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
751 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal |
752 ((line2 >> (k + 1)) & 0x0008);
758 for (int32_t k = 0; k < nBitsLeft; k++) {
762 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
763 cVal1 |= bVal << (7 - k);
764 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal |
765 ((line2 >> (8 - k)) & 0x0008);
767 m_pLine[nLineBytes] = cVal1;
771 if (pState->pPause && pState->pPause->NeedToPauseNow()) {
785 pdfium::span<JBig2ArithCtx> gbContexts = pState->gbContexts;
787 for (uint32_t h = 0; h <
GBH; h++) {
792 m_LTP = m_LTP ^ pArithDecoder
->Decode(&gbContexts[0x0795]
);
804 for (uint32_t w = 0; w <
GBW; w++) {
806 if (USESKIP && SKIP->GetPixel(w, h)) {
809 uint32_t CONTEXT = line3;
810 CONTEXT |= pImage->GetPixel(w + GBAT[0], h + GBAT[1]) << 3;
811 CONTEXT |= line2 << 4;
812 CONTEXT |= line1 << 9;
816 bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
821 line1 = ((line1 << 1) | pImage
->GetPixel(w + 3
, h - 2
)) & 0x0f;
822 line2 = ((line2 << 1) | pImage
->GetPixel(w + 3
, h - 1
)) & 0x1f;
823 line3 = ((line3 << 1) | bVal) & 0x07;
826 if (pState->pPause && pState->pPause->NeedToPauseNow()) {
839 pdfium::span<JBig2ArithCtx> gbContexts = pState->gbContexts;
844 int32_t nStride2 = nStride << 1;
845 int32_t nLineBytes = ((
GBW + 7) >> 3) - 1;
846 int32_t nBitsLeft =
GBW - (nLineBytes << 3);
848 for (; m_loopIndex <
GBH; m_loopIndex++) {
854 m_LTP = m_LTP ^ pArithDecoder
->Decode(&gbContexts[0x00e5]
);
859 if (m_loopIndex > 1) {
860 uint8_t* pLine1 = m_pLine - nStride2;
861 uint8_t* pLine2 = m_pLine - nStride;
862 uint32_t line1 = (*pLine1++) << 1;
863 uint32_t line2 = *pLine2++;
864 uint32_t CONTEXT = (line1 & 0x0380) | ((line2 >> 3) & 0x007c);
865 for (int32_t cc = 0; cc < nLineBytes; cc++) {
866 line1 = (line1 << 8) | ((*pLine1++) << 1);
867 line2 = (line2 << 8) | (*pLine2++);
869 for (int32_t k = 7; k >= 0; k--) {
874 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
876 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
877 ((line1 >> k) & 0x0080) | ((line2 >> (k + 3)) & 0x0004);
884 for (int32_t k = 0; k < nBitsLeft; k++) {
888 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
889 cVal1 |= bVal << (7 - k);
890 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
891 ((line1 >> (7 - k)) & 0x0080) |
892 ((line2 >> (10 - k)) & 0x0004);
894 m_pLine[nLineBytes] = cVal1;
896 uint8_t* pLine2 = m_pLine - nStride;
897 uint32_t line2 = (m_loopIndex & 1) ? (*pLine2++) : 0;
898 uint32_t CONTEXT = (line2 >> 3) & 0x007c;
899 for (int32_t cc = 0; cc < nLineBytes; cc++) {
900 if (m_loopIndex & 1) {
901 line2 = (line2 << 8) | (*pLine2++);
904 for (int32_t k = 7; k >= 0; k--) {
909 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
911 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
912 ((line2 >> (k + 3)) & 0x0004);
918 for (int32_t k = 0; k < nBitsLeft; k++) {
922 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
923 cVal1 |= bVal << (7 - k);
924 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
925 (((line2 >> (10 - k))) & 0x0004);
927 m_pLine[nLineBytes] = cVal1;
931 if (pState->pPause && m_loopIndex % 50 == 0 &&
932 pState->pPause->NeedToPauseNow()) {
946 pdfium::span<JBig2ArithCtx> gbContexts = pState->gbContexts;
948 for (; m_loopIndex <
GBH; m_loopIndex++) {
953 m_LTP = m_LTP ^ pArithDecoder
->Decode(&gbContexts[0x00e5]
);
963 for (uint32_t w = 0; w <
GBW; w++) {
965 if (USESKIP && SKIP->GetPixel(w, m_loopIndex)) {
968 uint32_t CONTEXT = line3;
969 CONTEXT |= pImage->GetPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 2;
970 CONTEXT |= line2 << 3;
971 CONTEXT |= line1 << 7;
975 bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
981 ((line1 << 1) | pImage
->GetPixel(w + 2
, m_loopIndex - 2
)) & 0x07;
983 ((line2 << 1) | pImage
->GetPixel(w + 2
, m_loopIndex - 1
)) & 0x0f;
984 line3 = ((line3 << 1) | bVal) & 0x03;
987 if (pState->pPause && pState->pPause->NeedToPauseNow()) {
1000 pdfium::span<JBig2ArithCtx> gbContexts = pState->gbContexts;
1005 int32_t nLineBytes = ((
GBW + 7) >> 3) - 1;
1006 int32_t nBitsLeft =
GBW - (nLineBytes << 3);
1008 for (; m_loopIndex <
GBH; m_loopIndex++) {
1014 m_LTP = m_LTP ^ pArithDecoder
->Decode(&gbContexts[0x0195]
);
1019 if (m_loopIndex > 0) {
1020 uint8_t* pLine1 = m_pLine - nStride;
1021 uint32_t line1 = *pLine1++;
1022 uint32_t CONTEXT = (line1 >> 1) & 0x03f0;
1023 for (int32_t cc = 0; cc < nLineBytes; cc++) {
1024 line1 = (line1 << 8) | (*pLine1++);
1026 for (int32_t k = 7; k >= 0; k--) {
1031 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
1033 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal |
1034 ((line1 >> (k + 1)) & 0x0010);
1040 for (int32_t k = 0; k < nBitsLeft; k++) {
1044 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
1045 cVal1 |= bVal << (7 - k);
1046 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal |
1047 ((line1 >> (8 - k)) & 0x0010);
1049 m_pLine[nLineBytes] = cVal1;
1051 uint32_t CONTEXT = 0;
1052 for (int32_t cc = 0; cc < nLineBytes; cc++) {
1054 for (int32_t k = 7; k >= 0; k--) {
1059 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
1061 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal;
1066 for (int32_t k = 0; k < nBitsLeft; k++) {
1070 int bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
1071 cVal1 |= bVal << (7 - k);
1072 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal;
1074 m_pLine[nLineBytes] = cVal1;
1078 if (pState->pPause && pState->pPause->NeedToPauseNow()) {
1092 pdfium::span<JBig2ArithCtx> gbContexts = pState->gbContexts;
1094 for (; m_loopIndex <
GBH; m_loopIndex++) {
1099 m_LTP = m_LTP ^ pArithDecoder
->Decode(&gbContexts[0x0195]
);
1107 for (uint32_t w = 0; w <
GBW; w++) {
1109 if (USESKIP && SKIP->GetPixel(w, m_loopIndex)) {
1112 uint32_t CONTEXT = line2;
1113 CONTEXT |= pImage->GetPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 4;
1114 CONTEXT |= line1 << 5;
1118 bVal = pArithDecoder
->Decode(&gbContexts[CONTEXT]
);
1124 ((line1 << 1) | pImage
->GetPixel(w + 2
, m_loopIndex - 1
)) & 0x1f;
1125 line2 = ((line2 << 1) | bVal) & 0x0f;
1128 if (pState->pPause && pState->pPause->NeedToPauseNow()) {
int Decode(JBig2ArithCtx *pCX)
uint32_t getBitPos() const
void setBitPos(uint32_t dwBitPos)
~ProgressiveArithDecodeState()
ProgressiveArithDecodeState()
FXCODEC_STATUS StartDecodeMMR(std::unique_ptr< CJBig2_Image > *pImage, CJBig2_BitStream *pStream)
std::unique_ptr< CJBig2_Image > DecodeArith(CJBig2_ArithDecoder *pArithDecoder, pdfium::span< JBig2ArithCtx > gbContexts)
FXCODEC_STATUS ContinueDecode(ProgressiveArithDecodeState *pState)
FXCODEC_STATUS StartDecodeArith(ProgressiveArithDecodeState *pState)
void SetPixel(int32_t x, int32_t y, int v)
void CopyLine(int32_t hTo, int32_t hFrom)
static bool IsValidImageSize(int32_t w, int32_t h)
int GetPixel(int32_t x, int32_t y) const