OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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 "JBig2_GeneralDecoder.h" | 7 #include "JBig2_GeneralDecoder.h" |
| 8 |
| 9 #include "../../../../third_party/base/nonstd_unique_ptr.h" |
8 #include "JBig2_ArithDecoder.h" | 10 #include "JBig2_ArithDecoder.h" |
9 #include "JBig2_ArithIntDecoder.h" | 11 #include "JBig2_ArithIntDecoder.h" |
10 #include "JBig2_HuffmanDecoder.h" | 12 #include "JBig2_HuffmanDecoder.h" |
11 #include "JBig2_HuffmanTable.h" | 13 #include "JBig2_HuffmanTable.h" |
12 #include "JBig2_PatternDict.h" | 14 #include "JBig2_PatternDict.h" |
13 | 15 |
14 extern const JBig2ArithQe QeTable[] = { | 16 extern const JBig2ArithQe QeTable[] = { |
15 {0x5601, 1, 1, 1}, {0x3401, 2, 6, 0}, {0x1801, 3, 9, 0}, | 17 {0x5601, 1, 1, 1}, {0x3401, 2, 6, 0}, {0x1801, 3, 9, 0}, |
16 {0x0AC1, 4, 12, 0}, {0x0521, 5, 29, 0}, {0x0221, 38, 33, 0}, | 18 {0x0AC1, 4, 12, 0}, {0x0521, 5, 29, 0}, {0x0221, 38, 33, 0}, |
17 {0x5601, 7, 6, 1}, {0x5401, 8, 14, 0}, {0x4801, 9, 14, 0}, | 19 {0x5601, 7, 6, 1}, {0x5401, 8, 14, 0}, {0x4801, 9, 14, 0}, |
18 {0x3801, 10, 14, 0}, {0x3001, 11, 17, 0}, {0x2401, 12, 18, 0}, | 20 {0x3801, 10, 14, 0}, {0x3001, 11, 17, 0}, {0x2401, 12, 18, 0}, |
19 {0x1C01, 13, 20, 0}, {0x1601, 29, 21, 0}, {0x5601, 15, 14, 1}, | 21 {0x1C01, 13, 20, 0}, {0x1601, 29, 21, 0}, {0x5601, 15, 14, 1}, |
20 {0x5401, 16, 14, 0}, {0x5101, 17, 15, 0}, {0x4801, 18, 16, 0}, | 22 {0x5401, 16, 14, 0}, {0x5101, 17, 15, 0}, {0x4801, 18, 16, 0}, |
21 {0x3801, 19, 17, 0}, {0x3401, 20, 18, 0}, {0x3001, 21, 19, 0}, | 23 {0x3801, 19, 17, 0}, {0x3401, 20, 18, 0}, {0x3001, 21, 19, 0}, |
22 {0x2801, 22, 19, 0}, {0x2401, 23, 20, 0}, {0x2201, 24, 21, 0}, | 24 {0x2801, 22, 19, 0}, {0x2401, 23, 20, 0}, {0x2201, 24, 21, 0}, |
23 {0x1C01, 25, 22, 0}, {0x1801, 26, 23, 0}, {0x1601, 27, 24, 0}, | 25 {0x1C01, 25, 22, 0}, {0x1801, 26, 23, 0}, {0x1601, 27, 24, 0}, |
24 {0x1401, 28, 25, 0}, {0x1201, 29, 26, 0}, {0x1101, 30, 27, 0}, | 26 {0x1401, 28, 25, 0}, {0x1201, 29, 26, 0}, {0x1101, 30, 27, 0}, |
25 {0x0AC1, 31, 28, 0}, {0x09C1, 32, 29, 0}, {0x08A1, 33, 30, 0}, | 27 {0x0AC1, 31, 28, 0}, {0x09C1, 32, 29, 0}, {0x08A1, 33, 30, 0}, |
26 {0x0521, 34, 31, 0}, {0x0441, 35, 32, 0}, {0x02A1, 36, 33, 0}, | 28 {0x0521, 34, 31, 0}, {0x0441, 35, 32, 0}, {0x02A1, 36, 33, 0}, |
27 {0x0221, 37, 34, 0}, {0x0141, 38, 35, 0}, {0x0111, 39, 36, 0}, | 29 {0x0221, 37, 34, 0}, {0x0141, 38, 35, 0}, {0x0111, 39, 36, 0}, |
28 {0x0085, 40, 37, 0}, {0x0049, 41, 38, 0}, {0x0025, 42, 39, 0}, | 30 {0x0085, 40, 37, 0}, {0x0049, 41, 38, 0}, {0x0025, 42, 39, 0}, |
29 {0x0015, 43, 40, 0}, {0x0009, 44, 41, 0}, {0x0005, 45, 42, 0}, | 31 {0x0015, 43, 40, 0}, {0x0009, 44, 41, 0}, {0x0005, 45, 42, 0}, |
30 {0x0001, 45, 43, 0}, {0x5601, 46, 46, 0}}; | 32 {0x0001, 45, 43, 0}, {0x5601, 46, 46, 0}}; |
31 | 33 |
32 extern const unsigned int JBIG2_QE_NUM = FX_ArraySize(QeTable); | 34 extern const unsigned int JBIG2_QE_NUM = FX_ArraySize(QeTable); |
33 | 35 |
| 36 bool CJBig2_GRDProc::UseTemplate0Opt3() const { |
| 37 return (GBAT[0] == 3) && (GBAT[1] == -1) && (GBAT[2] == -3) && |
| 38 (GBAT[3] == -1) && (GBAT[4] == 2) && (GBAT[5] == -2) && |
| 39 (GBAT[6] == -2) && (GBAT[7] == -2); |
| 40 } |
| 41 |
| 42 bool CJBig2_GRDProc::UseTemplate1Opt3() const { |
| 43 return (GBAT[0] == 3) && (GBAT[1] == -1); |
| 44 } |
| 45 |
| 46 bool CJBig2_GRDProc::UseTemplate23Opt3() const { |
| 47 return (GBAT[0] == 2) && (GBAT[1] == -1); |
| 48 } |
| 49 |
34 CJBig2_Image* CJBig2_GRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, | 50 CJBig2_Image* CJBig2_GRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, |
35 JBig2ArithCtx* gbContext) { | 51 JBig2ArithCtx* gbContext) { |
36 if (GBW == 0 || GBH == 0) { | 52 if (GBW == 0 || GBH == 0) |
37 return new CJBig2_Image(GBW, GBH); | 53 return new CJBig2_Image(GBW, GBH); |
38 } | 54 |
39 if (GBTEMPLATE == 0) { | 55 if (GBTEMPLATE == 0) { |
40 if ((GBAT[0] == 3) && (GBAT[1] == (int8_t)-1) && (GBAT[2] == (int8_t)-3) && | 56 if (UseTemplate0Opt3()) |
41 (GBAT[3] == (int8_t)-1) && (GBAT[4] == 2) && (GBAT[5] == (int8_t)-2) && | |
42 (GBAT[6] == (int8_t)-2) && (GBAT[7] == (int8_t)-2)) { | |
43 return decode_Arith_Template0_opt3(pArithDecoder, gbContext); | 57 return decode_Arith_Template0_opt3(pArithDecoder, gbContext); |
44 } else { | 58 return decode_Arith_Template0_unopt(pArithDecoder, gbContext); |
45 return decode_Arith_Template0_unopt(pArithDecoder, gbContext); | |
46 } | |
47 } else if (GBTEMPLATE == 1) { | 59 } else if (GBTEMPLATE == 1) { |
48 if ((GBAT[0] == 3) && (GBAT[1] == (int8_t)-1)) { | 60 if (UseTemplate1Opt3()) |
49 return decode_Arith_Template1_opt3(pArithDecoder, gbContext); | 61 return decode_Arith_Template1_opt3(pArithDecoder, gbContext); |
50 } else { | 62 return decode_Arith_Template1_unopt(pArithDecoder, gbContext); |
51 return decode_Arith_Template1_unopt(pArithDecoder, gbContext); | |
52 } | |
53 } else if (GBTEMPLATE == 2) { | 63 } else if (GBTEMPLATE == 2) { |
54 if ((GBAT[0] == 2) && (GBAT[1] == (int8_t)-1)) { | 64 if (UseTemplate23Opt3()) |
55 return decode_Arith_Template2_opt3(pArithDecoder, gbContext); | 65 return decode_Arith_Template2_opt3(pArithDecoder, gbContext); |
56 } else { | 66 return decode_Arith_Template2_unopt(pArithDecoder, gbContext); |
57 return decode_Arith_Template2_unopt(pArithDecoder, gbContext); | |
58 } | |
59 } else { | 67 } else { |
60 if ((GBAT[0] == 2) && (GBAT[1] == (int8_t)-1)) { | 68 if (UseTemplate23Opt3()) |
61 return decode_Arith_Template3_opt3(pArithDecoder, gbContext); | 69 return decode_Arith_Template3_opt3(pArithDecoder, gbContext); |
62 } else { | 70 return decode_Arith_Template3_unopt(pArithDecoder, gbContext); |
63 return decode_Arith_Template3_unopt(pArithDecoder, gbContext); | |
64 } | |
65 } | 71 } |
66 } | 72 } |
67 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3( | 73 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3( |
68 CJBig2_ArithDecoder* pArithDecoder, | 74 CJBig2_ArithDecoder* pArithDecoder, |
69 JBig2ArithCtx* gbContext) { | 75 JBig2ArithCtx* gbContext) { |
70 FX_BOOL LTP, SLTP, bVal; | 76 FX_BOOL LTP, SLTP, bVal; |
71 FX_DWORD CONTEXT; | 77 FX_DWORD CONTEXT; |
72 FX_DWORD line1, line2; | 78 FX_DWORD line1, line2; |
73 uint8_t *pLine, *pLine1, *pLine2, cVal; | 79 uint8_t *pLine, *pLine1, *pLine2, cVal; |
74 int32_t nStride, nStride2, k; | 80 int32_t nStride, nStride2, k; |
75 int32_t nLineBytes, nBitsLeft, cc; | 81 int32_t nLineBytes, nBitsLeft, cc; |
76 LTP = 0; | 82 LTP = 0; |
77 CJBig2_Image* GBREG = new CJBig2_Image(GBW, GBH); | 83 nonstd::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); |
78 if (GBREG->m_pData == NULL) { | 84 if (!GBREG->m_pData) |
79 delete GBREG; | 85 return nullptr; |
80 return NULL; | 86 |
81 } | |
82 pLine = GBREG->m_pData; | 87 pLine = GBREG->m_pData; |
83 nStride = GBREG->m_nStride; | 88 nStride = GBREG->m_nStride; |
84 nStride2 = nStride << 1; | 89 nStride2 = nStride << 1; |
85 nLineBytes = ((GBW + 7) >> 3) - 1; | 90 nLineBytes = ((GBW + 7) >> 3) - 1; |
86 nBitsLeft = GBW - (nLineBytes << 3); | 91 nBitsLeft = GBW - (nLineBytes << 3); |
87 FX_DWORD height = GBH & 0x7fffffff; | 92 FX_DWORD height = GBH & 0x7fffffff; |
88 for (FX_DWORD h = 0; h < height; h++) { | 93 for (FX_DWORD h = 0; h < height; h++) { |
89 if (TPGDON) { | 94 if (TPGDON) { |
90 SLTP = pArithDecoder->DECODE(&gbContext[0x9b25]); | 95 SLTP = pArithDecoder->DECODE(&gbContext[0x9b25]); |
91 LTP = LTP ^ SLTP; | 96 LTP = LTP ^ SLTP; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 150 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
146 cVal |= bVal << (7 - k); | 151 cVal |= bVal << (7 - k); |
147 CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | | 152 CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal | |
148 (((line2 >> (7 - k))) & 0x0010)); | 153 (((line2 >> (7 - k))) & 0x0010)); |
149 } | 154 } |
150 pLine[nLineBytes] = cVal; | 155 pLine[nLineBytes] = cVal; |
151 } | 156 } |
152 } | 157 } |
153 pLine += nStride; | 158 pLine += nStride; |
154 } | 159 } |
155 return GBREG; | 160 return GBREG.release(); |
156 } | 161 } |
| 162 |
157 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt( | 163 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt( |
158 CJBig2_ArithDecoder* pArithDecoder, | 164 CJBig2_ArithDecoder* pArithDecoder, |
159 JBig2ArithCtx* gbContext) { | 165 JBig2ArithCtx* gbContext) { |
160 FX_BOOL LTP, SLTP, bVal; | 166 FX_BOOL LTP, SLTP, bVal; |
161 FX_DWORD CONTEXT; | 167 FX_DWORD CONTEXT; |
162 FX_DWORD line1, line2, line3; | 168 FX_DWORD line1, line2, line3; |
163 LTP = 0; | 169 LTP = 0; |
164 CJBig2_Image* GBREG = new CJBig2_Image(GBW, GBH); | 170 nonstd::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); |
165 GBREG->fill(0); | 171 GBREG->fill(0); |
166 for (FX_DWORD h = 0; h < GBH; h++) { | 172 for (FX_DWORD h = 0; h < GBH; h++) { |
167 if (TPGDON) { | 173 if (TPGDON) { |
168 SLTP = pArithDecoder->DECODE(&gbContext[0x9b25]); | 174 SLTP = pArithDecoder->DECODE(&gbContext[0x9b25]); |
169 LTP = LTP ^ SLTP; | 175 LTP = LTP ^ SLTP; |
170 } | 176 } |
171 if (LTP == 1) { | 177 if (LTP == 1) { |
172 GBREG->copyLine(h, h - 1); | 178 GBREG->copyLine(h, h - 1); |
173 } else { | 179 } else { |
174 line1 = GBREG->getPixel(1, h - 2); | 180 line1 = GBREG->getPixel(1, h - 2); |
(...skipping 17 matching lines...) Expand all Loading... |
192 } | 198 } |
193 if (bVal) { | 199 if (bVal) { |
194 GBREG->setPixel(w, h, bVal); | 200 GBREG->setPixel(w, h, bVal); |
195 } | 201 } |
196 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 2)) & 0x07; | 202 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 2)) & 0x07; |
197 line2 = ((line2 << 1) | GBREG->getPixel(w + 3, h - 1)) & 0x1f; | 203 line2 = ((line2 << 1) | GBREG->getPixel(w + 3, h - 1)) & 0x1f; |
198 line3 = ((line3 << 1) | bVal) & 0x0f; | 204 line3 = ((line3 << 1) | bVal) & 0x0f; |
199 } | 205 } |
200 } | 206 } |
201 } | 207 } |
202 return GBREG; | 208 return GBREG.release(); |
203 } | 209 } |
| 210 |
204 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3( | 211 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3( |
205 CJBig2_ArithDecoder* pArithDecoder, | 212 CJBig2_ArithDecoder* pArithDecoder, |
206 JBig2ArithCtx* gbContext) { | 213 JBig2ArithCtx* gbContext) { |
207 FX_BOOL LTP, SLTP, bVal; | 214 FX_BOOL LTP, SLTP, bVal; |
208 FX_DWORD CONTEXT; | 215 FX_DWORD CONTEXT; |
209 FX_DWORD line1, line2; | 216 FX_DWORD line1, line2; |
210 uint8_t *pLine, *pLine1, *pLine2, cVal; | 217 uint8_t *pLine, *pLine1, *pLine2, cVal; |
211 int32_t nStride, nStride2, k; | 218 int32_t nStride, nStride2, k; |
212 int32_t nLineBytes, nBitsLeft, cc; | 219 int32_t nLineBytes, nBitsLeft, cc; |
213 LTP = 0; | 220 LTP = 0; |
214 CJBig2_Image* GBREG = new CJBig2_Image(GBW, GBH); | 221 nonstd::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); |
215 if (GBREG->m_pData == NULL) { | 222 if (!GBREG->m_pData) |
216 delete GBREG; | 223 return nullptr; |
217 return NULL; | 224 |
218 } | |
219 pLine = GBREG->m_pData; | 225 pLine = GBREG->m_pData; |
220 nStride = GBREG->m_nStride; | 226 nStride = GBREG->m_nStride; |
221 nStride2 = nStride << 1; | 227 nStride2 = nStride << 1; |
222 nLineBytes = ((GBW + 7) >> 3) - 1; | 228 nLineBytes = ((GBW + 7) >> 3) - 1; |
223 nBitsLeft = GBW - (nLineBytes << 3); | 229 nBitsLeft = GBW - (nLineBytes << 3); |
224 for (FX_DWORD h = 0; h < GBH; h++) { | 230 for (FX_DWORD h = 0; h < GBH; h++) { |
225 if (TPGDON) { | 231 if (TPGDON) { |
226 SLTP = pArithDecoder->DECODE(&gbContext[0x0795]); | 232 SLTP = pArithDecoder->DECODE(&gbContext[0x0795]); |
227 LTP = LTP ^ SLTP; | 233 LTP = LTP ^ SLTP; |
228 } | 234 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 287 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
282 cVal |= bVal << (7 - k); | 288 cVal |= bVal << (7 - k); |
283 CONTEXT = | 289 CONTEXT = |
284 ((CONTEXT & 0x0efb) << 1) | bVal | ((line2 >> (8 - k)) & 0x0008); | 290 ((CONTEXT & 0x0efb) << 1) | bVal | ((line2 >> (8 - k)) & 0x0008); |
285 } | 291 } |
286 pLine[nLineBytes] = cVal; | 292 pLine[nLineBytes] = cVal; |
287 } | 293 } |
288 } | 294 } |
289 pLine += nStride; | 295 pLine += nStride; |
290 } | 296 } |
291 return GBREG; | 297 return GBREG.release(); |
292 } | 298 } |
| 299 |
293 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt( | 300 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt( |
294 CJBig2_ArithDecoder* pArithDecoder, | 301 CJBig2_ArithDecoder* pArithDecoder, |
295 JBig2ArithCtx* gbContext) { | 302 JBig2ArithCtx* gbContext) { |
296 FX_BOOL LTP, SLTP, bVal; | 303 FX_BOOL LTP, SLTP, bVal; |
297 FX_DWORD CONTEXT; | 304 FX_DWORD CONTEXT; |
298 FX_DWORD line1, line2, line3; | 305 FX_DWORD line1, line2, line3; |
299 LTP = 0; | 306 LTP = 0; |
300 CJBig2_Image* GBREG = new CJBig2_Image(GBW, GBH); | 307 nonstd::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); |
301 GBREG->fill(0); | 308 GBREG->fill(0); |
302 for (FX_DWORD h = 0; h < GBH; h++) { | 309 for (FX_DWORD h = 0; h < GBH; h++) { |
303 if (TPGDON) { | 310 if (TPGDON) { |
304 SLTP = pArithDecoder->DECODE(&gbContext[0x0795]); | 311 SLTP = pArithDecoder->DECODE(&gbContext[0x0795]); |
305 LTP = LTP ^ SLTP; | 312 LTP = LTP ^ SLTP; |
306 } | 313 } |
307 if (LTP == 1) { | 314 if (LTP == 1) { |
308 GBREG->copyLine(h, h - 1); | 315 GBREG->copyLine(h, h - 1); |
309 } else { | 316 } else { |
310 line1 = GBREG->getPixel(2, h - 2); | 317 line1 = GBREG->getPixel(2, h - 2); |
(...skipping 15 matching lines...) Expand all Loading... |
326 } | 333 } |
327 if (bVal) { | 334 if (bVal) { |
328 GBREG->setPixel(w, h, bVal); | 335 GBREG->setPixel(w, h, bVal); |
329 } | 336 } |
330 line1 = ((line1 << 1) | GBREG->getPixel(w + 3, h - 2)) & 0x0f; | 337 line1 = ((line1 << 1) | GBREG->getPixel(w + 3, h - 2)) & 0x0f; |
331 line2 = ((line2 << 1) | GBREG->getPixel(w + 3, h - 1)) & 0x1f; | 338 line2 = ((line2 << 1) | GBREG->getPixel(w + 3, h - 1)) & 0x1f; |
332 line3 = ((line3 << 1) | bVal) & 0x07; | 339 line3 = ((line3 << 1) | bVal) & 0x07; |
333 } | 340 } |
334 } | 341 } |
335 } | 342 } |
336 return GBREG; | 343 return GBREG.release(); |
337 } | 344 } |
338 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3( | 345 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3( |
339 CJBig2_ArithDecoder* pArithDecoder, | 346 CJBig2_ArithDecoder* pArithDecoder, |
340 JBig2ArithCtx* gbContext) { | 347 JBig2ArithCtx* gbContext) { |
341 FX_BOOL LTP, SLTP, bVal; | 348 FX_BOOL LTP, SLTP, bVal; |
342 FX_DWORD CONTEXT; | 349 FX_DWORD CONTEXT; |
343 FX_DWORD line1, line2; | 350 FX_DWORD line1, line2; |
344 uint8_t *pLine, *pLine1, *pLine2, cVal; | 351 uint8_t *pLine, *pLine1, *pLine2, cVal; |
345 int32_t nStride, nStride2, k; | 352 int32_t nStride, nStride2, k; |
346 int32_t nLineBytes, nBitsLeft, cc; | 353 int32_t nLineBytes, nBitsLeft, cc; |
347 LTP = 0; | 354 LTP = 0; |
348 CJBig2_Image* GBREG = new CJBig2_Image(GBW, GBH); | 355 nonstd::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); |
349 if (GBREG->m_pData == NULL) { | 356 if (!GBREG->m_pData) |
350 delete GBREG; | 357 return nullptr; |
351 return NULL; | 358 |
352 } | |
353 pLine = GBREG->m_pData; | 359 pLine = GBREG->m_pData; |
354 nStride = GBREG->m_nStride; | 360 nStride = GBREG->m_nStride; |
355 nStride2 = nStride << 1; | 361 nStride2 = nStride << 1; |
356 nLineBytes = ((GBW + 7) >> 3) - 1; | 362 nLineBytes = ((GBW + 7) >> 3) - 1; |
357 nBitsLeft = GBW - (nLineBytes << 3); | 363 nBitsLeft = GBW - (nLineBytes << 3); |
358 for (FX_DWORD h = 0; h < GBH; h++) { | 364 for (FX_DWORD h = 0; h < GBH; h++) { |
359 if (TPGDON) { | 365 if (TPGDON) { |
360 SLTP = pArithDecoder->DECODE(&gbContext[0x00e5]); | 366 SLTP = pArithDecoder->DECODE(&gbContext[0x00e5]); |
361 LTP = LTP ^ SLTP; | 367 LTP = LTP ^ SLTP; |
362 } | 368 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 421 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
416 cVal |= bVal << (7 - k); | 422 cVal |= bVal << (7 - k); |
417 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | | 423 CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal | |
418 (((line2 >> (10 - k))) & 0x0004); | 424 (((line2 >> (10 - k))) & 0x0004); |
419 } | 425 } |
420 pLine[nLineBytes] = cVal; | 426 pLine[nLineBytes] = cVal; |
421 } | 427 } |
422 } | 428 } |
423 pLine += nStride; | 429 pLine += nStride; |
424 } | 430 } |
425 return GBREG; | 431 return GBREG.release(); |
426 } | 432 } |
| 433 |
427 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt( | 434 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt( |
428 CJBig2_ArithDecoder* pArithDecoder, | 435 CJBig2_ArithDecoder* pArithDecoder, |
429 JBig2ArithCtx* gbContext) { | 436 JBig2ArithCtx* gbContext) { |
430 FX_BOOL LTP, SLTP, bVal; | 437 FX_BOOL LTP, SLTP, bVal; |
431 FX_DWORD CONTEXT; | 438 FX_DWORD CONTEXT; |
432 FX_DWORD line1, line2, line3; | 439 FX_DWORD line1, line2, line3; |
433 LTP = 0; | 440 LTP = 0; |
434 CJBig2_Image* GBREG = new CJBig2_Image(GBW, GBH); | 441 nonstd::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); |
435 GBREG->fill(0); | 442 GBREG->fill(0); |
436 for (FX_DWORD h = 0; h < GBH; h++) { | 443 for (FX_DWORD h = 0; h < GBH; h++) { |
437 if (TPGDON) { | 444 if (TPGDON) { |
438 SLTP = pArithDecoder->DECODE(&gbContext[0x00e5]); | 445 SLTP = pArithDecoder->DECODE(&gbContext[0x00e5]); |
439 LTP = LTP ^ SLTP; | 446 LTP = LTP ^ SLTP; |
440 } | 447 } |
441 if (LTP == 1) { | 448 if (LTP == 1) { |
442 GBREG->copyLine(h, h - 1); | 449 GBREG->copyLine(h, h - 1); |
443 } else { | 450 } else { |
444 line1 = GBREG->getPixel(1, h - 2); | 451 line1 = GBREG->getPixel(1, h - 2); |
(...skipping 13 matching lines...) Expand all Loading... |
458 } | 465 } |
459 if (bVal) { | 466 if (bVal) { |
460 GBREG->setPixel(w, h, bVal); | 467 GBREG->setPixel(w, h, bVal); |
461 } | 468 } |
462 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 2)) & 0x07; | 469 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 2)) & 0x07; |
463 line2 = ((line2 << 1) | GBREG->getPixel(w + 2, h - 1)) & 0x0f; | 470 line2 = ((line2 << 1) | GBREG->getPixel(w + 2, h - 1)) & 0x0f; |
464 line3 = ((line3 << 1) | bVal) & 0x03; | 471 line3 = ((line3 << 1) | bVal) & 0x03; |
465 } | 472 } |
466 } | 473 } |
467 } | 474 } |
468 return GBREG; | 475 return GBREG.release(); |
469 } | 476 } |
| 477 |
470 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3( | 478 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3( |
471 CJBig2_ArithDecoder* pArithDecoder, | 479 CJBig2_ArithDecoder* pArithDecoder, |
472 JBig2ArithCtx* gbContext) { | 480 JBig2ArithCtx* gbContext) { |
473 FX_BOOL LTP, SLTP, bVal; | 481 FX_BOOL LTP, SLTP, bVal; |
474 FX_DWORD CONTEXT; | 482 FX_DWORD CONTEXT; |
475 FX_DWORD line1; | 483 FX_DWORD line1; |
476 uint8_t *pLine, *pLine1, cVal; | 484 uint8_t *pLine, *pLine1, cVal; |
477 int32_t nStride, k; | 485 int32_t nStride, k; |
478 int32_t nLineBytes, nBitsLeft, cc; | 486 int32_t nLineBytes, nBitsLeft, cc; |
479 LTP = 0; | 487 LTP = 0; |
480 CJBig2_Image* GBREG = new CJBig2_Image(GBW, GBH); | 488 nonstd::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); |
481 if (GBREG->m_pData == NULL) { | 489 if (!GBREG->m_pData) |
482 delete GBREG; | 490 return nullptr; |
483 return NULL; | 491 |
484 } | |
485 pLine = GBREG->m_pData; | 492 pLine = GBREG->m_pData; |
486 nStride = GBREG->m_nStride; | 493 nStride = GBREG->m_nStride; |
487 nLineBytes = ((GBW + 7) >> 3) - 1; | 494 nLineBytes = ((GBW + 7) >> 3) - 1; |
488 nBitsLeft = GBW - (nLineBytes << 3); | 495 nBitsLeft = GBW - (nLineBytes << 3); |
489 for (FX_DWORD h = 0; h < GBH; h++) { | 496 for (FX_DWORD h = 0; h < GBH; h++) { |
490 if (TPGDON) { | 497 if (TPGDON) { |
491 SLTP = pArithDecoder->DECODE(&gbContext[0x0195]); | 498 SLTP = pArithDecoder->DECODE(&gbContext[0x0195]); |
492 LTP = LTP ^ SLTP; | 499 LTP = LTP ^ SLTP; |
493 } | 500 } |
494 if (LTP == 1) { | 501 if (LTP == 1) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 for (k = 0; k < nBitsLeft; k++) { | 540 for (k = 0; k < nBitsLeft; k++) { |
534 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 541 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
535 cVal |= bVal << (7 - k); | 542 cVal |= bVal << (7 - k); |
536 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal; | 543 CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal; |
537 } | 544 } |
538 pLine[nLineBytes] = cVal; | 545 pLine[nLineBytes] = cVal; |
539 } | 546 } |
540 } | 547 } |
541 pLine += nStride; | 548 pLine += nStride; |
542 } | 549 } |
543 return GBREG; | 550 return GBREG.release(); |
544 } | 551 } |
| 552 |
545 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_unopt( | 553 CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_unopt( |
546 CJBig2_ArithDecoder* pArithDecoder, | 554 CJBig2_ArithDecoder* pArithDecoder, |
547 JBig2ArithCtx* gbContext) { | 555 JBig2ArithCtx* gbContext) { |
548 FX_BOOL LTP, SLTP, bVal; | 556 FX_BOOL LTP, SLTP, bVal; |
549 FX_DWORD CONTEXT; | 557 FX_DWORD CONTEXT; |
550 FX_DWORD line1, line2; | 558 FX_DWORD line1, line2; |
551 LTP = 0; | 559 LTP = 0; |
552 CJBig2_Image* GBREG = new CJBig2_Image(GBW, GBH); | 560 nonstd::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH)); |
553 GBREG->fill(0); | 561 GBREG->fill(0); |
554 for (FX_DWORD h = 0; h < GBH; h++) { | 562 for (FX_DWORD h = 0; h < GBH; h++) { |
555 if (TPGDON) { | 563 if (TPGDON) { |
556 SLTP = pArithDecoder->DECODE(&gbContext[0x0195]); | 564 SLTP = pArithDecoder->DECODE(&gbContext[0x0195]); |
557 LTP = LTP ^ SLTP; | 565 LTP = LTP ^ SLTP; |
558 } | 566 } |
559 if (LTP == 1) { | 567 if (LTP == 1) { |
560 GBREG->copyLine(h, h - 1); | 568 GBREG->copyLine(h, h - 1); |
561 } else { | 569 } else { |
562 line1 = GBREG->getPixel(1, h - 1); | 570 line1 = GBREG->getPixel(1, h - 1); |
563 line1 |= GBREG->getPixel(0, h - 1) << 1; | 571 line1 |= GBREG->getPixel(0, h - 1) << 1; |
564 line2 = 0; | 572 line2 = 0; |
565 for (FX_DWORD w = 0; w < GBW; w++) { | 573 for (FX_DWORD w = 0; w < GBW; w++) { |
566 if (USESKIP && SKIP->getPixel(w, h)) { | 574 if (USESKIP && SKIP->getPixel(w, h)) { |
567 bVal = 0; | 575 bVal = 0; |
568 } else { | 576 } else { |
569 CONTEXT = line2; | 577 CONTEXT = line2; |
570 CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 4; | 578 CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 4; |
571 CONTEXT |= line1 << 5; | 579 CONTEXT |= line1 << 5; |
572 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); | 580 bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]); |
573 } | 581 } |
574 if (bVal) { | 582 if (bVal) { |
575 GBREG->setPixel(w, h, bVal); | 583 GBREG->setPixel(w, h, bVal); |
576 } | 584 } |
577 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 1)) & 0x1f; | 585 line1 = ((line1 << 1) | GBREG->getPixel(w + 2, h - 1)) & 0x1f; |
578 line2 = ((line2 << 1) | bVal) & 0x0f; | 586 line2 = ((line2 << 1) | bVal) & 0x0f; |
579 } | 587 } |
580 } | 588 } |
581 } | 589 } |
582 return GBREG; | 590 return GBREG.release(); |
583 } | 591 } |
| 592 |
584 CJBig2_Image* CJBig2_GRRDProc::decode(CJBig2_ArithDecoder* pArithDecoder, | 593 CJBig2_Image* CJBig2_GRRDProc::decode(CJBig2_ArithDecoder* pArithDecoder, |
585 JBig2ArithCtx* grContext) { | 594 JBig2ArithCtx* grContext) { |
586 if (GRW == 0 || GRH == 0) { | 595 if (GRW == 0 || GRH == 0) |
587 return new CJBig2_Image(GRW, GRH); | 596 return new CJBig2_Image(GRW, GRH); |
| 597 |
| 598 if (GRTEMPLATE == 0) { |
| 599 if ((GRAT[0] == -1) && (GRAT[1] == -1) && (GRAT[2] == -1) && |
| 600 (GRAT[3] == -1) && (GRREFERENCEDX == 0) && |
| 601 (GRW == (FX_DWORD)GRREFERENCE->m_nWidth)) { |
| 602 return decode_Template0_opt(pArithDecoder, grContext); |
| 603 } |
| 604 return decode_Template0_unopt(pArithDecoder, grContext); |
588 } | 605 } |
589 if (GRTEMPLATE == 0) { | 606 |
590 if ((GRAT[0] == (int8_t)-1) && (GRAT[1] == (int8_t)-1) && | 607 if ((GRREFERENCEDX == 0) && (GRW == (FX_DWORD)GRREFERENCE->m_nWidth)) |
591 (GRAT[2] == (int8_t)-1) && (GRAT[3] == (int8_t)-1) && | 608 return decode_Template1_opt(pArithDecoder, grContext); |
592 (GRREFERENCEDX == 0) && (GRW == (FX_DWORD)GRREFERENCE->m_nWidth)) { | 609 return decode_Template1_unopt(pArithDecoder, grContext); |
593 return decode_Template0_opt(pArithDecoder, grContext); | |
594 } else { | |
595 return decode_Template0_unopt(pArithDecoder, grContext); | |
596 } | |
597 } else { | |
598 if ((GRREFERENCEDX == 0) && (GRW == (FX_DWORD)GRREFERENCE->m_nWidth)) { | |
599 return decode_Template1_opt(pArithDecoder, grContext); | |
600 } else { | |
601 return decode_Template1_unopt(pArithDecoder, grContext); | |
602 } | |
603 } | |
604 } | 610 } |
| 611 |
605 CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt( | 612 CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt( |
606 CJBig2_ArithDecoder* pArithDecoder, | 613 CJBig2_ArithDecoder* pArithDecoder, |
607 JBig2ArithCtx* grContext) { | 614 JBig2ArithCtx* grContext) { |
608 FX_BOOL LTP, SLTP, bVal; | 615 FX_BOOL LTP, SLTP, bVal; |
609 FX_DWORD CONTEXT; | 616 FX_DWORD CONTEXT; |
610 FX_DWORD line1, line2, line3, line4, line5; | 617 FX_DWORD line1, line2, line3, line4, line5; |
611 LTP = 0; | 618 LTP = 0; |
612 CJBig2_Image* GRREG = new CJBig2_Image(GRW, GRH); | 619 nonstd::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); |
613 GRREG->fill(0); | 620 GRREG->fill(0); |
614 for (FX_DWORD h = 0; h < GRH; h++) { | 621 for (FX_DWORD h = 0; h < GRH; h++) { |
615 if (TPGRON) { | 622 if (TPGRON) { |
616 SLTP = pArithDecoder->DECODE(&grContext[0x0010]); | 623 SLTP = pArithDecoder->DECODE(&grContext[0x0010]); |
617 LTP = LTP ^ SLTP; | 624 LTP = LTP ^ SLTP; |
618 } | 625 } |
619 if (LTP == 0) { | 626 if (LTP == 0) { |
620 line1 = GRREG->getPixel(1, h - 1); | 627 line1 = GRREG->getPixel(1, h - 1); |
621 line1 |= GRREG->getPixel(0, h - 1) << 1; | 628 line1 |= GRREG->getPixel(0, h - 1) << 1; |
622 line2 = 0; | 629 line2 = 0; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 ((line4 << 1) | | 714 ((line4 << 1) | |
708 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, h - GRREFERENCEDY)) & | 715 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, h - GRREFERENCEDY)) & |
709 0x07; | 716 0x07; |
710 line5 = ((line5 << 1) | | 717 line5 = ((line5 << 1) | |
711 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, | 718 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, |
712 h - GRREFERENCEDY + 1)) & | 719 h - GRREFERENCEDY + 1)) & |
713 0x07; | 720 0x07; |
714 } | 721 } |
715 } | 722 } |
716 } | 723 } |
717 return GRREG; | 724 return GRREG.release(); |
718 } | 725 } |
| 726 |
719 CJBig2_Image* CJBig2_GRRDProc::decode_Template0_opt( | 727 CJBig2_Image* CJBig2_GRRDProc::decode_Template0_opt( |
720 CJBig2_ArithDecoder* pArithDecoder, | 728 CJBig2_ArithDecoder* pArithDecoder, |
721 JBig2ArithCtx* grContext) { | 729 JBig2ArithCtx* grContext) { |
722 if (!GRREFERENCE->m_pData) | 730 if (!GRREFERENCE->m_pData) |
723 return nullptr; | 731 return nullptr; |
724 | 732 |
725 FX_BOOL LTP, SLTP, bVal; | 733 FX_BOOL LTP, SLTP, bVal; |
726 FX_DWORD CONTEXT; | 734 FX_DWORD CONTEXT; |
727 FX_DWORD line1, line1_r, line2_r, line3_r; | 735 FX_DWORD line1, line1_r, line2_r, line3_r; |
728 uint8_t *pLine, *pLineR, cVal; | 736 uint8_t *pLine, *pLineR, cVal; |
729 intptr_t nStride, nStrideR, nOffset; | 737 intptr_t nStride, nStrideR, nOffset; |
730 int32_t k, nBits; | 738 int32_t k, nBits; |
731 int32_t GRWR, GRHR; | 739 int32_t GRWR, GRHR; |
732 int32_t GRW, GRH; | 740 int32_t GRW, GRH; |
733 GRW = (int32_t)CJBig2_GRRDProc::GRW; | 741 GRW = (int32_t)CJBig2_GRRDProc::GRW; |
734 GRH = (int32_t)CJBig2_GRRDProc::GRH; | 742 GRH = (int32_t)CJBig2_GRRDProc::GRH; |
735 LTP = 0; | 743 LTP = 0; |
736 CJBig2_Image* GRREG = new CJBig2_Image(GRW, GRH); | 744 nonstd::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); |
737 if (GRREG->m_pData == NULL) { | 745 if (!GRREG->m_pData) |
738 delete GRREG; | 746 return nullptr; |
739 return NULL; | 747 |
740 } | |
741 pLine = GRREG->m_pData; | 748 pLine = GRREG->m_pData; |
742 pLineR = GRREFERENCE->m_pData; | 749 pLineR = GRREFERENCE->m_pData; |
743 nStride = GRREG->m_nStride; | 750 nStride = GRREG->m_nStride; |
744 nStrideR = GRREFERENCE->m_nStride; | 751 nStrideR = GRREFERENCE->m_nStride; |
745 GRWR = (int32_t)GRREFERENCE->m_nWidth; | 752 GRWR = (int32_t)GRREFERENCE->m_nWidth; |
746 GRHR = (int32_t)GRREFERENCE->m_nHeight; | 753 GRHR = (int32_t)GRREFERENCE->m_nHeight; |
747 if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) { | 754 if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) { |
748 GRREFERENCEDY = 0; | 755 GRREFERENCEDY = 0; |
749 } | 756 } |
750 nOffset = -GRREFERENCEDY * nStrideR; | 757 nOffset = -GRREFERENCEDY * nStrideR; |
(...skipping 23 matching lines...) Expand all Loading... |
774 line2_r = 0; | 781 line2_r = 0; |
775 line3_r = 0; | 782 line3_r = 0; |
776 } else { | 783 } else { |
777 if (line1_r_ok) | 784 if (line1_r_ok) |
778 line1_r = | 785 line1_r = |
779 (line1_r << 8) | | 786 (line1_r << 8) | |
780 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); | 787 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); |
781 if (line2_r_ok) | 788 if (line2_r_ok) |
782 line2_r = (line2_r << 8) | | 789 line2_r = (line2_r << 8) | |
783 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); | 790 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); |
784 if (line3_r_ok) | 791 if (line3_r_ok) { |
785 line3_r = | 792 line3_r = |
786 (line3_r << 8) | | 793 (line3_r << 8) | |
787 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); | 794 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); |
788 else { | 795 } else { |
789 line3_r = 0; | 796 line3_r = 0; |
790 } | 797 } |
791 } | 798 } |
792 cVal = 0; | 799 cVal = 0; |
793 for (k = 0; k < nBits; k++) { | 800 for (k = 0; k < nBits; k++) { |
794 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); | 801 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); |
795 cVal |= bVal << (7 - k); | 802 cVal |= bVal << (7 - k); |
796 CONTEXT = ((CONTEXT & 0x0cdb) << 1) | (bVal << 9) | | 803 CONTEXT = ((CONTEXT & 0x0cdb) << 1) | (bVal << 9) | |
797 ((line1 >> (7 - k)) & 0x0400) | | 804 ((line1 >> (7 - k)) & 0x0400) | |
798 ((line1_r >> (7 - k)) & 0x0040) | | 805 ((line1_r >> (7 - k)) & 0x0040) | |
(...skipping 10 matching lines...) Expand all Loading... |
809 if (h > 0) | 816 if (h > 0) |
810 line1 = (line1 << 8) | | 817 line1 = (line1 << 8) | |
811 (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 4 : 0); | 818 (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 4 : 0); |
812 if (line1_r_ok) | 819 if (line1_r_ok) |
813 line1_r = | 820 line1_r = |
814 (line1_r << 8) | | 821 (line1_r << 8) | |
815 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); | 822 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); |
816 if (line2_r_ok) | 823 if (line2_r_ok) |
817 line2_r = (line2_r << 8) | | 824 line2_r = (line2_r << 8) | |
818 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); | 825 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); |
819 if (line3_r_ok) | 826 if (line3_r_ok) { |
820 line3_r = | 827 line3_r = |
821 (line3_r << 8) | | 828 (line3_r << 8) | |
822 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); | 829 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); |
823 else { | 830 } else { |
824 line3_r = 0; | 831 line3_r = 0; |
825 } | 832 } |
826 cVal = 0; | 833 cVal = 0; |
827 for (k = 0; k < nBits; k++) { | 834 for (k = 0; k < nBits; k++) { |
828 bVal = GRREFERENCE->getPixel(w + k, h); | 835 bVal = GRREFERENCE->getPixel(w + k, h); |
829 if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w + k - 1, h - 1)) && | 836 if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w + k - 1, h - 1)) && |
830 (bVal == GRREFERENCE->getPixel(w + k, h - 1)) && | 837 (bVal == GRREFERENCE->getPixel(w + k, h - 1)) && |
831 (bVal == GRREFERENCE->getPixel(w + k + 1, h - 1)) && | 838 (bVal == GRREFERENCE->getPixel(w + k + 1, h - 1)) && |
832 (bVal == GRREFERENCE->getPixel(w + k - 1, h)) && | 839 (bVal == GRREFERENCE->getPixel(w + k - 1, h)) && |
833 (bVal == GRREFERENCE->getPixel(w + k + 1, h)) && | 840 (bVal == GRREFERENCE->getPixel(w + k + 1, h)) && |
(...skipping 10 matching lines...) Expand all Loading... |
844 ((line3_r >> (13 - k)) & 0x0001); | 851 ((line3_r >> (13 - k)) & 0x0001); |
845 } | 852 } |
846 pLine[w >> 3] = cVal; | 853 pLine[w >> 3] = cVal; |
847 } | 854 } |
848 } | 855 } |
849 pLine += nStride; | 856 pLine += nStride; |
850 if (h < GRHR + GRREFERENCEDY) { | 857 if (h < GRHR + GRREFERENCEDY) { |
851 pLineR += nStrideR; | 858 pLineR += nStrideR; |
852 } | 859 } |
853 } | 860 } |
854 return GRREG; | 861 return GRREG.release(); |
855 } | 862 } |
| 863 |
856 CJBig2_Image* CJBig2_GRRDProc::decode_Template1_unopt( | 864 CJBig2_Image* CJBig2_GRRDProc::decode_Template1_unopt( |
857 CJBig2_ArithDecoder* pArithDecoder, | 865 CJBig2_ArithDecoder* pArithDecoder, |
858 JBig2ArithCtx* grContext) { | 866 JBig2ArithCtx* grContext) { |
859 FX_BOOL LTP, SLTP, bVal; | 867 FX_BOOL LTP, SLTP, bVal; |
860 FX_DWORD CONTEXT; | 868 FX_DWORD CONTEXT; |
861 FX_DWORD line1, line2, line3, line4, line5; | 869 FX_DWORD line1, line2, line3, line4, line5; |
862 LTP = 0; | 870 LTP = 0; |
863 CJBig2_Image* GRREG = new CJBig2_Image(GRW, GRH); | 871 nonstd::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); |
864 GRREG->fill(0); | 872 GRREG->fill(0); |
865 for (FX_DWORD h = 0; h < GRH; h++) { | 873 for (FX_DWORD h = 0; h < GRH; h++) { |
866 if (TPGRON) { | 874 if (TPGRON) { |
867 SLTP = pArithDecoder->DECODE(&grContext[0x0008]); | 875 SLTP = pArithDecoder->DECODE(&grContext[0x0008]); |
868 LTP = LTP ^ SLTP; | 876 LTP = LTP ^ SLTP; |
869 } | 877 } |
870 if (LTP == 0) { | 878 if (LTP == 0) { |
871 line1 = GRREG->getPixel(1, h - 1); | 879 line1 = GRREG->getPixel(1, h - 1); |
872 line1 |= GRREG->getPixel(0, h - 1) << 1; | 880 line1 |= GRREG->getPixel(0, h - 1) << 1; |
873 line1 |= GRREG->getPixel(-1, h - 1) << 2; | 881 line1 |= GRREG->getPixel(-1, h - 1) << 2; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 ((line4 << 1) | | 952 ((line4 << 1) | |
945 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, h - GRREFERENCEDY)) & | 953 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, h - GRREFERENCEDY)) & |
946 0x07; | 954 0x07; |
947 line5 = ((line5 << 1) | | 955 line5 = ((line5 << 1) | |
948 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, | 956 GRREFERENCE->getPixel(w - GRREFERENCEDX + 2, |
949 h - GRREFERENCEDY + 1)) & | 957 h - GRREFERENCEDY + 1)) & |
950 0x03; | 958 0x03; |
951 } | 959 } |
952 } | 960 } |
953 } | 961 } |
954 return GRREG; | 962 return GRREG.release(); |
955 } | 963 } |
| 964 |
956 CJBig2_Image* CJBig2_GRRDProc::decode_Template1_opt( | 965 CJBig2_Image* CJBig2_GRRDProc::decode_Template1_opt( |
957 CJBig2_ArithDecoder* pArithDecoder, | 966 CJBig2_ArithDecoder* pArithDecoder, |
958 JBig2ArithCtx* grContext) { | 967 JBig2ArithCtx* grContext) { |
959 if (!GRREFERENCE->m_pData) | 968 if (!GRREFERENCE->m_pData) |
960 return nullptr; | 969 return nullptr; |
961 | 970 |
962 FX_BOOL LTP, SLTP, bVal; | 971 FX_BOOL LTP, SLTP, bVal; |
963 FX_DWORD CONTEXT; | 972 FX_DWORD CONTEXT; |
964 FX_DWORD line1, line1_r, line2_r, line3_r; | 973 FX_DWORD line1, line1_r, line2_r, line3_r; |
965 uint8_t *pLine, *pLineR, cVal; | 974 uint8_t *pLine, *pLineR, cVal; |
966 intptr_t nStride, nStrideR, nOffset; | 975 intptr_t nStride, nStrideR, nOffset; |
967 int32_t k, nBits; | 976 int32_t k, nBits; |
968 int32_t GRWR, GRHR; | 977 int32_t GRWR, GRHR; |
969 int32_t GRW, GRH; | 978 int32_t GRW, GRH; |
970 GRW = (int32_t)CJBig2_GRRDProc::GRW; | 979 GRW = (int32_t)CJBig2_GRRDProc::GRW; |
971 GRH = (int32_t)CJBig2_GRRDProc::GRH; | 980 GRH = (int32_t)CJBig2_GRRDProc::GRH; |
972 LTP = 0; | 981 LTP = 0; |
973 CJBig2_Image* GRREG = new CJBig2_Image(GRW, GRH); | 982 nonstd::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH)); |
974 if (GRREG->m_pData == NULL) { | 983 if (!GRREG->m_pData) |
975 delete GRREG; | 984 return nullptr; |
976 return NULL; | 985 |
977 } | |
978 pLine = GRREG->m_pData; | 986 pLine = GRREG->m_pData; |
979 pLineR = GRREFERENCE->m_pData; | 987 pLineR = GRREFERENCE->m_pData; |
980 nStride = GRREG->m_nStride; | 988 nStride = GRREG->m_nStride; |
981 nStrideR = GRREFERENCE->m_nStride; | 989 nStrideR = GRREFERENCE->m_nStride; |
982 GRWR = (int32_t)GRREFERENCE->m_nWidth; | 990 GRWR = (int32_t)GRREFERENCE->m_nWidth; |
983 GRHR = (int32_t)GRREFERENCE->m_nHeight; | 991 GRHR = (int32_t)GRREFERENCE->m_nHeight; |
984 if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) { | 992 if (GRREFERENCEDY < -GRHR + 1 || GRREFERENCEDY > GRHR - 1) { |
985 GRREFERENCEDY = 0; | 993 GRREFERENCEDY = 0; |
986 } | 994 } |
987 nOffset = -GRREFERENCEDY * nStrideR; | 995 nOffset = -GRREFERENCEDY * nStrideR; |
(...skipping 18 matching lines...) Expand all Loading... |
1006 if (h > 0) | 1014 if (h > 0) |
1007 line1 = (line1 << 8) | | 1015 line1 = (line1 << 8) | |
1008 (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 1 : 0); | 1016 (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 1 : 0); |
1009 if (line1_r_ok) | 1017 if (line1_r_ok) |
1010 line1_r = | 1018 line1_r = |
1011 (line1_r << 8) | | 1019 (line1_r << 8) | |
1012 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); | 1020 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); |
1013 if (line2_r_ok) | 1021 if (line2_r_ok) |
1014 line2_r = (line2_r << 8) | | 1022 line2_r = (line2_r << 8) | |
1015 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); | 1023 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); |
1016 if (line3_r_ok) | 1024 if (line3_r_ok) { |
1017 line3_r = | 1025 line3_r = |
1018 (line3_r << 8) | | 1026 (line3_r << 8) | |
1019 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); | 1027 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); |
1020 else { | 1028 } else { |
1021 line3_r = 0; | 1029 line3_r = 0; |
1022 } | 1030 } |
1023 cVal = 0; | 1031 cVal = 0; |
1024 for (k = 0; k < nBits; k++) { | 1032 for (k = 0; k < nBits; k++) { |
1025 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); | 1033 bVal = pArithDecoder->DECODE(&grContext[CONTEXT]); |
1026 cVal |= bVal << (7 - k); | 1034 cVal |= bVal << (7 - k); |
1027 CONTEXT = ((CONTEXT & 0x018d) << 1) | (bVal << 6) | | 1035 CONTEXT = ((CONTEXT & 0x018d) << 1) | (bVal << 6) | |
1028 ((line1 >> (7 - k)) & 0x0080) | | 1036 ((line1 >> (7 - k)) & 0x0080) | |
1029 ((line1_r >> (9 - k)) & 0x0020) | | 1037 ((line1_r >> (9 - k)) & 0x0020) | |
1030 ((line2_r >> (11 - k)) & 0x0004) | | 1038 ((line2_r >> (11 - k)) & 0x0004) | |
1031 ((line3_r >> (13 - k)) & 0x0001); | 1039 ((line3_r >> (13 - k)) & 0x0001); |
1032 } | 1040 } |
1033 pLine[w >> 3] = cVal; | 1041 pLine[w >> 3] = cVal; |
1034 } | 1042 } |
1035 } else { | 1043 } else { |
1036 CONTEXT = (line1 & 0x0380) | ((line1_r >> 2) & 0x0020) | | 1044 CONTEXT = (line1 & 0x0380) | ((line1_r >> 2) & 0x0020) | |
1037 ((line2_r >> 4) & 0x001c) | ((line3_r >> 6) & 0x0003); | 1045 ((line2_r >> 4) & 0x001c) | ((line3_r >> 6) & 0x0003); |
1038 for (int32_t w = 0; w < GRW; w += 8) { | 1046 for (int32_t w = 0; w < GRW; w += 8) { |
1039 nBits = GRW - w > 8 ? 8 : GRW - w; | 1047 nBits = GRW - w > 8 ? 8 : GRW - w; |
1040 if (h > 0) | 1048 if (h > 0) |
1041 line1 = (line1 << 8) | | 1049 line1 = (line1 << 8) | |
1042 (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 1 : 0); | 1050 (w + 8 < GRW ? pLine[-nStride + (w >> 3) + 1] << 1 : 0); |
1043 if (line1_r_ok) | 1051 if (line1_r_ok) |
1044 line1_r = | 1052 line1_r = |
1045 (line1_r << 8) | | 1053 (line1_r << 8) | |
1046 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); | 1054 (w + 8 < GRWR ? pLineR[nOffset - nStrideR + (w >> 3) + 1] : 0); |
1047 if (line2_r_ok) | 1055 if (line2_r_ok) |
1048 line2_r = (line2_r << 8) | | 1056 line2_r = (line2_r << 8) | |
1049 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); | 1057 (w + 8 < GRWR ? pLineR[nOffset + (w >> 3) + 1] : 0); |
1050 if (line3_r_ok) | 1058 if (line3_r_ok) { |
1051 line3_r = | 1059 line3_r = |
1052 (line3_r << 8) | | 1060 (line3_r << 8) | |
1053 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); | 1061 (w + 8 < GRWR ? pLineR[nOffset + nStrideR + (w >> 3) + 1] : 0); |
1054 else { | 1062 } else { |
1055 line3_r = 0; | 1063 line3_r = 0; |
1056 } | 1064 } |
1057 cVal = 0; | 1065 cVal = 0; |
1058 for (k = 0; k < nBits; k++) { | 1066 for (k = 0; k < nBits; k++) { |
1059 bVal = GRREFERENCE->getPixel(w + k, h); | 1067 bVal = GRREFERENCE->getPixel(w + k, h); |
1060 if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w + k - 1, h - 1)) && | 1068 if (!(TPGRON && (bVal == GRREFERENCE->getPixel(w + k - 1, h - 1)) && |
1061 (bVal == GRREFERENCE->getPixel(w + k, h - 1)) && | 1069 (bVal == GRREFERENCE->getPixel(w + k, h - 1)) && |
1062 (bVal == GRREFERENCE->getPixel(w + k + 1, h - 1)) && | 1070 (bVal == GRREFERENCE->getPixel(w + k + 1, h - 1)) && |
1063 (bVal == GRREFERENCE->getPixel(w + k - 1, h)) && | 1071 (bVal == GRREFERENCE->getPixel(w + k - 1, h)) && |
1064 (bVal == GRREFERENCE->getPixel(w + k + 1, h)) && | 1072 (bVal == GRREFERENCE->getPixel(w + k + 1, h)) && |
(...skipping 10 matching lines...) Expand all Loading... |
1075 ((line3_r >> (13 - k)) & 0x0001); | 1083 ((line3_r >> (13 - k)) & 0x0001); |
1076 } | 1084 } |
1077 pLine[w >> 3] = cVal; | 1085 pLine[w >> 3] = cVal; |
1078 } | 1086 } |
1079 } | 1087 } |
1080 pLine += nStride; | 1088 pLine += nStride; |
1081 if (h < GRHR + GRREFERENCEDY) { | 1089 if (h < GRHR + GRREFERENCEDY) { |
1082 pLineR += nStrideR; | 1090 pLineR += nStrideR; |
1083 } | 1091 } |
1084 } | 1092 } |
1085 return GRREG; | 1093 return GRREG.release(); |
1086 } | 1094 } |
1087 | 1095 |
1088 CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, | 1096 CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, |
1089 JBig2ArithCtx* grContext) { | 1097 JBig2ArithCtx* grContext) { |
1090 int32_t STRIPT, FIRSTS; | 1098 int32_t STRIPT, FIRSTS; |
1091 FX_DWORD NINSTANCES; | 1099 FX_DWORD NINSTANCES; |
1092 int32_t DT, DFS, CURS; | 1100 int32_t DT, DFS, CURS; |
1093 uint8_t CURT; | 1101 uint8_t CURT; |
1094 int32_t SI, TI; | 1102 int32_t SI, TI; |
1095 FX_DWORD IDI; | 1103 FX_DWORD IDI; |
1096 CJBig2_Image* IBI; | 1104 CJBig2_Image* IBI; |
1097 FX_DWORD WI, HI; | 1105 FX_DWORD WI, HI; |
1098 int32_t IDS; | 1106 int32_t IDS; |
1099 FX_BOOL RI; | 1107 FX_BOOL RI; |
1100 int32_t RDWI, RDHI, RDXI, RDYI; | 1108 int32_t RDWI, RDHI, RDXI, RDYI; |
1101 CJBig2_Image* IBOI; | 1109 CJBig2_Image* IBOI; |
1102 FX_DWORD WOI, HOI; | 1110 FX_DWORD WOI, HOI; |
1103 FX_BOOL bFirst; | 1111 FX_BOOL bFirst; |
1104 FX_DWORD nTmp; | 1112 FX_DWORD nTmp; |
1105 int32_t nVal, nBits; | 1113 int32_t nVal, nBits; |
1106 CJBig2_GRRDProc* pGRRD; | 1114 nonstd::unique_ptr<CJBig2_HuffmanDecoder> pHuffmanDecoder( |
1107 CJBig2_ArithDecoder* pArithDecoder; | 1115 new CJBig2_HuffmanDecoder(pStream)); |
1108 CJBig2_HuffmanDecoder* pHuffmanDecoder = new CJBig2_HuffmanDecoder(pStream); | 1116 nonstd::unique_ptr<CJBig2_Image> SBREG(new CJBig2_Image(SBW, SBH)); |
1109 CJBig2_Image* SBREG = new CJBig2_Image(SBW, SBH); | |
1110 SBREG->fill(SBDEFPIXEL); | 1117 SBREG->fill(SBDEFPIXEL); |
1111 if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &STRIPT) != 0) { | 1118 if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &STRIPT) != 0) |
1112 goto failed; | 1119 return nullptr; |
1113 } | 1120 |
1114 STRIPT *= SBSTRIPS; | 1121 STRIPT *= SBSTRIPS; |
1115 STRIPT = -STRIPT; | 1122 STRIPT = -STRIPT; |
1116 FIRSTS = 0; | 1123 FIRSTS = 0; |
1117 NINSTANCES = 0; | 1124 NINSTANCES = 0; |
1118 while (NINSTANCES < SBNUMINSTANCES) { | 1125 while (NINSTANCES < SBNUMINSTANCES) { |
1119 if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &DT) != 0) { | 1126 if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &DT) != 0) |
1120 goto failed; | 1127 return nullptr; |
1121 } | 1128 |
1122 DT *= SBSTRIPS; | 1129 DT *= SBSTRIPS; |
1123 STRIPT = STRIPT + DT; | 1130 STRIPT = STRIPT + DT; |
1124 bFirst = TRUE; | 1131 bFirst = TRUE; |
1125 for (;;) { | 1132 for (;;) { |
1126 if (bFirst) { | 1133 if (bFirst) { |
1127 if (pHuffmanDecoder->decodeAValue(SBHUFFFS, &DFS) != 0) { | 1134 if (pHuffmanDecoder->decodeAValue(SBHUFFFS, &DFS) != 0) |
1128 goto failed; | 1135 return nullptr; |
1129 } | 1136 |
1130 FIRSTS = FIRSTS + DFS; | 1137 FIRSTS = FIRSTS + DFS; |
1131 CURS = FIRSTS; | 1138 CURS = FIRSTS; |
1132 bFirst = FALSE; | 1139 bFirst = FALSE; |
1133 } else { | 1140 } else { |
1134 nVal = pHuffmanDecoder->decodeAValue(SBHUFFDS, &IDS); | 1141 nVal = pHuffmanDecoder->decodeAValue(SBHUFFDS, &IDS); |
1135 if (nVal == JBIG2_OOB) { | 1142 if (nVal == JBIG2_OOB) { |
1136 break; | 1143 break; |
1137 } else if (nVal != 0) { | 1144 } else if (nVal != 0) { |
1138 goto failed; | 1145 return nullptr; |
1139 } else { | 1146 } else { |
1140 CURS = CURS + IDS + SBDSOFFSET; | 1147 CURS = CURS + IDS + SBDSOFFSET; |
1141 } | 1148 } |
1142 } | 1149 } |
1143 if (SBSTRIPS == 1) { | 1150 if (SBSTRIPS == 1) { |
1144 CURT = 0; | 1151 CURT = 0; |
1145 } else { | 1152 } else { |
1146 nTmp = 1; | 1153 nTmp = 1; |
1147 while ((FX_DWORD)(1 << nTmp) < SBSTRIPS) { | 1154 while ((FX_DWORD)(1 << nTmp) < SBSTRIPS) { |
1148 nTmp++; | 1155 nTmp++; |
1149 } | 1156 } |
1150 if (pStream->readNBits(nTmp, &nVal) != 0) { | 1157 if (pStream->readNBits(nTmp, &nVal) != 0) |
1151 goto failed; | 1158 return nullptr; |
1152 } | 1159 |
1153 CURT = nVal; | 1160 CURT = nVal; |
1154 } | 1161 } |
1155 TI = STRIPT + CURT; | 1162 TI = STRIPT + CURT; |
1156 nVal = 0; | 1163 nVal = 0; |
1157 nBits = 0; | 1164 nBits = 0; |
1158 for (;;) { | 1165 for (;;) { |
1159 if (pStream->read1Bit(&nTmp) != 0) { | 1166 if (pStream->read1Bit(&nTmp) != 0) |
1160 goto failed; | 1167 return nullptr; |
1161 } | 1168 |
1162 nVal = (nVal << 1) | nTmp; | 1169 nVal = (nVal << 1) | nTmp; |
1163 nBits++; | 1170 nBits++; |
1164 for (IDI = 0; IDI < SBNUMSYMS; IDI++) { | 1171 for (IDI = 0; IDI < SBNUMSYMS; IDI++) { |
1165 if ((nBits == SBSYMCODES[IDI].codelen) && | 1172 if ((nBits == SBSYMCODES[IDI].codelen) && |
1166 (nVal == SBSYMCODES[IDI].code)) { | 1173 (nVal == SBSYMCODES[IDI].code)) { |
1167 break; | 1174 break; |
1168 } | 1175 } |
1169 } | 1176 } |
1170 if (IDI < SBNUMSYMS) { | 1177 if (IDI < SBNUMSYMS) { |
1171 break; | 1178 break; |
1172 } | 1179 } |
1173 } | 1180 } |
1174 if (SBREFINE == 0) { | 1181 if (SBREFINE == 0) { |
1175 RI = 0; | 1182 RI = 0; |
1176 } else { | 1183 } else { |
1177 if (pStream->read1Bit(&RI) != 0) { | 1184 if (pStream->read1Bit(&RI) != 0) { |
1178 goto failed; | 1185 return nullptr; |
1179 } | 1186 } |
1180 } | 1187 } |
1181 if (RI == 0) { | 1188 if (RI == 0) { |
1182 IBI = SBSYMS[IDI]; | 1189 IBI = SBSYMS[IDI]; |
1183 } else { | 1190 } else { |
1184 if ((pHuffmanDecoder->decodeAValue(SBHUFFRDW, &RDWI) != 0) || | 1191 if ((pHuffmanDecoder->decodeAValue(SBHUFFRDW, &RDWI) != 0) || |
1185 (pHuffmanDecoder->decodeAValue(SBHUFFRDH, &RDHI) != 0) || | 1192 (pHuffmanDecoder->decodeAValue(SBHUFFRDH, &RDHI) != 0) || |
1186 (pHuffmanDecoder->decodeAValue(SBHUFFRDX, &RDXI) != 0) || | 1193 (pHuffmanDecoder->decodeAValue(SBHUFFRDX, &RDXI) != 0) || |
1187 (pHuffmanDecoder->decodeAValue(SBHUFFRDY, &RDYI) != 0) || | 1194 (pHuffmanDecoder->decodeAValue(SBHUFFRDY, &RDYI) != 0) || |
1188 (pHuffmanDecoder->decodeAValue(SBHUFFRSIZE, &nVal) != 0)) { | 1195 (pHuffmanDecoder->decodeAValue(SBHUFFRSIZE, &nVal) != 0)) { |
1189 goto failed; | 1196 return nullptr; |
1190 } | 1197 } |
1191 pStream->alignByte(); | 1198 pStream->alignByte(); |
1192 nTmp = pStream->getOffset(); | 1199 nTmp = pStream->getOffset(); |
1193 IBOI = SBSYMS[IDI]; | 1200 IBOI = SBSYMS[IDI]; |
1194 if (!IBOI) { | 1201 if (!IBOI) |
1195 goto failed; | 1202 return nullptr; |
1196 } | 1203 |
1197 WOI = IBOI->m_nWidth; | 1204 WOI = IBOI->m_nWidth; |
1198 HOI = IBOI->m_nHeight; | 1205 HOI = IBOI->m_nHeight; |
1199 if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) { | 1206 if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) |
1200 goto failed; | 1207 return nullptr; |
1201 } | 1208 |
1202 pGRRD = new CJBig2_GRRDProc(); | 1209 nonstd::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc()); |
1203 pGRRD->GRW = WOI + RDWI; | 1210 pGRRD->GRW = WOI + RDWI; |
1204 pGRRD->GRH = HOI + RDHI; | 1211 pGRRD->GRH = HOI + RDHI; |
1205 pGRRD->GRTEMPLATE = SBRTEMPLATE; | 1212 pGRRD->GRTEMPLATE = SBRTEMPLATE; |
1206 pGRRD->GRREFERENCE = IBOI; | 1213 pGRRD->GRREFERENCE = IBOI; |
1207 pGRRD->GRREFERENCEDX = (RDWI >> 2) + RDXI; | 1214 pGRRD->GRREFERENCEDX = (RDWI >> 2) + RDXI; |
1208 pGRRD->GRREFERENCEDY = (RDHI >> 2) + RDYI; | 1215 pGRRD->GRREFERENCEDY = (RDHI >> 2) + RDYI; |
1209 pGRRD->TPGRON = 0; | 1216 pGRRD->TPGRON = 0; |
1210 pGRRD->GRAT[0] = SBRAT[0]; | 1217 pGRRD->GRAT[0] = SBRAT[0]; |
1211 pGRRD->GRAT[1] = SBRAT[1]; | 1218 pGRRD->GRAT[1] = SBRAT[1]; |
1212 pGRRD->GRAT[2] = SBRAT[2]; | 1219 pGRRD->GRAT[2] = SBRAT[2]; |
1213 pGRRD->GRAT[3] = SBRAT[3]; | 1220 pGRRD->GRAT[3] = SBRAT[3]; |
1214 pArithDecoder = new CJBig2_ArithDecoder(pStream); | 1221 |
1215 IBI = pGRRD->decode(pArithDecoder, grContext); | 1222 { |
1216 if (IBI == NULL) { | 1223 nonstd::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( |
1217 delete pGRRD; | 1224 new CJBig2_ArithDecoder(pStream)); |
1218 delete pArithDecoder; | 1225 IBI = pGRRD->decode(pArithDecoder.get(), grContext); |
1219 goto failed; | 1226 if (!IBI) |
| 1227 return nullptr; |
1220 } | 1228 } |
1221 delete pArithDecoder; | 1229 |
1222 pStream->alignByte(); | 1230 pStream->alignByte(); |
1223 pStream->offset(2); | 1231 pStream->offset(2); |
1224 if ((FX_DWORD)nVal != (pStream->getOffset() - nTmp)) { | 1232 if ((FX_DWORD)nVal != (pStream->getOffset() - nTmp)) { |
1225 delete IBI; | 1233 delete IBI; |
1226 delete pGRRD; | 1234 return nullptr; |
1227 goto failed; | |
1228 } | 1235 } |
1229 delete pGRRD; | |
1230 } | 1236 } |
1231 if (!IBI) { | 1237 if (!IBI) { |
1232 continue; | 1238 continue; |
1233 } | 1239 } |
1234 WI = IBI->m_nWidth; | 1240 WI = IBI->m_nWidth; |
1235 HI = IBI->m_nHeight; | 1241 HI = IBI->m_nHeight; |
1236 if (TRANSPOSED == 0 && ((REFCORNER == JBIG2_CORNER_TOPRIGHT) || | 1242 if (TRANSPOSED == 0 && ((REFCORNER == JBIG2_CORNER_TOPRIGHT) || |
1237 (REFCORNER == JBIG2_CORNER_BOTTOMRIGHT))) { | 1243 (REFCORNER == JBIG2_CORNER_BOTTOMRIGHT))) { |
1238 CURS = CURS + WI - 1; | 1244 CURS = CURS + WI - 1; |
1239 } else if (TRANSPOSED == 1 && ((REFCORNER == JBIG2_CORNER_BOTTOMLEFT) || | 1245 } else if (TRANSPOSED == 1 && ((REFCORNER == JBIG2_CORNER_BOTTOMLEFT) || |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 if (TRANSPOSED == 0 && ((REFCORNER == JBIG2_CORNER_TOPLEFT) || | 1284 if (TRANSPOSED == 0 && ((REFCORNER == JBIG2_CORNER_TOPLEFT) || |
1279 (REFCORNER == JBIG2_CORNER_BOTTOMLEFT))) { | 1285 (REFCORNER == JBIG2_CORNER_BOTTOMLEFT))) { |
1280 CURS = CURS + WI - 1; | 1286 CURS = CURS + WI - 1; |
1281 } else if (TRANSPOSED == 1 && ((REFCORNER == JBIG2_CORNER_TOPLEFT) || | 1287 } else if (TRANSPOSED == 1 && ((REFCORNER == JBIG2_CORNER_TOPLEFT) || |
1282 (REFCORNER == JBIG2_CORNER_TOPRIGHT))) { | 1288 (REFCORNER == JBIG2_CORNER_TOPRIGHT))) { |
1283 CURS = CURS + HI - 1; | 1289 CURS = CURS + HI - 1; |
1284 } | 1290 } |
1285 NINSTANCES = NINSTANCES + 1; | 1291 NINSTANCES = NINSTANCES + 1; |
1286 } | 1292 } |
1287 } | 1293 } |
1288 delete pHuffmanDecoder; | 1294 return SBREG.release(); |
1289 return SBREG; | |
1290 failed: | |
1291 delete pHuffmanDecoder; | |
1292 delete SBREG; | |
1293 return NULL; | |
1294 } | 1295 } |
| 1296 |
1295 CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, | 1297 CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, |
1296 JBig2ArithCtx* grContext, | 1298 JBig2ArithCtx* grContext, |
1297 JBig2IntDecoderState* pIDS) { | 1299 JBig2IntDecoderState* pIDS) { |
1298 int32_t STRIPT, FIRSTS; | 1300 int32_t STRIPT, FIRSTS; |
1299 FX_DWORD NINSTANCES; | 1301 FX_DWORD NINSTANCES; |
1300 int32_t DT, DFS, CURS; | 1302 int32_t DT, DFS, CURS; |
1301 int32_t CURT; | 1303 int32_t CURT; |
1302 int32_t SI, TI; | 1304 int32_t SI, TI; |
1303 FX_DWORD IDI; | 1305 FX_DWORD IDI; |
1304 CJBig2_Image* IBI; | 1306 CJBig2_Image* IBI; |
1305 FX_DWORD WI, HI; | 1307 FX_DWORD WI, HI; |
1306 int32_t IDS; | 1308 int32_t IDS; |
1307 int RI; | 1309 int RI; |
1308 int32_t RDWI, RDHI, RDXI, RDYI; | 1310 int32_t RDWI, RDHI, RDXI, RDYI; |
1309 CJBig2_Image* IBOI; | 1311 CJBig2_Image* IBOI; |
1310 FX_DWORD WOI, HOI; | 1312 FX_DWORD WOI, HOI; |
1311 CJBig2_Image* SBREG; | |
1312 FX_BOOL bFirst; | 1313 FX_BOOL bFirst; |
1313 int32_t nRet, nVal; | 1314 int32_t nRet, nVal; |
1314 int32_t bRetained; | 1315 int32_t bRetained; |
1315 CJBig2_ArithIntDecoder *IADT, *IAFS, *IADS, *IAIT, *IARI, *IARDW, *IARDH, | 1316 CJBig2_ArithIntDecoder *IADT, *IAFS, *IADS, *IAIT, *IARI, *IARDW, *IARDH, |
1316 *IARDX, *IARDY; | 1317 *IARDX, *IARDY; |
1317 CJBig2_ArithIaidDecoder* IAID; | 1318 CJBig2_ArithIaidDecoder* IAID; |
1318 CJBig2_GRRDProc* pGRRD; | |
1319 if (pIDS) { | 1319 if (pIDS) { |
1320 IADT = pIDS->IADT; | 1320 IADT = pIDS->IADT; |
1321 IAFS = pIDS->IAFS; | 1321 IAFS = pIDS->IAFS; |
1322 IADS = pIDS->IADS; | 1322 IADS = pIDS->IADS; |
1323 IAIT = pIDS->IAIT; | 1323 IAIT = pIDS->IAIT; |
1324 IARI = pIDS->IARI; | 1324 IARI = pIDS->IARI; |
1325 IARDW = pIDS->IARDW; | 1325 IARDW = pIDS->IARDW; |
1326 IARDH = pIDS->IARDH; | 1326 IARDH = pIDS->IARDH; |
1327 IARDX = pIDS->IARDX; | 1327 IARDX = pIDS->IARDX; |
1328 IARDY = pIDS->IARDY; | 1328 IARDY = pIDS->IARDY; |
1329 IAID = pIDS->IAID; | 1329 IAID = pIDS->IAID; |
1330 bRetained = TRUE; | 1330 bRetained = TRUE; |
1331 } else { | 1331 } else { |
1332 IADT = new CJBig2_ArithIntDecoder(); | 1332 IADT = new CJBig2_ArithIntDecoder(); |
1333 IAFS = new CJBig2_ArithIntDecoder(); | 1333 IAFS = new CJBig2_ArithIntDecoder(); |
1334 IADS = new CJBig2_ArithIntDecoder(); | 1334 IADS = new CJBig2_ArithIntDecoder(); |
1335 IAIT = new CJBig2_ArithIntDecoder(); | 1335 IAIT = new CJBig2_ArithIntDecoder(); |
1336 IARI = new CJBig2_ArithIntDecoder(); | 1336 IARI = new CJBig2_ArithIntDecoder(); |
1337 IARDW = new CJBig2_ArithIntDecoder(); | 1337 IARDW = new CJBig2_ArithIntDecoder(); |
1338 IARDH = new CJBig2_ArithIntDecoder(); | 1338 IARDH = new CJBig2_ArithIntDecoder(); |
1339 IARDX = new CJBig2_ArithIntDecoder(); | 1339 IARDX = new CJBig2_ArithIntDecoder(); |
1340 IARDY = new CJBig2_ArithIntDecoder(); | 1340 IARDY = new CJBig2_ArithIntDecoder(); |
1341 IAID = new CJBig2_ArithIaidDecoder(SBSYMCODELEN); | 1341 IAID = new CJBig2_ArithIaidDecoder(SBSYMCODELEN); |
1342 bRetained = FALSE; | 1342 bRetained = FALSE; |
1343 } | 1343 } |
1344 SBREG = new CJBig2_Image(SBW, SBH); | 1344 nonstd::unique_ptr<CJBig2_Image> SBREG(new CJBig2_Image(SBW, SBH)); |
1345 SBREG->fill(SBDEFPIXEL); | 1345 SBREG->fill(SBDEFPIXEL); |
1346 if (IADT->decode(pArithDecoder, &STRIPT) == -1) { | 1346 if (IADT->decode(pArithDecoder, &STRIPT) == -1) { |
1347 goto failed; | 1347 goto failed; |
1348 } | 1348 } |
1349 STRIPT *= SBSTRIPS; | 1349 STRIPT *= SBSTRIPS; |
1350 STRIPT = -STRIPT; | 1350 STRIPT = -STRIPT; |
1351 FIRSTS = 0; | 1351 FIRSTS = 0; |
1352 NINSTANCES = 0; | 1352 NINSTANCES = 0; |
1353 while (NINSTANCES < SBNUMINSTANCES) { | 1353 while (NINSTANCES < SBNUMINSTANCES) { |
1354 if (IADT->decode(pArithDecoder, &DT) == -1) { | 1354 if (IADT->decode(pArithDecoder, &DT) == -1) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 (IARDX->decode(pArithDecoder, &RDXI) == -1) || | 1412 (IARDX->decode(pArithDecoder, &RDXI) == -1) || |
1413 (IARDY->decode(pArithDecoder, &RDYI) == -1)) { | 1413 (IARDY->decode(pArithDecoder, &RDYI) == -1)) { |
1414 goto failed; | 1414 goto failed; |
1415 } | 1415 } |
1416 IBOI = SBSYMS[IDI]; | 1416 IBOI = SBSYMS[IDI]; |
1417 WOI = IBOI->m_nWidth; | 1417 WOI = IBOI->m_nWidth; |
1418 HOI = IBOI->m_nHeight; | 1418 HOI = IBOI->m_nHeight; |
1419 if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) { | 1419 if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) { |
1420 goto failed; | 1420 goto failed; |
1421 } | 1421 } |
1422 pGRRD = new CJBig2_GRRDProc(); | 1422 nonstd::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc()); |
1423 pGRRD->GRW = WOI + RDWI; | 1423 pGRRD->GRW = WOI + RDWI; |
1424 pGRRD->GRH = HOI + RDHI; | 1424 pGRRD->GRH = HOI + RDHI; |
1425 pGRRD->GRTEMPLATE = SBRTEMPLATE; | 1425 pGRRD->GRTEMPLATE = SBRTEMPLATE; |
1426 pGRRD->GRREFERENCE = IBOI; | 1426 pGRRD->GRREFERENCE = IBOI; |
1427 pGRRD->GRREFERENCEDX = (RDWI >> 1) + RDXI; | 1427 pGRRD->GRREFERENCEDX = (RDWI >> 1) + RDXI; |
1428 pGRRD->GRREFERENCEDY = (RDHI >> 1) + RDYI; | 1428 pGRRD->GRREFERENCEDY = (RDHI >> 1) + RDYI; |
1429 pGRRD->TPGRON = 0; | 1429 pGRRD->TPGRON = 0; |
1430 pGRRD->GRAT[0] = SBRAT[0]; | 1430 pGRRD->GRAT[0] = SBRAT[0]; |
1431 pGRRD->GRAT[1] = SBRAT[1]; | 1431 pGRRD->GRAT[1] = SBRAT[1]; |
1432 pGRRD->GRAT[2] = SBRAT[2]; | 1432 pGRRD->GRAT[2] = SBRAT[2]; |
1433 pGRRD->GRAT[3] = SBRAT[3]; | 1433 pGRRD->GRAT[3] = SBRAT[3]; |
1434 IBI = pGRRD->decode(pArithDecoder, grContext); | 1434 IBI = pGRRD->decode(pArithDecoder, grContext); |
1435 if (IBI == NULL) { | 1435 if (!IBI) |
1436 delete pGRRD; | |
1437 goto failed; | 1436 goto failed; |
1438 } | |
1439 delete pGRRD; | |
1440 } | 1437 } |
1441 WI = IBI->m_nWidth; | 1438 WI = IBI->m_nWidth; |
1442 HI = IBI->m_nHeight; | 1439 HI = IBI->m_nHeight; |
1443 if (TRANSPOSED == 0 && ((REFCORNER == JBIG2_CORNER_TOPRIGHT) || | 1440 if (TRANSPOSED == 0 && ((REFCORNER == JBIG2_CORNER_TOPRIGHT) || |
1444 (REFCORNER == JBIG2_CORNER_BOTTOMRIGHT))) { | 1441 (REFCORNER == JBIG2_CORNER_BOTTOMRIGHT))) { |
1445 CURS = CURS + WI - 1; | 1442 CURS = CURS + WI - 1; |
1446 } else if (TRANSPOSED == 1 && ((REFCORNER == JBIG2_CORNER_BOTTOMLEFT) || | 1443 } else if (TRANSPOSED == 1 && ((REFCORNER == JBIG2_CORNER_BOTTOMLEFT) || |
1447 (REFCORNER == JBIG2_CORNER_BOTTOMRIGHT))) { | 1444 (REFCORNER == JBIG2_CORNER_BOTTOMRIGHT))) { |
1448 CURS = CURS + HI - 1; | 1445 CURS = CURS + HI - 1; |
1449 } | 1446 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1497 delete IAFS; | 1494 delete IAFS; |
1498 delete IADS; | 1495 delete IADS; |
1499 delete IAIT; | 1496 delete IAIT; |
1500 delete IARI; | 1497 delete IARI; |
1501 delete IARDW; | 1498 delete IARDW; |
1502 delete IARDH; | 1499 delete IARDH; |
1503 delete IARDX; | 1500 delete IARDX; |
1504 delete IARDY; | 1501 delete IARDY; |
1505 delete IAID; | 1502 delete IAID; |
1506 } | 1503 } |
1507 return SBREG; | 1504 return SBREG.release(); |
1508 failed: | 1505 failed: |
1509 if (bRetained == FALSE) { | 1506 if (bRetained == FALSE) { |
1510 delete IADT; | 1507 delete IADT; |
1511 delete IAFS; | 1508 delete IAFS; |
1512 delete IADS; | 1509 delete IADS; |
1513 delete IAIT; | 1510 delete IAIT; |
1514 delete IARI; | 1511 delete IARI; |
1515 delete IARDW; | 1512 delete IARDW; |
1516 delete IARDH; | 1513 delete IARDH; |
1517 delete IARDX; | 1514 delete IARDX; |
1518 delete IARDY; | 1515 delete IARDY; |
1519 delete IAID; | 1516 delete IAID; |
1520 } | 1517 } |
1521 delete SBREG; | 1518 return nullptr; |
1522 return NULL; | |
1523 } | 1519 } |
| 1520 |
1524 CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith( | 1521 CJBig2_SymbolDict* CJBig2_SDDProc::decode_Arith( |
1525 CJBig2_ArithDecoder* pArithDecoder, | 1522 CJBig2_ArithDecoder* pArithDecoder, |
1526 JBig2ArithCtx* gbContext, | 1523 JBig2ArithCtx* gbContext, |
1527 JBig2ArithCtx* grContext) { | 1524 JBig2ArithCtx* grContext) { |
1528 CJBig2_Image** SDNEWSYMS; | 1525 CJBig2_Image** SDNEWSYMS; |
1529 FX_DWORD HCHEIGHT, NSYMSDECODED; | 1526 FX_DWORD HCHEIGHT, NSYMSDECODED; |
1530 int32_t HCDH; | 1527 int32_t HCDH; |
1531 FX_DWORD SYMWIDTH, TOTWIDTH; | 1528 FX_DWORD SYMWIDTH, TOTWIDTH; |
1532 int32_t DW; | 1529 int32_t DW; |
1533 CJBig2_Image* BS; | 1530 CJBig2_Image* BS; |
1534 FX_DWORD I, J, REFAGGNINST; | 1531 FX_DWORD I, J, REFAGGNINST; |
1535 FX_BOOL* EXFLAGS; | 1532 FX_BOOL* EXFLAGS; |
1536 FX_DWORD EXINDEX; | 1533 FX_DWORD EXINDEX; |
1537 FX_BOOL CUREXFLAG; | 1534 FX_BOOL CUREXFLAG; |
1538 FX_DWORD EXRUNLENGTH; | 1535 FX_DWORD EXRUNLENGTH; |
1539 int32_t nVal; | 1536 int32_t nVal; |
1540 FX_DWORD nTmp; | 1537 FX_DWORD nTmp; |
1541 FX_DWORD SBNUMSYMS; | 1538 FX_DWORD SBNUMSYMS; |
1542 uint8_t SBSYMCODELEN; | 1539 uint8_t SBSYMCODELEN; |
1543 FX_DWORD IDI; | 1540 FX_DWORD IDI; |
1544 int32_t RDXI, RDYI; | 1541 int32_t RDXI, RDYI; |
1545 CJBig2_Image** SBSYMS; | 1542 CJBig2_Image** SBSYMS; |
1546 CJBig2_HuffmanTable *SBHUFFFS, *SBHUFFDS, *SBHUFFDT, *SBHUFFRDW, *SBHUFFRDH, | 1543 nonstd::unique_ptr<CJBig2_ArithIaidDecoder> IAID; |
1547 *SBHUFFRDX, *SBHUFFRDY, *SBHUFFRSIZE; | 1544 nonstd::unique_ptr<CJBig2_SymbolDict> pDict; |
1548 CJBig2_GRRDProc* pGRRD; | 1545 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IADH(new CJBig2_ArithIntDecoder); |
1549 CJBig2_GRDProc* pGRD; | 1546 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IADW(new CJBig2_ArithIntDecoder); |
1550 CJBig2_ArithIntDecoder *IADH, *IADW, *IAAI, *IARDX, *IARDY, *IAEX, *IADT, | 1547 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IAAI(new CJBig2_ArithIntDecoder); |
1551 *IAFS, *IADS, *IAIT, *IARI, *IARDW, *IARDH; | 1548 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IARDX(new CJBig2_ArithIntDecoder); |
1552 CJBig2_ArithIaidDecoder* IAID; | 1549 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IARDY(new CJBig2_ArithIntDecoder); |
1553 CJBig2_SymbolDict* pDict; | 1550 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IAEX(new CJBig2_ArithIntDecoder); |
1554 IADH = new CJBig2_ArithIntDecoder(); | 1551 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IADT(new CJBig2_ArithIntDecoder); |
1555 IADW = new CJBig2_ArithIntDecoder(); | 1552 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IAFS(new CJBig2_ArithIntDecoder); |
1556 IAAI = new CJBig2_ArithIntDecoder(); | 1553 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IADS(new CJBig2_ArithIntDecoder); |
1557 IARDX = new CJBig2_ArithIntDecoder(); | 1554 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IAIT(new CJBig2_ArithIntDecoder); |
1558 IARDY = new CJBig2_ArithIntDecoder(); | 1555 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IARI(new CJBig2_ArithIntDecoder); |
1559 IAEX = new CJBig2_ArithIntDecoder(); | 1556 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IARDW(new CJBig2_ArithIntDecoder); |
1560 IADT = new CJBig2_ArithIntDecoder(); | 1557 nonstd::unique_ptr<CJBig2_ArithIntDecoder> IARDH(new CJBig2_ArithIntDecoder); |
1561 IAFS = new CJBig2_ArithIntDecoder(); | |
1562 IADS = new CJBig2_ArithIntDecoder(); | |
1563 IAIT = new CJBig2_ArithIntDecoder(); | |
1564 IARI = new CJBig2_ArithIntDecoder(); | |
1565 IARDW = new CJBig2_ArithIntDecoder(); | |
1566 IARDH = new CJBig2_ArithIntDecoder(); | |
1567 nTmp = 0; | 1558 nTmp = 0; |
1568 while ((FX_DWORD)(1 << nTmp) < (SDNUMINSYMS + SDNUMNEWSYMS)) { | 1559 while ((FX_DWORD)(1 << nTmp) < (SDNUMINSYMS + SDNUMNEWSYMS)) { |
1569 nTmp++; | 1560 nTmp++; |
1570 } | 1561 } |
1571 IAID = new CJBig2_ArithIaidDecoder((uint8_t)nTmp); | 1562 IAID.reset(new CJBig2_ArithIaidDecoder((uint8_t)nTmp)); |
1572 SDNEWSYMS = FX_Alloc(CJBig2_Image*, SDNUMNEWSYMS); | 1563 SDNEWSYMS = FX_Alloc(CJBig2_Image*, SDNUMNEWSYMS); |
1573 FXSYS_memset(SDNEWSYMS, 0, SDNUMNEWSYMS * sizeof(CJBig2_Image*)); | 1564 FXSYS_memset(SDNEWSYMS, 0, SDNUMNEWSYMS * sizeof(CJBig2_Image*)); |
| 1565 |
1574 HCHEIGHT = 0; | 1566 HCHEIGHT = 0; |
1575 NSYMSDECODED = 0; | 1567 NSYMSDECODED = 0; |
1576 while (NSYMSDECODED < SDNUMNEWSYMS) { | 1568 while (NSYMSDECODED < SDNUMNEWSYMS) { |
1577 BS = NULL; | 1569 BS = nullptr; |
1578 if (IADH->decode(pArithDecoder, &HCDH) == -1) { | 1570 if (IADH->decode(pArithDecoder, &HCDH) == -1) { |
1579 goto failed; | 1571 goto failed; |
1580 } | 1572 } |
1581 HCHEIGHT = HCHEIGHT + HCDH; | 1573 HCHEIGHT = HCHEIGHT + HCDH; |
1582 if ((int)HCHEIGHT < 0 || (int)HCHEIGHT > JBIG2_MAX_IMAGE_SIZE) { | 1574 if ((int)HCHEIGHT < 0 || (int)HCHEIGHT > JBIG2_MAX_IMAGE_SIZE) { |
1583 goto failed; | 1575 goto failed; |
1584 } | 1576 } |
1585 SYMWIDTH = 0; | 1577 SYMWIDTH = 0; |
1586 TOTWIDTH = 0; | 1578 TOTWIDTH = 0; |
1587 for (;;) { | 1579 for (;;) { |
1588 nVal = IADW->decode(pArithDecoder, &DW); | 1580 nVal = IADW->decode(pArithDecoder, &DW); |
1589 if (nVal == JBIG2_OOB) { | 1581 if (nVal == JBIG2_OOB) { |
1590 break; | 1582 break; |
1591 } else if (nVal != 0) { | 1583 } else if (nVal != 0) { |
1592 goto failed; | 1584 goto failed; |
1593 } else { | 1585 } else { |
1594 if (NSYMSDECODED >= SDNUMNEWSYMS) { | 1586 if (NSYMSDECODED >= SDNUMNEWSYMS) { |
1595 goto failed; | 1587 goto failed; |
1596 } | 1588 } |
1597 SYMWIDTH = SYMWIDTH + DW; | 1589 SYMWIDTH = SYMWIDTH + DW; |
1598 if ((int)SYMWIDTH < 0 || (int)SYMWIDTH > JBIG2_MAX_IMAGE_SIZE) { | 1590 if ((int)SYMWIDTH < 0 || (int)SYMWIDTH > JBIG2_MAX_IMAGE_SIZE) { |
1599 goto failed; | 1591 goto failed; |
1600 } else if (HCHEIGHT == 0 || SYMWIDTH == 0) { | 1592 } else if (HCHEIGHT == 0 || SYMWIDTH == 0) { |
1601 TOTWIDTH = TOTWIDTH + SYMWIDTH; | 1593 TOTWIDTH = TOTWIDTH + SYMWIDTH; |
1602 SDNEWSYMS[NSYMSDECODED] = NULL; | 1594 SDNEWSYMS[NSYMSDECODED] = nullptr; |
1603 NSYMSDECODED = NSYMSDECODED + 1; | 1595 NSYMSDECODED = NSYMSDECODED + 1; |
1604 continue; | 1596 continue; |
1605 } | 1597 } |
1606 TOTWIDTH = TOTWIDTH + SYMWIDTH; | 1598 TOTWIDTH = TOTWIDTH + SYMWIDTH; |
1607 } | 1599 } |
1608 if (SDREFAGG == 0) { | 1600 if (SDREFAGG == 0) { |
1609 pGRD = new CJBig2_GRDProc(); | 1601 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); |
1610 pGRD->MMR = 0; | 1602 pGRD->MMR = 0; |
1611 pGRD->GBW = SYMWIDTH; | 1603 pGRD->GBW = SYMWIDTH; |
1612 pGRD->GBH = HCHEIGHT; | 1604 pGRD->GBH = HCHEIGHT; |
1613 pGRD->GBTEMPLATE = SDTEMPLATE; | 1605 pGRD->GBTEMPLATE = SDTEMPLATE; |
1614 pGRD->TPGDON = 0; | 1606 pGRD->TPGDON = 0; |
1615 pGRD->USESKIP = 0; | 1607 pGRD->USESKIP = 0; |
1616 pGRD->GBAT[0] = SDAT[0]; | 1608 pGRD->GBAT[0] = SDAT[0]; |
1617 pGRD->GBAT[1] = SDAT[1]; | 1609 pGRD->GBAT[1] = SDAT[1]; |
1618 pGRD->GBAT[2] = SDAT[2]; | 1610 pGRD->GBAT[2] = SDAT[2]; |
1619 pGRD->GBAT[3] = SDAT[3]; | 1611 pGRD->GBAT[3] = SDAT[3]; |
1620 pGRD->GBAT[4] = SDAT[4]; | 1612 pGRD->GBAT[4] = SDAT[4]; |
1621 pGRD->GBAT[5] = SDAT[5]; | 1613 pGRD->GBAT[5] = SDAT[5]; |
1622 pGRD->GBAT[6] = SDAT[6]; | 1614 pGRD->GBAT[6] = SDAT[6]; |
1623 pGRD->GBAT[7] = SDAT[7]; | 1615 pGRD->GBAT[7] = SDAT[7]; |
1624 BS = pGRD->decode_Arith(pArithDecoder, gbContext); | 1616 BS = pGRD->decode_Arith(pArithDecoder, gbContext); |
1625 if (BS == NULL) { | 1617 if (!BS) { |
1626 delete pGRD; | |
1627 goto failed; | 1618 goto failed; |
1628 } | 1619 } |
1629 delete pGRD; | |
1630 } else { | 1620 } else { |
1631 if (IAAI->decode(pArithDecoder, (int*)&REFAGGNINST) == -1) { | 1621 if (IAAI->decode(pArithDecoder, (int*)&REFAGGNINST) == -1) { |
1632 goto failed; | 1622 goto failed; |
1633 } | 1623 } |
1634 if (REFAGGNINST > 1) { | 1624 if (REFAGGNINST > 1) { |
1635 CJBig2_TRDProc* pDecoder; | 1625 nonstd::unique_ptr<CJBig2_TRDProc> pDecoder(new CJBig2_TRDProc()); |
1636 pDecoder = new CJBig2_TRDProc(); | |
1637 pDecoder->SBHUFF = SDHUFF; | 1626 pDecoder->SBHUFF = SDHUFF; |
1638 pDecoder->SBREFINE = 1; | 1627 pDecoder->SBREFINE = 1; |
1639 pDecoder->SBW = SYMWIDTH; | 1628 pDecoder->SBW = SYMWIDTH; |
1640 pDecoder->SBH = HCHEIGHT; | 1629 pDecoder->SBH = HCHEIGHT; |
1641 pDecoder->SBNUMINSTANCES = REFAGGNINST; | 1630 pDecoder->SBNUMINSTANCES = REFAGGNINST; |
1642 pDecoder->SBSTRIPS = 1; | 1631 pDecoder->SBSTRIPS = 1; |
1643 pDecoder->SBNUMSYMS = SDNUMINSYMS + NSYMSDECODED; | 1632 pDecoder->SBNUMSYMS = SDNUMINSYMS + NSYMSDECODED; |
1644 SBNUMSYMS = pDecoder->SBNUMSYMS; | 1633 SBNUMSYMS = pDecoder->SBNUMSYMS; |
1645 nTmp = 0; | 1634 nTmp = 0; |
1646 while ((FX_DWORD)(1 << nTmp) < SBNUMSYMS) { | 1635 while ((FX_DWORD)(1 << nTmp) < SBNUMSYMS) { |
1647 nTmp++; | 1636 nTmp++; |
1648 } | 1637 } |
1649 SBSYMCODELEN = (uint8_t)nTmp; | 1638 SBSYMCODELEN = (uint8_t)nTmp; |
1650 pDecoder->SBSYMCODELEN = SBSYMCODELEN; | 1639 pDecoder->SBSYMCODELEN = SBSYMCODELEN; |
1651 SBSYMS = FX_Alloc(CJBig2_Image*, SBNUMSYMS); | 1640 SBSYMS = FX_Alloc(CJBig2_Image*, SBNUMSYMS); |
1652 JBIG2_memcpy(SBSYMS, SDINSYMS, SDNUMINSYMS * sizeof(CJBig2_Image*)); | 1641 JBIG2_memcpy(SBSYMS, SDINSYMS, SDNUMINSYMS * sizeof(CJBig2_Image*)); |
1653 JBIG2_memcpy(SBSYMS + SDNUMINSYMS, SDNEWSYMS, | 1642 JBIG2_memcpy(SBSYMS + SDNUMINSYMS, SDNEWSYMS, |
1654 NSYMSDECODED * sizeof(CJBig2_Image*)); | 1643 NSYMSDECODED * sizeof(CJBig2_Image*)); |
1655 pDecoder->SBSYMS = SBSYMS; | 1644 pDecoder->SBSYMS = SBSYMS; |
1656 pDecoder->SBDEFPIXEL = 0; | 1645 pDecoder->SBDEFPIXEL = 0; |
1657 pDecoder->SBCOMBOP = JBIG2_COMPOSE_OR; | 1646 pDecoder->SBCOMBOP = JBIG2_COMPOSE_OR; |
1658 pDecoder->TRANSPOSED = 0; | 1647 pDecoder->TRANSPOSED = 0; |
1659 pDecoder->REFCORNER = JBIG2_CORNER_TOPLEFT; | 1648 pDecoder->REFCORNER = JBIG2_CORNER_TOPLEFT; |
1660 pDecoder->SBDSOFFSET = 0; | 1649 pDecoder->SBDSOFFSET = 0; |
1661 SBHUFFFS = new CJBig2_HuffmanTable(HuffmanTable_B6, | 1650 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFFS( |
1662 FX_ArraySize(HuffmanTable_B6), | 1651 new CJBig2_HuffmanTable(HuffmanTable_B6, |
1663 HuffmanTable_HTOOB_B6); | 1652 FX_ArraySize(HuffmanTable_B6), |
1664 SBHUFFDS = new CJBig2_HuffmanTable(HuffmanTable_B8, | 1653 HuffmanTable_HTOOB_B6)); |
1665 FX_ArraySize(HuffmanTable_B8), | 1654 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFDS( |
1666 HuffmanTable_HTOOB_B8); | 1655 new CJBig2_HuffmanTable(HuffmanTable_B8, |
1667 SBHUFFDT = new CJBig2_HuffmanTable(HuffmanTable_B11, | 1656 FX_ArraySize(HuffmanTable_B8), |
1668 FX_ArraySize(HuffmanTable_B11), | 1657 HuffmanTable_HTOOB_B8)); |
1669 HuffmanTable_HTOOB_B11); | 1658 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFDT( |
1670 SBHUFFRDW = new CJBig2_HuffmanTable(HuffmanTable_B15, | 1659 new CJBig2_HuffmanTable(HuffmanTable_B11, |
1671 FX_ArraySize(HuffmanTable_B15), | 1660 FX_ArraySize(HuffmanTable_B11), |
1672 HuffmanTable_HTOOB_B15); | 1661 HuffmanTable_HTOOB_B11)); |
1673 SBHUFFRDH = new CJBig2_HuffmanTable(HuffmanTable_B15, | 1662 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFRDW( |
1674 FX_ArraySize(HuffmanTable_B15), | 1663 new CJBig2_HuffmanTable(HuffmanTable_B15, |
1675 HuffmanTable_HTOOB_B15); | 1664 FX_ArraySize(HuffmanTable_B15), |
1676 SBHUFFRDX = new CJBig2_HuffmanTable(HuffmanTable_B15, | 1665 HuffmanTable_HTOOB_B15)); |
1677 FX_ArraySize(HuffmanTable_B15), | 1666 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFRDH( |
1678 HuffmanTable_HTOOB_B15); | 1667 new CJBig2_HuffmanTable(HuffmanTable_B15, |
1679 SBHUFFRDY = new CJBig2_HuffmanTable(HuffmanTable_B15, | 1668 FX_ArraySize(HuffmanTable_B15), |
1680 FX_ArraySize(HuffmanTable_B15), | 1669 HuffmanTable_HTOOB_B15)); |
1681 HuffmanTable_HTOOB_B15); | 1670 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFRDX( |
1682 SBHUFFRSIZE = new CJBig2_HuffmanTable(HuffmanTable_B1, | 1671 new CJBig2_HuffmanTable(HuffmanTable_B15, |
1683 FX_ArraySize(HuffmanTable_B1), | 1672 FX_ArraySize(HuffmanTable_B15), |
1684 HuffmanTable_HTOOB_B1); | 1673 HuffmanTable_HTOOB_B15)); |
1685 pDecoder->SBHUFFFS = SBHUFFFS; | 1674 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFRDY( |
1686 pDecoder->SBHUFFDS = SBHUFFDS; | 1675 new CJBig2_HuffmanTable(HuffmanTable_B15, |
1687 pDecoder->SBHUFFDT = SBHUFFDT; | 1676 FX_ArraySize(HuffmanTable_B15), |
1688 pDecoder->SBHUFFRDW = SBHUFFRDW; | 1677 HuffmanTable_HTOOB_B15)); |
1689 pDecoder->SBHUFFRDH = SBHUFFRDH; | 1678 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFRSIZE( |
1690 pDecoder->SBHUFFRDX = SBHUFFRDX; | 1679 new CJBig2_HuffmanTable(HuffmanTable_B1, |
1691 pDecoder->SBHUFFRDY = SBHUFFRDY; | 1680 FX_ArraySize(HuffmanTable_B1), |
1692 pDecoder->SBHUFFRSIZE = SBHUFFRSIZE; | 1681 HuffmanTable_HTOOB_B1)); |
| 1682 pDecoder->SBHUFFFS = SBHUFFFS.get(); |
| 1683 pDecoder->SBHUFFDS = SBHUFFDS.get(); |
| 1684 pDecoder->SBHUFFDT = SBHUFFDT.get(); |
| 1685 pDecoder->SBHUFFRDW = SBHUFFRDW.get(); |
| 1686 pDecoder->SBHUFFRDH = SBHUFFRDH.get(); |
| 1687 pDecoder->SBHUFFRDX = SBHUFFRDX.get(); |
| 1688 pDecoder->SBHUFFRDY = SBHUFFRDY.get(); |
| 1689 pDecoder->SBHUFFRSIZE = SBHUFFRSIZE.get(); |
1693 pDecoder->SBRTEMPLATE = SDRTEMPLATE; | 1690 pDecoder->SBRTEMPLATE = SDRTEMPLATE; |
1694 pDecoder->SBRAT[0] = SDRAT[0]; | 1691 pDecoder->SBRAT[0] = SDRAT[0]; |
1695 pDecoder->SBRAT[1] = SDRAT[1]; | 1692 pDecoder->SBRAT[1] = SDRAT[1]; |
1696 pDecoder->SBRAT[2] = SDRAT[2]; | 1693 pDecoder->SBRAT[2] = SDRAT[2]; |
1697 pDecoder->SBRAT[3] = SDRAT[3]; | 1694 pDecoder->SBRAT[3] = SDRAT[3]; |
1698 JBig2IntDecoderState ids; | 1695 JBig2IntDecoderState ids; |
1699 ids.IADT = IADT; | 1696 ids.IADT = IADT.get(); |
1700 ids.IAFS = IAFS; | 1697 ids.IAFS = IAFS.get(); |
1701 ids.IADS = IADS; | 1698 ids.IADS = IADS.get(); |
1702 ids.IAIT = IAIT; | 1699 ids.IAIT = IAIT.get(); |
1703 ids.IARI = IARI; | 1700 ids.IARI = IARI.get(); |
1704 ids.IARDW = IARDW; | 1701 ids.IARDW = IARDW.get(); |
1705 ids.IARDH = IARDH; | 1702 ids.IARDH = IARDH.get(); |
1706 ids.IARDX = IARDX; | 1703 ids.IARDX = IARDX.get(); |
1707 ids.IARDY = IARDY; | 1704 ids.IARDY = IARDY.get(); |
1708 ids.IAID = IAID; | 1705 ids.IAID = IAID.get(); |
1709 BS = pDecoder->decode_Arith(pArithDecoder, grContext, &ids); | 1706 BS = pDecoder->decode_Arith(pArithDecoder, grContext, &ids); |
1710 if (BS == NULL) { | 1707 if (!BS) { |
1711 FX_Free(SBSYMS); | 1708 FX_Free(SBSYMS); |
1712 delete SBHUFFFS; | |
1713 delete SBHUFFDS; | |
1714 delete SBHUFFDT; | |
1715 delete SBHUFFRDW; | |
1716 delete SBHUFFRDH; | |
1717 delete SBHUFFRDX; | |
1718 delete SBHUFFRDY; | |
1719 delete SBHUFFRSIZE; | |
1720 delete pDecoder; | |
1721 goto failed; | 1709 goto failed; |
1722 } | 1710 } |
1723 FX_Free(SBSYMS); | 1711 FX_Free(SBSYMS); |
1724 delete SBHUFFFS; | |
1725 delete SBHUFFDS; | |
1726 delete SBHUFFDT; | |
1727 delete SBHUFFRDW; | |
1728 delete SBHUFFRDH; | |
1729 delete SBHUFFRDX; | |
1730 delete SBHUFFRDY; | |
1731 delete SBHUFFRSIZE; | |
1732 delete pDecoder; | |
1733 } else if (REFAGGNINST == 1) { | 1712 } else if (REFAGGNINST == 1) { |
1734 SBNUMSYMS = SDNUMINSYMS + NSYMSDECODED; | 1713 SBNUMSYMS = SDNUMINSYMS + NSYMSDECODED; |
1735 if (IAID->decode(pArithDecoder, (int*)&IDI) == -1) { | 1714 if (IAID->decode(pArithDecoder, (int*)&IDI) == -1) { |
1736 goto failed; | 1715 goto failed; |
1737 } | 1716 } |
1738 if ((IARDX->decode(pArithDecoder, &RDXI) == -1) || | 1717 if ((IARDX->decode(pArithDecoder, &RDXI) == -1) || |
1739 (IARDY->decode(pArithDecoder, &RDYI) == -1)) { | 1718 (IARDY->decode(pArithDecoder, &RDYI) == -1)) { |
1740 goto failed; | 1719 goto failed; |
1741 } | 1720 } |
1742 if (IDI >= SBNUMSYMS) { | 1721 if (IDI >= SBNUMSYMS) { |
1743 goto failed; | 1722 goto failed; |
1744 } | 1723 } |
1745 SBSYMS = FX_Alloc(CJBig2_Image*, SBNUMSYMS); | 1724 SBSYMS = FX_Alloc(CJBig2_Image*, SBNUMSYMS); |
1746 JBIG2_memcpy(SBSYMS, SDINSYMS, SDNUMINSYMS * sizeof(CJBig2_Image*)); | 1725 JBIG2_memcpy(SBSYMS, SDINSYMS, SDNUMINSYMS * sizeof(CJBig2_Image*)); |
1747 JBIG2_memcpy(SBSYMS + SDNUMINSYMS, SDNEWSYMS, | 1726 JBIG2_memcpy(SBSYMS + SDNUMINSYMS, SDNEWSYMS, |
1748 NSYMSDECODED * sizeof(CJBig2_Image*)); | 1727 NSYMSDECODED * sizeof(CJBig2_Image*)); |
1749 if (!SBSYMS[IDI]) { | 1728 if (!SBSYMS[IDI]) { |
1750 FX_Free(SBSYMS); | 1729 FX_Free(SBSYMS); |
1751 goto failed; | 1730 goto failed; |
1752 } | 1731 } |
1753 pGRRD = new CJBig2_GRRDProc(); | 1732 nonstd::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc()); |
1754 pGRRD->GRW = SYMWIDTH; | 1733 pGRRD->GRW = SYMWIDTH; |
1755 pGRRD->GRH = HCHEIGHT; | 1734 pGRRD->GRH = HCHEIGHT; |
1756 pGRRD->GRTEMPLATE = SDRTEMPLATE; | 1735 pGRRD->GRTEMPLATE = SDRTEMPLATE; |
1757 pGRRD->GRREFERENCE = SBSYMS[IDI]; | 1736 pGRRD->GRREFERENCE = SBSYMS[IDI]; |
1758 pGRRD->GRREFERENCEDX = RDXI; | 1737 pGRRD->GRREFERENCEDX = RDXI; |
1759 pGRRD->GRREFERENCEDY = RDYI; | 1738 pGRRD->GRREFERENCEDY = RDYI; |
1760 pGRRD->TPGRON = 0; | 1739 pGRRD->TPGRON = 0; |
1761 pGRRD->GRAT[0] = SDRAT[0]; | 1740 pGRRD->GRAT[0] = SDRAT[0]; |
1762 pGRRD->GRAT[1] = SDRAT[1]; | 1741 pGRRD->GRAT[1] = SDRAT[1]; |
1763 pGRRD->GRAT[2] = SDRAT[2]; | 1742 pGRRD->GRAT[2] = SDRAT[2]; |
1764 pGRRD->GRAT[3] = SDRAT[3]; | 1743 pGRRD->GRAT[3] = SDRAT[3]; |
1765 BS = pGRRD->decode(pArithDecoder, grContext); | 1744 BS = pGRRD->decode(pArithDecoder, grContext); |
1766 if (BS == NULL) { | 1745 if (!BS) { |
1767 FX_Free(SBSYMS); | 1746 FX_Free(SBSYMS); |
1768 delete pGRRD; | |
1769 goto failed; | 1747 goto failed; |
1770 } | 1748 } |
1771 FX_Free(SBSYMS); | 1749 FX_Free(SBSYMS); |
1772 delete pGRRD; | |
1773 } | 1750 } |
1774 } | 1751 } |
1775 SDNEWSYMS[NSYMSDECODED] = BS; | 1752 SDNEWSYMS[NSYMSDECODED] = BS; |
1776 BS = NULL; | 1753 BS = nullptr; |
1777 NSYMSDECODED = NSYMSDECODED + 1; | 1754 NSYMSDECODED = NSYMSDECODED + 1; |
1778 } | 1755 } |
1779 } | 1756 } |
1780 EXINDEX = 0; | 1757 EXINDEX = 0; |
1781 CUREXFLAG = 0; | 1758 CUREXFLAG = 0; |
1782 EXFLAGS = FX_Alloc(FX_BOOL, SDNUMINSYMS + SDNUMNEWSYMS); | 1759 EXFLAGS = FX_Alloc(FX_BOOL, SDNUMINSYMS + SDNUMNEWSYMS); |
1783 while (EXINDEX < SDNUMINSYMS + SDNUMNEWSYMS) { | 1760 while (EXINDEX < SDNUMINSYMS + SDNUMNEWSYMS) { |
1784 if (IAEX->decode(pArithDecoder, (int*)&EXRUNLENGTH) == -1) { | 1761 if (IAEX->decode(pArithDecoder, (int*)&EXRUNLENGTH) == -1) { |
1785 FX_Free(EXFLAGS); | 1762 FX_Free(EXFLAGS); |
1786 goto failed; | 1763 goto failed; |
1787 } | 1764 } |
1788 if (EXINDEX + EXRUNLENGTH > SDNUMINSYMS + SDNUMNEWSYMS) { | 1765 if (EXINDEX + EXRUNLENGTH > SDNUMINSYMS + SDNUMNEWSYMS) { |
1789 FX_Free(EXFLAGS); | 1766 FX_Free(EXFLAGS); |
1790 goto failed; | 1767 goto failed; |
1791 } | 1768 } |
1792 if (EXRUNLENGTH != 0) { | 1769 if (EXRUNLENGTH != 0) { |
1793 for (I = EXINDEX; I < EXINDEX + EXRUNLENGTH; I++) { | 1770 for (I = EXINDEX; I < EXINDEX + EXRUNLENGTH; I++) { |
1794 EXFLAGS[I] = CUREXFLAG; | 1771 EXFLAGS[I] = CUREXFLAG; |
1795 } | 1772 } |
1796 } | 1773 } |
1797 EXINDEX = EXINDEX + EXRUNLENGTH; | 1774 EXINDEX = EXINDEX + EXRUNLENGTH; |
1798 CUREXFLAG = !CUREXFLAG; | 1775 CUREXFLAG = !CUREXFLAG; |
1799 } | 1776 } |
1800 pDict = new CJBig2_SymbolDict(); | 1777 pDict.reset(new CJBig2_SymbolDict); |
1801 pDict->SDNUMEXSYMS = SDNUMEXSYMS; | 1778 pDict->SDNUMEXSYMS = SDNUMEXSYMS; |
1802 pDict->SDEXSYMS = FX_Alloc(CJBig2_Image*, SDNUMEXSYMS); | 1779 pDict->SDEXSYMS = FX_Alloc(CJBig2_Image*, SDNUMEXSYMS); |
1803 I = J = 0; | 1780 I = J = 0; |
1804 for (I = 0; I < SDNUMINSYMS + SDNUMNEWSYMS; I++) { | 1781 for (I = 0; I < SDNUMINSYMS + SDNUMNEWSYMS; I++) { |
1805 if (EXFLAGS[I] && J < SDNUMEXSYMS) { | 1782 if (EXFLAGS[I] && J < SDNUMEXSYMS) { |
1806 if (I < SDNUMINSYMS) { | 1783 if (I < SDNUMINSYMS) { |
1807 pDict->SDEXSYMS[J] = new CJBig2_Image(*SDINSYMS[I]); | 1784 pDict->SDEXSYMS[J] = new CJBig2_Image(*SDINSYMS[I]); |
1808 } else { | 1785 } else { |
1809 pDict->SDEXSYMS[J] = SDNEWSYMS[I - SDNUMINSYMS]; | 1786 pDict->SDEXSYMS[J] = SDNEWSYMS[I - SDNUMINSYMS]; |
1810 } | 1787 } |
1811 J = J + 1; | 1788 J = J + 1; |
1812 } else if (!EXFLAGS[I] && I >= SDNUMINSYMS) { | 1789 } else if (!EXFLAGS[I] && I >= SDNUMINSYMS) { |
1813 delete SDNEWSYMS[I - SDNUMINSYMS]; | 1790 delete SDNEWSYMS[I - SDNUMINSYMS]; |
1814 } | 1791 } |
1815 } | 1792 } |
1816 if (J < SDNUMEXSYMS) { | 1793 if (J < SDNUMEXSYMS) { |
1817 pDict->SDNUMEXSYMS = J; | 1794 pDict->SDNUMEXSYMS = J; |
1818 } | 1795 } |
1819 FX_Free(EXFLAGS); | 1796 FX_Free(EXFLAGS); |
1820 FX_Free(SDNEWSYMS); | 1797 FX_Free(SDNEWSYMS); |
1821 delete IADH; | 1798 return pDict.release(); |
1822 delete IADW; | |
1823 delete IAAI; | |
1824 delete IARDX; | |
1825 delete IARDY; | |
1826 delete IAEX; | |
1827 delete IAID; | |
1828 delete IADT; | |
1829 delete IAFS; | |
1830 delete IADS; | |
1831 delete IAIT; | |
1832 delete IARI; | |
1833 delete IARDW; | |
1834 delete IARDH; | |
1835 return pDict; | |
1836 failed: | 1799 failed: |
1837 for (I = 0; I < NSYMSDECODED; I++) { | 1800 for (I = 0; I < NSYMSDECODED; I++) { |
1838 if (SDNEWSYMS[I]) { | 1801 if (SDNEWSYMS[I]) { |
1839 delete SDNEWSYMS[I]; | 1802 delete SDNEWSYMS[I]; |
1840 SDNEWSYMS[I] = NULL; | 1803 SDNEWSYMS[I] = nullptr; |
1841 } | 1804 } |
1842 } | 1805 } |
1843 FX_Free(SDNEWSYMS); | 1806 FX_Free(SDNEWSYMS); |
1844 delete IADH; | 1807 return nullptr; |
1845 delete IADW; | |
1846 delete IAAI; | |
1847 delete IARDX; | |
1848 delete IARDY; | |
1849 delete IAEX; | |
1850 delete IAID; | |
1851 delete IADT; | |
1852 delete IAFS; | |
1853 delete IADS; | |
1854 delete IAIT; | |
1855 delete IARI; | |
1856 delete IARDW; | |
1857 delete IARDH; | |
1858 return NULL; | |
1859 } | 1808 } |
| 1809 |
1860 CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman(CJBig2_BitStream* pStream, | 1810 CJBig2_SymbolDict* CJBig2_SDDProc::decode_Huffman(CJBig2_BitStream* pStream, |
1861 JBig2ArithCtx* gbContext, | 1811 JBig2ArithCtx* gbContext, |
1862 JBig2ArithCtx* grContext, | 1812 JBig2ArithCtx* grContext, |
1863 IFX_Pause* pPause) { | 1813 IFX_Pause* pPause) { |
1864 CJBig2_Image** SDNEWSYMS; | 1814 CJBig2_Image** SDNEWSYMS; |
1865 FX_DWORD* SDNEWSYMWIDTHS; | 1815 FX_DWORD* SDNEWSYMWIDTHS; |
1866 FX_DWORD HCHEIGHT, NSYMSDECODED; | 1816 FX_DWORD HCHEIGHT, NSYMSDECODED; |
1867 int32_t HCDH; | 1817 int32_t HCDH; |
1868 FX_DWORD SYMWIDTH, TOTWIDTH, HCFIRSTSYM; | 1818 FX_DWORD SYMWIDTH, TOTWIDTH, HCFIRSTSYM; |
1869 int32_t DW; | 1819 int32_t DW; |
1870 CJBig2_Image *BS, *BHC; | 1820 CJBig2_Image *BS, *BHC; |
1871 FX_DWORD I, J, REFAGGNINST; | 1821 FX_DWORD I, J, REFAGGNINST; |
1872 FX_BOOL* EXFLAGS; | 1822 FX_BOOL* EXFLAGS; |
1873 FX_DWORD EXINDEX; | 1823 FX_DWORD EXINDEX; |
1874 FX_BOOL CUREXFLAG; | 1824 FX_BOOL CUREXFLAG; |
1875 FX_DWORD EXRUNLENGTH; | 1825 FX_DWORD EXRUNLENGTH; |
1876 int32_t nVal, nBits; | 1826 int32_t nVal, nBits; |
1877 FX_DWORD nTmp; | 1827 FX_DWORD nTmp; |
1878 FX_DWORD SBNUMSYMS; | 1828 FX_DWORD SBNUMSYMS; |
1879 uint8_t SBSYMCODELEN; | 1829 uint8_t SBSYMCODELEN; |
1880 JBig2HuffmanCode* SBSYMCODES; | 1830 JBig2HuffmanCode* SBSYMCODES; |
1881 FX_DWORD IDI; | 1831 FX_DWORD IDI; |
1882 int32_t RDXI, RDYI; | 1832 int32_t RDXI, RDYI; |
1883 FX_DWORD BMSIZE; | 1833 FX_DWORD BMSIZE; |
1884 FX_DWORD stride; | 1834 FX_DWORD stride; |
1885 CJBig2_Image** SBSYMS; | 1835 CJBig2_Image** SBSYMS; |
1886 CJBig2_HuffmanTable *SBHUFFFS, *SBHUFFDS, *SBHUFFDT, *SBHUFFRDW, *SBHUFFRDH, | 1836 nonstd::unique_ptr<CJBig2_HuffmanDecoder> pHuffmanDecoder( |
1887 *SBHUFFRDX, *SBHUFFRDY, *SBHUFFRSIZE, *pTable; | 1837 new CJBig2_HuffmanDecoder(pStream)); |
1888 CJBig2_HuffmanDecoder* pHuffmanDecoder; | |
1889 CJBig2_GRRDProc* pGRRD; | |
1890 CJBig2_ArithDecoder* pArithDecoder; | |
1891 CJBig2_GRDProc* pGRD; | |
1892 CJBig2_SymbolDict* pDict; | |
1893 pHuffmanDecoder = new CJBig2_HuffmanDecoder(pStream); | |
1894 SDNEWSYMS = FX_Alloc(CJBig2_Image*, SDNUMNEWSYMS); | 1838 SDNEWSYMS = FX_Alloc(CJBig2_Image*, SDNUMNEWSYMS); |
1895 FXSYS_memset(SDNEWSYMS, 0, SDNUMNEWSYMS * sizeof(CJBig2_Image*)); | 1839 FXSYS_memset(SDNEWSYMS, 0, SDNUMNEWSYMS * sizeof(CJBig2_Image*)); |
1896 SDNEWSYMWIDTHS = NULL; | 1840 SDNEWSYMWIDTHS = nullptr; |
1897 BHC = NULL; | 1841 BHC = nullptr; |
1898 if (SDREFAGG == 0) { | 1842 if (SDREFAGG == 0) { |
1899 SDNEWSYMWIDTHS = FX_Alloc(FX_DWORD, SDNUMNEWSYMS); | 1843 SDNEWSYMWIDTHS = FX_Alloc(FX_DWORD, SDNUMNEWSYMS); |
1900 FXSYS_memset(SDNEWSYMWIDTHS, 0, SDNUMNEWSYMS * sizeof(FX_DWORD)); | 1844 FXSYS_memset(SDNEWSYMWIDTHS, 0, SDNUMNEWSYMS * sizeof(FX_DWORD)); |
1901 } | 1845 } |
| 1846 nonstd::unique_ptr<CJBig2_SymbolDict> pDict(new CJBig2_SymbolDict()); |
| 1847 nonstd::unique_ptr<CJBig2_HuffmanTable> pTable; |
| 1848 |
1902 HCHEIGHT = 0; | 1849 HCHEIGHT = 0; |
1903 NSYMSDECODED = 0; | 1850 NSYMSDECODED = 0; |
1904 BS = NULL; | 1851 BS = nullptr; |
1905 while (NSYMSDECODED < SDNUMNEWSYMS) { | 1852 while (NSYMSDECODED < SDNUMNEWSYMS) { |
1906 if (pHuffmanDecoder->decodeAValue(SDHUFFDH, &HCDH) != 0) { | 1853 if (pHuffmanDecoder->decodeAValue(SDHUFFDH, &HCDH) != 0) { |
1907 goto failed; | 1854 goto failed; |
1908 } | 1855 } |
1909 HCHEIGHT = HCHEIGHT + HCDH; | 1856 HCHEIGHT = HCHEIGHT + HCDH; |
1910 if ((int)HCHEIGHT < 0 || (int)HCHEIGHT > JBIG2_MAX_IMAGE_SIZE) { | 1857 if ((int)HCHEIGHT < 0 || (int)HCHEIGHT > JBIG2_MAX_IMAGE_SIZE) { |
1911 goto failed; | 1858 goto failed; |
1912 } | 1859 } |
1913 SYMWIDTH = 0; | 1860 SYMWIDTH = 0; |
1914 TOTWIDTH = 0; | 1861 TOTWIDTH = 0; |
1915 HCFIRSTSYM = NSYMSDECODED; | 1862 HCFIRSTSYM = NSYMSDECODED; |
1916 for (;;) { | 1863 for (;;) { |
1917 nVal = pHuffmanDecoder->decodeAValue(SDHUFFDW, &DW); | 1864 nVal = pHuffmanDecoder->decodeAValue(SDHUFFDW, &DW); |
1918 if (nVal == JBIG2_OOB) { | 1865 if (nVal == JBIG2_OOB) { |
1919 break; | 1866 break; |
1920 } else if (nVal != 0) { | 1867 } else if (nVal != 0) { |
1921 goto failed; | 1868 goto failed; |
1922 } else { | 1869 } else { |
1923 if (NSYMSDECODED >= SDNUMNEWSYMS) { | 1870 if (NSYMSDECODED >= SDNUMNEWSYMS) { |
1924 goto failed; | 1871 goto failed; |
1925 } | 1872 } |
1926 SYMWIDTH = SYMWIDTH + DW; | 1873 SYMWIDTH = SYMWIDTH + DW; |
1927 if ((int)SYMWIDTH < 0 || (int)SYMWIDTH > JBIG2_MAX_IMAGE_SIZE) { | 1874 if ((int)SYMWIDTH < 0 || (int)SYMWIDTH > JBIG2_MAX_IMAGE_SIZE) { |
1928 goto failed; | 1875 goto failed; |
1929 } else if (HCHEIGHT == 0 || SYMWIDTH == 0) { | 1876 } else if (HCHEIGHT == 0 || SYMWIDTH == 0) { |
1930 TOTWIDTH = TOTWIDTH + SYMWIDTH; | 1877 TOTWIDTH = TOTWIDTH + SYMWIDTH; |
1931 SDNEWSYMS[NSYMSDECODED] = NULL; | 1878 SDNEWSYMS[NSYMSDECODED] = nullptr; |
1932 NSYMSDECODED = NSYMSDECODED + 1; | 1879 NSYMSDECODED = NSYMSDECODED + 1; |
1933 continue; | 1880 continue; |
1934 } | 1881 } |
1935 TOTWIDTH = TOTWIDTH + SYMWIDTH; | 1882 TOTWIDTH = TOTWIDTH + SYMWIDTH; |
1936 } | 1883 } |
1937 if (SDREFAGG == 1) { | 1884 if (SDREFAGG == 1) { |
1938 if (pHuffmanDecoder->decodeAValue(SDHUFFAGGINST, (int*)&REFAGGNINST) != | 1885 if (pHuffmanDecoder->decodeAValue(SDHUFFAGGINST, (int*)&REFAGGNINST) != |
1939 0) { | 1886 0) { |
1940 goto failed; | 1887 goto failed; |
1941 } | 1888 } |
1942 BS = NULL; | 1889 BS = nullptr; |
1943 if (REFAGGNINST > 1) { | 1890 if (REFAGGNINST > 1) { |
1944 CJBig2_TRDProc* pDecoder = new CJBig2_TRDProc(); | 1891 nonstd::unique_ptr<CJBig2_TRDProc> pDecoder(new CJBig2_TRDProc()); |
1945 pDecoder->SBHUFF = SDHUFF; | 1892 pDecoder->SBHUFF = SDHUFF; |
1946 pDecoder->SBREFINE = 1; | 1893 pDecoder->SBREFINE = 1; |
1947 pDecoder->SBW = SYMWIDTH; | 1894 pDecoder->SBW = SYMWIDTH; |
1948 pDecoder->SBH = HCHEIGHT; | 1895 pDecoder->SBH = HCHEIGHT; |
1949 pDecoder->SBNUMINSTANCES = REFAGGNINST; | 1896 pDecoder->SBNUMINSTANCES = REFAGGNINST; |
1950 pDecoder->SBSTRIPS = 1; | 1897 pDecoder->SBSTRIPS = 1; |
1951 pDecoder->SBNUMSYMS = SDNUMINSYMS + NSYMSDECODED; | 1898 pDecoder->SBNUMSYMS = SDNUMINSYMS + NSYMSDECODED; |
1952 SBNUMSYMS = pDecoder->SBNUMSYMS; | 1899 SBNUMSYMS = pDecoder->SBNUMSYMS; |
1953 SBSYMCODES = FX_Alloc(JBig2HuffmanCode, SBNUMSYMS); | 1900 SBSYMCODES = FX_Alloc(JBig2HuffmanCode, SBNUMSYMS); |
1954 nTmp = 1; | 1901 nTmp = 1; |
1955 while ((FX_DWORD)(1 << nTmp) < SBNUMSYMS) { | 1902 while ((FX_DWORD)(1 << nTmp) < SBNUMSYMS) { |
1956 nTmp++; | 1903 nTmp++; |
1957 } | 1904 } |
1958 for (I = 0; I < SBNUMSYMS; I++) { | 1905 for (I = 0; I < SBNUMSYMS; I++) { |
1959 SBSYMCODES[I].codelen = nTmp; | 1906 SBSYMCODES[I].codelen = nTmp; |
1960 SBSYMCODES[I].code = I; | 1907 SBSYMCODES[I].code = I; |
1961 } | 1908 } |
1962 pDecoder->SBSYMCODES = SBSYMCODES; | 1909 pDecoder->SBSYMCODES = SBSYMCODES; |
1963 SBSYMS = FX_Alloc(CJBig2_Image*, SBNUMSYMS); | 1910 SBSYMS = FX_Alloc(CJBig2_Image*, SBNUMSYMS); |
1964 JBIG2_memcpy(SBSYMS, SDINSYMS, SDNUMINSYMS * sizeof(CJBig2_Image*)); | 1911 JBIG2_memcpy(SBSYMS, SDINSYMS, SDNUMINSYMS * sizeof(CJBig2_Image*)); |
1965 JBIG2_memcpy(SBSYMS + SDNUMINSYMS, SDNEWSYMS, | 1912 JBIG2_memcpy(SBSYMS + SDNUMINSYMS, SDNEWSYMS, |
1966 NSYMSDECODED * sizeof(CJBig2_Image*)); | 1913 NSYMSDECODED * sizeof(CJBig2_Image*)); |
1967 pDecoder->SBSYMS = SBSYMS; | 1914 pDecoder->SBSYMS = SBSYMS; |
1968 pDecoder->SBDEFPIXEL = 0; | 1915 pDecoder->SBDEFPIXEL = 0; |
1969 pDecoder->SBCOMBOP = JBIG2_COMPOSE_OR; | 1916 pDecoder->SBCOMBOP = JBIG2_COMPOSE_OR; |
1970 pDecoder->TRANSPOSED = 0; | 1917 pDecoder->TRANSPOSED = 0; |
1971 pDecoder->REFCORNER = JBIG2_CORNER_TOPLEFT; | 1918 pDecoder->REFCORNER = JBIG2_CORNER_TOPLEFT; |
1972 pDecoder->SBDSOFFSET = 0; | 1919 pDecoder->SBDSOFFSET = 0; |
1973 SBHUFFFS = new CJBig2_HuffmanTable(HuffmanTable_B6, | 1920 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFFS( |
1974 FX_ArraySize(HuffmanTable_B6), | 1921 new CJBig2_HuffmanTable(HuffmanTable_B6, |
1975 HuffmanTable_HTOOB_B6); | 1922 FX_ArraySize(HuffmanTable_B6), |
1976 SBHUFFDS = new CJBig2_HuffmanTable(HuffmanTable_B8, | 1923 HuffmanTable_HTOOB_B6)); |
1977 FX_ArraySize(HuffmanTable_B8), | 1924 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFDS( |
1978 HuffmanTable_HTOOB_B8); | 1925 new CJBig2_HuffmanTable(HuffmanTable_B8, |
1979 SBHUFFDT = new CJBig2_HuffmanTable(HuffmanTable_B11, | 1926 FX_ArraySize(HuffmanTable_B8), |
1980 FX_ArraySize(HuffmanTable_B11), | 1927 HuffmanTable_HTOOB_B8)); |
1981 HuffmanTable_HTOOB_B11); | 1928 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFDT( |
1982 SBHUFFRDW = new CJBig2_HuffmanTable(HuffmanTable_B15, | 1929 new CJBig2_HuffmanTable(HuffmanTable_B11, |
1983 FX_ArraySize(HuffmanTable_B15), | 1930 FX_ArraySize(HuffmanTable_B11), |
1984 HuffmanTable_HTOOB_B15); | 1931 HuffmanTable_HTOOB_B11)); |
1985 SBHUFFRDH = new CJBig2_HuffmanTable(HuffmanTable_B15, | 1932 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFRDW( |
1986 FX_ArraySize(HuffmanTable_B15), | 1933 new CJBig2_HuffmanTable(HuffmanTable_B15, |
1987 HuffmanTable_HTOOB_B15); | 1934 FX_ArraySize(HuffmanTable_B15), |
1988 SBHUFFRDX = new CJBig2_HuffmanTable(HuffmanTable_B15, | 1935 HuffmanTable_HTOOB_B15)); |
1989 FX_ArraySize(HuffmanTable_B15), | 1936 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFRDH( |
1990 HuffmanTable_HTOOB_B15); | 1937 new CJBig2_HuffmanTable(HuffmanTable_B15, |
1991 SBHUFFRDY = new CJBig2_HuffmanTable(HuffmanTable_B15, | 1938 FX_ArraySize(HuffmanTable_B15), |
1992 FX_ArraySize(HuffmanTable_B15), | 1939 HuffmanTable_HTOOB_B15)); |
1993 HuffmanTable_HTOOB_B15); | 1940 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFRDX( |
1994 SBHUFFRSIZE = new CJBig2_HuffmanTable(HuffmanTable_B1, | 1941 new CJBig2_HuffmanTable(HuffmanTable_B15, |
1995 FX_ArraySize(HuffmanTable_B1), | 1942 FX_ArraySize(HuffmanTable_B15), |
1996 HuffmanTable_HTOOB_B1); | 1943 HuffmanTable_HTOOB_B15)); |
1997 pDecoder->SBHUFFFS = SBHUFFFS; | 1944 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFRDY( |
1998 pDecoder->SBHUFFDS = SBHUFFDS; | 1945 new CJBig2_HuffmanTable(HuffmanTable_B15, |
1999 pDecoder->SBHUFFDT = SBHUFFDT; | 1946 FX_ArraySize(HuffmanTable_B15), |
2000 pDecoder->SBHUFFRDW = SBHUFFRDW; | 1947 HuffmanTable_HTOOB_B15)); |
2001 pDecoder->SBHUFFRDH = SBHUFFRDH; | 1948 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFRSIZE( |
2002 pDecoder->SBHUFFRDX = SBHUFFRDX; | 1949 new CJBig2_HuffmanTable(HuffmanTable_B1, |
2003 pDecoder->SBHUFFRDY = SBHUFFRDY; | 1950 FX_ArraySize(HuffmanTable_B1), |
2004 pDecoder->SBHUFFRSIZE = SBHUFFRSIZE; | 1951 HuffmanTable_HTOOB_B1)); |
| 1952 pDecoder->SBHUFFFS = SBHUFFFS.get(); |
| 1953 pDecoder->SBHUFFDS = SBHUFFDS.get(); |
| 1954 pDecoder->SBHUFFDT = SBHUFFDT.get(); |
| 1955 pDecoder->SBHUFFRDW = SBHUFFRDW.get(); |
| 1956 pDecoder->SBHUFFRDH = SBHUFFRDH.get(); |
| 1957 pDecoder->SBHUFFRDX = SBHUFFRDX.get(); |
| 1958 pDecoder->SBHUFFRDY = SBHUFFRDY.get(); |
| 1959 pDecoder->SBHUFFRSIZE = SBHUFFRSIZE.get(); |
2005 pDecoder->SBRTEMPLATE = SDRTEMPLATE; | 1960 pDecoder->SBRTEMPLATE = SDRTEMPLATE; |
2006 pDecoder->SBRAT[0] = SDRAT[0]; | 1961 pDecoder->SBRAT[0] = SDRAT[0]; |
2007 pDecoder->SBRAT[1] = SDRAT[1]; | 1962 pDecoder->SBRAT[1] = SDRAT[1]; |
2008 pDecoder->SBRAT[2] = SDRAT[2]; | 1963 pDecoder->SBRAT[2] = SDRAT[2]; |
2009 pDecoder->SBRAT[3] = SDRAT[3]; | 1964 pDecoder->SBRAT[3] = SDRAT[3]; |
2010 BS = pDecoder->decode_Huffman(pStream, grContext); | 1965 BS = pDecoder->decode_Huffman(pStream, grContext); |
2011 if (BS == NULL) { | 1966 if (!BS) { |
2012 FX_Free(SBSYMCODES); | 1967 FX_Free(SBSYMCODES); |
2013 FX_Free(SBSYMS); | 1968 FX_Free(SBSYMS); |
2014 delete SBHUFFFS; | |
2015 delete SBHUFFDS; | |
2016 delete SBHUFFDT; | |
2017 delete SBHUFFRDW; | |
2018 delete SBHUFFRDH; | |
2019 delete SBHUFFRDX; | |
2020 delete SBHUFFRDY; | |
2021 delete SBHUFFRSIZE; | |
2022 delete pDecoder; | |
2023 goto failed; | 1969 goto failed; |
2024 } | 1970 } |
2025 FX_Free(SBSYMCODES); | 1971 FX_Free(SBSYMCODES); |
2026 FX_Free(SBSYMS); | 1972 FX_Free(SBSYMS); |
2027 delete SBHUFFFS; | |
2028 delete SBHUFFDS; | |
2029 delete SBHUFFDT; | |
2030 delete SBHUFFRDW; | |
2031 delete SBHUFFRDH; | |
2032 delete SBHUFFRDX; | |
2033 delete SBHUFFRDY; | |
2034 delete SBHUFFRSIZE; | |
2035 delete pDecoder; | |
2036 } else if (REFAGGNINST == 1) { | 1973 } else if (REFAGGNINST == 1) { |
2037 SBNUMSYMS = SDNUMINSYMS + SDNUMNEWSYMS; | 1974 SBNUMSYMS = SDNUMINSYMS + SDNUMNEWSYMS; |
2038 nTmp = 1; | 1975 nTmp = 1; |
2039 while ((FX_DWORD)(1 << nTmp) < SBNUMSYMS) { | 1976 while ((FX_DWORD)(1 << nTmp) < SBNUMSYMS) { |
2040 nTmp++; | 1977 nTmp++; |
2041 } | 1978 } |
2042 SBSYMCODELEN = (uint8_t)nTmp; | 1979 SBSYMCODELEN = (uint8_t)nTmp; |
2043 SBSYMCODES = FX_Alloc(JBig2HuffmanCode, SBNUMSYMS); | 1980 SBSYMCODES = FX_Alloc(JBig2HuffmanCode, SBNUMSYMS); |
2044 for (I = 0; I < SBNUMSYMS; I++) { | 1981 for (I = 0; I < SBNUMSYMS; I++) { |
2045 SBSYMCODES[I].codelen = SBSYMCODELEN; | 1982 SBSYMCODES[I].codelen = SBSYMCODELEN; |
(...skipping 11 matching lines...) Expand all Loading... |
2057 if ((nVal == SBSYMCODES[IDI].code) && | 1994 if ((nVal == SBSYMCODES[IDI].code) && |
2058 (nBits == SBSYMCODES[IDI].codelen)) { | 1995 (nBits == SBSYMCODES[IDI].codelen)) { |
2059 break; | 1996 break; |
2060 } | 1997 } |
2061 } | 1998 } |
2062 if (IDI < SBNUMSYMS) { | 1999 if (IDI < SBNUMSYMS) { |
2063 break; | 2000 break; |
2064 } | 2001 } |
2065 } | 2002 } |
2066 FX_Free(SBSYMCODES); | 2003 FX_Free(SBSYMCODES); |
2067 SBHUFFRDX = new CJBig2_HuffmanTable(HuffmanTable_B15, | 2004 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFRDX( |
2068 FX_ArraySize(HuffmanTable_B15), | 2005 new CJBig2_HuffmanTable(HuffmanTable_B15, |
2069 HuffmanTable_HTOOB_B15); | 2006 FX_ArraySize(HuffmanTable_B15), |
2070 SBHUFFRSIZE = new CJBig2_HuffmanTable(HuffmanTable_B1, | 2007 HuffmanTable_HTOOB_B15)); |
2071 FX_ArraySize(HuffmanTable_B1), | 2008 nonstd::unique_ptr<CJBig2_HuffmanTable> SBHUFFRSIZE( |
2072 HuffmanTable_HTOOB_B1); | 2009 new CJBig2_HuffmanTable(HuffmanTable_B1, |
2073 if ((pHuffmanDecoder->decodeAValue(SBHUFFRDX, &RDXI) != 0) || | 2010 FX_ArraySize(HuffmanTable_B1), |
2074 (pHuffmanDecoder->decodeAValue(SBHUFFRDX, &RDYI) != 0) || | 2011 HuffmanTable_HTOOB_B1)); |
2075 (pHuffmanDecoder->decodeAValue(SBHUFFRSIZE, &nVal) != 0)) { | 2012 if ((pHuffmanDecoder->decodeAValue(SBHUFFRDX.get(), &RDXI) != 0) || |
2076 delete SBHUFFRDX; | 2013 (pHuffmanDecoder->decodeAValue(SBHUFFRDX.get(), &RDYI) != 0) || |
2077 delete SBHUFFRSIZE; | 2014 (pHuffmanDecoder->decodeAValue(SBHUFFRSIZE.get(), &nVal) != 0)) { |
2078 goto failed; | 2015 goto failed; |
2079 } | 2016 } |
2080 delete SBHUFFRDX; | |
2081 delete SBHUFFRSIZE; | |
2082 pStream->alignByte(); | 2017 pStream->alignByte(); |
2083 nTmp = pStream->getOffset(); | 2018 nTmp = pStream->getOffset(); |
2084 SBSYMS = FX_Alloc(CJBig2_Image*, SBNUMSYMS); | 2019 SBSYMS = FX_Alloc(CJBig2_Image*, SBNUMSYMS); |
2085 JBIG2_memcpy(SBSYMS, SDINSYMS, SDNUMINSYMS * sizeof(CJBig2_Image*)); | 2020 JBIG2_memcpy(SBSYMS, SDINSYMS, SDNUMINSYMS * sizeof(CJBig2_Image*)); |
2086 JBIG2_memcpy(SBSYMS + SDNUMINSYMS, SDNEWSYMS, | 2021 JBIG2_memcpy(SBSYMS + SDNUMINSYMS, SDNEWSYMS, |
2087 NSYMSDECODED * sizeof(CJBig2_Image*)); | 2022 NSYMSDECODED * sizeof(CJBig2_Image*)); |
2088 pGRRD = new CJBig2_GRRDProc(); | 2023 nonstd::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc()); |
2089 pGRRD->GRW = SYMWIDTH; | 2024 pGRRD->GRW = SYMWIDTH; |
2090 pGRRD->GRH = HCHEIGHT; | 2025 pGRRD->GRH = HCHEIGHT; |
2091 pGRRD->GRTEMPLATE = SDRTEMPLATE; | 2026 pGRRD->GRTEMPLATE = SDRTEMPLATE; |
2092 pGRRD->GRREFERENCE = SBSYMS[IDI]; | 2027 pGRRD->GRREFERENCE = SBSYMS[IDI]; |
2093 pGRRD->GRREFERENCEDX = RDXI; | 2028 pGRRD->GRREFERENCEDX = RDXI; |
2094 pGRRD->GRREFERENCEDY = RDYI; | 2029 pGRRD->GRREFERENCEDY = RDYI; |
2095 pGRRD->TPGRON = 0; | 2030 pGRRD->TPGRON = 0; |
2096 pGRRD->GRAT[0] = SDRAT[0]; | 2031 pGRRD->GRAT[0] = SDRAT[0]; |
2097 pGRRD->GRAT[1] = SDRAT[1]; | 2032 pGRRD->GRAT[1] = SDRAT[1]; |
2098 pGRRD->GRAT[2] = SDRAT[2]; | 2033 pGRRD->GRAT[2] = SDRAT[2]; |
2099 pGRRD->GRAT[3] = SDRAT[3]; | 2034 pGRRD->GRAT[3] = SDRAT[3]; |
2100 pArithDecoder = new CJBig2_ArithDecoder(pStream); | 2035 nonstd::unique_ptr<CJBig2_ArithDecoder> pArithDecoder( |
2101 BS = pGRRD->decode(pArithDecoder, grContext); | 2036 new CJBig2_ArithDecoder(pStream)); |
2102 if (BS == NULL) { | 2037 BS = pGRRD->decode(pArithDecoder.get(), grContext); |
| 2038 if (!BS) { |
2103 FX_Free(SBSYMS); | 2039 FX_Free(SBSYMS); |
2104 delete pGRRD; | |
2105 delete pArithDecoder; | |
2106 goto failed; | 2040 goto failed; |
2107 } | 2041 } |
2108 pStream->alignByte(); | 2042 pStream->alignByte(); |
2109 pStream->offset(2); | 2043 pStream->offset(2); |
2110 if ((FX_DWORD)nVal != (pStream->getOffset() - nTmp)) { | 2044 if ((FX_DWORD)nVal != (pStream->getOffset() - nTmp)) { |
2111 delete BS; | 2045 delete BS; |
2112 FX_Free(SBSYMS); | 2046 FX_Free(SBSYMS); |
2113 delete pGRRD; | |
2114 delete pArithDecoder; | |
2115 goto failed; | 2047 goto failed; |
2116 } | 2048 } |
2117 FX_Free(SBSYMS); | 2049 FX_Free(SBSYMS); |
2118 delete pGRRD; | |
2119 delete pArithDecoder; | |
2120 } | 2050 } |
2121 SDNEWSYMS[NSYMSDECODED] = BS; | 2051 SDNEWSYMS[NSYMSDECODED] = BS; |
2122 } | 2052 } |
2123 if (SDREFAGG == 0) { | 2053 if (SDREFAGG == 0) { |
2124 SDNEWSYMWIDTHS[NSYMSDECODED] = SYMWIDTH; | 2054 SDNEWSYMWIDTHS[NSYMSDECODED] = SYMWIDTH; |
2125 } | 2055 } |
2126 NSYMSDECODED = NSYMSDECODED + 1; | 2056 NSYMSDECODED = NSYMSDECODED + 1; |
2127 } | 2057 } |
2128 if (SDREFAGG == 0) { | 2058 if (SDREFAGG == 0) { |
2129 if (pHuffmanDecoder->decodeAValue(SDHUFFBMSIZE, (int32_t*)&BMSIZE) != 0) { | 2059 if (pHuffmanDecoder->decodeAValue(SDHUFFBMSIZE, (int32_t*)&BMSIZE) != 0) { |
2130 goto failed; | 2060 goto failed; |
2131 } | 2061 } |
2132 pStream->alignByte(); | 2062 pStream->alignByte(); |
2133 if (BMSIZE == 0) { | 2063 if (BMSIZE == 0) { |
2134 stride = (TOTWIDTH + 7) >> 3; | 2064 stride = (TOTWIDTH + 7) >> 3; |
2135 if (pStream->getByteLeft() >= stride * HCHEIGHT) { | 2065 if (pStream->getByteLeft() >= stride * HCHEIGHT) { |
2136 BHC = new CJBig2_Image(TOTWIDTH, HCHEIGHT); | 2066 BHC = new CJBig2_Image(TOTWIDTH, HCHEIGHT); |
2137 for (I = 0; I < HCHEIGHT; I++) { | 2067 for (I = 0; I < HCHEIGHT; I++) { |
2138 JBIG2_memcpy(BHC->m_pData + I * BHC->m_nStride, | 2068 JBIG2_memcpy(BHC->m_pData + I * BHC->m_nStride, |
2139 pStream->getPointer(), stride); | 2069 pStream->getPointer(), stride); |
2140 pStream->offset(stride); | 2070 pStream->offset(stride); |
2141 } | 2071 } |
2142 } else { | 2072 } else { |
2143 goto failed; | 2073 goto failed; |
2144 } | 2074 } |
2145 } else { | 2075 } else { |
2146 pGRD = new CJBig2_GRDProc(); | 2076 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); |
2147 pGRD->MMR = 1; | 2077 pGRD->MMR = 1; |
2148 pGRD->GBW = TOTWIDTH; | 2078 pGRD->GBW = TOTWIDTH; |
2149 pGRD->GBH = HCHEIGHT; | 2079 pGRD->GBH = HCHEIGHT; |
2150 FXCODEC_STATUS status = pGRD->Start_decode_MMR(&BHC, pStream); | 2080 FXCODEC_STATUS status = pGRD->Start_decode_MMR(&BHC, pStream); |
2151 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 2081 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
2152 pGRD->Continue_decode(pPause); | 2082 pGRD->Continue_decode(pPause); |
2153 } | 2083 } |
2154 delete pGRD; | |
2155 pStream->alignByte(); | 2084 pStream->alignByte(); |
2156 } | 2085 } |
2157 nTmp = 0; | 2086 nTmp = 0; |
2158 if (!BHC) { | 2087 if (!BHC) { |
2159 continue; | 2088 continue; |
2160 } | 2089 } |
2161 for (I = HCFIRSTSYM; I < NSYMSDECODED; I++) { | 2090 for (I = HCFIRSTSYM; I < NSYMSDECODED; I++) { |
2162 SDNEWSYMS[I] = BHC->subImage(nTmp, 0, SDNEWSYMWIDTHS[I], HCHEIGHT); | 2091 SDNEWSYMS[I] = BHC->subImage(nTmp, 0, SDNEWSYMWIDTHS[I], HCHEIGHT); |
2163 nTmp += SDNEWSYMWIDTHS[I]; | 2092 nTmp += SDNEWSYMWIDTHS[I]; |
2164 } | 2093 } |
2165 delete BHC; | 2094 delete BHC; |
2166 BHC = NULL; | 2095 BHC = nullptr; |
2167 } | 2096 } |
2168 } | 2097 } |
2169 EXINDEX = 0; | 2098 EXINDEX = 0; |
2170 CUREXFLAG = 0; | 2099 CUREXFLAG = 0; |
2171 pTable = new CJBig2_HuffmanTable( | 2100 pTable.reset(new CJBig2_HuffmanTable( |
2172 HuffmanTable_B1, FX_ArraySize(HuffmanTable_B1), HuffmanTable_HTOOB_B1); | 2101 HuffmanTable_B1, FX_ArraySize(HuffmanTable_B1), HuffmanTable_HTOOB_B1)); |
2173 EXFLAGS = FX_Alloc(FX_BOOL, SDNUMINSYMS + SDNUMNEWSYMS); | 2102 EXFLAGS = FX_Alloc(FX_BOOL, SDNUMINSYMS + SDNUMNEWSYMS); |
2174 while (EXINDEX < SDNUMINSYMS + SDNUMNEWSYMS) { | 2103 while (EXINDEX < SDNUMINSYMS + SDNUMNEWSYMS) { |
2175 if (pHuffmanDecoder->decodeAValue(pTable, (int*)&EXRUNLENGTH) != 0) { | 2104 if (pHuffmanDecoder->decodeAValue(pTable.get(), (int*)&EXRUNLENGTH) != 0) { |
2176 delete pTable; | |
2177 FX_Free(EXFLAGS); | 2105 FX_Free(EXFLAGS); |
2178 goto failed; | 2106 goto failed; |
2179 } | 2107 } |
2180 if (EXINDEX + EXRUNLENGTH > SDNUMINSYMS + SDNUMNEWSYMS) { | 2108 if (EXINDEX + EXRUNLENGTH > SDNUMINSYMS + SDNUMNEWSYMS) { |
2181 delete pTable; | |
2182 FX_Free(EXFLAGS); | 2109 FX_Free(EXFLAGS); |
2183 goto failed; | 2110 goto failed; |
2184 } | 2111 } |
2185 if (EXRUNLENGTH != 0) { | 2112 if (EXRUNLENGTH != 0) { |
2186 for (I = EXINDEX; I < EXINDEX + EXRUNLENGTH; I++) { | 2113 for (I = EXINDEX; I < EXINDEX + EXRUNLENGTH; I++) { |
2187 EXFLAGS[I] = CUREXFLAG; | 2114 EXFLAGS[I] = CUREXFLAG; |
2188 } | 2115 } |
2189 } | 2116 } |
2190 EXINDEX = EXINDEX + EXRUNLENGTH; | 2117 EXINDEX = EXINDEX + EXRUNLENGTH; |
2191 CUREXFLAG = !CUREXFLAG; | 2118 CUREXFLAG = !CUREXFLAG; |
2192 } | 2119 } |
2193 delete pTable; | |
2194 pDict = new CJBig2_SymbolDict(); | |
2195 pDict->SDNUMEXSYMS = SDNUMEXSYMS; | 2120 pDict->SDNUMEXSYMS = SDNUMEXSYMS; |
2196 pDict->SDEXSYMS = FX_Alloc(CJBig2_Image*, SDNUMEXSYMS); | 2121 pDict->SDEXSYMS = FX_Alloc(CJBig2_Image*, SDNUMEXSYMS); |
2197 I = J = 0; | 2122 I = J = 0; |
2198 for (I = 0; I < SDNUMINSYMS + SDNUMNEWSYMS; I++) { | 2123 for (I = 0; I < SDNUMINSYMS + SDNUMNEWSYMS; I++) { |
2199 if (EXFLAGS[I] && J < SDNUMEXSYMS) { | 2124 if (EXFLAGS[I] && J < SDNUMEXSYMS) { |
2200 if (I < SDNUMINSYMS) { | 2125 if (I < SDNUMINSYMS) { |
2201 pDict->SDEXSYMS[J] = new CJBig2_Image(*SDINSYMS[I]); | 2126 pDict->SDEXSYMS[J] = new CJBig2_Image(*SDINSYMS[I]); |
2202 } else { | 2127 } else { |
2203 pDict->SDEXSYMS[J] = SDNEWSYMS[I - SDNUMINSYMS]; | 2128 pDict->SDEXSYMS[J] = SDNEWSYMS[I - SDNUMINSYMS]; |
2204 } | 2129 } |
2205 J = J + 1; | 2130 J = J + 1; |
2206 } else if (!EXFLAGS[I] && I >= SDNUMINSYMS) { | 2131 } else if (!EXFLAGS[I] && I >= SDNUMINSYMS) { |
2207 delete SDNEWSYMS[I - SDNUMINSYMS]; | 2132 delete SDNEWSYMS[I - SDNUMINSYMS]; |
2208 } | 2133 } |
2209 } | 2134 } |
2210 if (J < SDNUMEXSYMS) { | 2135 if (J < SDNUMEXSYMS) { |
2211 pDict->SDNUMEXSYMS = J; | 2136 pDict->SDNUMEXSYMS = J; |
2212 } | 2137 } |
2213 FX_Free(EXFLAGS); | 2138 FX_Free(EXFLAGS); |
2214 FX_Free(SDNEWSYMS); | 2139 FX_Free(SDNEWSYMS); |
2215 if (SDREFAGG == 0) { | 2140 if (SDREFAGG == 0) { |
2216 FX_Free(SDNEWSYMWIDTHS); | 2141 FX_Free(SDNEWSYMWIDTHS); |
2217 } | 2142 } |
2218 delete pHuffmanDecoder; | 2143 return pDict.release(); |
2219 return pDict; | |
2220 failed: | 2144 failed: |
2221 for (I = 0; I < NSYMSDECODED; I++) { | 2145 for (I = 0; I < NSYMSDECODED; I++) { |
2222 delete SDNEWSYMS[I]; | 2146 delete SDNEWSYMS[I]; |
2223 } | 2147 } |
2224 FX_Free(SDNEWSYMS); | 2148 FX_Free(SDNEWSYMS); |
2225 if (SDREFAGG == 0) { | 2149 if (SDREFAGG == 0) { |
2226 FX_Free(SDNEWSYMWIDTHS); | 2150 FX_Free(SDNEWSYMWIDTHS); |
2227 } | 2151 } |
2228 delete pHuffmanDecoder; | 2152 return nullptr; |
2229 return NULL; | |
2230 } | 2153 } |
| 2154 |
2231 CJBig2_Image* CJBig2_HTRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, | 2155 CJBig2_Image* CJBig2_HTRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, |
2232 JBig2ArithCtx* gbContext, | 2156 JBig2ArithCtx* gbContext, |
2233 IFX_Pause* pPause) { | 2157 IFX_Pause* pPause) { |
2234 FX_DWORD ng, mg; | 2158 FX_DWORD ng, mg; |
2235 int32_t x, y; | 2159 int32_t x, y; |
2236 FX_DWORD HBPP; | 2160 FX_DWORD HBPP; |
2237 FX_DWORD* GI; | 2161 FX_DWORD* GI; |
2238 CJBig2_Image* HSKIP = nullptr; | 2162 nonstd::unique_ptr<CJBig2_Image> HSKIP; |
2239 CJBig2_Image* HTREG = new CJBig2_Image(HBW, HBH); | 2163 nonstd::unique_ptr<CJBig2_Image> HTREG(new CJBig2_Image(HBW, HBH)); |
2240 HTREG->fill(HDEFPIXEL); | 2164 HTREG->fill(HDEFPIXEL); |
2241 if (HENABLESKIP == 1) { | 2165 if (HENABLESKIP == 1) { |
2242 HSKIP = new CJBig2_Image(HGW, HGH); | 2166 HSKIP.reset(new CJBig2_Image(HGW, HGH)); |
2243 for (mg = 0; mg < HGH; mg++) { | 2167 for (mg = 0; mg < HGH; mg++) { |
2244 for (ng = 0; ng < HGW; ng++) { | 2168 for (ng = 0; ng < HGW; ng++) { |
2245 x = (HGX + mg * HRY + ng * HRX) >> 8; | 2169 x = (HGX + mg * HRY + ng * HRX) >> 8; |
2246 y = (HGY + mg * HRX - ng * HRY) >> 8; | 2170 y = (HGY + mg * HRX - ng * HRY) >> 8; |
2247 if ((x + HPW <= 0) | (x >= (int32_t)HBW) | (y + HPH <= 0) | | 2171 if ((x + HPW <= 0) | (x >= (int32_t)HBW) | (y + HPH <= 0) | |
2248 (y >= (int32_t)HPH)) { | 2172 (y >= (int32_t)HPH)) { |
2249 HSKIP->setPixel(ng, mg, 1); | 2173 HSKIP->setPixel(ng, mg, 1); |
2250 } else { | 2174 } else { |
2251 HSKIP->setPixel(ng, mg, 0); | 2175 HSKIP->setPixel(ng, mg, 0); |
2252 } | 2176 } |
2253 } | 2177 } |
2254 } | 2178 } |
2255 } | 2179 } |
2256 HBPP = 1; | 2180 HBPP = 1; |
2257 while ((FX_DWORD)(1 << HBPP) < HNUMPATS) { | 2181 while ((FX_DWORD)(1 << HBPP) < HNUMPATS) { |
2258 HBPP++; | 2182 HBPP++; |
2259 } | 2183 } |
2260 CJBig2_GSIDProc* pGID = new CJBig2_GSIDProc(); | 2184 nonstd::unique_ptr<CJBig2_GSIDProc> pGID(new CJBig2_GSIDProc()); |
2261 pGID->GSMMR = HMMR; | 2185 pGID->GSMMR = HMMR; |
2262 pGID->GSW = HGW; | 2186 pGID->GSW = HGW; |
2263 pGID->GSH = HGH; | 2187 pGID->GSH = HGH; |
2264 pGID->GSBPP = (uint8_t)HBPP; | 2188 pGID->GSBPP = (uint8_t)HBPP; |
2265 pGID->GSUSESKIP = HENABLESKIP; | 2189 pGID->GSUSESKIP = HENABLESKIP; |
2266 pGID->GSKIP = HSKIP; | 2190 pGID->GSKIP = HSKIP.get(); |
2267 pGID->GSTEMPLATE = HTEMPLATE; | 2191 pGID->GSTEMPLATE = HTEMPLATE; |
2268 GI = pGID->decode_Arith(pArithDecoder, gbContext, pPause); | 2192 GI = pGID->decode_Arith(pArithDecoder, gbContext, pPause); |
2269 if (GI == NULL) { | 2193 if (!GI) |
2270 goto failed; | 2194 return nullptr; |
2271 } | 2195 |
2272 for (mg = 0; mg < HGH; mg++) { | 2196 for (mg = 0; mg < HGH; mg++) { |
2273 for (ng = 0; ng < HGW; ng++) { | 2197 for (ng = 0; ng < HGW; ng++) { |
2274 x = (HGX + mg * HRY + ng * HRX) >> 8; | 2198 x = (HGX + mg * HRY + ng * HRX) >> 8; |
2275 y = (HGY + mg * HRX - ng * HRY) >> 8; | 2199 y = (HGY + mg * HRX - ng * HRY) >> 8; |
2276 FX_DWORD pat_index = GI[mg * HGW + ng]; | 2200 FX_DWORD pat_index = GI[mg * HGW + ng]; |
2277 if (pat_index >= HNUMPATS) { | 2201 if (pat_index >= HNUMPATS) { |
2278 pat_index = HNUMPATS - 1; | 2202 pat_index = HNUMPATS - 1; |
2279 } | 2203 } |
2280 HTREG->composeFrom(x, y, HPATS[pat_index], HCOMBOP); | 2204 HTREG->composeFrom(x, y, HPATS[pat_index], HCOMBOP); |
2281 } | 2205 } |
2282 } | 2206 } |
2283 FX_Free(GI); | 2207 FX_Free(GI); |
2284 delete HSKIP; | 2208 return HTREG.release(); |
2285 delete pGID; | |
2286 return HTREG; | |
2287 failed: | |
2288 delete HSKIP; | |
2289 delete pGID; | |
2290 delete HTREG; | |
2291 return NULL; | |
2292 } | 2209 } |
| 2210 |
2293 CJBig2_Image* CJBig2_HTRDProc::decode_MMR(CJBig2_BitStream* pStream, | 2211 CJBig2_Image* CJBig2_HTRDProc::decode_MMR(CJBig2_BitStream* pStream, |
2294 IFX_Pause* pPause) { | 2212 IFX_Pause* pPause) { |
2295 FX_DWORD ng, mg; | 2213 FX_DWORD ng, mg; |
2296 int32_t x, y; | 2214 int32_t x, y; |
2297 FX_DWORD* GI; | 2215 FX_DWORD* GI; |
2298 CJBig2_Image* HTREG = new CJBig2_Image(HBW, HBH); | 2216 nonstd::unique_ptr<CJBig2_Image> HTREG(new CJBig2_Image(HBW, HBH)); |
2299 HTREG->fill(HDEFPIXEL); | 2217 HTREG->fill(HDEFPIXEL); |
2300 FX_DWORD HBPP = 1; | 2218 FX_DWORD HBPP = 1; |
2301 while ((FX_DWORD)(1 << HBPP) < HNUMPATS) { | 2219 while ((FX_DWORD)(1 << HBPP) < HNUMPATS) { |
2302 HBPP++; | 2220 HBPP++; |
2303 } | 2221 } |
2304 CJBig2_GSIDProc* pGID = new CJBig2_GSIDProc(); | 2222 nonstd::unique_ptr<CJBig2_GSIDProc> pGID(new CJBig2_GSIDProc()); |
2305 pGID->GSMMR = HMMR; | 2223 pGID->GSMMR = HMMR; |
2306 pGID->GSW = HGW; | 2224 pGID->GSW = HGW; |
2307 pGID->GSH = HGH; | 2225 pGID->GSH = HGH; |
2308 pGID->GSBPP = (uint8_t)HBPP; | 2226 pGID->GSBPP = (uint8_t)HBPP; |
2309 pGID->GSUSESKIP = 0; | 2227 pGID->GSUSESKIP = 0; |
2310 GI = pGID->decode_MMR(pStream, pPause); | 2228 GI = pGID->decode_MMR(pStream, pPause); |
2311 if (GI == NULL) { | 2229 if (!GI) |
2312 goto failed; | 2230 return nullptr; |
2313 } | 2231 |
2314 for (mg = 0; mg < HGH; mg++) { | 2232 for (mg = 0; mg < HGH; mg++) { |
2315 for (ng = 0; ng < HGW; ng++) { | 2233 for (ng = 0; ng < HGW; ng++) { |
2316 x = (HGX + mg * HRY + ng * HRX) >> 8; | 2234 x = (HGX + mg * HRY + ng * HRX) >> 8; |
2317 y = (HGY + mg * HRX - ng * HRY) >> 8; | 2235 y = (HGY + mg * HRX - ng * HRY) >> 8; |
2318 FX_DWORD pat_index = GI[mg * HGW + ng]; | 2236 FX_DWORD pat_index = GI[mg * HGW + ng]; |
2319 if (pat_index >= HNUMPATS) { | 2237 if (pat_index >= HNUMPATS) { |
2320 pat_index = HNUMPATS - 1; | 2238 pat_index = HNUMPATS - 1; |
2321 } | 2239 } |
2322 HTREG->composeFrom(x, y, HPATS[pat_index], HCOMBOP); | 2240 HTREG->composeFrom(x, y, HPATS[pat_index], HCOMBOP); |
2323 } | 2241 } |
2324 } | 2242 } |
2325 FX_Free(GI); | 2243 FX_Free(GI); |
2326 delete pGID; | 2244 return HTREG.release(); |
2327 return HTREG; | |
2328 failed: | |
2329 delete pGID; | |
2330 delete HTREG; | |
2331 return NULL; | |
2332 } | 2245 } |
| 2246 |
2333 CJBig2_PatternDict* CJBig2_PDDProc::decode_Arith( | 2247 CJBig2_PatternDict* CJBig2_PDDProc::decode_Arith( |
2334 CJBig2_ArithDecoder* pArithDecoder, | 2248 CJBig2_ArithDecoder* pArithDecoder, |
2335 JBig2ArithCtx* gbContext, | 2249 JBig2ArithCtx* gbContext, |
2336 IFX_Pause* pPause) { | 2250 IFX_Pause* pPause) { |
2337 FX_DWORD GRAY; | 2251 FX_DWORD GRAY; |
2338 CJBig2_Image* BHDC = NULL; | 2252 CJBig2_Image* BHDC = nullptr; |
2339 CJBig2_PatternDict* pDict = new CJBig2_PatternDict(); | 2253 nonstd::unique_ptr<CJBig2_PatternDict> pDict(new CJBig2_PatternDict()); |
2340 pDict->NUMPATS = GRAYMAX + 1; | 2254 pDict->NUMPATS = GRAYMAX + 1; |
2341 pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS); | 2255 pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS); |
2342 JBIG2_memset(pDict->HDPATS, 0, sizeof(CJBig2_Image*) * pDict->NUMPATS); | 2256 JBIG2_memset(pDict->HDPATS, 0, sizeof(CJBig2_Image*) * pDict->NUMPATS); |
2343 CJBig2_GRDProc* pGRD = new CJBig2_GRDProc(); | 2257 |
| 2258 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); |
2344 pGRD->MMR = HDMMR; | 2259 pGRD->MMR = HDMMR; |
2345 pGRD->GBW = (GRAYMAX + 1) * HDPW; | 2260 pGRD->GBW = (GRAYMAX + 1) * HDPW; |
2346 pGRD->GBH = HDPH; | 2261 pGRD->GBH = HDPH; |
2347 pGRD->GBTEMPLATE = HDTEMPLATE; | 2262 pGRD->GBTEMPLATE = HDTEMPLATE; |
2348 pGRD->TPGDON = 0; | 2263 pGRD->TPGDON = 0; |
2349 pGRD->USESKIP = 0; | 2264 pGRD->USESKIP = 0; |
2350 pGRD->GBAT[0] = -(int32_t)HDPW; | 2265 pGRD->GBAT[0] = -(int32_t)HDPW; |
2351 pGRD->GBAT[1] = 0; | 2266 pGRD->GBAT[1] = 0; |
2352 if (pGRD->GBTEMPLATE == 0) { | 2267 if (pGRD->GBTEMPLATE == 0) { |
2353 pGRD->GBAT[2] = -3; | 2268 pGRD->GBAT[2] = -3; |
2354 pGRD->GBAT[3] = -1; | 2269 pGRD->GBAT[3] = -1; |
2355 pGRD->GBAT[4] = 2; | 2270 pGRD->GBAT[4] = 2; |
2356 pGRD->GBAT[5] = -2; | 2271 pGRD->GBAT[5] = -2; |
2357 pGRD->GBAT[6] = -2; | 2272 pGRD->GBAT[6] = -2; |
2358 pGRD->GBAT[7] = -2; | 2273 pGRD->GBAT[7] = -2; |
2359 } | 2274 } |
2360 FXCODEC_STATUS status = | 2275 FXCODEC_STATUS status = |
2361 pGRD->Start_decode_Arith(&BHDC, pArithDecoder, gbContext); | 2276 pGRD->Start_decode_Arith(&BHDC, pArithDecoder, gbContext); |
2362 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 2277 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
2363 pGRD->Continue_decode(pPause); | 2278 pGRD->Continue_decode(pPause); |
2364 } | 2279 } |
2365 if (BHDC == NULL) { | 2280 if (!BHDC) |
2366 delete pGRD; | 2281 return nullptr; |
2367 goto failed; | 2282 |
2368 } | |
2369 delete pGRD; | |
2370 GRAY = 0; | 2283 GRAY = 0; |
2371 while (GRAY <= GRAYMAX) { | 2284 while (GRAY <= GRAYMAX) { |
2372 pDict->HDPATS[GRAY] = BHDC->subImage(HDPW * GRAY, 0, HDPW, HDPH); | 2285 pDict->HDPATS[GRAY] = BHDC->subImage(HDPW * GRAY, 0, HDPW, HDPH); |
2373 GRAY = GRAY + 1; | 2286 GRAY = GRAY + 1; |
2374 } | 2287 } |
2375 delete BHDC; | 2288 delete BHDC; |
2376 return pDict; | 2289 return pDict.release(); |
2377 failed: | |
2378 delete pDict; | |
2379 return NULL; | |
2380 } | 2290 } |
2381 | 2291 |
2382 CJBig2_PatternDict* CJBig2_PDDProc::decode_MMR(CJBig2_BitStream* pStream, | 2292 CJBig2_PatternDict* CJBig2_PDDProc::decode_MMR(CJBig2_BitStream* pStream, |
2383 IFX_Pause* pPause) { | 2293 IFX_Pause* pPause) { |
2384 FX_DWORD GRAY; | 2294 FX_DWORD GRAY; |
2385 CJBig2_Image* BHDC = NULL; | 2295 CJBig2_Image* BHDC = nullptr; |
2386 CJBig2_PatternDict* pDict = new CJBig2_PatternDict(); | 2296 nonstd::unique_ptr<CJBig2_PatternDict> pDict(new CJBig2_PatternDict()); |
2387 pDict->NUMPATS = GRAYMAX + 1; | 2297 pDict->NUMPATS = GRAYMAX + 1; |
2388 pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS); | 2298 pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS); |
2389 JBIG2_memset(pDict->HDPATS, 0, sizeof(CJBig2_Image*) * pDict->NUMPATS); | 2299 JBIG2_memset(pDict->HDPATS, 0, sizeof(CJBig2_Image*) * pDict->NUMPATS); |
2390 CJBig2_GRDProc* pGRD = new CJBig2_GRDProc(); | 2300 |
| 2301 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); |
2391 pGRD->MMR = HDMMR; | 2302 pGRD->MMR = HDMMR; |
2392 pGRD->GBW = (GRAYMAX + 1) * HDPW; | 2303 pGRD->GBW = (GRAYMAX + 1) * HDPW; |
2393 pGRD->GBH = HDPH; | 2304 pGRD->GBH = HDPH; |
2394 FXCODEC_STATUS status = pGRD->Start_decode_MMR(&BHDC, pStream); | 2305 FXCODEC_STATUS status = pGRD->Start_decode_MMR(&BHDC, pStream); |
2395 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 2306 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
2396 pGRD->Continue_decode(pPause); | 2307 pGRD->Continue_decode(pPause); |
2397 } | 2308 } |
2398 if (BHDC == NULL) { | 2309 if (!BHDC) |
2399 delete pGRD; | 2310 return nullptr; |
2400 goto failed; | 2311 |
2401 } | |
2402 delete pGRD; | |
2403 GRAY = 0; | 2312 GRAY = 0; |
2404 while (GRAY <= GRAYMAX) { | 2313 while (GRAY <= GRAYMAX) { |
2405 pDict->HDPATS[GRAY] = BHDC->subImage(HDPW * GRAY, 0, HDPW, HDPH); | 2314 pDict->HDPATS[GRAY] = BHDC->subImage(HDPW * GRAY, 0, HDPW, HDPH); |
2406 GRAY = GRAY + 1; | 2315 GRAY = GRAY + 1; |
2407 } | 2316 } |
2408 delete BHDC; | 2317 delete BHDC; |
2409 return pDict; | 2318 return pDict.release(); |
2410 failed: | |
2411 delete pDict; | |
2412 return NULL; | |
2413 } | 2319 } |
| 2320 |
2414 FX_DWORD* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, | 2321 FX_DWORD* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, |
2415 JBig2ArithCtx* gbContext, | 2322 JBig2ArithCtx* gbContext, |
2416 IFX_Pause* pPause) { | 2323 IFX_Pause* pPause) { |
2417 CJBig2_Image** GSPLANES; | 2324 CJBig2_Image** GSPLANES; |
2418 int32_t J, K; | 2325 int32_t J, K; |
2419 FX_DWORD x, y; | 2326 FX_DWORD x, y; |
2420 FX_DWORD* GSVALS; | 2327 FX_DWORD* GSVALS; |
2421 GSPLANES = FX_Alloc(CJBig2_Image*, GSBPP); | 2328 GSPLANES = FX_Alloc(CJBig2_Image*, GSBPP); |
2422 if (!GSPLANES) { | |
2423 return NULL; | |
2424 } | |
2425 GSVALS = FX_Alloc2D(FX_DWORD, GSW, GSH); | 2329 GSVALS = FX_Alloc2D(FX_DWORD, GSW, GSH); |
2426 if (!GSVALS) { | |
2427 FX_Free(GSPLANES); | |
2428 return NULL; | |
2429 } | |
2430 JBIG2_memset(GSPLANES, 0, sizeof(CJBig2_Image*) * GSBPP); | 2330 JBIG2_memset(GSPLANES, 0, sizeof(CJBig2_Image*) * GSBPP); |
2431 JBIG2_memset(GSVALS, 0, sizeof(FX_DWORD) * GSW * GSH); | 2331 JBIG2_memset(GSVALS, 0, sizeof(FX_DWORD) * GSW * GSH); |
2432 CJBig2_GRDProc* pGRD = new CJBig2_GRDProc(); | 2332 |
| 2333 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); |
2433 pGRD->MMR = GSMMR; | 2334 pGRD->MMR = GSMMR; |
2434 pGRD->GBW = GSW; | 2335 pGRD->GBW = GSW; |
2435 pGRD->GBH = GSH; | 2336 pGRD->GBH = GSH; |
2436 pGRD->GBTEMPLATE = GSTEMPLATE; | 2337 pGRD->GBTEMPLATE = GSTEMPLATE; |
2437 pGRD->TPGDON = 0; | 2338 pGRD->TPGDON = 0; |
2438 pGRD->USESKIP = GSUSESKIP; | 2339 pGRD->USESKIP = GSUSESKIP; |
2439 pGRD->SKIP = GSKIP; | 2340 pGRD->SKIP = GSKIP; |
2440 if (GSTEMPLATE <= 1) { | 2341 if (GSTEMPLATE <= 1) { |
2441 pGRD->GBAT[0] = 3; | 2342 pGRD->GBAT[0] = 3; |
2442 } else { | 2343 } else { |
2443 pGRD->GBAT[0] = 2; | 2344 pGRD->GBAT[0] = 2; |
2444 } | 2345 } |
2445 pGRD->GBAT[1] = -1; | 2346 pGRD->GBAT[1] = -1; |
2446 if (pGRD->GBTEMPLATE == 0) { | 2347 if (pGRD->GBTEMPLATE == 0) { |
2447 pGRD->GBAT[2] = -3; | 2348 pGRD->GBAT[2] = -3; |
2448 pGRD->GBAT[3] = -1; | 2349 pGRD->GBAT[3] = -1; |
2449 pGRD->GBAT[4] = 2; | 2350 pGRD->GBAT[4] = 2; |
2450 pGRD->GBAT[5] = -2; | 2351 pGRD->GBAT[5] = -2; |
2451 pGRD->GBAT[6] = -2; | 2352 pGRD->GBAT[6] = -2; |
2452 pGRD->GBAT[7] = -2; | 2353 pGRD->GBAT[7] = -2; |
2453 } | 2354 } |
2454 FXCODEC_STATUS status = | 2355 FXCODEC_STATUS status = |
2455 pGRD->Start_decode_Arith(&GSPLANES[GSBPP - 1], pArithDecoder, gbContext); | 2356 pGRD->Start_decode_Arith(&GSPLANES[GSBPP - 1], pArithDecoder, gbContext); |
2456 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 2357 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
2457 pGRD->Continue_decode(pPause); | 2358 pGRD->Continue_decode(pPause); |
2458 } | 2359 } |
2459 if (GSPLANES[GSBPP - 1] == NULL) { | 2360 if (!GSPLANES[GSBPP - 1]) { |
2460 goto failed; | 2361 goto failed; |
2461 } | 2362 } |
2462 J = GSBPP - 2; | 2363 J = GSBPP - 2; |
2463 while (J >= 0) { | 2364 while (J >= 0) { |
2464 FXCODEC_STATUS status = | 2365 FXCODEC_STATUS status = |
2465 pGRD->Start_decode_Arith(&GSPLANES[J], pArithDecoder, gbContext); | 2366 pGRD->Start_decode_Arith(&GSPLANES[J], pArithDecoder, gbContext); |
2466 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 2367 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
2467 pGRD->Continue_decode(pPause); | 2368 pGRD->Continue_decode(pPause); |
2468 } | 2369 } |
2469 if (GSPLANES[J] == NULL) { | 2370 if (!GSPLANES[J]) { |
2470 for (K = GSBPP - 1; K > J; K--) { | 2371 for (K = GSBPP - 1; K > J; K--) { |
2471 delete GSPLANES[K]; | 2372 delete GSPLANES[K]; |
2472 goto failed; | 2373 goto failed; |
2473 } | 2374 } |
2474 } | 2375 } |
2475 GSPLANES[J]->composeFrom(0, 0, GSPLANES[J + 1], JBIG2_COMPOSE_XOR); | 2376 GSPLANES[J]->composeFrom(0, 0, GSPLANES[J + 1], JBIG2_COMPOSE_XOR); |
2476 J = J - 1; | 2377 J = J - 1; |
2477 } | 2378 } |
2478 for (y = 0; y < GSH; y++) { | 2379 for (y = 0; y < GSH; y++) { |
2479 for (x = 0; x < GSW; x++) { | 2380 for (x = 0; x < GSW; x++) { |
2480 for (J = 0; J < GSBPP; J++) { | 2381 for (J = 0; J < GSBPP; J++) { |
2481 GSVALS[y * GSW + x] |= GSPLANES[J]->getPixel(x, y) << J; | 2382 GSVALS[y * GSW + x] |= GSPLANES[J]->getPixel(x, y) << J; |
2482 } | 2383 } |
2483 } | 2384 } |
2484 } | 2385 } |
2485 for (J = 0; J < GSBPP; J++) { | 2386 for (J = 0; J < GSBPP; J++) { |
2486 delete GSPLANES[J]; | 2387 delete GSPLANES[J]; |
2487 } | 2388 } |
2488 FX_Free(GSPLANES); | 2389 FX_Free(GSPLANES); |
2489 delete pGRD; | |
2490 return GSVALS; | 2390 return GSVALS; |
2491 failed: | 2391 failed: |
2492 FX_Free(GSPLANES); | 2392 FX_Free(GSPLANES); |
2493 delete pGRD; | |
2494 FX_Free(GSVALS); | 2393 FX_Free(GSVALS); |
2495 return NULL; | 2394 return nullptr; |
2496 } | 2395 } |
| 2396 |
2497 FX_DWORD* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream, | 2397 FX_DWORD* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream, |
2498 IFX_Pause* pPause) { | 2398 IFX_Pause* pPause) { |
2499 CJBig2_Image** GSPLANES; | 2399 CJBig2_Image** GSPLANES; |
2500 int32_t J, K; | 2400 int32_t J, K; |
2501 FX_DWORD x, y; | 2401 FX_DWORD x, y; |
2502 FX_DWORD* GSVALS; | 2402 FX_DWORD* GSVALS; |
2503 GSPLANES = FX_Alloc(CJBig2_Image*, GSBPP); | 2403 GSPLANES = FX_Alloc(CJBig2_Image*, GSBPP); |
2504 if (!GSPLANES) { | |
2505 return NULL; | |
2506 } | |
2507 GSVALS = FX_Alloc2D(FX_DWORD, GSW, GSH); | 2404 GSVALS = FX_Alloc2D(FX_DWORD, GSW, GSH); |
2508 if (!GSVALS) { | |
2509 FX_Free(GSPLANES); | |
2510 return NULL; | |
2511 } | |
2512 JBIG2_memset(GSPLANES, 0, sizeof(CJBig2_Image*) * GSBPP); | 2405 JBIG2_memset(GSPLANES, 0, sizeof(CJBig2_Image*) * GSBPP); |
2513 JBIG2_memset(GSVALS, 0, sizeof(FX_DWORD) * GSW * GSH); | 2406 JBIG2_memset(GSVALS, 0, sizeof(FX_DWORD) * GSW * GSH); |
2514 CJBig2_GRDProc* pGRD = new CJBig2_GRDProc(); | 2407 |
| 2408 nonstd::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc()); |
2515 pGRD->MMR = GSMMR; | 2409 pGRD->MMR = GSMMR; |
2516 pGRD->GBW = GSW; | 2410 pGRD->GBW = GSW; |
2517 pGRD->GBH = GSH; | 2411 pGRD->GBH = GSH; |
2518 FXCODEC_STATUS status = pGRD->Start_decode_MMR(&GSPLANES[GSBPP - 1], pStream); | 2412 FXCODEC_STATUS status = pGRD->Start_decode_MMR(&GSPLANES[GSBPP - 1], pStream); |
2519 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 2413 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
2520 pGRD->Continue_decode(pPause); | 2414 pGRD->Continue_decode(pPause); |
2521 } | 2415 } |
2522 if (GSPLANES[GSBPP - 1] == NULL) { | 2416 if (!GSPLANES[GSBPP - 1]) { |
2523 goto failed; | 2417 goto failed; |
2524 } | 2418 } |
2525 pStream->alignByte(); | 2419 pStream->alignByte(); |
2526 pStream->offset(3); | 2420 pStream->offset(3); |
2527 J = GSBPP - 2; | 2421 J = GSBPP - 2; |
2528 while (J >= 0) { | 2422 while (J >= 0) { |
2529 FXCODEC_STATUS status = pGRD->Start_decode_MMR(&GSPLANES[J], pStream); | 2423 FXCODEC_STATUS status = pGRD->Start_decode_MMR(&GSPLANES[J], pStream); |
2530 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 2424 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
2531 pGRD->Continue_decode(pPause); | 2425 pGRD->Continue_decode(pPause); |
2532 } | 2426 } |
2533 if (GSPLANES[J] == NULL) { | 2427 if (!GSPLANES[J]) { |
2534 for (K = GSBPP - 1; K > J; K--) { | 2428 for (K = GSBPP - 1; K > J; K--) { |
2535 delete GSPLANES[K]; | 2429 delete GSPLANES[K]; |
2536 goto failed; | 2430 goto failed; |
2537 } | 2431 } |
2538 } | 2432 } |
2539 pStream->alignByte(); | 2433 pStream->alignByte(); |
2540 pStream->offset(3); | 2434 pStream->offset(3); |
2541 GSPLANES[J]->composeFrom(0, 0, GSPLANES[J + 1], JBIG2_COMPOSE_XOR); | 2435 GSPLANES[J]->composeFrom(0, 0, GSPLANES[J + 1], JBIG2_COMPOSE_XOR); |
2542 J = J - 1; | 2436 J = J - 1; |
2543 } | 2437 } |
2544 for (y = 0; y < GSH; y++) { | 2438 for (y = 0; y < GSH; y++) { |
2545 for (x = 0; x < GSW; x++) { | 2439 for (x = 0; x < GSW; x++) { |
2546 for (J = 0; J < GSBPP; J++) { | 2440 for (J = 0; J < GSBPP; J++) { |
2547 GSVALS[y * GSW + x] |= GSPLANES[J]->getPixel(x, y) << J; | 2441 GSVALS[y * GSW + x] |= GSPLANES[J]->getPixel(x, y) << J; |
2548 } | 2442 } |
2549 } | 2443 } |
2550 } | 2444 } |
2551 for (J = 0; J < GSBPP; J++) { | 2445 for (J = 0; J < GSBPP; J++) { |
2552 delete GSPLANES[J]; | 2446 delete GSPLANES[J]; |
2553 } | 2447 } |
2554 FX_Free(GSPLANES); | 2448 FX_Free(GSPLANES); |
2555 delete pGRD; | |
2556 return GSVALS; | 2449 return GSVALS; |
2557 failed: | 2450 failed: |
2558 FX_Free(GSPLANES); | 2451 FX_Free(GSPLANES); |
2559 delete pGRD; | |
2560 FX_Free(GSVALS); | 2452 FX_Free(GSVALS); |
2561 return NULL; | 2453 return nullptr; |
2562 } | 2454 } |
| 2455 |
2563 FXCODEC_STATUS CJBig2_GRDProc::Start_decode_Arith( | 2456 FXCODEC_STATUS CJBig2_GRDProc::Start_decode_Arith( |
2564 CJBig2_Image** pImage, | 2457 CJBig2_Image** pImage, |
2565 CJBig2_ArithDecoder* pArithDecoder, | 2458 CJBig2_ArithDecoder* pArithDecoder, |
2566 JBig2ArithCtx* gbContext, | 2459 JBig2ArithCtx* gbContext, |
2567 IFX_Pause* pPause) { | 2460 IFX_Pause* pPause) { |
2568 if (GBW == 0 || GBH == 0) { | 2461 if (GBW == 0 || GBH == 0) { |
2569 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 2462 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
2570 return FXCODEC_STATUS_DECODE_FINISH; | 2463 return FXCODEC_STATUS_DECODE_FINISH; |
2571 } | 2464 } |
2572 m_ProssiveStatus = FXCODEC_STATUS_DECODE_READY; | 2465 m_ProssiveStatus = FXCODEC_STATUS_DECODE_READY; |
2573 m_pPause = pPause; | 2466 m_pPause = pPause; |
2574 if (!*pImage) | 2467 if (!*pImage) |
2575 *pImage = new CJBig2_Image(GBW, GBH); | 2468 *pImage = new CJBig2_Image(GBW, GBH); |
2576 if ((*pImage)->m_pData == NULL) { | 2469 if (!(*pImage)->m_pData) { |
2577 delete *pImage; | 2470 delete *pImage; |
2578 *pImage = NULL; | 2471 *pImage = nullptr; |
2579 m_ProssiveStatus = FXCODEC_STATUS_ERROR; | 2472 m_ProssiveStatus = FXCODEC_STATUS_ERROR; |
2580 return FXCODEC_STATUS_ERROR; | 2473 return FXCODEC_STATUS_ERROR; |
2581 } | 2474 } |
2582 m_DecodeType = 1; | 2475 m_DecodeType = 1; |
2583 m_pImage = pImage; | 2476 m_pImage = pImage; |
2584 (*m_pImage)->fill(0); | 2477 (*m_pImage)->fill(0); |
2585 m_pArithDecoder = pArithDecoder; | 2478 m_pArithDecoder = pArithDecoder; |
2586 m_gbContext = gbContext; | 2479 m_gbContext = gbContext; |
2587 LTP = 0; | 2480 LTP = 0; |
2588 m_pLine = NULL; | 2481 m_pLine = nullptr; |
2589 m_loopIndex = 0; | 2482 m_loopIndex = 0; |
2590 return decode_Arith(pPause); | 2483 return decode_Arith(pPause); |
2591 } | 2484 } |
| 2485 |
2592 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith(IFX_Pause* pPause) { | 2486 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith(IFX_Pause* pPause) { |
2593 int iline = m_loopIndex; | 2487 int iline = m_loopIndex; |
2594 CJBig2_Image* pImage = *m_pImage; | 2488 CJBig2_Image* pImage = *m_pImage; |
2595 if (GBTEMPLATE == 0) { | 2489 if (GBTEMPLATE == 0) { |
2596 if ((GBAT[0] == 3) && (GBAT[1] == (int8_t)-1) && (GBAT[2] == (int8_t)-3) && | 2490 if (UseTemplate0Opt3()) { |
2597 (GBAT[3] == (int8_t)-1) && (GBAT[4] == 2) && (GBAT[5] == (int8_t)-2) && | |
2598 (GBAT[6] == (int8_t)-2) && (GBAT[7] == (int8_t)-2)) { | |
2599 m_ProssiveStatus = decode_Arith_Template0_opt3(pImage, m_pArithDecoder, | 2491 m_ProssiveStatus = decode_Arith_Template0_opt3(pImage, m_pArithDecoder, |
2600 m_gbContext, pPause); | 2492 m_gbContext, pPause); |
2601 } else { | 2493 } else { |
2602 m_ProssiveStatus = decode_Arith_Template0_unopt(pImage, m_pArithDecoder, | 2494 m_ProssiveStatus = decode_Arith_Template0_unopt(pImage, m_pArithDecoder, |
2603 m_gbContext, pPause); | 2495 m_gbContext, pPause); |
2604 } | 2496 } |
2605 } else if (GBTEMPLATE == 1) { | 2497 } else if (GBTEMPLATE == 1) { |
2606 if ((GBAT[0] == 3) && (GBAT[1] == (int8_t)-1)) { | 2498 if (UseTemplate1Opt3()) { |
2607 m_ProssiveStatus = decode_Arith_Template1_opt3(pImage, m_pArithDecoder, | 2499 m_ProssiveStatus = decode_Arith_Template1_opt3(pImage, m_pArithDecoder, |
2608 m_gbContext, pPause); | 2500 m_gbContext, pPause); |
2609 } else { | 2501 } else { |
2610 m_ProssiveStatus = decode_Arith_Template1_unopt(pImage, m_pArithDecoder, | 2502 m_ProssiveStatus = decode_Arith_Template1_unopt(pImage, m_pArithDecoder, |
2611 m_gbContext, pPause); | 2503 m_gbContext, pPause); |
2612 } | 2504 } |
2613 } else if (GBTEMPLATE == 2) { | 2505 } else if (GBTEMPLATE == 2) { |
2614 if ((GBAT[0] == 2) && (GBAT[1] == (int8_t)-1)) { | 2506 if (UseTemplate23Opt3()) { |
2615 m_ProssiveStatus = decode_Arith_Template2_opt3(pImage, m_pArithDecoder, | 2507 m_ProssiveStatus = decode_Arith_Template2_opt3(pImage, m_pArithDecoder, |
2616 m_gbContext, pPause); | 2508 m_gbContext, pPause); |
2617 } else { | 2509 } else { |
2618 m_ProssiveStatus = decode_Arith_Template2_unopt(pImage, m_pArithDecoder, | 2510 m_ProssiveStatus = decode_Arith_Template2_unopt(pImage, m_pArithDecoder, |
2619 m_gbContext, pPause); | 2511 m_gbContext, pPause); |
2620 } | 2512 } |
2621 } else { | 2513 } else { |
2622 if ((GBAT[0] == 2) && (GBAT[1] == (int8_t)-1)) { | 2514 if (UseTemplate23Opt3()) { |
2623 m_ProssiveStatus = decode_Arith_Template3_opt3(pImage, m_pArithDecoder, | 2515 m_ProssiveStatus = decode_Arith_Template3_opt3(pImage, m_pArithDecoder, |
2624 m_gbContext, pPause); | 2516 m_gbContext, pPause); |
2625 } else { | 2517 } else { |
2626 m_ProssiveStatus = decode_Arith_Template3_unopt(pImage, m_pArithDecoder, | 2518 m_ProssiveStatus = decode_Arith_Template3_unopt(pImage, m_pArithDecoder, |
2627 m_gbContext, pPause); | 2519 m_gbContext, pPause); |
2628 } | 2520 } |
2629 } | 2521 } |
2630 m_ReplaceRect.left = 0; | 2522 m_ReplaceRect.left = 0; |
2631 m_ReplaceRect.right = pImage->m_nWidth; | 2523 m_ReplaceRect.right = pImage->m_nWidth; |
2632 m_ReplaceRect.top = iline; | 2524 m_ReplaceRect.top = iline; |
2633 m_ReplaceRect.bottom = m_loopIndex; | 2525 m_ReplaceRect.bottom = m_loopIndex; |
2634 if (m_ProssiveStatus == FXCODEC_STATUS_DECODE_FINISH) { | 2526 if (m_ProssiveStatus == FXCODEC_STATUS_DECODE_FINISH) { |
2635 m_loopIndex = 0; | 2527 m_loopIndex = 0; |
2636 } | 2528 } |
2637 return m_ProssiveStatus; | 2529 return m_ProssiveStatus; |
2638 } | 2530 } |
| 2531 |
2639 FXCODEC_STATUS CJBig2_GRDProc::Start_decode_MMR(CJBig2_Image** pImage, | 2532 FXCODEC_STATUS CJBig2_GRDProc::Start_decode_MMR(CJBig2_Image** pImage, |
2640 CJBig2_BitStream* pStream, | 2533 CJBig2_BitStream* pStream, |
2641 IFX_Pause* pPause) { | 2534 IFX_Pause* pPause) { |
2642 int bitpos, i; | 2535 int bitpos, i; |
2643 *pImage = new CJBig2_Image(GBW, GBH); | 2536 *pImage = new CJBig2_Image(GBW, GBH); |
2644 if ((*pImage)->m_pData == NULL) { | 2537 if (!(*pImage)->m_pData) { |
2645 delete (*pImage); | 2538 delete (*pImage); |
2646 (*pImage) = NULL; | 2539 (*pImage) = nullptr; |
2647 m_ProssiveStatus = FXCODEC_STATUS_ERROR; | 2540 m_ProssiveStatus = FXCODEC_STATUS_ERROR; |
2648 return m_ProssiveStatus; | 2541 return m_ProssiveStatus; |
2649 } | 2542 } |
2650 bitpos = (int)pStream->getBitPos(); | 2543 bitpos = (int)pStream->getBitPos(); |
2651 _FaxG4Decode(pStream->getBuf(), pStream->getLength(), &bitpos, | 2544 _FaxG4Decode(pStream->getBuf(), pStream->getLength(), &bitpos, |
2652 (*pImage)->m_pData, GBW, GBH, (*pImage)->m_nStride); | 2545 (*pImage)->m_pData, GBW, GBH, (*pImage)->m_nStride); |
2653 pStream->setBitPos(bitpos); | 2546 pStream->setBitPos(bitpos); |
2654 for (i = 0; (FX_DWORD)i < (*pImage)->m_nStride * GBH; i++) { | 2547 for (i = 0; (FX_DWORD)i < (*pImage)->m_nStride * GBH; i++) { |
2655 (*pImage)->m_pData[i] = ~(*pImage)->m_pData[i]; | 2548 (*pImage)->m_pData[i] = ~(*pImage)->m_pData[i]; |
2656 } | 2549 } |
(...skipping 17 matching lines...) Expand all Loading... |
2674 CJBig2_Image* pImage, | 2567 CJBig2_Image* pImage, |
2675 CJBig2_ArithDecoder* pArithDecoder, | 2568 CJBig2_ArithDecoder* pArithDecoder, |
2676 JBig2ArithCtx* gbContext, | 2569 JBig2ArithCtx* gbContext, |
2677 IFX_Pause* pPause) { | 2570 IFX_Pause* pPause) { |
2678 FX_BOOL SLTP, bVal; | 2571 FX_BOOL SLTP, bVal; |
2679 FX_DWORD CONTEXT; | 2572 FX_DWORD CONTEXT; |
2680 FX_DWORD line1, line2; | 2573 FX_DWORD line1, line2; |
2681 uint8_t *pLine1, *pLine2, cVal; | 2574 uint8_t *pLine1, *pLine2, cVal; |
2682 int32_t nStride, nStride2, k; | 2575 int32_t nStride, nStride2, k; |
2683 int32_t nLineBytes, nBitsLeft, cc; | 2576 int32_t nLineBytes, nBitsLeft, cc; |
2684 if (m_pLine == NULL) { | 2577 if (!m_pLine) { |
2685 m_pLine = pImage->m_pData; | 2578 m_pLine = pImage->m_pData; |
2686 } | 2579 } |
2687 nStride = pImage->m_nStride; | 2580 nStride = pImage->m_nStride; |
2688 nStride2 = nStride << 1; | 2581 nStride2 = nStride << 1; |
2689 nLineBytes = ((GBW + 7) >> 3) - 1; | 2582 nLineBytes = ((GBW + 7) >> 3) - 1; |
2690 nBitsLeft = GBW - (nLineBytes << 3); | 2583 nBitsLeft = GBW - (nLineBytes << 3); |
2691 FX_DWORD height = GBH & 0x7fffffff; | 2584 FX_DWORD height = GBH & 0x7fffffff; |
2692 for (; m_loopIndex < height; m_loopIndex++) { | 2585 for (; m_loopIndex < height; m_loopIndex++) { |
2693 if (TPGDON) { | 2586 if (TPGDON) { |
2694 SLTP = pArithDecoder->DECODE(&gbContext[0x9b25]); | 2587 SLTP = pArithDecoder->DECODE(&gbContext[0x9b25]); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2757 m_pLine += nStride; | 2650 m_pLine += nStride; |
2758 if (pPause && pPause->NeedToPauseNow()) { | 2651 if (pPause && pPause->NeedToPauseNow()) { |
2759 m_loopIndex++; | 2652 m_loopIndex++; |
2760 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 2653 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
2761 return FXCODEC_STATUS_DECODE_TOBECONTINUE; | 2654 return FXCODEC_STATUS_DECODE_TOBECONTINUE; |
2762 } | 2655 } |
2763 } | 2656 } |
2764 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 2657 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
2765 return FXCODEC_STATUS_DECODE_FINISH; | 2658 return FXCODEC_STATUS_DECODE_FINISH; |
2766 } | 2659 } |
| 2660 |
2767 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_unopt( | 2661 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_unopt( |
2768 CJBig2_Image* pImage, | 2662 CJBig2_Image* pImage, |
2769 CJBig2_ArithDecoder* pArithDecoder, | 2663 CJBig2_ArithDecoder* pArithDecoder, |
2770 JBig2ArithCtx* gbContext, | 2664 JBig2ArithCtx* gbContext, |
2771 IFX_Pause* pPause) { | 2665 IFX_Pause* pPause) { |
2772 FX_BOOL SLTP, bVal; | 2666 FX_BOOL SLTP, bVal; |
2773 FX_DWORD CONTEXT; | 2667 FX_DWORD CONTEXT; |
2774 FX_DWORD line1, line2, line3; | 2668 FX_DWORD line1, line2, line3; |
2775 for (; m_loopIndex < GBH; m_loopIndex++) { | 2669 for (; m_loopIndex < GBH; m_loopIndex++) { |
2776 if (TPGDON) { | 2670 if (TPGDON) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2811 } | 2705 } |
2812 if (pPause && pPause->NeedToPauseNow()) { | 2706 if (pPause && pPause->NeedToPauseNow()) { |
2813 m_loopIndex++; | 2707 m_loopIndex++; |
2814 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 2708 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
2815 return FXCODEC_STATUS_DECODE_TOBECONTINUE; | 2709 return FXCODEC_STATUS_DECODE_TOBECONTINUE; |
2816 } | 2710 } |
2817 } | 2711 } |
2818 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 2712 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
2819 return FXCODEC_STATUS_DECODE_FINISH; | 2713 return FXCODEC_STATUS_DECODE_FINISH; |
2820 } | 2714 } |
| 2715 |
2821 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_opt3( | 2716 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_opt3( |
2822 CJBig2_Image* pImage, | 2717 CJBig2_Image* pImage, |
2823 CJBig2_ArithDecoder* pArithDecoder, | 2718 CJBig2_ArithDecoder* pArithDecoder, |
2824 JBig2ArithCtx* gbContext, | 2719 JBig2ArithCtx* gbContext, |
2825 IFX_Pause* pPause) { | 2720 IFX_Pause* pPause) { |
2826 FX_BOOL SLTP, bVal; | 2721 FX_BOOL SLTP, bVal; |
2827 FX_DWORD CONTEXT; | 2722 FX_DWORD CONTEXT; |
2828 FX_DWORD line1, line2; | 2723 FX_DWORD line1, line2; |
2829 uint8_t *pLine1, *pLine2, cVal; | 2724 uint8_t *pLine1, *pLine2, cVal; |
2830 int32_t nStride, nStride2, k; | 2725 int32_t nStride, nStride2, k; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2904 m_pLine += nStride; | 2799 m_pLine += nStride; |
2905 if (pPause && pPause->NeedToPauseNow()) { | 2800 if (pPause && pPause->NeedToPauseNow()) { |
2906 m_loopIndex++; | 2801 m_loopIndex++; |
2907 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 2802 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
2908 return FXCODEC_STATUS_DECODE_TOBECONTINUE; | 2803 return FXCODEC_STATUS_DECODE_TOBECONTINUE; |
2909 } | 2804 } |
2910 } | 2805 } |
2911 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 2806 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
2912 return FXCODEC_STATUS_DECODE_FINISH; | 2807 return FXCODEC_STATUS_DECODE_FINISH; |
2913 } | 2808 } |
| 2809 |
2914 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_unopt( | 2810 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_unopt( |
2915 CJBig2_Image* pImage, | 2811 CJBig2_Image* pImage, |
2916 CJBig2_ArithDecoder* pArithDecoder, | 2812 CJBig2_ArithDecoder* pArithDecoder, |
2917 JBig2ArithCtx* gbContext, | 2813 JBig2ArithCtx* gbContext, |
2918 IFX_Pause* pPause) { | 2814 IFX_Pause* pPause) { |
2919 FX_BOOL SLTP, bVal; | 2815 FX_BOOL SLTP, bVal; |
2920 FX_DWORD CONTEXT; | 2816 FX_DWORD CONTEXT; |
2921 FX_DWORD line1, line2, line3; | 2817 FX_DWORD line1, line2, line3; |
2922 for (FX_DWORD h = 0; h < GBH; h++) { | 2818 for (FX_DWORD h = 0; h < GBH; h++) { |
2923 if (TPGDON) { | 2819 if (TPGDON) { |
(...skipping 30 matching lines...) Expand all Loading... |
2954 } | 2850 } |
2955 if (pPause && pPause->NeedToPauseNow()) { | 2851 if (pPause && pPause->NeedToPauseNow()) { |
2956 m_loopIndex++; | 2852 m_loopIndex++; |
2957 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 2853 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
2958 return FXCODEC_STATUS_DECODE_TOBECONTINUE; | 2854 return FXCODEC_STATUS_DECODE_TOBECONTINUE; |
2959 } | 2855 } |
2960 } | 2856 } |
2961 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 2857 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
2962 return FXCODEC_STATUS_DECODE_FINISH; | 2858 return FXCODEC_STATUS_DECODE_FINISH; |
2963 } | 2859 } |
| 2860 |
2964 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_opt3( | 2861 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_opt3( |
2965 CJBig2_Image* pImage, | 2862 CJBig2_Image* pImage, |
2966 CJBig2_ArithDecoder* pArithDecoder, | 2863 CJBig2_ArithDecoder* pArithDecoder, |
2967 JBig2ArithCtx* gbContext, | 2864 JBig2ArithCtx* gbContext, |
2968 IFX_Pause* pPause) { | 2865 IFX_Pause* pPause) { |
2969 FX_BOOL SLTP, bVal; | 2866 FX_BOOL SLTP, bVal; |
2970 FX_DWORD CONTEXT; | 2867 FX_DWORD CONTEXT; |
2971 FX_DWORD line1, line2; | 2868 FX_DWORD line1, line2; |
2972 uint8_t *pLine1, *pLine2, cVal; | 2869 uint8_t *pLine1, *pLine2, cVal; |
2973 int32_t nStride, nStride2, k; | 2870 int32_t nStride, nStride2, k; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3047 m_pLine += nStride; | 2944 m_pLine += nStride; |
3048 if (pPause && m_loopIndex % 50 == 0 && pPause->NeedToPauseNow()) { | 2945 if (pPause && m_loopIndex % 50 == 0 && pPause->NeedToPauseNow()) { |
3049 m_loopIndex++; | 2946 m_loopIndex++; |
3050 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 2947 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
3051 return FXCODEC_STATUS_DECODE_TOBECONTINUE; | 2948 return FXCODEC_STATUS_DECODE_TOBECONTINUE; |
3052 } | 2949 } |
3053 } | 2950 } |
3054 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 2951 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
3055 return FXCODEC_STATUS_DECODE_FINISH; | 2952 return FXCODEC_STATUS_DECODE_FINISH; |
3056 } | 2953 } |
| 2954 |
3057 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_unopt( | 2955 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_unopt( |
3058 CJBig2_Image* pImage, | 2956 CJBig2_Image* pImage, |
3059 CJBig2_ArithDecoder* pArithDecoder, | 2957 CJBig2_ArithDecoder* pArithDecoder, |
3060 JBig2ArithCtx* gbContext, | 2958 JBig2ArithCtx* gbContext, |
3061 IFX_Pause* pPause) { | 2959 IFX_Pause* pPause) { |
3062 FX_BOOL SLTP, bVal; | 2960 FX_BOOL SLTP, bVal; |
3063 FX_DWORD CONTEXT; | 2961 FX_DWORD CONTEXT; |
3064 FX_DWORD line1, line2, line3; | 2962 FX_DWORD line1, line2, line3; |
3065 for (; m_loopIndex < GBH; m_loopIndex++) { | 2963 for (; m_loopIndex < GBH; m_loopIndex++) { |
3066 if (TPGDON) { | 2964 if (TPGDON) { |
(...skipping 30 matching lines...) Expand all Loading... |
3097 } | 2995 } |
3098 if (pPause && pPause->NeedToPauseNow()) { | 2996 if (pPause && pPause->NeedToPauseNow()) { |
3099 m_loopIndex++; | 2997 m_loopIndex++; |
3100 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 2998 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
3101 return FXCODEC_STATUS_DECODE_TOBECONTINUE; | 2999 return FXCODEC_STATUS_DECODE_TOBECONTINUE; |
3102 } | 3000 } |
3103 } | 3001 } |
3104 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 3002 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
3105 return FXCODEC_STATUS_DECODE_FINISH; | 3003 return FXCODEC_STATUS_DECODE_FINISH; |
3106 } | 3004 } |
| 3005 |
3107 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_opt3( | 3006 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_opt3( |
3108 CJBig2_Image* pImage, | 3007 CJBig2_Image* pImage, |
3109 CJBig2_ArithDecoder* pArithDecoder, | 3008 CJBig2_ArithDecoder* pArithDecoder, |
3110 JBig2ArithCtx* gbContext, | 3009 JBig2ArithCtx* gbContext, |
3111 IFX_Pause* pPause) { | 3010 IFX_Pause* pPause) { |
3112 FX_BOOL SLTP, bVal; | 3011 FX_BOOL SLTP, bVal; |
3113 FX_DWORD CONTEXT; | 3012 FX_DWORD CONTEXT; |
3114 FX_DWORD line1; | 3013 FX_DWORD line1; |
3115 uint8_t *pLine1, cVal; | 3014 uint8_t *pLine1, cVal; |
3116 int32_t nStride, k; | 3015 int32_t nStride, k; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3176 m_pLine += nStride; | 3075 m_pLine += nStride; |
3177 if (pPause && pPause->NeedToPauseNow()) { | 3076 if (pPause && pPause->NeedToPauseNow()) { |
3178 m_loopIndex++; | 3077 m_loopIndex++; |
3179 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 3078 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
3180 return FXCODEC_STATUS_DECODE_TOBECONTINUE; | 3079 return FXCODEC_STATUS_DECODE_TOBECONTINUE; |
3181 } | 3080 } |
3182 } | 3081 } |
3183 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 3082 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
3184 return FXCODEC_STATUS_DECODE_FINISH; | 3083 return FXCODEC_STATUS_DECODE_FINISH; |
3185 } | 3084 } |
| 3085 |
3186 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_unopt( | 3086 FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_unopt( |
3187 CJBig2_Image* pImage, | 3087 CJBig2_Image* pImage, |
3188 CJBig2_ArithDecoder* pArithDecoder, | 3088 CJBig2_ArithDecoder* pArithDecoder, |
3189 JBig2ArithCtx* gbContext, | 3089 JBig2ArithCtx* gbContext, |
3190 IFX_Pause* pPause) { | 3090 IFX_Pause* pPause) { |
3191 FX_BOOL SLTP, bVal; | 3091 FX_BOOL SLTP, bVal; |
3192 FX_DWORD CONTEXT; | 3092 FX_DWORD CONTEXT; |
3193 FX_DWORD line1, line2; | 3093 FX_DWORD line1, line2; |
3194 for (; m_loopIndex < GBH; m_loopIndex++) { | 3094 for (; m_loopIndex < GBH; m_loopIndex++) { |
3195 if (TPGDON) { | 3095 if (TPGDON) { |
(...skipping 25 matching lines...) Expand all Loading... |
3221 } | 3121 } |
3222 if (pPause && pPause->NeedToPauseNow()) { | 3122 if (pPause && pPause->NeedToPauseNow()) { |
3223 m_loopIndex++; | 3123 m_loopIndex++; |
3224 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 3124 m_ProssiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
3225 return FXCODEC_STATUS_DECODE_TOBECONTINUE; | 3125 return FXCODEC_STATUS_DECODE_TOBECONTINUE; |
3226 } | 3126 } |
3227 } | 3127 } |
3228 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 3128 m_ProssiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
3229 return FXCODEC_STATUS_DECODE_FINISH; | 3129 return FXCODEC_STATUS_DECODE_FINISH; |
3230 } | 3130 } |
OLD | NEW |