OLD | NEW |
1 // Copyright 2015 PDFium Authors. All rights reserved. | 1 // Copyright 2015 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fxcodec/jbig2/JBig2_GrdProc.h" | 7 #include "core/fxcodec/jbig2/JBig2_GrdProc.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "core/fxcodec/include/fx_codec.h" | 11 #include "core/fxcodec/include/fx_codec.h" |
12 #include "core/fxcodec/jbig2/JBig2_ArithDecoder.h" | 12 #include "core/fxcodec/jbig2/JBig2_ArithDecoder.h" |
13 #include "core/fxcodec/jbig2/JBig2_BitStream.h" | 13 #include "core/fxcodec/jbig2/JBig2_BitStream.h" |
14 #include "core/fxcodec/jbig2/JBig2_Image.h" | 14 #include "core/fxcodec/jbig2/JBig2_Image.h" |
15 | 15 |
16 CJBig2_GRDProc::CJBig2_GRDProc() | 16 CJBig2_GRDProc::CJBig2_GRDProc() |
17 : m_loopIndex(0), | 17 : m_loopIndex(0), |
18 m_pLine(nullptr), | 18 m_pLine(nullptr), |
19 m_pPause(nullptr), | 19 m_pPause(nullptr), |
20 m_DecodeType(0), | 20 m_DecodeType(0), |
21 LTP(0) { | 21 m_LTP(FALSE) { |
22 m_ReplaceRect.left = 0; | 22 m_ReplaceRect.left = 0; |
23 m_ReplaceRect.bottom = 0; | 23 m_ReplaceRect.bottom = 0; |
24 m_ReplaceRect.top = 0; | 24 m_ReplaceRect.top = 0; |
25 m_ReplaceRect.right = 0; | 25 m_ReplaceRect.right = 0; |
26 } | 26 } |
27 | 27 |
28 bool CJBig2_GRDProc::UseTemplate0Opt3() const { | 28 bool CJBig2_GRDProc::UseTemplate0Opt3() const { |
29 return (GBAT[0] == 3) && (GBAT[1] == -1) && (GBAT[2] == -3) && | 29 return (GBAT[0] == 3) && (GBAT[1] == -1) && (GBAT[2] == -3) && |
30 (GBAT[3] == -1) && (GBAT[4] == 2) && (GBAT[5] == -2) && | 30 (GBAT[3] == -1) && (GBAT[4] == 2) && (GBAT[5] == -2) && |
31 (GBAT[6] == -2) && (GBAT[7] == -2); | 31 (GBAT[6] == -2) && (GBAT[7] == -2); |
(...skipping 26 matching lines...) Expand all Loading... |
58 return decode_Arith_Template2_unopt(pArithDecoder, gbContext); | 58 return decode_Arith_Template2_unopt(pArithDecoder, gbContext); |
59 } else { | 59 } else { |
60 if (UseTemplate23Opt3()) | 60 if (UseTemplate23Opt3()) |
61 return decode_Arith_Template3_opt3(pArithDecoder, gbContext); | 61 return decode_Arith_Template3_opt3(pArithDecoder, gbContext); |
62 return decode_Arith_Template3_unopt(pArithDecoder, gbContext); | 62 return decode_Arith_Template3_unopt(pArithDecoder, gbContext); |
63 } | 63 } |
64 } | 64 } |
65 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3( | 65 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3( |
66 CJBig2_ArithDecoder* pArithDecoder, | 66 CJBig2_ArithDecoder* pArithDecoder, |
67 JBig2ArithCtx* gbContext) { | 67 JBig2ArithCtx* gbContext) { |
68 FX_BOOL LTP, SLTP, bVal; | |
69 uint32_t CONTEXT; | |
70 uint32_t line1, line2; | |
71 uint8_t *pLine, *pLine1, *pLine2, cVal; | |
72 int32_t nStride, nStride2, k; | |
73 int32_t nLineBytes, nBitsLeft, cc; | |
74 LTP = 0; | |
75 std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); | 68 std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); |
76 if (!GBREG->m_pData) | 69 if (!GBREG->m_pData) |
77 return nullptr; | 70 return nullptr; |
78 | 71 |
79 pLine = GBREG->m_pData; | 72 FX_BOOL LTP = FALSE; |
80 nStride = GBREG->m_nStride; | 73 uint8_t* pLine = GBREG->m_pData; |
81 nStride2 = nStride << 1; | 74 int32_t nStride = GBREG->m_nStride; |
82 nLineBytes = ((GBW + 7) >> 3) - 1; | 75 int32_t nStride2 = nStride << 1; |
83 nBitsLeft = GBW - (nLineBytes << 3); | 76 int32_t nLineBytes = ((GBW + 7) >> 3) - 1; |
| 77 int32_t nBitsLeft = GBW - (nLineBytes << 3); |
84 uint32_t height = GBH & 0x7fffffff; | 78 uint32_t height = GBH & 0x7fffffff; |
85 for (uint32_t h = 0; h < height; h++) { | 79 for (uint32_t h = 0; h < height; h++) { |
86 if (TPGDON) { | 80 if (TPGDON) |
87 SLTP = pArithDecoder->DECODE(&gbContext[0x9b25]); | 81 LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x9b25]); |
88 LTP = LTP ^ SLTP; | 82 if (LTP) { |
89 } | |
90 if (LTP == 1) { | |
91 GBREG->copyLine(h, h - 1); | 83 GBREG->copyLine(h, h - 1); |
92 } else { | 84 } else { |
93 if (h > 1) { | 85 if (h > 1) { |
94 pLine1 = pLine - nStride2; | 86 uint8_t* pLine1 = pLine - nStride2; |
95 pLine2 = pLine - nStride; | 87 uint8_t* pLine2 = pLine - nStride; |
96 line1 = (*pLine1++) << 6; | 88 uint32_t line1 = (*pLine1++) << 6; |
97 line2 = *pLine2++; | 89 uint32_t line2 = *pLine2++; |
98 CONTEXT = ((line1 & 0xf800) | (line2 & 0x07f0)); | 90 uint32_t CONTEXT = ((line1 & 0xf800) | (line2 & 0x07f0)); |
99 for (cc = 0; cc < nLineBytes; cc++) { | 91 for (int32_t cc = 0; cc < nLineBytes; cc++) { |
100 line1 = (line1 << 8) | ((*pLine1++) << 6); | 92 line1 = (line1 << 8) | ((*pLine1++) << 6); |
101 line2 = (line2 << 8) | (*pLine2++); | 93 line2 = (line2 << 8) | (*pLine2++); |
102 cVal = 0; | 94 uint8_t cVal = 0; |
103 for (k = 7; k >= 0; k--) { | 95 for (int32_t k = 7; k >= 0; k--) { |
104 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 96 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
105 cVal |= bVal << k; | 97 cVal |= bVal << k; |
106 CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | | 98 CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | |
107 ((line1 >> k) & 0x0800) | ((line2 >> k) & 0x0010)); | 99 ((line1 >> k) & 0x0800) | ((line2 >> k) & 0x0010)); |
108 } | 100 } |
109 pLine[cc] = cVal; | 101 pLine[cc] = cVal; |
110 } | 102 } |
111 line1 <<= 8; | 103 line1 <<= 8; |
112 line2 <<= 8; | 104 line2 <<= 8; |
113 cVal = 0; | 105 uint8_t cVal1 = 0; |
114 for (k = 0; k < nBitsLeft; k++) { | 106 for (int32_t k = 0; k < nBitsLeft; k++) { |
115 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 107 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
116 cVal |= bVal << (7 - k); | 108 cVal1 |= bVal << (7 - k); |
117 CONTEXT = | 109 CONTEXT = |
118 (((CONTEXT & 0x7bf7) << 1) | bVal | | 110 (((CONTEXT & 0x7bf7) << 1) | bVal | |
119 ((line1 >> (7 - k)) & 0x0800) | ((line2 >> (7 - k)) & 0x0010)); | 111 ((line1 >> (7 - k)) & 0x0800) | ((line2 >> (7 - k)) & 0x0010)); |
120 } | 112 } |
121 pLine[nLineBytes] = cVal; | 113 pLine[nLineBytes] = cVal1; |
122 } else { | 114 } else { |
123 pLine2 = pLine - nStride; | 115 uint8_t* pLine2 = pLine - nStride; |
124 line2 = (h & 1) ? (*pLine2++) : 0; | 116 uint32_t line2 = (h & 1) ? (*pLine2++) : 0; |
125 CONTEXT = (line2 & 0x07f0); | 117 uint32_t CONTEXT = (line2 & 0x07f0); |
126 for (cc = 0; cc < nLineBytes; cc++) { | 118 for (int32_t cc = 0; cc < nLineBytes; cc++) { |
127 if (h & 1) { | 119 if (h & 1) { |
128 line2 = (line2 << 8) | (*pLine2++); | 120 line2 = (line2 << 8) | (*pLine2++); |
129 } | 121 } |
130 cVal = 0; | 122 uint8_t cVal = 0; |
131 for (k = 7; k >= 0; k--) { | 123 for (int32_t k = 7; k >= 0; k--) { |
132 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 124 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
133 cVal |= bVal << k; | 125 cVal |= bVal << k; |
134 CONTEXT = | 126 CONTEXT = |
135 (((CONTEXT & 0x7bf7) << 1) | bVal | ((line2 >> k) & 0x0010)); | 127 (((CONTEXT & 0x7bf7) << 1) | bVal | ((line2 >> k) & 0x0010)); |
136 } | 128 } |
137 pLine[cc] = cVal; | 129 pLine[cc] = cVal; |
138 } | 130 } |
139 line2 <<= 8; | 131 line2 <<= 8; |
140 cVal = 0; | 132 uint8_t cVal1 = 0; |
141 for (k = 0; k < nBitsLeft; k++) { | 133 for (int32_t k = 0; k < nBitsLeft; k++) { |
142 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 134 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
143 cVal |= bVal << (7 - k); | 135 cVal1 |= bVal << (7 - k); |
144 CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | | 136 CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | |
145 (((line2 >> (7 - k))) & 0x0010)); | 137 (((line2 >> (7 - k))) & 0x0010)); |
146 } | 138 } |
147 pLine[nLineBytes] = cVal; | 139 pLine[nLineBytes] = cVal1; |
148 } | 140 } |
149 } | 141 } |
150 pLine += nStride; | 142 pLine += nStride; |
151 } | 143 } |
152 return GBREG.release(); | 144 return GBREG.release(); |
153 } | 145 } |
154 | 146 |
155 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt( | 147 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt( |
156 CJBig2_ArithDecoder* pArithDecoder, | 148 CJBig2_ArithDecoder* pArithDecoder, |
157 JBig2ArithCtx* gbContext) { | 149 JBig2ArithCtx* gbContext) { |
158 FX_BOOL LTP, SLTP, bVal; | 150 FX_BOOL LTP = FALSE; |
159 uint32_t CONTEXT; | |
160 uint32_t line1, line2, line3; | |
161 LTP = 0; | |
162 std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); | 151 std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); |
163 GBREG->fill(0); | 152 GBREG->fill(0); |
164 for (uint32_t h = 0; h < GBH; h++) { | 153 for (uint32_t h = 0; h < GBH; h++) { |
165 if (TPGDON) { | 154 if (TPGDON) |
166 SLTP = pArithDecoder->DECODE(&gbContext[0x9b25]); | 155 LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x9b25]); |
167 LTP = LTP ^ SLTP; | 156 if (LTP) { |
168 } | |
169 if (LTP == 1) { | |
170 GBREG->copyLine(h, h - 1); | 157 GBREG->copyLine(h, h - 1); |
171 } else { | 158 } else { |
172 line1 = GBREG->getPixel(1, h - 2); | 159 uint32_t line1 = GBREG->getPixel(1, h - 2); |
173 line1 |= GBREG->getPixel(0, h - 2) << 1; | 160 line1 |= GBREG->getPixel(0, h - 2) << 1; |
174 line2 = GBREG->getPixel(2, h - 1); | 161 uint32_t line2 = GBREG->getPixel(2, h - 1); |
175 line2 |= GBREG->getPixel(1, h - 1) << 1; | 162 line2 |= GBREG->getPixel(1, h - 1) << 1; |
176 line2 |= GBREG->getPixel(0, h - 1) << 2; | 163 line2 |= GBREG->getPixel(0, h - 1) << 2; |
177 line3 = 0; | 164 uint32_t line3 = 0; |
178 for (uint32_t w = 0; w < GBW; w++) { | 165 for (uint32_t w = 0; w < GBW; w++) { |
| 166 FX_BOOL bVal; |
179 if (USESKIP && SKIP->getPixel(w, h)) { | 167 if (USESKIP && SKIP->getPixel(w, h)) { |
180 bVal = 0; | 168 bVal = 0; |
181 } else { | 169 } else { |
182 CONTEXT = line3; | 170 uint32_t CONTEXT = line3; |
183 CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 4; | 171 CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 4; |
184 CONTEXT |= line2 << 5; | 172 CONTEXT |= line2 << 5; |
185 CONTEXT |= GBREG->getPixel(w + GBAT[2], h + GBAT[3]) << 10; | 173 CONTEXT |= GBREG->getPixel(w + GBAT[2], h + GBAT[3]) << 10; |
186 CONTEXT |= GBREG->getPixel(w + GBAT[4], h + GBAT[5]) << 11; | 174 CONTEXT |= GBREG->getPixel(w + GBAT[4], h + GBAT[5]) << 11; |
187 CONTEXT |= line1 << 12; | 175 CONTEXT |= line1 << 12; |
188 CONTEXT |= GBREG->getPixel(w + GBAT[6], h + GBAT[7]) << 15; | 176 CONTEXT |= GBREG->getPixel(w + GBAT[6], h + GBAT[7]) << 15; |
189 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 177 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
190 } | 178 } |
191 if (bVal) { | 179 if (bVal) { |
192 GBREG->setPixel(w, h, bVal); | 180 GBREG->setPixel(w, h, bVal); |
193 } | 181 } |
194 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 2)) & 0x07; | 182 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 2)) & 0x07; |
195 line2 = ((line2 << 1) | GBREG->getPixel(w + 3, h - 1)) & 0x1f; | 183 line2 = ((line2 << 1) | GBREG->getPixel(w + 3, h - 1)) & 0x1f; |
196 line3 = ((line3 << 1) | bVal) & 0x0f; | 184 line3 = ((line3 << 1) | bVal) & 0x0f; |
197 } | 185 } |
198 } | 186 } |
199 } | 187 } |
200 return GBREG.release(); | 188 return GBREG.release(); |
201 } | 189 } |
202 | 190 |
203 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3( | 191 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3( |
204 CJBig2_ArithDecoder* pArithDecoder, | 192 CJBig2_ArithDecoder* pArithDecoder, |
205 JBig2ArithCtx* gbContext) { | 193 JBig2ArithCtx* gbContext) { |
206 FX_BOOL LTP, SLTP, bVal; | |
207 uint32_t CONTEXT; | |
208 uint32_t line1, line2; | |
209 uint8_t *pLine, *pLine1, *pLine2, cVal; | |
210 int32_t nStride, nStride2, k; | |
211 int32_t nLineBytes, nBitsLeft, cc; | |
212 LTP = 0; | |
213 std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); | 194 std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); |
214 if (!GBREG->m_pData) | 195 if (!GBREG->m_pData) |
215 return nullptr; | 196 return nullptr; |
216 | 197 |
217 pLine = GBREG->m_pData; | 198 FX_BOOL LTP = FALSE; |
218 nStride = GBREG->m_nStride; | 199 uint8_t* pLine = GBREG->m_pData; |
219 nStride2 = nStride << 1; | 200 int32_t nStride = GBREG->m_nStride; |
220 nLineBytes = ((GBW + 7) >> 3) - 1; | 201 int32_t nStride2 = nStride << 1; |
221 nBitsLeft = GBW - (nLineBytes << 3); | 202 int32_t nLineBytes = ((GBW + 7) >> 3) - 1; |
| 203 int32_t nBitsLeft = GBW - (nLineBytes << 3); |
222 for (uint32_t h = 0; h < GBH; h++) { | 204 for (uint32_t h = 0; h < GBH; h++) { |
223 if (TPGDON) { | 205 if (TPGDON) |
224 SLTP = pArithDecoder->DECODE(&gbContext[0x0795]); | 206 LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x0795]); |
225 LTP = LTP ^ SLTP; | 207 if (LTP) { |
226 } | |
227 if (LTP == 1) { | |
228 GBREG->copyLine(h, h - 1); | 208 GBREG->copyLine(h, h - 1); |
229 } else { | 209 } else { |
230 if (h > 1) { | 210 if (h > 1) { |
231 pLine1 = pLine - nStride2; | 211 uint8_t* pLine1 = pLine - nStride2; |
232 pLine2 = pLine - nStride; | 212 uint8_t* pLine2 = pLine - nStride; |
233 line1 = (*pLine1++) << 4; | 213 uint32_t line1 = (*pLine1++) << 4; |
234 line2 = *pLine2++; | 214 uint32_t line2 = *pLine2++; |
235 CONTEXT = (line1 & 0x1e00) | ((line2 >> 1) & 0x01f8); | 215 uint32_t CONTEXT = (line1 & 0x1e00) | ((line2 >> 1) & 0x01f8); |
236 for (cc = 0; cc < nLineBytes; cc++) { | 216 for (int32_t cc = 0; cc < nLineBytes; cc++) { |
237 line1 = (line1 << 8) | ((*pLine1++) << 4); | 217 line1 = (line1 << 8) | ((*pLine1++) << 4); |
238 line2 = (line2 << 8) | (*pLine2++); | 218 line2 = (line2 << 8) | (*pLine2++); |
239 cVal = 0; | 219 uint8_t cVal = 0; |
240 for (k = 7; k >= 0; k--) { | 220 for (int32_t k = 7; k >= 0; k--) { |
241 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 221 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
242 cVal |= bVal << k; | 222 cVal |= bVal << k; |
243 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | | 223 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | |
244 ((line1 >> k) & 0x0200) | ((line2 >> (k + 1)) & 0x0008); | 224 ((line1 >> k) & 0x0200) | ((line2 >> (k + 1)) & 0x0008); |
245 } | 225 } |
246 pLine[cc] = cVal; | 226 pLine[cc] = cVal; |
247 } | 227 } |
248 line1 <<= 8; | 228 line1 <<= 8; |
249 line2 <<= 8; | 229 line2 <<= 8; |
250 cVal = 0; | 230 uint8_t cVal1 = 0; |
251 for (k = 0; k < nBitsLeft; k++) { | 231 for (int32_t k = 0; k < nBitsLeft; k++) { |
252 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 232 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
253 cVal |= bVal << (7 - k); | 233 cVal1 |= bVal << (7 - k); |
254 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | | 234 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | |
255 ((line1 >> (7 - k)) & 0x0200) | | 235 ((line1 >> (7 - k)) & 0x0200) | |
256 ((line2 >> (8 - k)) & 0x0008); | 236 ((line2 >> (8 - k)) & 0x0008); |
257 } | 237 } |
258 pLine[nLineBytes] = cVal; | 238 pLine[nLineBytes] = cVal1; |
259 } else { | 239 } else { |
260 pLine2 = pLine - nStride; | 240 uint8_t* pLine2 = pLine - nStride; |
261 line2 = (h & 1) ? (*pLine2++) : 0; | 241 uint32_t line2 = (h & 1) ? (*pLine2++) : 0; |
262 CONTEXT = (line2 >> 1) & 0x01f8; | 242 uint32_t CONTEXT = (line2 >> 1) & 0x01f8; |
263 for (cc = 0; cc < nLineBytes; cc++) { | 243 for (int32_t cc = 0; cc < nLineBytes; cc++) { |
264 if (h & 1) { | 244 if (h & 1) { |
265 line2 = (line2 << 8) | (*pLine2++); | 245 line2 = (line2 << 8) | (*pLine2++); |
266 } | 246 } |
267 cVal = 0; | 247 uint8_t cVal = 0; |
268 for (k = 7; k >= 0; k--) { | 248 for (int32_t k = 7; k >= 0; k--) { |
269 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 249 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
270 cVal |= bVal << k; | 250 cVal |= bVal << k; |
271 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | | 251 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | |
272 ((line2 >> (k + 1)) & 0x0008); | 252 ((line2 >> (k + 1)) & 0x0008); |
273 } | 253 } |
274 pLine[cc] = cVal; | 254 pLine[cc] = cVal; |
275 } | 255 } |
276 line2 <<= 8; | 256 line2 <<= 8; |
277 cVal = 0; | 257 uint8_t cVal1 = 0; |
278 for (k = 0; k < nBitsLeft; k++) { | 258 for (int32_t k = 0; k < nBitsLeft; k++) { |
279 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 259 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
280 cVal |= bVal << (7 - k); | 260 cVal1 |= bVal << (7 - k); |
281 CONTEXT = | 261 CONTEXT = |
282 ((CONTEXT & 0x0efb) << 1) | bVal | ((line2 >> (8 - k)) & 0x0008); | 262 ((CONTEXT & 0x0efb) << 1) | bVal | ((line2 >> (8 - k)) & 0x0008); |
283 } | 263 } |
284 pLine[nLineBytes] = cVal; | 264 pLine[nLineBytes] = cVal1; |
285 } | 265 } |
286 } | 266 } |
287 pLine += nStride; | 267 pLine += nStride; |
288 } | 268 } |
289 return GBREG.release(); | 269 return GBREG.release(); |
290 } | 270 } |
291 | 271 |
292 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt( | 272 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt( |
293 CJBig2_ArithDecoder* pArithDecoder, | 273 CJBig2_ArithDecoder* pArithDecoder, |
294 JBig2ArithCtx* gbContext) { | 274 JBig2ArithCtx* gbContext) { |
295 FX_BOOL LTP, SLTP, bVal; | 275 FX_BOOL LTP = FALSE; |
296 uint32_t CONTEXT; | |
297 uint32_t line1, line2, line3; | |
298 LTP = 0; | |
299 std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); | 276 std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); |
300 GBREG->fill(0); | 277 GBREG->fill(0); |
301 for (uint32_t h = 0; h < GBH; h++) { | 278 for (uint32_t h = 0; h < GBH; h++) { |
302 if (TPGDON) { | 279 if (TPGDON) |
303 SLTP = pArithDecoder->DECODE(&gbContext[0x0795]); | 280 LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x0795]); |
304 LTP = LTP ^ SLTP; | 281 if (LTP) { |
305 } | |
306 if (LTP == 1) { | |
307 GBREG->copyLine(h, h - 1); | 282 GBREG->copyLine(h, h - 1); |
308 } else { | 283 } else { |
309 line1 = GBREG->getPixel(2, h - 2); | 284 uint32_t line1 = GBREG->getPixel(2, h - 2); |
310 line1 |= GBREG->getPixel(1, h - 2) << 1; | 285 line1 |= GBREG->getPixel(1, h - 2) << 1; |
311 line1 |= GBREG->getPixel(0, h - 2) << 2; | 286 line1 |= GBREG->getPixel(0, h - 2) << 2; |
312 line2 = GBREG->getPixel(2, h - 1); | 287 uint32_t line2 = GBREG->getPixel(2, h - 1); |
313 line2 |= GBREG->getPixel(1, h - 1) << 1; | 288 line2 |= GBREG->getPixel(1, h - 1) << 1; |
314 line2 |= GBREG->getPixel(0, h - 1) << 2; | 289 line2 |= GBREG->getPixel(0, h - 1) << 2; |
315 line3 = 0; | 290 uint32_t line3 = 0; |
316 for (uint32_t w = 0; w < GBW; w++) { | 291 for (uint32_t w = 0; w < GBW; w++) { |
| 292 FX_BOOL bVal; |
317 if (USESKIP && SKIP->getPixel(w, h)) { | 293 if (USESKIP && SKIP->getPixel(w, h)) { |
318 bVal = 0; | 294 bVal = 0; |
319 } else { | 295 } else { |
320 CONTEXT = line3; | 296 uint32_t CONTEXT = line3; |
321 CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 3; | 297 CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 3; |
322 CONTEXT |= line2 << 4; | 298 CONTEXT |= line2 << 4; |
323 CONTEXT |= line1 << 9; | 299 CONTEXT |= line1 << 9; |
324 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 300 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
325 } | 301 } |
326 if (bVal) { | 302 if (bVal) { |
327 GBREG->setPixel(w, h, bVal); | 303 GBREG->setPixel(w, h, bVal); |
328 } | 304 } |
329 line1 = ((line1 << 1) | GBREG->getPixel(w + 3, h - 2)) & 0x0f; | 305 line1 = ((line1 << 1) | GBREG->getPixel(w + 3, h - 2)) & 0x0f; |
330 line2 = ((line2 << 1) | GBREG->getPixel(w + 3, h - 1)) & 0x1f; | 306 line2 = ((line2 << 1) | GBREG->getPixel(w + 3, h - 1)) & 0x1f; |
331 line3 = ((line3 << 1) | bVal) & 0x07; | 307 line3 = ((line3 << 1) | bVal) & 0x07; |
332 } | 308 } |
333 } | 309 } |
334 } | 310 } |
335 return GBREG.release(); | 311 return GBREG.release(); |
336 } | 312 } |
| 313 |
337 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3( | 314 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3( |
338 CJBig2_ArithDecoder* pArithDecoder, | 315 CJBig2_ArithDecoder* pArithDecoder, |
339 JBig2ArithCtx* gbContext) { | 316 JBig2ArithCtx* gbContext) { |
340 FX_BOOL LTP, SLTP, bVal; | |
341 uint32_t CONTEXT; | |
342 uint32_t line1, line2; | |
343 uint8_t *pLine, *pLine1, *pLine2, cVal; | |
344 int32_t nStride, nStride2, k; | |
345 int32_t nLineBytes, nBitsLeft, cc; | |
346 LTP = 0; | |
347 std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); | 317 std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); |
348 if (!GBREG->m_pData) | 318 if (!GBREG->m_pData) |
349 return nullptr; | 319 return nullptr; |
350 | 320 |
351 pLine = GBREG->m_pData; | 321 FX_BOOL LTP = FALSE; |
352 nStride = GBREG->m_nStride; | 322 uint8_t* pLine = GBREG->m_pData; |
353 nStride2 = nStride << 1; | 323 int32_t nStride = GBREG->m_nStride; |
354 nLineBytes = ((GBW + 7) >> 3) - 1; | 324 int32_t nStride2 = nStride << 1; |
355 nBitsLeft = GBW - (nLineBytes << 3); | 325 int32_t nLineBytes = ((GBW + 7) >> 3) - 1; |
| 326 int32_t nBitsLeft = GBW - (nLineBytes << 3); |
356 for (uint32_t h = 0; h < GBH; h++) { | 327 for (uint32_t h = 0; h < GBH; h++) { |
357 if (TPGDON) { | 328 if (TPGDON) |
358 SLTP = pArithDecoder->DECODE(&gbContext[0x00e5]); | 329 LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x00e5]); |
359 LTP = LTP ^ SLTP; | 330 if (LTP) { |
360 } | |
361 if (LTP == 1) { | |
362 GBREG->copyLine(h, h - 1); | 331 GBREG->copyLine(h, h - 1); |
363 } else { | 332 } else { |
364 if (h > 1) { | 333 if (h > 1) { |
365 pLine1 = pLine - nStride2; | 334 uint8_t* pLine1 = pLine - nStride2; |
366 pLine2 = pLine - nStride; | 335 uint8_t* pLine2 = pLine - nStride; |
367 line1 = (*pLine1++) << 1; | 336 uint32_t line1 = (*pLine1++) << 1; |
368 line2 = *pLine2++; | 337 uint32_t line2 = *pLine2++; |
369 CONTEXT = (line1 & 0x0380) | ((line2 >> 3) & 0x007c); | 338 uint32_t CONTEXT = (line1 & 0x0380) | ((line2 >> 3) & 0x007c); |
370 for (cc = 0; cc < nLineBytes; cc++) { | 339 for (int32_t cc = 0; cc < nLineBytes; cc++) { |
371 line1 = (line1 << 8) | ((*pLine1++) << 1); | 340 line1 = (line1 << 8) | ((*pLine1++) << 1); |
372 line2 = (line2 << 8) | (*pLine2++); | 341 line2 = (line2 << 8) | (*pLine2++); |
373 cVal = 0; | 342 uint8_t cVal = 0; |
374 for (k = 7; k >= 0; k--) { | 343 for (int32_t k = 7; k >= 0; k--) { |
375 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 344 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
376 cVal |= bVal << k; | 345 cVal |= bVal << k; |
377 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | | 346 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | |
378 ((line1 >> k) & 0x0080) | ((line2 >> (k + 3)) & 0x0004); | 347 ((line1 >> k) & 0x0080) | ((line2 >> (k + 3)) & 0x0004); |
379 } | 348 } |
380 pLine[cc] = cVal; | 349 pLine[cc] = cVal; |
381 } | 350 } |
382 line1 <<= 8; | 351 line1 <<= 8; |
383 line2 <<= 8; | 352 line2 <<= 8; |
384 cVal = 0; | 353 uint8_t cVal1 = 0; |
385 for (k = 0; k < nBitsLeft; k++) { | 354 for (int32_t k = 0; k < nBitsLeft; k++) { |
386 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 355 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
387 cVal |= bVal << (7 - k); | 356 cVal1 |= bVal << (7 - k); |
388 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | | 357 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | |
389 ((line1 >> (7 - k)) & 0x0080) | | 358 ((line1 >> (7 - k)) & 0x0080) | |
390 ((line2 >> (10 - k)) & 0x0004); | 359 ((line2 >> (10 - k)) & 0x0004); |
391 } | 360 } |
392 pLine[nLineBytes] = cVal; | 361 pLine[nLineBytes] = cVal1; |
393 } else { | 362 } else { |
394 pLine2 = pLine - nStride; | 363 uint8_t* pLine2 = pLine - nStride; |
395 line2 = (h & 1) ? (*pLine2++) : 0; | 364 uint32_t line2 = (h & 1) ? (*pLine2++) : 0; |
396 CONTEXT = (line2 >> 3) & 0x007c; | 365 uint32_t CONTEXT = (line2 >> 3) & 0x007c; |
397 for (cc = 0; cc < nLineBytes; cc++) { | 366 for (int32_t cc = 0; cc < nLineBytes; cc++) { |
398 if (h & 1) { | 367 if (h & 1) { |
399 line2 = (line2 << 8) | (*pLine2++); | 368 line2 = (line2 << 8) | (*pLine2++); |
400 } | 369 } |
401 cVal = 0; | 370 uint8_t cVal = 0; |
402 for (k = 7; k >= 0; k--) { | 371 for (int32_t k = 7; k >= 0; k--) { |
403 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 372 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
404 cVal |= bVal << k; | 373 cVal |= bVal << k; |
405 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | | 374 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | |
406 ((line2 >> (k + 3)) & 0x0004); | 375 ((line2 >> (k + 3)) & 0x0004); |
407 } | 376 } |
408 pLine[cc] = cVal; | 377 pLine[cc] = cVal; |
409 } | 378 } |
410 line2 <<= 8; | 379 line2 <<= 8; |
411 cVal = 0; | 380 uint8_t cVal1 = 0; |
412 for (k = 0; k < nBitsLeft; k++) { | 381 for (int32_t k = 0; k < nBitsLeft; k++) { |
413 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 382 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
414 cVal |= bVal << (7 - k); | 383 cVal1 |= bVal << (7 - k); |
415 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | | 384 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | |
416 (((line2 >> (10 - k))) & 0x0004); | 385 (((line2 >> (10 - k))) & 0x0004); |
417 } | 386 } |
418 pLine[nLineBytes] = cVal; | 387 pLine[nLineBytes] = cVal1; |
419 } | 388 } |
420 } | 389 } |
421 pLine += nStride; | 390 pLine += nStride; |
422 } | 391 } |
423 return GBREG.release(); | 392 return GBREG.release(); |
424 } | 393 } |
425 | 394 |
426 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt( | 395 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt( |
427 CJBig2_ArithDecoder* pArithDecoder, | 396 CJBig2_ArithDecoder* pArithDecoder, |
428 JBig2ArithCtx* gbContext) { | 397 JBig2ArithCtx* gbContext) { |
429 FX_BOOL LTP, SLTP, bVal; | 398 FX_BOOL LTP = FALSE; |
430 uint32_t CONTEXT; | |
431 uint32_t line1, line2, line3; | |
432 LTP = 0; | |
433 std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); | 399 std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); |
434 GBREG->fill(0); | 400 GBREG->fill(0); |
435 for (uint32_t h = 0; h < GBH; h++) { | 401 for (uint32_t h = 0; h < GBH; h++) { |
436 if (TPGDON) { | 402 if (TPGDON) |
437 SLTP = pArithDecoder->DECODE(&gbContext[0x00e5]); | 403 LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x00e5]); |
438 LTP = LTP ^ SLTP; | 404 if (LTP) { |
439 } | |
440 if (LTP == 1) { | |
441 GBREG->copyLine(h, h - 1); | 405 GBREG->copyLine(h, h - 1); |
442 } else { | 406 } else { |
443 line1 = GBREG->getPixel(1, h - 2); | 407 uint32_t line1 = GBREG->getPixel(1, h - 2); |
444 line1 |= GBREG->getPixel(0, h - 2) << 1; | 408 line1 |= GBREG->getPixel(0, h - 2) << 1; |
445 line2 = GBREG->getPixel(1, h - 1); | 409 uint32_t line2 = GBREG->getPixel(1, h - 1); |
446 line2 |= GBREG->getPixel(0, h - 1) << 1; | 410 line2 |= GBREG->getPixel(0, h - 1) << 1; |
447 line3 = 0; | 411 uint32_t line3 = 0; |
448 for (uint32_t w = 0; w < GBW; w++) { | 412 for (uint32_t w = 0; w < GBW; w++) { |
| 413 FX_BOOL bVal; |
449 if (USESKIP && SKIP->getPixel(w, h)) { | 414 if (USESKIP && SKIP->getPixel(w, h)) { |
450 bVal = 0; | 415 bVal = 0; |
451 } else { | 416 } else { |
452 CONTEXT = line3; | 417 uint32_t CONTEXT = line3; |
453 CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 2; | 418 CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 2; |
454 CONTEXT |= line2 << 3; | 419 CONTEXT |= line2 << 3; |
455 CONTEXT |= line1 << 7; | 420 CONTEXT |= line1 << 7; |
456 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 421 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
457 } | 422 } |
458 if (bVal) { | 423 if (bVal) { |
459 GBREG->setPixel(w, h, bVal); | 424 GBREG->setPixel(w, h, bVal); |
460 } | 425 } |
461 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 2)) & 0x07; | 426 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 2)) & 0x07; |
462 line2 = ((line2 << 1) | GBREG->getPixel(w + 2, h - 1)) & 0x0f; | 427 line2 = ((line2 << 1) | GBREG->getPixel(w + 2, h - 1)) & 0x0f; |
463 line3 = ((line3 << 1) | bVal) & 0x03; | 428 line3 = ((line3 << 1) | bVal) & 0x03; |
464 } | 429 } |
465 } | 430 } |
466 } | 431 } |
467 return GBREG.release(); | 432 return GBREG.release(); |
468 } | 433 } |
469 | 434 |
470 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3( | 435 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3( |
471 CJBig2_ArithDecoder* pArithDecoder, | 436 CJBig2_ArithDecoder* pArithDecoder, |
472 JBig2ArithCtx* gbContext) { | 437 JBig2ArithCtx* gbContext) { |
473 FX_BOOL LTP, SLTP, bVal; | |
474 uint32_t CONTEXT; | |
475 uint32_t line1; | |
476 uint8_t *pLine, *pLine1, cVal; | |
477 int32_t nStride, k; | |
478 int32_t nLineBytes, nBitsLeft, cc; | |
479 LTP = 0; | |
480 std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); | 438 std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); |
481 if (!GBREG->m_pData) | 439 if (!GBREG->m_pData) |
482 return nullptr; | 440 return nullptr; |
483 | 441 |
484 pLine = GBREG->m_pData; | 442 FX_BOOL LTP = FALSE; |
485 nStride = GBREG->m_nStride; | 443 uint8_t* pLine = GBREG->m_pData; |
486 nLineBytes = ((GBW + 7) >> 3) - 1; | 444 int32_t nStride = GBREG->m_nStride; |
487 nBitsLeft = GBW - (nLineBytes << 3); | 445 int32_t nLineBytes = ((GBW + 7) >> 3) - 1; |
| 446 int32_t nBitsLeft = GBW - (nLineBytes << 3); |
488 for (uint32_t h = 0; h < GBH; h++) { | 447 for (uint32_t h = 0; h < GBH; h++) { |
489 if (TPGDON) { | 448 if (TPGDON) |
490 SLTP = pArithDecoder->DECODE(&gbContext[0x0195]); | 449 LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x0195]); |
491 LTP = LTP ^ SLTP; | 450 if (LTP) { |
492 } | |
493 if (LTP == 1) { | |
494 GBREG->copyLine(h, h - 1); | 451 GBREG->copyLine(h, h - 1); |
495 } else { | 452 } else { |
496 if (h > 0) { | 453 if (h > 0) { |
497 pLine1 = pLine - nStride; | 454 uint8_t* pLine1 = pLine - nStride; |
498 line1 = *pLine1++; | 455 uint32_t line1 = *pLine1++; |
499 CONTEXT = (line1 >> 1) & 0x03f0; | 456 uint32_t CONTEXT = (line1 >> 1) & 0x03f0; |
500 for (cc = 0; cc < nLineBytes; cc++) { | 457 for (int32_t cc = 0; cc < nLineBytes; cc++) { |
501 line1 = (line1 << 8) | (*pLine1++); | 458 line1 = (line1 << 8) | (*pLine1++); |
502 cVal = 0; | 459 uint8_t cVal = 0; |
503 for (k = 7; k >= 0; k--) { | 460 for (int32_t k = 7; k >= 0; k--) { |
504 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 461 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
505 cVal |= bVal << k; | 462 cVal |= bVal << k; |
506 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal | | 463 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal | |
507 ((line1 >> (k + 1)) & 0x0010); | 464 ((line1 >> (k + 1)) & 0x0010); |
508 } | 465 } |
509 pLine[cc] = cVal; | 466 pLine[cc] = cVal; |
510 } | 467 } |
511 line1 <<= 8; | 468 line1 <<= 8; |
512 cVal = 0; | 469 uint8_t cVal1 = 0; |
513 for (k = 0; k < nBitsLeft; k++) { | 470 for (int32_t k = 0; k < nBitsLeft; k++) { |
514 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 471 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
515 cVal |= bVal << (7 - k); | 472 cVal1 |= bVal << (7 - k); |
516 CONTEXT = | 473 CONTEXT = |
517 ((CONTEXT & 0x01f7) << 1) | bVal | ((line1 >> (8 - k)) & 0x0010); | 474 ((CONTEXT & 0x01f7) << 1) | bVal | ((line1 >> (8 - k)) & 0x0010); |
518 } | 475 } |
519 pLine[nLineBytes] = cVal; | 476 pLine[nLineBytes] = cVal1; |
520 } else { | 477 } else { |
521 CONTEXT = 0; | 478 uint32_t CONTEXT = 0; |
522 for (cc = 0; cc < nLineBytes; cc++) { | 479 for (int32_t cc = 0; cc < nLineBytes; cc++) { |
523 cVal = 0; | 480 uint8_t cVal = 0; |
524 for (k = 7; k >= 0; k--) { | 481 for (int32_t k = 7; k >= 0; k--) { |
525 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 482 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
526 cVal |= bVal << k; | 483 cVal |= bVal << k; |
527 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal; | 484 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal; |
528 } | 485 } |
529 pLine[cc] = cVal; | 486 pLine[cc] = cVal; |
530 } | 487 } |
531 cVal = 0; | 488 uint8_t cVal1 = 0; |
532 for (k = 0; k < nBitsLeft; k++) { | 489 for (int32_t k = 0; k < nBitsLeft; k++) { |
533 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 490 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
534 cVal |= bVal << (7 - k); | 491 cVal1 |= bVal << (7 - k); |
535 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal; | 492 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal; |
536 } | 493 } |
537 pLine[nLineBytes] = cVal; | 494 pLine[nLineBytes] = cVal1; |
538 } | 495 } |
539 } | 496 } |
540 pLine += nStride; | 497 pLine += nStride; |
541 } | 498 } |
542 return GBREG.release(); | 499 return GBREG.release(); |
543 } | 500 } |
544 | 501 |
545 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_unopt( | 502 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_unopt( |
546 CJBig2_ArithDecoder* pArithDecoder, | 503 CJBig2_ArithDecoder* pArithDecoder, |
547 JBig2ArithCtx* gbContext) { | 504 JBig2ArithCtx* gbContext) { |
548 FX_BOOL LTP, SLTP, bVal; | 505 FX_BOOL LTP = FALSE; |
549 uint32_t CONTEXT; | |
550 uint32_t line1, line2; | |
551 LTP = 0; | |
552 std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); | 506 std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); |
553 GBREG->fill(0); | 507 GBREG->fill(0); |
554 for (uint32_t h = 0; h < GBH; h++) { | 508 for (uint32_t h = 0; h < GBH; h++) { |
555 if (TPGDON) { | 509 if (TPGDON) |
556 SLTP = pArithDecoder->DECODE(&gbContext[0x0195]); | 510 LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x0195]); |
557 LTP = LTP ^ SLTP; | |
558 } | |
559 if (LTP == 1) { | 511 if (LTP == 1) { |
560 GBREG->copyLine(h, h - 1); | 512 GBREG->copyLine(h, h - 1); |
561 } else { | 513 } else { |
562 line1 = GBREG->getPixel(1, h - 1); | 514 uint32_t line1 = GBREG->getPixel(1, h - 1); |
563 line1 |= GBREG->getPixel(0, h - 1) << 1; | 515 line1 |= GBREG->getPixel(0, h - 1) << 1; |
564 line2 = 0; | 516 uint32_t line2 = 0; |
565 for (uint32_t w = 0; w < GBW; w++) { | 517 for (uint32_t w = 0; w < GBW; w++) { |
| 518 FX_BOOL bVal; |
566 if (USESKIP && SKIP->getPixel(w, h)) { | 519 if (USESKIP && SKIP->getPixel(w, h)) { |
567 bVal = 0; | 520 bVal = 0; |
568 } else { | 521 } else { |
569 CONTEXT = line2; | 522 uint32_t CONTEXT = line2; |
570 CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 4; | 523 CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 4; |
571 CONTEXT |= line1 << 5; | 524 CONTEXT |= line1 << 5; |
572 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 525 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
573 } | 526 } |
574 if (bVal) { | 527 if (bVal) { |
575 GBREG->setPixel(w, h, bVal); | 528 GBREG->setPixel(w, h, bVal); |
576 } | 529 } |
577 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 1)) & 0x1f; | 530 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 1)) & 0x1f; |
578 line2 = ((line2 << 1) | bVal) & 0x0f; | 531 line2 = ((line2 << 1) | bVal) & 0x0f; |
579 } | 532 } |
(...skipping 19 matching lines...) Expand all Loading... |
599 delete *pImage; | 552 delete *pImage; |
600 *pImage = nullptr; | 553 *pImage = nullptr; |
601 m_ProssiveStatus = FXCODEC_STATUS_ERROR; | 554 m_ProssiveStatus = FXCODEC_STATUS_ERROR; |
602 return FXCODEC_STATUS_ERROR; | 555 return FXCODEC_STATUS_ERROR; |
603 } | 556 } |
604 m_DecodeType = 1; | 557 m_DecodeType = 1; |
605 m_pImage = pImage; | 558 m_pImage = pImage; |
606 (*m_pImage)->fill(0); | 559 (*m_pImage)->fill(0); |
607 m_pArithDecoder = pArithDecoder; | 560 m_pArithDecoder = pArithDecoder; |
608 m_gbContext = gbContext; | 561 m_gbContext = gbContext; |
609 LTP = 0; | 562 m_LTP = FALSE; |
610 m_pLine = nullptr; | 563 m_pLine = nullptr; |
611 m_loopIndex = 0; | 564 m_loopIndex = 0; |
612 return decode_Arith(pPause); | 565 return decode_Arith(pPause); |
613 } | 566 } |
614 | 567 |
615 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith(IFX_Pause* pPause) { | 568 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith(IFX_Pause* pPause) { |
616 int iline = m_loopIndex; | 569 int iline = m_loopIndex; |
617 CJBig2_Image* pImage = *m_pImage; | 570 CJBig2_Image* pImage = *m_pImage; |
618 if (GBTEMPLATE == 0) { | 571 if (GBTEMPLATE == 0) { |
619 if (UseTemplate0Opt3()) { | 572 if (UseTemplate0Opt3()) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 } | 643 } |
691 | 644 |
692 return decode_Arith(pPause); | 645 return decode_Arith(pPause); |
693 } | 646 } |
694 | 647 |
695 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_opt3( | 648 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_opt3( |
696 CJBig2_Image* pImage, | 649 CJBig2_Image* pImage, |
697 CJBig2_ArithDecoder* pArithDecoder, | 650 CJBig2_ArithDecoder* pArithDecoder, |
698 JBig2ArithCtx* gbContext, | 651 JBig2ArithCtx* gbContext, |
699 IFX_Pause* pPause) { | 652 IFX_Pause* pPause) { |
700 FX_BOOL SLTP, bVal; | |
701 uint32_t CONTEXT; | |
702 uint32_t line1, line2; | |
703 uint8_t *pLine1, *pLine2, cVal; | |
704 int32_t nStride, nStride2, k; | |
705 int32_t nLineBytes, nBitsLeft, cc; | |
706 if (!m_pLine) { | 653 if (!m_pLine) { |
707 m_pLine = pImage->m_pData; | 654 m_pLine = pImage->m_pData; |
708 } | 655 } |
709 nStride = pImage->m_nStride; | 656 int32_t nStride = pImage->m_nStride; |
710 nStride2 = nStride << 1; | 657 int32_t nStride2 = nStride << 1; |
711 nLineBytes = ((GBW + 7) >> 3) - 1; | 658 int32_t nLineBytes = ((GBW + 7) >> 3) - 1; |
712 nBitsLeft = GBW - (nLineBytes << 3); | 659 int32_t nBitsLeft = GBW - (nLineBytes << 3); |
713 uint32_t height = GBH & 0x7fffffff; | 660 uint32_t height = GBH & 0x7fffffff; |
714 for (; m_loopIndex < height; m_loopIndex++) { | 661 for (; m_loopIndex < height; m_loopIndex++) { |
715 if (TPGDON) { | 662 if (TPGDON) |
716 SLTP = pArithDecoder->DECODE(&gbContext[0x9b25]); | 663 m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x9b25]); |
717 LTP = LTP ^ SLTP; | 664 if (m_LTP) { |
718 } | |
719 if (LTP == 1) { | |
720 pImage->copyLine(m_loopIndex, m_loopIndex - 1); | 665 pImage->copyLine(m_loopIndex, m_loopIndex - 1); |
721 } else { | 666 } else { |
722 if (m_loopIndex > 1) { | 667 if (m_loopIndex > 1) { |
723 pLine1 = m_pLine - nStride2; | 668 uint8_t* pLine1 = m_pLine - nStride2; |
724 pLine2 = m_pLine - nStride; | 669 uint8_t* pLine2 = m_pLine - nStride; |
725 line1 = (*pLine1++) << 6; | 670 uint32_t line1 = (*pLine1++) << 6; |
726 line2 = *pLine2++; | 671 uint32_t line2 = *pLine2++; |
727 CONTEXT = ((line1 & 0xf800) | (line2 & 0x07f0)); | 672 uint32_t CONTEXT = ((line1 & 0xf800) | (line2 & 0x07f0)); |
728 for (cc = 0; cc < nLineBytes; cc++) { | 673 for (int32_t cc = 0; cc < nLineBytes; cc++) { |
729 line1 = (line1 << 8) | ((*pLine1++) << 6); | 674 line1 = (line1 << 8) | ((*pLine1++) << 6); |
730 line2 = (line2 << 8) | (*pLine2++); | 675 line2 = (line2 << 8) | (*pLine2++); |
731 cVal = 0; | 676 uint8_t cVal = 0; |
732 for (k = 7; k >= 0; k--) { | 677 for (int32_t k = 7; k >= 0; k--) { |
733 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 678 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
734 cVal |= bVal << k; | 679 cVal |= bVal << k; |
735 CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | | 680 CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | |
736 ((line1 >> k) & 0x0800) | ((line2 >> k) & 0x0010)); | 681 ((line1 >> k) & 0x0800) | ((line2 >> k) & 0x0010)); |
737 } | 682 } |
738 m_pLine[cc] = cVal; | 683 m_pLine[cc] = cVal; |
739 } | 684 } |
740 line1 <<= 8; | 685 line1 <<= 8; |
741 line2 <<= 8; | 686 line2 <<= 8; |
742 cVal = 0; | 687 uint8_t cVal1 = 0; |
743 for (k = 0; k < nBitsLeft; k++) { | 688 for (int32_t k = 0; k < nBitsLeft; k++) { |
744 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 689 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
745 cVal |= bVal << (7 - k); | 690 cVal1 |= bVal << (7 - k); |
746 CONTEXT = | 691 CONTEXT = |
747 (((CONTEXT & 0x7bf7) << 1) | bVal | | 692 (((CONTEXT & 0x7bf7) << 1) | bVal | |
748 ((line1 >> (7 - k)) & 0x0800) | ((line2 >> (7 - k)) & 0x0010)); | 693 ((line1 >> (7 - k)) & 0x0800) | ((line2 >> (7 - k)) & 0x0010)); |
749 } | 694 } |
750 m_pLine[nLineBytes] = cVal; | 695 m_pLine[nLineBytes] = cVal1; |
751 } else { | 696 } else { |
752 pLine2 = m_pLine - nStride; | 697 uint8_t* pLine2 = m_pLine - nStride; |
753 line2 = (m_loopIndex & 1) ? (*pLine2++) : 0; | 698 uint32_t line2 = (m_loopIndex & 1) ? (*pLine2++) : 0; |
754 CONTEXT = (line2 & 0x07f0); | 699 uint32_t CONTEXT = (line2 & 0x07f0); |
755 for (cc = 0; cc < nLineBytes; cc++) { | 700 for (int32_t cc = 0; cc < nLineBytes; cc++) { |
756 if (m_loopIndex & 1) { | 701 if (m_loopIndex & 1) { |
757 line2 = (line2 << 8) | (*pLine2++); | 702 line2 = (line2 << 8) | (*pLine2++); |
758 } | 703 } |
759 cVal = 0; | 704 uint8_t cVal = 0; |
760 for (k = 7; k >= 0; k--) { | 705 for (int32_t k = 7; k >= 0; k--) { |
761 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 706 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
762 cVal |= bVal << k; | 707 cVal |= bVal << k; |
763 CONTEXT = | 708 CONTEXT = |
764 (((CONTEXT & 0x7bf7) << 1) | bVal | ((line2 >> k) & 0x0010)); | 709 (((CONTEXT & 0x7bf7) << 1) | bVal | ((line2 >> k) & 0x0010)); |
765 } | 710 } |
766 m_pLine[cc] = cVal; | 711 m_pLine[cc] = cVal; |
767 } | 712 } |
768 line2 <<= 8; | 713 line2 <<= 8; |
769 cVal = 0; | 714 uint8_t cVal1 = 0; |
770 for (k = 0; k < nBitsLeft; k++) { | 715 for (int32_t k = 0; k < nBitsLeft; k++) { |
771 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 716 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
772 cVal |= bVal << (7 - k); | 717 cVal1 |= bVal << (7 - k); |
773 CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | | 718 CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | |
774 ((line2 >> (7 - k)) & 0x0010)); | 719 ((line2 >> (7 - k)) & 0x0010)); |
775 } | 720 } |
776 m_pLine[nLineBytes] = cVal; | 721 m_pLine[nLineBytes] = cVal1; |
777 } | 722 } |
778 } | 723 } |
779 m_pLine += nStride; | 724 m_pLine += nStride; |
780 if (pPause && pPause->NeedToPauseNow()) { | 725 if (pPause && pPause->NeedToPauseNow()) { |
781 m_loopIndex++; | 726 m_loopIndex++; |
782 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 727 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
783 return FXCODEC_STATUS_DECODE_TOBECONTINUE; | 728 return FXCODEC_STATUS_DECODE_TOBECONTINUE; |
784 } | 729 } |
785 } | 730 } |
786 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 731 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
787 return FXCODEC_STATUS_DECODE_FINISH; | 732 return FXCODEC_STATUS_DECODE_FINISH; |
788 } | 733 } |
789 | 734 |
790 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_unopt( | 735 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_unopt( |
791 CJBig2_Image* pImage, | 736 CJBig2_Image* pImage, |
792 CJBig2_ArithDecoder* pArithDecoder, | 737 CJBig2_ArithDecoder* pArithDecoder, |
793 JBig2ArithCtx* gbContext, | 738 JBig2ArithCtx* gbContext, |
794 IFX_Pause* pPause) { | 739 IFX_Pause* pPause) { |
795 FX_BOOL SLTP, bVal; | |
796 uint32_t CONTEXT; | |
797 uint32_t line1, line2, line3; | |
798 for (; m_loopIndex < GBH; m_loopIndex++) { | 740 for (; m_loopIndex < GBH; m_loopIndex++) { |
799 if (TPGDON) { | 741 if (TPGDON) |
800 SLTP = pArithDecoder->DECODE(&gbContext[0x9b25]); | 742 m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x9b25]); |
801 LTP = LTP ^ SLTP; | 743 if (m_LTP) { |
802 } | |
803 if (LTP == 1) { | |
804 pImage->copyLine(m_loopIndex, m_loopIndex - 1); | 744 pImage->copyLine(m_loopIndex, m_loopIndex - 1); |
805 } else { | 745 } else { |
806 line1 = pImage->getPixel(1, m_loopIndex - 2); | 746 uint32_t line1 = pImage->getPixel(1, m_loopIndex - 2); |
807 line1 |= pImage->getPixel(0, m_loopIndex - 2) << 1; | 747 line1 |= pImage->getPixel(0, m_loopIndex - 2) << 1; |
808 line2 = pImage->getPixel(2, m_loopIndex - 1); | 748 uint32_t line2 = pImage->getPixel(2, m_loopIndex - 1); |
809 line2 |= pImage->getPixel(1, m_loopIndex - 1) << 1; | 749 line2 |= pImage->getPixel(1, m_loopIndex - 1) << 1; |
810 line2 |= pImage->getPixel(0, m_loopIndex - 1) << 2; | 750 line2 |= pImage->getPixel(0, m_loopIndex - 1) << 2; |
811 line3 = 0; | 751 uint32_t line3 = 0; |
812 for (uint32_t w = 0; w < GBW; w++) { | 752 for (uint32_t w = 0; w < GBW; w++) { |
| 753 FX_BOOL bVal; |
813 if (USESKIP && SKIP->getPixel(w, m_loopIndex)) { | 754 if (USESKIP && SKIP->getPixel(w, m_loopIndex)) { |
814 bVal = 0; | 755 bVal = 0; |
815 } else { | 756 } else { |
816 CONTEXT = line3; | 757 uint32_t CONTEXT = line3; |
817 CONTEXT |= pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 4; | 758 CONTEXT |= pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 4; |
818 CONTEXT |= line2 << 5; | 759 CONTEXT |= line2 << 5; |
819 CONTEXT |= pImage->getPixel(w + GBAT[2], m_loopIndex + GBAT[3]) << 10; | 760 CONTEXT |= pImage->getPixel(w + GBAT[2], m_loopIndex + GBAT[3]) << 10; |
820 CONTEXT |= pImage->getPixel(w + GBAT[4], m_loopIndex + GBAT[5]) << 11; | 761 CONTEXT |= pImage->getPixel(w + GBAT[4], m_loopIndex + GBAT[5]) << 11; |
821 CONTEXT |= line1 << 12; | 762 CONTEXT |= line1 << 12; |
822 CONTEXT |= pImage->getPixel(w + GBAT[6], m_loopIndex + GBAT[7]) << 15; | 763 CONTEXT |= pImage->getPixel(w + GBAT[6], m_loopIndex + GBAT[7]) << 15; |
823 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 764 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
824 } | 765 } |
825 if (bVal) { | 766 if (bVal) { |
826 pImage->setPixel(w, m_loopIndex, bVal); | 767 pImage->setPixel(w, m_loopIndex, bVal); |
(...skipping 13 matching lines...) Expand all Loading... |
840 } | 781 } |
841 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 782 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
842 return FXCODEC_STATUS_DECODE_FINISH; | 783 return FXCODEC_STATUS_DECODE_FINISH; |
843 } | 784 } |
844 | 785 |
845 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_opt3( | 786 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_opt3( |
846 CJBig2_Image* pImage, | 787 CJBig2_Image* pImage, |
847 CJBig2_ArithDecoder* pArithDecoder, | 788 CJBig2_ArithDecoder* pArithDecoder, |
848 JBig2ArithCtx* gbContext, | 789 JBig2ArithCtx* gbContext, |
849 IFX_Pause* pPause) { | 790 IFX_Pause* pPause) { |
850 FX_BOOL SLTP, bVal; | |
851 uint32_t CONTEXT; | |
852 uint32_t line1, line2; | |
853 uint8_t *pLine1, *pLine2, cVal; | |
854 int32_t nStride, nStride2, k; | |
855 int32_t nLineBytes, nBitsLeft, cc; | |
856 if (!m_pLine) { | 791 if (!m_pLine) { |
857 m_pLine = pImage->m_pData; | 792 m_pLine = pImage->m_pData; |
858 } | 793 } |
859 nStride = pImage->m_nStride; | 794 int32_t nStride = pImage->m_nStride; |
860 nStride2 = nStride << 1; | 795 int32_t nStride2 = nStride << 1; |
861 nLineBytes = ((GBW + 7) >> 3) - 1; | 796 int32_t nLineBytes = ((GBW + 7) >> 3) - 1; |
862 nBitsLeft = GBW - (nLineBytes << 3); | 797 int32_t nBitsLeft = GBW - (nLineBytes << 3); |
863 for (; m_loopIndex < GBH; m_loopIndex++) { | 798 for (; m_loopIndex < GBH; m_loopIndex++) { |
864 if (TPGDON) { | 799 if (TPGDON) |
865 SLTP = pArithDecoder->DECODE(&gbContext[0x0795]); | 800 m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x0795]); |
866 LTP = LTP ^ SLTP; | 801 if (m_LTP) { |
867 } | |
868 if (LTP == 1) { | |
869 pImage->copyLine(m_loopIndex, m_loopIndex - 1); | 802 pImage->copyLine(m_loopIndex, m_loopIndex - 1); |
870 } else { | 803 } else { |
871 if (m_loopIndex > 1) { | 804 if (m_loopIndex > 1) { |
872 pLine1 = m_pLine - nStride2; | 805 uint8_t* pLine1 = m_pLine - nStride2; |
873 pLine2 = m_pLine - nStride; | 806 uint8_t* pLine2 = m_pLine - nStride; |
874 line1 = (*pLine1++) << 4; | 807 uint32_t line1 = (*pLine1++) << 4; |
875 line2 = *pLine2++; | 808 uint32_t line2 = *pLine2++; |
876 CONTEXT = (line1 & 0x1e00) | ((line2 >> 1) & 0x01f8); | 809 uint32_t CONTEXT = (line1 & 0x1e00) | ((line2 >> 1) & 0x01f8); |
877 for (cc = 0; cc < nLineBytes; cc++) { | 810 for (int32_t cc = 0; cc < nLineBytes; cc++) { |
878 line1 = (line1 << 8) | ((*pLine1++) << 4); | 811 line1 = (line1 << 8) | ((*pLine1++) << 4); |
879 line2 = (line2 << 8) | (*pLine2++); | 812 line2 = (line2 << 8) | (*pLine2++); |
880 cVal = 0; | 813 uint8_t cVal = 0; |
881 for (k = 7; k >= 0; k--) { | 814 for (int32_t k = 7; k >= 0; k--) { |
882 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 815 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
883 cVal |= bVal << k; | 816 cVal |= bVal << k; |
884 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | | 817 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | |
885 ((line1 >> k) & 0x0200) | ((line2 >> (k + 1)) & 0x0008); | 818 ((line1 >> k) & 0x0200) | ((line2 >> (k + 1)) & 0x0008); |
886 } | 819 } |
887 m_pLine[cc] = cVal; | 820 m_pLine[cc] = cVal; |
888 } | 821 } |
889 line1 <<= 8; | 822 line1 <<= 8; |
890 line2 <<= 8; | 823 line2 <<= 8; |
891 cVal = 0; | 824 uint8_t cVal1 = 0; |
892 for (k = 0; k < nBitsLeft; k++) { | 825 for (int32_t k = 0; k < nBitsLeft; k++) { |
893 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 826 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
894 cVal |= bVal << (7 - k); | 827 cVal1 |= bVal << (7 - k); |
895 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | | 828 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | |
896 ((line1 >> (7 - k)) & 0x0200) | | 829 ((line1 >> (7 - k)) & 0x0200) | |
897 ((line2 >> (8 - k)) & 0x0008); | 830 ((line2 >> (8 - k)) & 0x0008); |
898 } | 831 } |
899 m_pLine[nLineBytes] = cVal; | 832 m_pLine[nLineBytes] = cVal1; |
900 } else { | 833 } else { |
901 pLine2 = m_pLine - nStride; | 834 uint8_t* pLine2 = m_pLine - nStride; |
902 line2 = (m_loopIndex & 1) ? (*pLine2++) : 0; | 835 uint32_t line2 = (m_loopIndex & 1) ? (*pLine2++) : 0; |
903 CONTEXT = (line2 >> 1) & 0x01f8; | 836 uint32_t CONTEXT = (line2 >> 1) & 0x01f8; |
904 for (cc = 0; cc < nLineBytes; cc++) { | 837 for (int32_t cc = 0; cc < nLineBytes; cc++) { |
905 if (m_loopIndex & 1) { | 838 if (m_loopIndex & 1) { |
906 line2 = (line2 << 8) | (*pLine2++); | 839 line2 = (line2 << 8) | (*pLine2++); |
907 } | 840 } |
908 cVal = 0; | 841 uint8_t cVal = 0; |
909 for (k = 7; k >= 0; k--) { | 842 for (int32_t k = 7; k >= 0; k--) { |
910 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 843 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
911 cVal |= bVal << k; | 844 cVal |= bVal << k; |
912 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | | 845 CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal | |
913 ((line2 >> (k + 1)) & 0x0008); | 846 ((line2 >> (k + 1)) & 0x0008); |
914 } | 847 } |
915 m_pLine[cc] = cVal; | 848 m_pLine[cc] = cVal; |
916 } | 849 } |
917 line2 <<= 8; | 850 line2 <<= 8; |
918 cVal = 0; | 851 uint8_t cVal1 = 0; |
919 for (k = 0; k < nBitsLeft; k++) { | 852 for (int32_t k = 0; k < nBitsLeft; k++) { |
920 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 853 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
921 cVal |= bVal << (7 - k); | 854 cVal1 |= bVal << (7 - k); |
922 CONTEXT = | 855 CONTEXT = |
923 ((CONTEXT & 0x0efb) << 1) | bVal | ((line2 >> (8 - k)) & 0x0008); | 856 ((CONTEXT & 0x0efb) << 1) | bVal | ((line2 >> (8 - k)) & 0x0008); |
924 } | 857 } |
925 m_pLine[nLineBytes] = cVal; | 858 m_pLine[nLineBytes] = cVal1; |
926 } | 859 } |
927 } | 860 } |
928 m_pLine += nStride; | 861 m_pLine += nStride; |
929 if (pPause && pPause->NeedToPauseNow()) { | 862 if (pPause && pPause->NeedToPauseNow()) { |
930 m_loopIndex++; | 863 m_loopIndex++; |
931 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 864 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
932 return FXCODEC_STATUS_DECODE_TOBECONTINUE; | 865 return FXCODEC_STATUS_DECODE_TOBECONTINUE; |
933 } | 866 } |
934 } | 867 } |
935 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 868 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
936 return FXCODEC_STATUS_DECODE_FINISH; | 869 return FXCODEC_STATUS_DECODE_FINISH; |
937 } | 870 } |
938 | 871 |
939 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_unopt( | 872 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_unopt( |
940 CJBig2_Image* pImage, | 873 CJBig2_Image* pImage, |
941 CJBig2_ArithDecoder* pArithDecoder, | 874 CJBig2_ArithDecoder* pArithDecoder, |
942 JBig2ArithCtx* gbContext, | 875 JBig2ArithCtx* gbContext, |
943 IFX_Pause* pPause) { | 876 IFX_Pause* pPause) { |
944 FX_BOOL SLTP, bVal; | |
945 uint32_t CONTEXT; | |
946 uint32_t line1, line2, line3; | |
947 for (uint32_t h = 0; h < GBH; h++) { | 877 for (uint32_t h = 0; h < GBH; h++) { |
948 if (TPGDON) { | 878 if (TPGDON) |
949 SLTP = pArithDecoder->DECODE(&gbContext[0x0795]); | 879 m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x0795]); |
950 LTP = LTP ^ SLTP; | 880 if (m_LTP) { |
951 } | |
952 if (LTP == 1) { | |
953 pImage->copyLine(h, h - 1); | 881 pImage->copyLine(h, h - 1); |
954 } else { | 882 } else { |
955 line1 = pImage->getPixel(2, h - 2); | 883 uint32_t line1 = pImage->getPixel(2, h - 2); |
956 line1 |= pImage->getPixel(1, h - 2) << 1; | 884 line1 |= pImage->getPixel(1, h - 2) << 1; |
957 line1 |= pImage->getPixel(0, h - 2) << 2; | 885 line1 |= pImage->getPixel(0, h - 2) << 2; |
958 line2 = pImage->getPixel(2, h - 1); | 886 uint32_t line2 = pImage->getPixel(2, h - 1); |
959 line2 |= pImage->getPixel(1, h - 1) << 1; | 887 line2 |= pImage->getPixel(1, h - 1) << 1; |
960 line2 |= pImage->getPixel(0, h - 1) << 2; | 888 line2 |= pImage->getPixel(0, h - 1) << 2; |
961 line3 = 0; | 889 uint32_t line3 = 0; |
962 for (uint32_t w = 0; w < GBW; w++) { | 890 for (uint32_t w = 0; w < GBW; w++) { |
| 891 FX_BOOL bVal; |
963 if (USESKIP && SKIP->getPixel(w, h)) { | 892 if (USESKIP && SKIP->getPixel(w, h)) { |
964 bVal = 0; | 893 bVal = 0; |
965 } else { | 894 } else { |
966 CONTEXT = line3; | 895 uint32_t CONTEXT = line3; |
967 CONTEXT |= pImage->getPixel(w + GBAT[0], h + GBAT[1]) << 3; | 896 CONTEXT |= pImage->getPixel(w + GBAT[0], h + GBAT[1]) << 3; |
968 CONTEXT |= line2 << 4; | 897 CONTEXT |= line2 << 4; |
969 CONTEXT |= line1 << 9; | 898 CONTEXT |= line1 << 9; |
970 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 899 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
971 } | 900 } |
972 if (bVal) { | 901 if (bVal) { |
973 pImage->setPixel(w, h, bVal); | 902 pImage->setPixel(w, h, bVal); |
974 } | 903 } |
975 line1 = ((line1 << 1) | pImage->getPixel(w + 3, h - 2)) & 0x0f; | 904 line1 = ((line1 << 1) | pImage->getPixel(w + 3, h - 2)) & 0x0f; |
976 line2 = ((line2 << 1) | pImage->getPixel(w + 3, h - 1)) & 0x1f; | 905 line2 = ((line2 << 1) | pImage->getPixel(w + 3, h - 1)) & 0x1f; |
977 line3 = ((line3 << 1) | bVal) & 0x07; | 906 line3 = ((line3 << 1) | bVal) & 0x07; |
978 } | 907 } |
979 } | 908 } |
980 if (pPause && pPause->NeedToPauseNow()) { | 909 if (pPause && pPause->NeedToPauseNow()) { |
981 m_loopIndex++; | 910 m_loopIndex++; |
982 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 911 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
983 return FXCODEC_STATUS_DECODE_TOBECONTINUE; | 912 return FXCODEC_STATUS_DECODE_TOBECONTINUE; |
984 } | 913 } |
985 } | 914 } |
986 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 915 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
987 return FXCODEC_STATUS_DECODE_FINISH; | 916 return FXCODEC_STATUS_DECODE_FINISH; |
988 } | 917 } |
989 | 918 |
990 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_opt3( | 919 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_opt3( |
991 CJBig2_Image* pImage, | 920 CJBig2_Image* pImage, |
992 CJBig2_ArithDecoder* pArithDecoder, | 921 CJBig2_ArithDecoder* pArithDecoder, |
993 JBig2ArithCtx* gbContext, | 922 JBig2ArithCtx* gbContext, |
994 IFX_Pause* pPause) { | 923 IFX_Pause* pPause) { |
995 FX_BOOL SLTP, bVal; | |
996 uint32_t CONTEXT; | |
997 uint32_t line1, line2; | |
998 uint8_t *pLine1, *pLine2, cVal; | |
999 int32_t nStride, nStride2, k; | |
1000 int32_t nLineBytes, nBitsLeft, cc; | |
1001 if (!m_pLine) { | 924 if (!m_pLine) { |
1002 m_pLine = pImage->m_pData; | 925 m_pLine = pImage->m_pData; |
1003 } | 926 } |
1004 nStride = pImage->m_nStride; | 927 int32_t nStride = pImage->m_nStride; |
1005 nStride2 = nStride << 1; | 928 int32_t nStride2 = nStride << 1; |
1006 nLineBytes = ((GBW + 7) >> 3) - 1; | 929 int32_t nLineBytes = ((GBW + 7) >> 3) - 1; |
1007 nBitsLeft = GBW - (nLineBytes << 3); | 930 int32_t nBitsLeft = GBW - (nLineBytes << 3); |
1008 for (; m_loopIndex < GBH; m_loopIndex++) { | 931 for (; m_loopIndex < GBH; m_loopIndex++) { |
1009 if (TPGDON) { | 932 if (TPGDON) |
1010 SLTP = pArithDecoder->DECODE(&gbContext[0x00e5]); | 933 m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x00e5]); |
1011 LTP = LTP ^ SLTP; | 934 if (m_LTP) { |
1012 } | |
1013 if (LTP == 1) { | |
1014 pImage->copyLine(m_loopIndex, m_loopIndex - 1); | 935 pImage->copyLine(m_loopIndex, m_loopIndex - 1); |
1015 } else { | 936 } else { |
1016 if (m_loopIndex > 1) { | 937 if (m_loopIndex > 1) { |
1017 pLine1 = m_pLine - nStride2; | 938 uint8_t* pLine1 = m_pLine - nStride2; |
1018 pLine2 = m_pLine - nStride; | 939 uint8_t* pLine2 = m_pLine - nStride; |
1019 line1 = (*pLine1++) << 1; | 940 uint32_t line1 = (*pLine1++) << 1; |
1020 line2 = *pLine2++; | 941 uint32_t line2 = *pLine2++; |
1021 CONTEXT = (line1 & 0x0380) | ((line2 >> 3) & 0x007c); | 942 uint32_t CONTEXT = (line1 & 0x0380) | ((line2 >> 3) & 0x007c); |
1022 for (cc = 0; cc < nLineBytes; cc++) { | 943 for (int32_t cc = 0; cc < nLineBytes; cc++) { |
1023 line1 = (line1 << 8) | ((*pLine1++) << 1); | 944 line1 = (line1 << 8) | ((*pLine1++) << 1); |
1024 line2 = (line2 << 8) | (*pLine2++); | 945 line2 = (line2 << 8) | (*pLine2++); |
1025 cVal = 0; | 946 uint8_t cVal = 0; |
1026 for (k = 7; k >= 0; k--) { | 947 for (int32_t k = 7; k >= 0; k--) { |
1027 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 948 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
1028 cVal |= bVal << k; | 949 cVal |= bVal << k; |
1029 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | | 950 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | |
1030 ((line1 >> k) & 0x0080) | ((line2 >> (k + 3)) & 0x0004); | 951 ((line1 >> k) & 0x0080) | ((line2 >> (k + 3)) & 0x0004); |
1031 } | 952 } |
1032 m_pLine[cc] = cVal; | 953 m_pLine[cc] = cVal; |
1033 } | 954 } |
1034 line1 <<= 8; | 955 line1 <<= 8; |
1035 line2 <<= 8; | 956 line2 <<= 8; |
1036 cVal = 0; | 957 uint8_t cVal1 = 0; |
1037 for (k = 0; k < nBitsLeft; k++) { | 958 for (int32_t k = 0; k < nBitsLeft; k++) { |
1038 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 959 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
1039 cVal |= bVal << (7 - k); | 960 cVal1 |= bVal << (7 - k); |
1040 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | | 961 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | |
1041 ((line1 >> (7 - k)) & 0x0080) | | 962 ((line1 >> (7 - k)) & 0x0080) | |
1042 ((line2 >> (10 - k)) & 0x0004); | 963 ((line2 >> (10 - k)) & 0x0004); |
1043 } | 964 } |
1044 m_pLine[nLineBytes] = cVal; | 965 m_pLine[nLineBytes] = cVal1; |
1045 } else { | 966 } else { |
1046 pLine2 = m_pLine - nStride; | 967 uint8_t* pLine2 = m_pLine - nStride; |
1047 line2 = (m_loopIndex & 1) ? (*pLine2++) : 0; | 968 uint32_t line2 = (m_loopIndex & 1) ? (*pLine2++) : 0; |
1048 CONTEXT = (line2 >> 3) & 0x007c; | 969 uint32_t CONTEXT = (line2 >> 3) & 0x007c; |
1049 for (cc = 0; cc < nLineBytes; cc++) { | 970 for (int32_t cc = 0; cc < nLineBytes; cc++) { |
1050 if (m_loopIndex & 1) { | 971 if (m_loopIndex & 1) { |
1051 line2 = (line2 << 8) | (*pLine2++); | 972 line2 = (line2 << 8) | (*pLine2++); |
1052 } | 973 } |
1053 cVal = 0; | 974 uint8_t cVal = 0; |
1054 for (k = 7; k >= 0; k--) { | 975 for (int32_t k = 7; k >= 0; k--) { |
1055 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 976 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
1056 cVal |= bVal << k; | 977 cVal |= bVal << k; |
1057 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | | 978 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | |
1058 ((line2 >> (k + 3)) & 0x0004); | 979 ((line2 >> (k + 3)) & 0x0004); |
1059 } | 980 } |
1060 m_pLine[cc] = cVal; | 981 m_pLine[cc] = cVal; |
1061 } | 982 } |
1062 line2 <<= 8; | 983 line2 <<= 8; |
1063 cVal = 0; | 984 uint8_t cVal1 = 0; |
1064 for (k = 0; k < nBitsLeft; k++) { | 985 for (int32_t k = 0; k < nBitsLeft; k++) { |
1065 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 986 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
1066 cVal |= bVal << (7 - k); | 987 cVal1 |= bVal << (7 - k); |
1067 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | | 988 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | |
1068 (((line2 >> (10 - k))) & 0x0004); | 989 (((line2 >> (10 - k))) & 0x0004); |
1069 } | 990 } |
1070 m_pLine[nLineBytes] = cVal; | 991 m_pLine[nLineBytes] = cVal1; |
1071 } | 992 } |
1072 } | 993 } |
1073 m_pLine += nStride; | 994 m_pLine += nStride; |
1074 if (pPause && m_loopIndex % 50 == 0 && pPause->NeedToPauseNow()) { | 995 if (pPause && m_loopIndex % 50 == 0 && pPause->NeedToPauseNow()) { |
1075 m_loopIndex++; | 996 m_loopIndex++; |
1076 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 997 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
1077 return FXCODEC_STATUS_DECODE_TOBECONTINUE; | 998 return FXCODEC_STATUS_DECODE_TOBECONTINUE; |
1078 } | 999 } |
1079 } | 1000 } |
1080 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 1001 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
1081 return FXCODEC_STATUS_DECODE_FINISH; | 1002 return FXCODEC_STATUS_DECODE_FINISH; |
1082 } | 1003 } |
1083 | 1004 |
1084 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_unopt( | 1005 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_unopt( |
1085 CJBig2_Image* pImage, | 1006 CJBig2_Image* pImage, |
1086 CJBig2_ArithDecoder* pArithDecoder, | 1007 CJBig2_ArithDecoder* pArithDecoder, |
1087 JBig2ArithCtx* gbContext, | 1008 JBig2ArithCtx* gbContext, |
1088 IFX_Pause* pPause) { | 1009 IFX_Pause* pPause) { |
1089 FX_BOOL SLTP, bVal; | |
1090 uint32_t CONTEXT; | |
1091 uint32_t line1, line2, line3; | |
1092 for (; m_loopIndex < GBH; m_loopIndex++) { | 1010 for (; m_loopIndex < GBH; m_loopIndex++) { |
1093 if (TPGDON) { | 1011 if (TPGDON) |
1094 SLTP = pArithDecoder->DECODE(&gbContext[0x00e5]); | 1012 m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x00e5]); |
1095 LTP = LTP ^ SLTP; | 1013 if (m_LTP) { |
1096 } | |
1097 if (LTP == 1) { | |
1098 pImage->copyLine(m_loopIndex, m_loopIndex - 1); | 1014 pImage->copyLine(m_loopIndex, m_loopIndex - 1); |
1099 } else { | 1015 } else { |
1100 line1 = pImage->getPixel(1, m_loopIndex - 2); | 1016 uint32_t line1 = pImage->getPixel(1, m_loopIndex - 2); |
1101 line1 |= pImage->getPixel(0, m_loopIndex - 2) << 1; | 1017 line1 |= pImage->getPixel(0, m_loopIndex - 2) << 1; |
1102 line2 = pImage->getPixel(1, m_loopIndex - 1); | 1018 uint32_t line2 = pImage->getPixel(1, m_loopIndex - 1); |
1103 line2 |= pImage->getPixel(0, m_loopIndex - 1) << 1; | 1019 line2 |= pImage->getPixel(0, m_loopIndex - 1) << 1; |
1104 line3 = 0; | 1020 uint32_t line3 = 0; |
1105 for (uint32_t w = 0; w < GBW; w++) { | 1021 for (uint32_t w = 0; w < GBW; w++) { |
| 1022 FX_BOOL bVal; |
1106 if (USESKIP && SKIP->getPixel(w, m_loopIndex)) { | 1023 if (USESKIP && SKIP->getPixel(w, m_loopIndex)) { |
1107 bVal = 0; | 1024 bVal = 0; |
1108 } else { | 1025 } else { |
1109 CONTEXT = line3; | 1026 uint32_t CONTEXT = line3; |
1110 CONTEXT |= pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 2; | 1027 CONTEXT |= pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 2; |
1111 CONTEXT |= line2 << 3; | 1028 CONTEXT |= line2 << 3; |
1112 CONTEXT |= line1 << 7; | 1029 CONTEXT |= line1 << 7; |
1113 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 1030 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
1114 } | 1031 } |
1115 if (bVal) { | 1032 if (bVal) { |
1116 pImage->setPixel(w, m_loopIndex, bVal); | 1033 pImage->setPixel(w, m_loopIndex, bVal); |
1117 } | 1034 } |
1118 line1 = | 1035 line1 = |
1119 ((line1 << 1) | pImage->getPixel(w + 2, m_loopIndex - 2)) & 0x07; | 1036 ((line1 << 1) | pImage->getPixel(w + 2, m_loopIndex - 2)) & 0x07; |
(...skipping 10 matching lines...) Expand all Loading... |
1130 } | 1047 } |
1131 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 1048 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
1132 return FXCODEC_STATUS_DECODE_FINISH; | 1049 return FXCODEC_STATUS_DECODE_FINISH; |
1133 } | 1050 } |
1134 | 1051 |
1135 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_opt3( | 1052 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_opt3( |
1136 CJBig2_Image* pImage, | 1053 CJBig2_Image* pImage, |
1137 CJBig2_ArithDecoder* pArithDecoder, | 1054 CJBig2_ArithDecoder* pArithDecoder, |
1138 JBig2ArithCtx* gbContext, | 1055 JBig2ArithCtx* gbContext, |
1139 IFX_Pause* pPause) { | 1056 IFX_Pause* pPause) { |
1140 FX_BOOL SLTP, bVal; | 1057 if (!m_pLine) |
1141 uint32_t CONTEXT; | |
1142 uint32_t line1; | |
1143 uint8_t *pLine1, cVal; | |
1144 int32_t nStride, k; | |
1145 int32_t nLineBytes, nBitsLeft, cc; | |
1146 if (!m_pLine) { | |
1147 m_pLine = pImage->m_pData; | 1058 m_pLine = pImage->m_pData; |
1148 } | 1059 |
1149 nStride = pImage->m_nStride; | 1060 int32_t nStride = pImage->m_nStride; |
1150 nLineBytes = ((GBW + 7) >> 3) - 1; | 1061 int32_t nLineBytes = ((GBW + 7) >> 3) - 1; |
1151 nBitsLeft = GBW - (nLineBytes << 3); | 1062 int32_t nBitsLeft = GBW - (nLineBytes << 3); |
1152 for (; m_loopIndex < GBH; m_loopIndex++) { | 1063 for (; m_loopIndex < GBH; m_loopIndex++) { |
1153 if (TPGDON) { | 1064 if (TPGDON) |
1154 SLTP = pArithDecoder->DECODE(&gbContext[0x0195]); | 1065 m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x0195]); |
1155 LTP = LTP ^ SLTP; | 1066 if (m_LTP) { |
1156 } | |
1157 if (LTP == 1) { | |
1158 pImage->copyLine(m_loopIndex, m_loopIndex - 1); | 1067 pImage->copyLine(m_loopIndex, m_loopIndex - 1); |
1159 } else { | 1068 } else { |
1160 if (m_loopIndex > 0) { | 1069 if (m_loopIndex > 0) { |
1161 pLine1 = m_pLine - nStride; | 1070 uint8_t* pLine1 = m_pLine - nStride; |
1162 line1 = *pLine1++; | 1071 uint32_t line1 = *pLine1++; |
1163 CONTEXT = (line1 >> 1) & 0x03f0; | 1072 uint32_t CONTEXT = (line1 >> 1) & 0x03f0; |
1164 for (cc = 0; cc < nLineBytes; cc++) { | 1073 for (int32_t cc = 0; cc < nLineBytes; cc++) { |
1165 line1 = (line1 << 8) | (*pLine1++); | 1074 line1 = (line1 << 8) | (*pLine1++); |
1166 cVal = 0; | 1075 uint8_t cVal = 0; |
1167 for (k = 7; k >= 0; k--) { | 1076 for (int32_t k = 7; k >= 0; k--) { |
1168 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 1077 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
1169 cVal |= bVal << k; | 1078 cVal |= bVal << k; |
1170 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal | | 1079 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal | |
1171 ((line1 >> (k + 1)) & 0x0010); | 1080 ((line1 >> (k + 1)) & 0x0010); |
1172 } | 1081 } |
1173 m_pLine[cc] = cVal; | 1082 m_pLine[cc] = cVal; |
1174 } | 1083 } |
1175 line1 <<= 8; | 1084 line1 <<= 8; |
1176 cVal = 0; | 1085 uint8_t cVal1 = 0; |
1177 for (k = 0; k < nBitsLeft; k++) { | 1086 for (int32_t k = 0; k < nBitsLeft; k++) { |
1178 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 1087 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
1179 cVal |= bVal << (7 - k); | 1088 cVal1 |= bVal << (7 - k); |
1180 CONTEXT = | 1089 CONTEXT = |
1181 ((CONTEXT & 0x01f7) << 1) | bVal | ((line1 >> (8 - k)) & 0x0010); | 1090 ((CONTEXT & 0x01f7) << 1) | bVal | ((line1 >> (8 - k)) & 0x0010); |
1182 } | 1091 } |
1183 m_pLine[nLineBytes] = cVal; | 1092 m_pLine[nLineBytes] = cVal1; |
1184 } else { | 1093 } else { |
1185 CONTEXT = 0; | 1094 uint32_t CONTEXT = 0; |
1186 for (cc = 0; cc < nLineBytes; cc++) { | 1095 for (int32_t cc = 0; cc < nLineBytes; cc++) { |
1187 cVal = 0; | 1096 uint8_t cVal = 0; |
1188 for (k = 7; k >= 0; k--) { | 1097 for (int32_t k = 7; k >= 0; k--) { |
1189 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 1098 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
1190 cVal |= bVal << k; | 1099 cVal |= bVal << k; |
1191 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal; | 1100 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal; |
1192 } | 1101 } |
1193 m_pLine[cc] = cVal; | 1102 m_pLine[cc] = cVal; |
1194 } | 1103 } |
1195 cVal = 0; | 1104 uint8_t cVal1 = 0; |
1196 for (k = 0; k < nBitsLeft; k++) { | 1105 for (int32_t k = 0; k < nBitsLeft; k++) { |
1197 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 1106 FX_BOOL bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
1198 cVal |= bVal << (7 - k); | 1107 cVal1 |= bVal << (7 - k); |
1199 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal; | 1108 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal; |
1200 } | 1109 } |
1201 m_pLine[nLineBytes] = cVal; | 1110 m_pLine[nLineBytes] = cVal1; |
1202 } | 1111 } |
1203 } | 1112 } |
1204 m_pLine += nStride; | 1113 m_pLine += nStride; |
1205 if (pPause && pPause->NeedToPauseNow()) { | 1114 if (pPause && pPause->NeedToPauseNow()) { |
1206 m_loopIndex++; | 1115 m_loopIndex++; |
1207 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 1116 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
1208 return FXCODEC_STATUS_DECODE_TOBECONTINUE; | 1117 return FXCODEC_STATUS_DECODE_TOBECONTINUE; |
1209 } | 1118 } |
1210 } | 1119 } |
1211 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 1120 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
1212 return FXCODEC_STATUS_DECODE_FINISH; | 1121 return FXCODEC_STATUS_DECODE_FINISH; |
1213 } | 1122 } |
1214 | 1123 |
1215 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_unopt( | 1124 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_unopt( |
1216 CJBig2_Image* pImage, | 1125 CJBig2_Image* pImage, |
1217 CJBig2_ArithDecoder* pArithDecoder, | 1126 CJBig2_ArithDecoder* pArithDecoder, |
1218 JBig2ArithCtx* gbContext, | 1127 JBig2ArithCtx* gbContext, |
1219 IFX_Pause* pPause) { | 1128 IFX_Pause* pPause) { |
1220 FX_BOOL SLTP, bVal; | |
1221 uint32_t CONTEXT; | |
1222 uint32_t line1, line2; | |
1223 for (; m_loopIndex < GBH; m_loopIndex++) { | 1129 for (; m_loopIndex < GBH; m_loopIndex++) { |
1224 if (TPGDON) { | 1130 if (TPGDON) |
1225 SLTP = pArithDecoder->DECODE(&gbContext[0x0195]); | 1131 m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x0195]); |
1226 LTP = LTP ^ SLTP; | 1132 if (m_LTP) { |
1227 } | |
1228 if (LTP == 1) { | |
1229 pImage->copyLine(m_loopIndex, m_loopIndex - 1); | 1133 pImage->copyLine(m_loopIndex, m_loopIndex - 1); |
1230 } else { | 1134 } else { |
1231 line1 = pImage->getPixel(1, m_loopIndex - 1); | 1135 uint32_t line1 = pImage->getPixel(1, m_loopIndex - 1); |
1232 line1 |= pImage->getPixel(0, m_loopIndex - 1) << 1; | 1136 line1 |= pImage->getPixel(0, m_loopIndex - 1) << 1; |
1233 line2 = 0; | 1137 uint32_t line2 = 0; |
1234 for (uint32_t w = 0; w < GBW; w++) { | 1138 for (uint32_t w = 0; w < GBW; w++) { |
| 1139 FX_BOOL bVal; |
1235 if (USESKIP && SKIP->getPixel(w, m_loopIndex)) { | 1140 if (USESKIP && SKIP->getPixel(w, m_loopIndex)) { |
1236 bVal = 0; | 1141 bVal = 0; |
1237 } else { | 1142 } else { |
1238 CONTEXT = line2; | 1143 uint32_t CONTEXT = line2; |
1239 CONTEXT |= pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 4; | 1144 CONTEXT |= pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 4; |
1240 CONTEXT |= line1 << 5; | 1145 CONTEXT |= line1 << 5; |
1241 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 1146 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
1242 } | 1147 } |
1243 if (bVal) { | 1148 if (bVal) { |
1244 pImage->setPixel(w, m_loopIndex, bVal); | 1149 pImage->setPixel(w, m_loopIndex, bVal); |
1245 } | 1150 } |
1246 line1 = | 1151 line1 = |
1247 ((line1 << 1) | pImage->getPixel(w + 2, m_loopIndex - 1)) & 0x1f; | 1152 ((line1 << 1) | pImage->getPixel(w + 2, m_loopIndex - 1)) & 0x1f; |
1248 line2 = ((line2 << 1) | bVal) & 0x0f; | 1153 line2 = ((line2 << 1) | bVal) & 0x0f; |
1249 } | 1154 } |
1250 } | 1155 } |
1251 if (pPause && pPause->NeedToPauseNow()) { | 1156 if (pPause && pPause->NeedToPauseNow()) { |
1252 m_loopIndex++; | 1157 m_loopIndex++; |
1253 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 1158 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
1254 return FXCODEC_STATUS_DECODE_TOBECONTINUE; | 1159 return FXCODEC_STATUS_DECODE_TOBECONTINUE; |
1255 } | 1160 } |
1256 } | 1161 } |
1257 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 1162 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
1258 return FXCODEC_STATUS_DECODE_FINISH; | 1163 return FXCODEC_STATUS_DECODE_FINISH; |
1259 } | 1164 } |
OLD | NEW |