7#include "core/fxcodec/jbig2/JBig2_GrdProc.h"
13#include "core/fxcodec/fax/faxmodule.h"
14#include "core/fxcodec/jbig2/JBig2_ArithDecoder.h"
15#include "core/fxcodec/jbig2/JBig2_BitStream.h"
16#include "core/fxcodec/jbig2/JBig2_Image.h"
17#include "core/fxcrt/pauseindicator_iface.h"
22constexpr uint16_t kOptConstant1[] = {0x9b25, 0x0795, 0x00e5};
23constexpr uint16_t kOptConstant2[] = {0x0006, 0x0004, 0x0001};
24constexpr uint16_t kOptConstant3[] = {0xf800, 0x1e00, 0x0380};
25constexpr uint16_t kOptConstant4[] = {0x0000, 0x0001, 0x0003};
26constexpr uint16_t kOptConstant5[] = {0x07f0, 0x01f8, 0x007c};
27constexpr uint16_t kOptConstant6[] = {0x7bf7, 0x0efb, 0x01bd};
28constexpr uint16_t kOptConstant7[] = {0x0800, 0x0200, 0x0080};
29constexpr uint16_t kOptConstant8[] = {0x0010, 0x0008, 0x0004};
30constexpr uint16_t kOptConstant9[] = {0x000c, 0x0009, 0x0007};
31constexpr uint16_t kOptConstant10[] = {0x0007, 0x000f, 0x0007};
32constexpr uint16_t kOptConstant11[] = {0x001f, 0x001f, 0x000f};
33constexpr uint16_t kOptConstant12[] = {0x000f, 0x0007, 0x0003};
48 return (
GBAT[0] == 3) && (
GBAT[1] == -1) && (
GBAT[2] == -3) &&
54 return (
GBAT[0] == 3) && (
GBAT[1] == -1);
58 return (
GBAT[0] == 2) && (
GBAT[1] == -1);
69 return UseTemplate0Opt3()
70 ? DecodeArithOpt3(pArithDecoder, gbContext, 0)
71 : DecodeArithTemplateUnopt(pArithDecoder, gbContext, 0);
73 return UseTemplate1Opt3()
74 ? DecodeArithOpt3(pArithDecoder, gbContext, 1)
75 : DecodeArithTemplateUnopt(pArithDecoder, gbContext, 1);
77 return UseTemplate23Opt3()
78 ? DecodeArithOpt3(pArithDecoder, gbContext, 2)
79 : DecodeArithTemplateUnopt(pArithDecoder, gbContext, 2);
81 return UseTemplate23Opt3()
82 ? DecodeArithTemplate3Opt3(pArithDecoder, gbContext)
83 : DecodeArithTemplate3Unopt(pArithDecoder, gbContext);
96 uint8_t* pLine = GBREG->data();
97 int32_t nStride = GBREG->stride();
98 int32_t nStride2 = nStride << 1;
99 int32_t nLineBytes = ((
GBW + 7) >> 3) - 1;
100 int32_t nBitsLeft =
GBW - (nLineBytes << 3);
102 uint32_t height = OPT == 0 ?
GBH & 0x7fffffff :
GBH;
103 for (uint32_t h = 0; h < height; ++h) {
108 LTP = LTP ^ pArithDecoder
->Decode(&gbContext[kOptConstant1[OPT]]
);
111 GBREG->CopyLine(h, h - 1);
114 uint8_t* pLine1 = pLine - nStride2;
115 uint8_t* pLine2 = pLine - nStride;
116 uint32_t line1 = (*pLine1++) << kOptConstant2[OPT];
117 uint32_t line2 = *pLine2++;
118 uint32_t CONTEXT = (line1 & kOptConstant3[OPT]) |
119 ((line2 >> kOptConstant4[OPT]) & kOptConstant5[OPT]);
120 for (int32_t cc = 0; cc < nLineBytes; ++cc) {
121 line1 = (line1 << 8) | ((*pLine1++) << kOptConstant2[OPT]);
122 line2 = (line2 << 8) | (*pLine2++);
124 for (int32_t k = 7; k >= 0; --k) {
128 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
131 (((CONTEXT & kOptConstant6[OPT]) << 1) | bVal |
132 ((line1 >> k) & kOptConstant7[OPT]) |
133 ((line2 >> (k + kOptConstant4[OPT])) & kOptConstant8[OPT]));
140 for (int32_t k = 0; k < nBitsLeft; ++k) {
144 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
145 cVal1 |= bVal << (7 - k);
147 (((CONTEXT & kOptConstant6[OPT]) << 1) | bVal |
148 ((line1 >> (7 - k)) & kOptConstant7[OPT]) |
149 ((line2 >> (7 + kOptConstant4[OPT] - k)) & kOptConstant8[OPT]));
151 pLine[nLineBytes] = cVal1;
153 uint8_t* pLine2 = pLine - nStride;
154 uint32_t line2 = (h & 1) ? (*pLine2++) : 0;
155 uint32_t CONTEXT = ((line2 >> kOptConstant4[OPT]) & kOptConstant5[OPT]);
156 for (int32_t cc = 0; cc < nLineBytes; ++cc) {
158 line2 = (line2 << 8) | (*pLine2++);
161 for (int32_t k = 7; k >= 0; --k) {
165 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
168 (((CONTEXT & kOptConstant6[OPT]) << 1) | bVal |
169 ((line2 >> (k + kOptConstant4[OPT])) & kOptConstant8[OPT]));
175 for (int32_t k = 0; k < nBitsLeft; ++k) {
179 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
180 cVal1 |= bVal << (7 - k);
181 CONTEXT = (((CONTEXT & kOptConstant6[OPT]) << 1) | bVal |
182 (((line2 >> (7 + kOptConstant4[OPT] - k))) &
183 kOptConstant8[OPT]));
185 pLine[nLineBytes] = cVal1;
193std::unique_ptr<CJBig2_Image>
CJBig2_GRDProc::DecodeArithTemplateUnopt(
203 uint8_t MOD2 = UNOPT % 2;
204 uint8_t DIV2 = UNOPT / 2;
205 uint8_t SHIFT = 4 - UNOPT;
206 for (uint32_t h = 0; h <
GBH; h++) {
211 LTP = LTP ^ pArithDecoder
->Decode(&gbContext[kOptConstant1[UNOPT]]
);
214 GBREG->CopyLine(h, h - 1);
217 uint32_t line1 = GBREG->GetPixel(1 + MOD2, h - 2);
218 line1 |= GBREG->GetPixel(MOD2, h - 2) << 1;
220 line1 |= GBREG->GetPixel(0, h - 2) << 2;
221 uint32_t line2 = GBREG->GetPixel(2 - DIV2, h - 1);
222 line2 |= GBREG->GetPixel(1 - DIV2, h - 1) << 1;
224 line2 |= GBREG->GetPixel(0, h - 1) << 2;
226 for (uint32_t w = 0; w <
GBW; w++) {
228 if (!USESKIP || !SKIP->GetPixel(w, h)) {
232 uint32_t CONTEXT = line3;
233 CONTEXT |= GBREG->GetPixel(w +
GBAT[0], h +
GBAT[1]) << SHIFT;
234 CONTEXT |= line2 << (SHIFT + 1);
235 CONTEXT |= line1 << kOptConstant9[UNOPT];
237 CONTEXT |= GBREG->GetPixel(w +
GBAT[2], h +
GBAT[3]) << 10;
238 CONTEXT |= GBREG->GetPixel(w +
GBAT[4], h +
GBAT[5]) << 11;
239 CONTEXT |= GBREG->GetPixel(w +
GBAT[6], h +
GBAT[7]) << 15;
241 bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
243 GBREG->SetPixel(w, h, bVal);
245 line1 = ((line1 << 1) | GBREG->GetPixel(w + 2 + MOD2, h - 2)) &
246 kOptConstant10[UNOPT];
247 line2 = ((line2 << 1) | GBREG->GetPixel(w + 3 - DIV2, h - 1)) &
248 kOptConstant11[UNOPT];
249 line3 = ((line3 << 1) | bVal) & kOptConstant12[UNOPT];
255std::unique_ptr<CJBig2_Image>
CJBig2_GRDProc::DecodeArithTemplate3Opt3(
263 uint8_t* pLine = GBREG->data();
264 int32_t nStride = GBREG->stride();
265 int32_t nLineBytes = ((
GBW + 7) >> 3) - 1;
266 int32_t nBitsLeft =
GBW - (nLineBytes << 3);
268 for (uint32_t h = 0; h <
GBH; h++) {
273 LTP = LTP ^ pArithDecoder
->Decode(&gbContext[0x0195]
);
277 GBREG->CopyLine(h, h - 1);
280 uint8_t* pLine1 = pLine - nStride;
281 uint32_t line1 = *pLine1++;
282 uint32_t CONTEXT = (line1 >> 1) & 0x03f0;
283 for (int32_t cc = 0; cc < nLineBytes; cc++) {
284 line1 = (line1 << 8) | (*pLine1++);
286 for (int32_t k = 7; k >= 0; k--) {
290 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
292 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal |
293 ((line1 >> (k + 1)) & 0x0010);
299 for (int32_t k = 0; k < nBitsLeft; k++) {
303 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
304 cVal1 |= bVal << (7 - k);
306 ((CONTEXT & 0x01f7) << 1) | bVal | ((line1 >> (8 - k)) & 0x0010);
308 pLine[nLineBytes] = cVal1;
310 uint32_t CONTEXT = 0;
311 for (int32_t cc = 0; cc < nLineBytes; cc++) {
313 for (int32_t k = 7; k >= 0; k--) {
317 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
319 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal;
324 for (int32_t k = 0; k < nBitsLeft; k++) {
328 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
329 cVal1 |= bVal << (7 - k);
330 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal;
332 pLine[nLineBytes] = cVal1;
340std::unique_ptr<CJBig2_Image>
CJBig2_GRDProc::DecodeArithTemplate3Unopt(
349 for (uint32_t h = 0; h <
GBH; h++) {
354 LTP = LTP ^ pArithDecoder
->Decode(&gbContext[0x0195]
);
357 GBREG->CopyLine(h, h - 1);
359 uint32_t line1 = GBREG->GetPixel(1, h - 1);
360 line1 |= GBREG->GetPixel(0, h - 1) << 1;
362 for (uint32_t w = 0; w <
GBW; w++) {
364 if (USESKIP && SKIP->GetPixel(w, h)) {
367 uint32_t CONTEXT = line2;
368 CONTEXT |= GBREG->GetPixel(w +
GBAT[0], h +
GBAT[1]) << 4;
369 CONTEXT |= line1 << 5;
373 bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
376 GBREG->SetPixel(w, h, bVal);
378 line1 = ((line1 << 1) | GBREG->GetPixel(w + 2, h - 1)) & 0x1f;
379 line2 = ((line2 << 1) | bVal) & 0x0f;
393 std::unique_ptr<CJBig2_Image>* pImage = pState->pImage;
396 if (!(*pImage)->data()) {
401 pImage->get()->Fill(
false);
406 return ProgressiveDecodeArith(pState);
411 int iline = m_loopIndex;
418 func = UseTemplate0Opt3()
423 func = UseTemplate1Opt3()
428 func = UseTemplate23Opt3()
433 func = UseTemplate23Opt3()
439 m_ProgressiveStatus = func(*
this, pState);
440 m_ReplaceRect
.left = 0;
442 m_ReplaceRect
.top = iline;
443 m_ReplaceRect
.bottom = m_loopIndex;
447 return m_ProgressiveStatus;
451 std::unique_ptr<CJBig2_Image>* pImage,
454 if (!image->data()) {
457 return m_ProgressiveStatus;
464 for (uint32_t i = 0; i < image->stride() *
GBH; ++i)
465 image->data()[i] = ~image->data()[i];
467 *pImage =
std::move(image);
468 return m_ProgressiveStatus;
474 return m_ProgressiveStatus;
476 if (m_DecodeType != 1) {
478 return m_ProgressiveStatus;
480 return ProgressiveDecodeArith(pState);
491 int32_t nStride2 = nStride << 1;
492 int32_t nLineBytes = ((
GBW + 7) >> 3) - 1;
493 int32_t nBitsLeft =
GBW - (nLineBytes << 3);
494 uint32_t height =
GBH & 0x7fffffff;
496 for (; m_loopIndex < height; m_loopIndex++) {
501 m_LTP = m_LTP ^ pArithDecoder
->Decode(&gbContext[0x9b25]
);
506 if (m_loopIndex > 1) {
507 uint8_t* pLine1 = m_pLine - nStride2;
508 uint8_t* pLine2 = m_pLine - nStride;
509 uint32_t line1 = (*pLine1++) << 6;
510 uint32_t line2 = *pLine2++;
511 uint32_t CONTEXT = ((line1 & 0xf800) | (line2 & 0x07f0));
512 for (int32_t cc = 0; cc < nLineBytes; cc++) {
513 line1 = (line1 << 8) | ((*pLine1++) << 6);
514 line2 = (line2 << 8) | (*pLine2++);
516 for (int32_t k = 7; k >= 0; k--) {
520 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
522 CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal |
523 ((line1 >> k) & 0x0800) | ((line2 >> k) & 0x0010));
530 for (int32_t k = 0; k < nBitsLeft; k++) {
534 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
535 cVal1 |= bVal << (7 - k);
537 (((CONTEXT & 0x7bf7) << 1) | bVal |
538 ((line1 >> (7 - k)) & 0x0800) | ((line2 >> (7 - k)) & 0x0010));
540 m_pLine[nLineBytes] = cVal1;
542 uint8_t* pLine2 = m_pLine - nStride;
543 uint32_t line2 = (m_loopIndex & 1) ? (*pLine2++) : 0;
544 uint32_t CONTEXT = (line2 & 0x07f0);
545 for (int32_t cc = 0; cc < nLineBytes; cc++) {
546 if (m_loopIndex & 1) {
547 line2 = (line2 << 8) | (*pLine2++);
550 for (int32_t k = 7; k >= 0; k--) {
554 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
557 (((CONTEXT & 0x7bf7) << 1) | bVal | ((line2 >> k) & 0x0010));
563 for (int32_t k = 0; k < nBitsLeft; k++) {
567 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
568 cVal1 |= bVal << (7 - k);
569 CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal |
570 ((line2 >> (7 - k)) & 0x0010));
572 m_pLine[nLineBytes] = cVal1;
576 if (pState->pPause && pState->pPause->NeedToPauseNow()) {
591 for (; m_loopIndex <
GBH; m_loopIndex++) {
596 m_LTP = m_LTP ^ pArithDecoder
->Decode(&gbContext[0x9b25]
);
607 for (uint32_t w = 0; w <
GBW; w++) {
609 if (USESKIP && SKIP->GetPixel(w, m_loopIndex)) {
612 uint32_t CONTEXT = line3;
614 CONTEXT |= line2 << 5;
617 CONTEXT |= line1 << 12;
622 bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
628 ((line1 << 1) | pImage
->GetPixel(w + 2
, m_loopIndex - 2
)) & 0x07;
630 ((line2 << 1) | pImage
->GetPixel(w + 3
, m_loopIndex - 1
)) & 0x1f;
631 line3 = ((line3 << 1) | bVal) & 0x0f;
634 if (pState->pPause && pState->pPause->NeedToPauseNow()) {
652 int32_t nStride2 = nStride << 1;
653 int32_t nLineBytes = ((
GBW + 7) >> 3) - 1;
654 int32_t nBitsLeft =
GBW - (nLineBytes << 3);
655 for (; m_loopIndex <
GBH; m_loopIndex++) {
660 m_LTP = m_LTP ^ pArithDecoder
->Decode(&gbContext[0x0795]
);
665 if (m_loopIndex > 1) {
666 uint8_t* pLine1 = m_pLine - nStride2;
667 uint8_t* pLine2 = m_pLine - nStride;
668 uint32_t line1 = (*pLine1++) << 4;
669 uint32_t line2 = *pLine2++;
670 uint32_t CONTEXT = (line1 & 0x1e00) | ((line2 >> 1) & 0x01f8);
671 for (int32_t cc = 0; cc < nLineBytes; cc++) {
672 line1 = (line1 << 8) | ((*pLine1++) << 4);
673 line2 = (line2 << 8) | (*pLine2++);
675 for (int32_t k = 7; k >= 0; k--) {
679 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
681 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal |
682 ((line1 >> k) & 0x0200) | ((line2 >> (k + 1)) & 0x0008);
689 for (int32_t k = 0; k < nBitsLeft; k++) {
693 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
694 cVal1 |= bVal << (7 - k);
695 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal |
696 ((line1 >> (7 - k)) & 0x0200) |
697 ((line2 >> (8 - k)) & 0x0008);
699 m_pLine[nLineBytes] = cVal1;
701 uint8_t* pLine2 = m_pLine - nStride;
702 uint32_t line2 = (m_loopIndex & 1) ? (*pLine2++) : 0;
703 uint32_t CONTEXT = (line2 >> 1) & 0x01f8;
704 for (int32_t cc = 0; cc < nLineBytes; cc++) {
705 if (m_loopIndex & 1) {
706 line2 = (line2 << 8) | (*pLine2++);
709 for (int32_t k = 7; k >= 0; k--) {
713 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
715 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal |
716 ((line2 >> (k + 1)) & 0x0008);
722 for (int32_t k = 0; k < nBitsLeft; k++) {
726 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
727 cVal1 |= bVal << (7 - k);
729 ((CONTEXT & 0x0efb) << 1) | bVal | ((line2 >> (8 - k)) & 0x0008);
731 m_pLine[nLineBytes] = cVal1;
735 if (pState->pPause && pState->pPause->NeedToPauseNow()) {
750 for (uint32_t h = 0; h <
GBH; h++) {
755 m_LTP = m_LTP ^ pArithDecoder
->Decode(&gbContext[0x0795]
);
767 for (uint32_t w = 0; w <
GBW; w++) {
769 if (USESKIP && SKIP->GetPixel(w, h)) {
772 uint32_t CONTEXT = line3;
774 CONTEXT |= line2 << 4;
775 CONTEXT |= line1 << 9;
779 bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
784 line1 = ((line1 << 1) | pImage
->GetPixel(w + 3
, h - 2
)) & 0x0f;
785 line2 = ((line2 << 1) | pImage
->GetPixel(w + 3
, h - 1
)) & 0x1f;
786 line3 = ((line3 << 1) | bVal) & 0x07;
789 if (pState->pPause && pState->pPause->NeedToPauseNow()) {
807 int32_t nStride2 = nStride << 1;
808 int32_t nLineBytes = ((
GBW + 7) >> 3) - 1;
809 int32_t nBitsLeft =
GBW - (nLineBytes << 3);
810 for (; m_loopIndex <
GBH; m_loopIndex++) {
815 m_LTP = m_LTP ^ pArithDecoder
->Decode(&gbContext[0x00e5]
);
820 if (m_loopIndex > 1) {
821 uint8_t* pLine1 = m_pLine - nStride2;
822 uint8_t* pLine2 = m_pLine - nStride;
823 uint32_t line1 = (*pLine1++) << 1;
824 uint32_t line2 = *pLine2++;
825 uint32_t CONTEXT = (line1 & 0x0380) | ((line2 >> 3) & 0x007c);
826 for (int32_t cc = 0; cc < nLineBytes; cc++) {
827 line1 = (line1 << 8) | ((*pLine1++) << 1);
828 line2 = (line2 << 8) | (*pLine2++);
830 for (int32_t k = 7; k >= 0; k--) {
834 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
836 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
837 ((line1 >> k) & 0x0080) | ((line2 >> (k + 3)) & 0x0004);
844 for (int32_t k = 0; k < nBitsLeft; k++) {
848 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
849 cVal1 |= bVal << (7 - k);
850 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
851 ((line1 >> (7 - k)) & 0x0080) |
852 ((line2 >> (10 - k)) & 0x0004);
854 m_pLine[nLineBytes] = cVal1;
856 uint8_t* pLine2 = m_pLine - nStride;
857 uint32_t line2 = (m_loopIndex & 1) ? (*pLine2++) : 0;
858 uint32_t CONTEXT = (line2 >> 3) & 0x007c;
859 for (int32_t cc = 0; cc < nLineBytes; cc++) {
860 if (m_loopIndex & 1) {
861 line2 = (line2 << 8) | (*pLine2++);
864 for (int32_t k = 7; k >= 0; k--) {
868 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
870 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
871 ((line2 >> (k + 3)) & 0x0004);
877 for (int32_t k = 0; k < nBitsLeft; k++) {
881 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
882 cVal1 |= bVal << (7 - k);
883 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
884 (((line2 >> (10 - k))) & 0x0004);
886 m_pLine[nLineBytes] = cVal1;
890 if (pState->pPause && m_loopIndex % 50 == 0 &&
891 pState->pPause->NeedToPauseNow()) {
906 for (; m_loopIndex <
GBH; m_loopIndex++) {
911 m_LTP = m_LTP ^ pArithDecoder
->Decode(&gbContext[0x00e5]
);
921 for (uint32_t w = 0; w <
GBW; w++) {
923 if (USESKIP && SKIP->GetPixel(w, m_loopIndex)) {
926 uint32_t CONTEXT = line3;
928 CONTEXT |= line2 << 3;
929 CONTEXT |= line1 << 7;
933 bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
939 ((line1 << 1) | pImage
->GetPixel(w + 2
, m_loopIndex - 2
)) & 0x07;
941 ((line2 << 1) | pImage
->GetPixel(w + 2
, m_loopIndex - 1
)) & 0x0f;
942 line3 = ((line3 << 1) | bVal) & 0x03;
945 if (pState->pPause && pState->pPause->NeedToPauseNow()) {
963 int32_t nLineBytes = ((
GBW + 7) >> 3) - 1;
964 int32_t nBitsLeft =
GBW - (nLineBytes << 3);
965 for (; m_loopIndex <
GBH; m_loopIndex++) {
970 m_LTP = m_LTP ^ pArithDecoder
->Decode(&gbContext[0x0195]
);
975 if (m_loopIndex > 0) {
976 uint8_t* pLine1 = m_pLine - nStride;
977 uint32_t line1 = *pLine1++;
978 uint32_t CONTEXT = (line1 >> 1) & 0x03f0;
979 for (int32_t cc = 0; cc < nLineBytes; cc++) {
980 line1 = (line1 << 8) | (*pLine1++);
982 for (int32_t k = 7; k >= 0; k--) {
986 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
988 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal |
989 ((line1 >> (k + 1)) & 0x0010);
995 for (int32_t k = 0; k < nBitsLeft; k++) {
999 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
1000 cVal1 |= bVal << (7 - k);
1002 ((CONTEXT & 0x01f7) << 1) | bVal | ((line1 >> (8 - k)) & 0x0010);
1004 m_pLine[nLineBytes] = cVal1;
1006 uint32_t CONTEXT = 0;
1007 for (int32_t cc = 0; cc < nLineBytes; cc++) {
1009 for (int32_t k = 7; k >= 0; k--) {
1013 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
1015 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal;
1020 for (int32_t k = 0; k < nBitsLeft; k++) {
1024 int bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
1025 cVal1 |= bVal << (7 - k);
1026 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal;
1028 m_pLine[nLineBytes] = cVal1;
1032 if (pState->pPause && pState->pPause->NeedToPauseNow()) {
1047 for (; m_loopIndex <
GBH; m_loopIndex++) {
1052 m_LTP = m_LTP ^ pArithDecoder
->Decode(&gbContext[0x0195]
);
1060 for (uint32_t w = 0; w <
GBW; w++) {
1062 if (USESKIP && SKIP->GetPixel(w, m_loopIndex)) {
1065 uint32_t CONTEXT = line2;
1067 CONTEXT |= line1 << 5;
1071 bVal = pArithDecoder
->Decode(&gbContext[CONTEXT]
);
1077 ((line1 << 1) | pImage
->GetPixel(w + 2
, m_loopIndex - 1
)) & 0x1f;
1078 line2 = ((line2 << 1) | bVal) & 0x0f;
1081 if (pState->pPause && pState->pPause->NeedToPauseNow()) {
int Decode(JBig2ArithCtx *pCX)
uint32_t getBitPos() const
void setBitPos(uint32_t dwBitPos)
uint32_t getLength() const
const uint8_t * getBuf() const
~ProgressiveArithDecodeState()
ProgressiveArithDecodeState()
FXCODEC_STATUS StartDecodeMMR(std::unique_ptr< CJBig2_Image > *pImage, CJBig2_BitStream *pStream)
FXCODEC_STATUS ContinueDecode(ProgressiveArithDecodeState *pState)
std::unique_ptr< CJBig2_Image > DecodeArith(CJBig2_ArithDecoder *pArithDecoder, JBig2ArithCtx *gbContext)
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
static int FaxG4Decode(const uint8_t *src_buf, uint32_t src_size, int starting_bitpos, int width, int height, int pitch, uint8_t *dest_buf)