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 <map> | |
8 #include <list> | 7 #include <list> |
9 #include "JBig2_Context.h" | 8 #include "JBig2_Context.h" |
10 | 9 |
11 // Implement a very small least recently used (LRU) cache. It is very | 10 // Implement a very small least recently used (LRU) cache. It is very |
12 // common for a JBIG2 dictionary to span multiple pages in a PDF file, | 11 // common for a JBIG2 dictionary to span multiple pages in a PDF file, |
13 // and we do not want to decode the same dictionary over and over | 12 // and we do not want to decode the same dictionary over and over |
14 // again. We key off of the memory location of the dictionary. The | 13 // again. We key off of the memory location of the dictionary. The |
15 // list keeps track of the freshness of entries, with freshest ones | 14 // list keeps track of the freshness of entries, with freshest ones |
16 // at the front. Even a tiny cache size like 2 makes a dramatic | 15 // at the front. Even a tiny cache size like 2 makes a dramatic |
17 // difference for typical JBIG2 documents. | 16 // difference for typical JBIG2 documents. |
(...skipping 22 matching lines...) Expand all Loading... | |
40 int32_t nStreamType, | 39 int32_t nStreamType, |
41 std::list<CJBig2_CachePair>* pSymbolDictCache, | 40 std::list<CJBig2_CachePair>* pSymbolDictCache, |
42 IFX_Pause* pPause) { | 41 IFX_Pause* pPause) { |
43 if (pGlobalData && (dwGlobalLength > 0)) { | 42 if (pGlobalData && (dwGlobalLength > 0)) { |
44 JBIG2_ALLOC(m_pGlobalContext, | 43 JBIG2_ALLOC(m_pGlobalContext, |
45 CJBig2_Context(NULL, 0, pGlobalData, dwGlobalLength, | 44 CJBig2_Context(NULL, 0, pGlobalData, dwGlobalLength, |
46 JBIG2_EMBED_STREAM, pSymbolDictCache, pPause)); | 45 JBIG2_EMBED_STREAM, pSymbolDictCache, pPause)); |
47 } else { | 46 } else { |
48 m_pGlobalContext = NULL; | 47 m_pGlobalContext = NULL; |
49 } | 48 } |
50 JBIG2_ALLOC(m_pStream, CJBig2_BitStream(pData, dwLength)); | 49 m_pStream = new CJBig2_BitStream(pData, dwLength); |
51 m_nStreamType = nStreamType; | 50 m_nStreamType = nStreamType; |
52 m_nState = JBIG2_OUT_OF_PAGE; | 51 m_nState = JBIG2_OUT_OF_PAGE; |
53 JBIG2_ALLOC(m_pSegmentList, CJBig2_List<CJBig2_Segment>); | |
54 JBIG2_ALLOC(m_pPageInfoList, CJBig2_List<JBig2PageInfo>(1)); | |
55 m_pPage = NULL; | 52 m_pPage = NULL; |
56 m_bBufSpecified = FALSE; | 53 m_bBufSpecified = FALSE; |
57 m_pPause = pPause; | 54 m_pPause = pPause; |
58 m_nSegmentDecoded = 0; | 55 m_nSegmentDecoded = 0; |
59 m_PauseStep = 10; | 56 m_PauseStep = 10; |
60 m_pArithDecoder = NULL; | 57 m_pArithDecoder = NULL; |
61 m_pGRD = NULL; | 58 m_pGRD = NULL; |
62 m_gbContext = NULL; | 59 m_gbContext = NULL; |
63 m_pSegment = NULL; | |
64 m_dwOffset = 0; | 60 m_dwOffset = 0; |
65 m_ProcessiveStatus = FXCODEC_STATUS_FRAME_READY; | 61 m_ProcessiveStatus = FXCODEC_STATUS_FRAME_READY; |
66 m_pSymbolDictCache = pSymbolDictCache; | 62 m_pSymbolDictCache = pSymbolDictCache; |
67 } | 63 } |
68 CJBig2_Context::~CJBig2_Context() { | 64 CJBig2_Context::~CJBig2_Context() { |
69 delete m_pArithDecoder; | 65 delete m_pArithDecoder; |
70 m_pArithDecoder = NULL; | 66 m_pArithDecoder = NULL; |
71 delete m_pGRD; | 67 delete m_pGRD; |
72 m_pGRD = NULL; | 68 m_pGRD = NULL; |
73 if (m_gbContext) { | 69 if (m_gbContext) { |
74 m_pModule->JBig2_Free(m_gbContext); | 70 m_pModule->JBig2_Free(m_gbContext); |
75 } | 71 } |
76 m_gbContext = NULL; | 72 m_gbContext = NULL; |
77 delete m_pGlobalContext; | 73 delete m_pGlobalContext; |
78 m_pGlobalContext = NULL; | 74 m_pGlobalContext = NULL; |
79 delete m_pPageInfoList; | |
80 m_pPageInfoList = NULL; | |
81 if (m_bBufSpecified) { | 75 if (m_bBufSpecified) { |
82 delete m_pPage; | 76 delete m_pPage; |
83 } | 77 } |
84 m_pPage = NULL; | 78 m_pPage = NULL; |
85 delete m_pStream; | 79 delete m_pStream; |
86 m_pStream = NULL; | 80 m_pStream = NULL; |
87 delete m_pSegmentList; | |
88 m_pSegmentList = NULL; | |
89 } | 81 } |
90 int32_t CJBig2_Context::decodeFile(IFX_Pause* pPause) { | 82 int32_t CJBig2_Context::decodeFile(IFX_Pause* pPause) { |
91 uint8_t cFlags; | 83 uint8_t cFlags; |
92 FX_DWORD dwTemp; | 84 FX_DWORD dwTemp; |
93 const uint8_t fileID[] = {0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 0x0A}; | 85 const uint8_t fileID[] = {0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 0x0A}; |
94 int32_t nRet; | 86 int32_t nRet; |
95 if (m_pStream->getByteLeft() < 8) { | 87 if (m_pStream->getByteLeft() < 8) { |
96 m_pModule->JBig2_Error("file header too short."); | 88 m_pModule->JBig2_Error("file header too short."); |
97 nRet = JBIG2_ERROR_TOO_SHORT; | 89 nRet = JBIG2_ERROR_TOO_SHORT; |
98 goto failed; | 90 goto failed; |
99 } | 91 } |
100 if (JBIG2_memcmp(m_pStream->getPointer(), fileID, 8) != 0) { | 92 if (JBIG2_memcmp(m_pStream->getPointer(), fileID, 8) != 0) { |
101 m_pModule->JBig2_Error("not jbig2 file"); | 93 m_pModule->JBig2_Error("not jbig2 file"); |
102 nRet = JBIG2_ERROR_FILE_FORMAT; | 94 nRet = JBIG2_ERROR_FILE_FORMAT; |
103 goto failed; | 95 goto failed; |
104 } | 96 } |
105 m_pStream->offset(8); | 97 m_pStream->offset(8); |
106 if (m_pStream->read1Byte(&cFlags) != 0) { | 98 if (m_pStream->read1Byte(&cFlags) != 0) { |
107 m_pModule->JBig2_Error("file header too short."); | 99 m_pModule->JBig2_Error("file header too short."); |
108 nRet = JBIG2_ERROR_TOO_SHORT; | 100 nRet = JBIG2_ERROR_TOO_SHORT; |
109 goto failed; | 101 goto failed; |
110 } | 102 } |
111 if (!(cFlags & 0x02)) { | 103 if (!(cFlags & 0x02)) { |
112 if (m_pStream->readInteger(&dwTemp) != 0) { | 104 if (m_pStream->readInteger(&dwTemp) != 0) { |
113 m_pModule->JBig2_Error("file header too short."); | 105 m_pModule->JBig2_Error("file header too short."); |
114 nRet = JBIG2_ERROR_TOO_SHORT; | 106 nRet = JBIG2_ERROR_TOO_SHORT; |
115 goto failed; | 107 goto failed; |
116 } | 108 } |
117 if (dwTemp > 0) { | 109 if (dwTemp > 0) { |
118 delete m_pPageInfoList; | 110 m_PageInfoList.clear(); |
119 JBIG2_ALLOC(m_pPageInfoList, CJBig2_List<JBig2PageInfo>(dwTemp)); | 111 m_PageInfoList.resize(dwTemp); |
120 } | 112 } |
121 } | 113 } |
122 if (cFlags & 0x01) { | 114 if (cFlags & 0x01) { |
123 m_nStreamType = JBIG2_SQUENTIAL_STREAM; | 115 m_nStreamType = JBIG2_SQUENTIAL_STREAM; |
124 return decode_SquentialOrgnazation(pPause); | 116 return decode_SquentialOrgnazation(pPause); |
125 } else { | 117 } else { |
126 m_nStreamType = JBIG2_RANDOM_STREAM; | 118 m_nStreamType = JBIG2_RANDOM_STREAM; |
127 return decode_RandomOrgnazation_FirstPage(pPause); | 119 return decode_RandomOrgnazation_FirstPage(pPause); |
128 } | 120 } |
129 failed: | 121 failed: |
130 return nRet; | 122 return nRet; |
131 } | 123 } |
132 int32_t CJBig2_Context::decode_SquentialOrgnazation(IFX_Pause* pPause) { | 124 int32_t CJBig2_Context::decode_SquentialOrgnazation(IFX_Pause* pPause) { |
133 int32_t nRet; | 125 int32_t nRet; |
134 if (m_pStream->getByteLeft() > 0) { | 126 if (m_pStream->getByteLeft() <= 0) |
135 while (m_pStream->getByteLeft() >= JBIG2_MIN_SEGMENT_SIZE) { | 127 return JBIG2_END_OF_FILE; |
136 if (m_pSegment == NULL) { | 128 |
137 JBIG2_ALLOC(m_pSegment, CJBig2_Segment()); | 129 while (m_pStream->getByteLeft() >= JBIG2_MIN_SEGMENT_SIZE) { |
138 nRet = parseSegmentHeader(m_pSegment); | 130 if (!m_pSegment) { |
139 if (nRet != JBIG2_SUCCESS) { | 131 m_pSegment.reset(new CJBig2_Segment); |
140 delete m_pSegment; | 132 nRet = parseSegmentHeader(m_pSegment.get()); |
141 m_pSegment = NULL; | 133 if (nRet != JBIG2_SUCCESS) { |
142 return nRet; | 134 m_pSegment.reset(); |
143 } | |
144 m_dwOffset = m_pStream->getOffset(); | |
145 } | |
146 nRet = parseSegmentData(m_pSegment, pPause); | |
147 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | |
148 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | |
149 m_PauseStep = 2; | |
150 return JBIG2_SUCCESS; | |
151 } | |
152 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) { | |
153 delete m_pSegment; | |
154 m_pSegment = NULL; | |
155 break; | |
156 } else if (nRet != JBIG2_SUCCESS) { | |
157 delete m_pSegment; | |
158 m_pSegment = NULL; | |
159 return nRet; | 135 return nRet; |
160 } | 136 } |
161 m_pSegmentList->addItem(m_pSegment); | 137 m_dwOffset = m_pStream->getOffset(); |
162 if (m_pSegment->m_dwData_length != 0xffffffff) { | |
163 m_dwOffset = m_dwOffset + m_pSegment->m_dwData_length; | |
164 m_pStream->setOffset(m_dwOffset); | |
165 } else { | |
166 m_pStream->offset(4); | |
167 } | |
168 m_pSegment = NULL; | |
169 if (m_pStream->getByteLeft() > 0 && m_pPage && pPause && | |
170 pPause->NeedToPauseNow()) { | |
171 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | |
172 m_PauseStep = 2; | |
173 return JBIG2_SUCCESS; | |
174 } | |
175 } | 138 } |
176 } else { | 139 nRet = parseSegmentData(m_pSegment.get(), pPause); |
177 return JBIG2_END_OF_FILE; | 140 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
141 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | |
142 m_PauseStep = 2; | |
143 return JBIG2_SUCCESS; | |
144 } | |
145 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) { | |
146 m_pSegment.reset(); | |
147 break; | |
148 } else if (nRet != JBIG2_SUCCESS) { | |
Tom Sepez
2015/09/03 20:24:58
nit: else after break.
Lei Zhang
2015/09/03 22:52:12
Done, changed the break to a return as well.
| |
149 m_pSegment.reset(); | |
150 return nRet; | |
151 } | |
152 if (m_pSegment->m_dwData_length != 0xffffffff) { | |
153 m_dwOffset = m_dwOffset + m_pSegment->m_dwData_length; | |
154 m_pStream->setOffset(m_dwOffset); | |
155 } else { | |
156 m_pStream->offset(4); | |
157 } | |
158 m_SegmentList.push_back(m_pSegment.release()); | |
159 if (m_pStream->getByteLeft() > 0 && m_pPage && pPause && | |
160 pPause->NeedToPauseNow()) { | |
161 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | |
162 m_PauseStep = 2; | |
163 return JBIG2_SUCCESS; | |
164 } | |
178 } | 165 } |
179 return JBIG2_SUCCESS; | 166 return JBIG2_SUCCESS; |
180 } | 167 } |
181 int32_t CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause) { | 168 int32_t CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause) { |
182 return decode_SquentialOrgnazation(pPause); | 169 return decode_SquentialOrgnazation(pPause); |
183 } | 170 } |
184 int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) { | 171 int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) { |
185 CJBig2_Segment* pSegment; | |
186 int32_t nRet; | 172 int32_t nRet; |
187 while (m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) { | 173 while (m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) { |
188 JBIG2_ALLOC(pSegment, CJBig2_Segment()); | 174 nonstd::unique_ptr<CJBig2_Segment> pSegment(new CJBig2_Segment); |
189 nRet = parseSegmentHeader(pSegment); | 175 nRet = parseSegmentHeader(pSegment.get()); |
190 if (nRet != JBIG2_SUCCESS) { | 176 if (nRet != JBIG2_SUCCESS) { |
191 delete pSegment; | |
192 return nRet; | 177 return nRet; |
193 } else if (pSegment->m_cFlags.s.type == 51) { | 178 } else if (pSegment->m_cFlags.s.type == 51) { |
194 delete pSegment; | |
195 break; | 179 break; |
196 } | 180 } |
197 m_pSegmentList->addItem(pSegment); | 181 m_SegmentList.push_back(pSegment.release()); |
198 if (pPause && m_pPause && pPause->NeedToPauseNow()) { | 182 if (pPause && m_pPause && pPause->NeedToPauseNow()) { |
199 m_PauseStep = 3; | 183 m_PauseStep = 3; |
200 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 184 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
201 return JBIG2_SUCCESS; | 185 return JBIG2_SUCCESS; |
202 } | 186 } |
203 } | 187 } |
204 m_nSegmentDecoded = 0; | 188 m_nSegmentDecoded = 0; |
205 return decode_RandomOrgnazation(pPause); | 189 return decode_RandomOrgnazation(pPause); |
206 } | 190 } |
207 int32_t CJBig2_Context::decode_RandomOrgnazation(IFX_Pause* pPause) { | 191 int32_t CJBig2_Context::decode_RandomOrgnazation(IFX_Pause* pPause) { |
208 int32_t nRet; | 192 for (; m_nSegmentDecoded < m_SegmentList.size(); ++m_nSegmentDecoded) { |
209 for (; m_nSegmentDecoded < m_pSegmentList->getLength(); m_nSegmentDecoded++) { | 193 int32_t nRet = |
210 nRet = parseSegmentData(m_pSegmentList->getAt(m_nSegmentDecoded), pPause); | 194 parseSegmentData(m_SegmentList.get(m_nSegmentDecoded), pPause); |
211 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) { | 195 if ((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) { |
212 break; | 196 break; |
213 } else if (nRet != JBIG2_SUCCESS) { | 197 } else if (nRet != JBIG2_SUCCESS) { |
Tom Sepez
2015/09/03 20:24:58
nit: else after break
Lei Zhang
2015/09/03 22:52:12
Done, break -> return.
| |
214 return nRet; | 198 return nRet; |
215 } | 199 } |
216 if (m_pPage && pPause && pPause->NeedToPauseNow()) { | 200 if (m_pPage && pPause && pPause->NeedToPauseNow()) { |
217 m_PauseStep = 4; | 201 m_PauseStep = 4; |
218 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 202 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
219 return JBIG2_SUCCESS; | 203 return JBIG2_SUCCESS; |
220 } | 204 } |
221 } | 205 } |
222 return JBIG2_SUCCESS; | 206 return JBIG2_SUCCESS; |
223 } | 207 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); | 289 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); |
306 if (nRet != JBIG2_SUCCESS) { | 290 if (nRet != JBIG2_SUCCESS) { |
307 return nRet; | 291 return nRet; |
308 } | 292 } |
309 } | 293 } |
310 m_bBufSpecified = FALSE; | 294 m_bBufSpecified = FALSE; |
311 return Continue(pPause); | 295 return Continue(pPause); |
312 } | 296 } |
313 CJBig2_Segment* CJBig2_Context::findSegmentByNumber(FX_DWORD dwNumber) { | 297 CJBig2_Segment* CJBig2_Context::findSegmentByNumber(FX_DWORD dwNumber) { |
314 CJBig2_Segment* pSeg; | 298 CJBig2_Segment* pSeg; |
315 int32_t i; | |
316 if (m_pGlobalContext) { | 299 if (m_pGlobalContext) { |
317 pSeg = m_pGlobalContext->findSegmentByNumber(dwNumber); | 300 pSeg = m_pGlobalContext->findSegmentByNumber(dwNumber); |
318 if (pSeg) { | 301 if (pSeg) { |
319 return pSeg; | 302 return pSeg; |
320 } | 303 } |
321 } | 304 } |
322 for (i = 0; i < m_pSegmentList->getLength(); i++) { | 305 for (size_t i = 0; i < m_SegmentList.size(); ++i) { |
323 pSeg = m_pSegmentList->getAt(i); | 306 pSeg = m_SegmentList.get(i); |
324 if (pSeg->m_dwNumber == dwNumber) { | 307 if (pSeg->m_dwNumber == dwNumber) { |
325 return pSeg; | 308 return pSeg; |
326 } | 309 } |
327 } | 310 } |
328 return NULL; | 311 return nullptr; |
329 } | 312 } |
330 CJBig2_Segment* CJBig2_Context::findReferredSegmentByTypeAndIndex( | 313 CJBig2_Segment* CJBig2_Context::findReferredSegmentByTypeAndIndex( |
331 CJBig2_Segment* pSegment, | 314 CJBig2_Segment* pSegment, |
332 uint8_t cType, | 315 uint8_t cType, |
333 int32_t nIndex) { | 316 int32_t nIndex) { |
334 CJBig2_Segment* pSeg; | 317 CJBig2_Segment* pSeg; |
335 int32_t i, count; | 318 int32_t i, count; |
336 count = 0; | 319 count = 0; |
337 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { | 320 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { |
338 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); | 321 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 case 40: | 456 case 40: |
474 case 42: | 457 case 42: |
475 case 43: | 458 case 43: |
476 if (m_nState == JBIG2_OUT_OF_PAGE) { | 459 if (m_nState == JBIG2_OUT_OF_PAGE) { |
477 goto failed2; | 460 goto failed2; |
478 } else { | 461 } else { |
479 return parseGenericRefinementRegion(pSegment); | 462 return parseGenericRefinementRegion(pSegment); |
480 } | 463 } |
481 case 48: { | 464 case 48: { |
482 FX_WORD wTemp; | 465 FX_WORD wTemp; |
483 JBig2PageInfo* pPageInfo; | 466 nonstd::unique_ptr<JBig2PageInfo> pPageInfo(new JBig2PageInfo); |
484 JBIG2_ALLOC(pPageInfo, JBig2PageInfo); | |
485 if ((m_pStream->readInteger(&pPageInfo->m_dwWidth) != 0) || | 467 if ((m_pStream->readInteger(&pPageInfo->m_dwWidth) != 0) || |
486 (m_pStream->readInteger(&pPageInfo->m_dwHeight) != 0) || | 468 (m_pStream->readInteger(&pPageInfo->m_dwHeight) != 0) || |
487 (m_pStream->readInteger(&pPageInfo->m_dwResolutionX) != 0) || | 469 (m_pStream->readInteger(&pPageInfo->m_dwResolutionX) != 0) || |
488 (m_pStream->readInteger(&pPageInfo->m_dwResolutionY) != 0) || | 470 (m_pStream->readInteger(&pPageInfo->m_dwResolutionY) != 0) || |
489 (m_pStream->read1Byte(&pPageInfo->m_cFlags) != 0) || | 471 (m_pStream->read1Byte(&pPageInfo->m_cFlags) != 0) || |
490 (m_pStream->readShortInteger(&wTemp) != 0)) { | 472 (m_pStream->readShortInteger(&wTemp) != 0)) { |
491 delete pPageInfo; | |
492 goto failed1; | 473 goto failed1; |
493 } | 474 } |
494 pPageInfo->m_bIsStriped = ((wTemp >> 15) & 1) ? 1 : 0; | 475 pPageInfo->m_bIsStriped = ((wTemp >> 15) & 1) ? 1 : 0; |
495 pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff; | 476 pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff; |
496 if ((pPageInfo->m_dwHeight == 0xffffffff) && | 477 if ((pPageInfo->m_dwHeight == 0xffffffff) && |
497 (pPageInfo->m_bIsStriped != 1)) { | 478 (pPageInfo->m_bIsStriped != TRUE)) { |
498 m_pModule->JBig2_Warn("page height = 0xffffffff buf stripe field is 0"); | 479 m_pModule->JBig2_Warn("page height = 0xffffffff buf stripe field is 0"); |
499 pPageInfo->m_bIsStriped = 1; | 480 pPageInfo->m_bIsStriped = TRUE; |
500 } | 481 } |
501 if (!m_bBufSpecified) { | 482 if (!m_bBufSpecified) { |
502 delete m_pPage; | 483 delete m_pPage; |
503 if (pPageInfo->m_dwHeight == 0xffffffff) { | 484 if (pPageInfo->m_dwHeight == 0xffffffff) { |
504 JBIG2_ALLOC(m_pPage, CJBig2_Image(pPageInfo->m_dwWidth, | 485 JBIG2_ALLOC(m_pPage, CJBig2_Image(pPageInfo->m_dwWidth, |
505 pPageInfo->m_wMaxStripeSize)); | 486 pPageInfo->m_wMaxStripeSize)); |
506 } else { | 487 } else { |
507 JBIG2_ALLOC(m_pPage, CJBig2_Image(pPageInfo->m_dwWidth, | 488 JBIG2_ALLOC(m_pPage, CJBig2_Image(pPageInfo->m_dwWidth, |
508 pPageInfo->m_dwHeight)); | 489 pPageInfo->m_dwHeight)); |
509 } | 490 } |
510 } | 491 } |
511 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); | 492 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); |
512 m_pPageInfoList->addItem(pPageInfo); | 493 m_PageInfoList.push_back(pPageInfo.release()); |
513 m_nState = JBIG2_IN_PAGE; | 494 m_nState = JBIG2_IN_PAGE; |
514 } break; | 495 } break; |
515 case 49: | 496 case 49: |
516 m_nState = JBIG2_OUT_OF_PAGE; | 497 m_nState = JBIG2_OUT_OF_PAGE; |
517 return JBIG2_END_OF_PAGE; | 498 return JBIG2_END_OF_PAGE; |
518 break; | 499 break; |
519 case 50: | 500 case 50: |
520 m_pStream->offset(pSegment->m_dwData_length); | 501 m_pStream->offset(pSegment->m_dwData_length); |
521 break; | 502 break; |
522 case 51: | 503 case 51: |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 if (pSymbolDictDecoder->SDHUFF == 1) { | 627 if (pSymbolDictDecoder->SDHUFF == 1) { |
647 if ((cSDHUFFDH == 2) || (cSDHUFFDW == 2)) { | 628 if ((cSDHUFFDH == 2) || (cSDHUFFDW == 2)) { |
648 m_pModule->JBig2_Error( | 629 m_pModule->JBig2_Error( |
649 "symbol dictionary segment : SDHUFFDH=2 or SDHUFFDW=2 is not " | 630 "symbol dictionary segment : SDHUFFDH=2 or SDHUFFDW=2 is not " |
650 "permitted."); | 631 "permitted."); |
651 nRet = JBIG2_ERROR_FATAL; | 632 nRet = JBIG2_ERROR_FATAL; |
652 goto failed; | 633 goto failed; |
653 } | 634 } |
654 nIndex = 0; | 635 nIndex = 0; |
655 if (cSDHUFFDH == 0) { | 636 if (cSDHUFFDH == 0) { |
656 JBIG2_ALLOC(Table_B4, CJBig2_HuffmanTable(HuffmanTable_B4, | 637 Table_B4 = new CJBig2_HuffmanTable( |
657 sizeof(HuffmanTable_B4) / | 638 HuffmanTable_B4, sizeof(HuffmanTable_B4) / sizeof(JBig2TableLine), |
Tom Sepez
2015/09/03 20:24:58
nit: use FX_ArraySize() if possible.
Lei Zhang
2015/09/03 22:52:12
Done.
| |
658 sizeof(JBig2TableLine), | 639 HuffmanTable_HTOOB_B4); |
659 HuffmanTable_HTOOB_B4)); | |
660 pSymbolDictDecoder->SDHUFFDH = Table_B4; | 640 pSymbolDictDecoder->SDHUFFDH = Table_B4; |
661 } else if (cSDHUFFDH == 1) { | 641 } else if (cSDHUFFDH == 1) { |
662 JBIG2_ALLOC(Table_B5, CJBig2_HuffmanTable(HuffmanTable_B5, | 642 Table_B5 = new CJBig2_HuffmanTable( |
663 sizeof(HuffmanTable_B5) / | 643 HuffmanTable_B5, sizeof(HuffmanTable_B5) / sizeof(JBig2TableLine), |
664 sizeof(JBig2TableLine), | 644 HuffmanTable_HTOOB_B5); |
665 HuffmanTable_HTOOB_B5)); | |
666 pSymbolDictDecoder->SDHUFFDH = Table_B5; | 645 pSymbolDictDecoder->SDHUFFDH = Table_B5; |
667 } else { | 646 } else { |
668 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 647 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
669 if (!pSeg) { | 648 if (!pSeg) { |
670 m_pModule->JBig2_Error( | 649 m_pModule->JBig2_Error( |
671 "symbol dictionary segment : SDHUFFDH can't find user supplied " | 650 "symbol dictionary segment : SDHUFFDH can't find user supplied " |
672 "table."); | 651 "table."); |
673 nRet = JBIG2_ERROR_FATAL; | 652 nRet = JBIG2_ERROR_FATAL; |
674 goto failed; | 653 goto failed; |
675 } | 654 } |
676 pSymbolDictDecoder->SDHUFFDH = pSeg->m_Result.ht; | 655 pSymbolDictDecoder->SDHUFFDH = pSeg->m_Result.ht; |
677 } | 656 } |
678 if (cSDHUFFDW == 0) { | 657 if (cSDHUFFDW == 0) { |
679 JBIG2_ALLOC(Table_B2, CJBig2_HuffmanTable(HuffmanTable_B2, | 658 Table_B2 = new CJBig2_HuffmanTable( |
680 sizeof(HuffmanTable_B2) / | 659 HuffmanTable_B2, sizeof(HuffmanTable_B2) / sizeof(JBig2TableLine), |
681 sizeof(JBig2TableLine), | 660 HuffmanTable_HTOOB_B2); |
682 HuffmanTable_HTOOB_B2)); | |
683 pSymbolDictDecoder->SDHUFFDW = Table_B2; | 661 pSymbolDictDecoder->SDHUFFDW = Table_B2; |
684 } else if (cSDHUFFDW == 1) { | 662 } else if (cSDHUFFDW == 1) { |
685 JBIG2_ALLOC(Table_B3, CJBig2_HuffmanTable(HuffmanTable_B3, | 663 Table_B3 = new CJBig2_HuffmanTable( |
686 sizeof(HuffmanTable_B3) / | 664 HuffmanTable_B3, sizeof(HuffmanTable_B3) / sizeof(JBig2TableLine), |
687 sizeof(JBig2TableLine), | 665 HuffmanTable_HTOOB_B3); |
688 HuffmanTable_HTOOB_B3)); | |
689 pSymbolDictDecoder->SDHUFFDW = Table_B3; | 666 pSymbolDictDecoder->SDHUFFDW = Table_B3; |
690 } else { | 667 } else { |
691 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 668 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
692 if (!pSeg) { | 669 if (!pSeg) { |
693 m_pModule->JBig2_Error( | 670 m_pModule->JBig2_Error( |
694 "symbol dictionary segment : SDHUFFDW can't find user supplied " | 671 "symbol dictionary segment : SDHUFFDW can't find user supplied " |
695 "table."); | 672 "table."); |
696 nRet = JBIG2_ERROR_FATAL; | 673 nRet = JBIG2_ERROR_FATAL; |
697 goto failed; | 674 goto failed; |
698 } | 675 } |
699 pSymbolDictDecoder->SDHUFFDW = pSeg->m_Result.ht; | 676 pSymbolDictDecoder->SDHUFFDW = pSeg->m_Result.ht; |
700 } | 677 } |
701 if (cSDHUFFBMSIZE == 0) { | 678 if (cSDHUFFBMSIZE == 0) { |
702 JBIG2_ALLOC(Table_B1, CJBig2_HuffmanTable(HuffmanTable_B1, | 679 Table_B1 = new CJBig2_HuffmanTable( |
703 sizeof(HuffmanTable_B1) / | 680 HuffmanTable_B1, sizeof(HuffmanTable_B1) / sizeof(JBig2TableLine), |
704 sizeof(JBig2TableLine), | 681 HuffmanTable_HTOOB_B1); |
705 HuffmanTable_HTOOB_B1)); | |
706 pSymbolDictDecoder->SDHUFFBMSIZE = Table_B1; | 682 pSymbolDictDecoder->SDHUFFBMSIZE = Table_B1; |
707 } else { | 683 } else { |
708 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 684 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
709 if (!pSeg) { | 685 if (!pSeg) { |
710 m_pModule->JBig2_Error( | 686 m_pModule->JBig2_Error( |
711 "symbol dictionary segment : SDHUFFBMSIZE can't find user supplied " | 687 "symbol dictionary segment : SDHUFFBMSIZE can't find user supplied " |
712 "table."); | 688 "table."); |
713 nRet = JBIG2_ERROR_FATAL; | 689 nRet = JBIG2_ERROR_FATAL; |
714 goto failed; | 690 goto failed; |
715 } | 691 } |
716 pSymbolDictDecoder->SDHUFFBMSIZE = pSeg->m_Result.ht; | 692 pSymbolDictDecoder->SDHUFFBMSIZE = pSeg->m_Result.ht; |
717 } | 693 } |
718 if (pSymbolDictDecoder->SDREFAGG == 1) { | 694 if (pSymbolDictDecoder->SDREFAGG == 1) { |
719 if (cSDHUFFAGGINST == 0) { | 695 if (cSDHUFFAGGINST == 0) { |
720 if (!Table_B1) { | 696 if (!Table_B1) { |
721 JBIG2_ALLOC(Table_B1, CJBig2_HuffmanTable(HuffmanTable_B1, | 697 Table_B1 = new CJBig2_HuffmanTable( |
722 sizeof(HuffmanTable_B1) / | 698 HuffmanTable_B1, sizeof(HuffmanTable_B1) / sizeof(JBig2TableLine), |
723 sizeof(JBig2TableLine), | 699 HuffmanTable_HTOOB_B1); |
724 HuffmanTable_HTOOB_B1)); | |
725 } | 700 } |
726 pSymbolDictDecoder->SDHUFFAGGINST = Table_B1; | 701 pSymbolDictDecoder->SDHUFFAGGINST = Table_B1; |
727 } else { | 702 } else { |
728 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 703 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
729 if (!pSeg) { | 704 if (!pSeg) { |
730 m_pModule->JBig2_Error( | 705 m_pModule->JBig2_Error( |
731 "symbol dictionary segment : SDHUFFAGGINST can't find user " | 706 "symbol dictionary segment : SDHUFFAGGINST can't find user " |
732 "supplied table."); | 707 "supplied table."); |
733 nRet = JBIG2_ERROR_FATAL; | 708 nRet = JBIG2_ERROR_FATAL; |
734 goto failed; | 709 goto failed; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
776 if (it->first == key) { | 751 if (it->first == key) { |
777 pSegment->m_Result.sd = it->second->DeepCopy(); | 752 pSegment->m_Result.sd = it->second->DeepCopy(); |
778 m_pSymbolDictCache->push_front(*it); | 753 m_pSymbolDictCache->push_front(*it); |
779 m_pSymbolDictCache->erase(it); | 754 m_pSymbolDictCache->erase(it); |
780 cache_hit = true; | 755 cache_hit = true; |
781 break; | 756 break; |
782 } | 757 } |
783 } | 758 } |
784 if (!cache_hit) { | 759 if (!cache_hit) { |
785 if (pSymbolDictDecoder->SDHUFF == 0) { | 760 if (pSymbolDictDecoder->SDHUFF == 0) { |
786 JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(m_pStream)); | 761 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
787 pSegment->m_Result.sd = | 762 pSegment->m_Result.sd = |
788 pSymbolDictDecoder->decode_Arith(pArithDecoder, gbContext, grContext); | 763 pSymbolDictDecoder->decode_Arith(pArithDecoder, gbContext, grContext); |
789 delete pArithDecoder; | 764 delete pArithDecoder; |
790 if (pSegment->m_Result.sd == NULL) { | 765 if (pSegment->m_Result.sd == NULL) { |
791 nRet = JBIG2_ERROR_FATAL; | 766 nRet = JBIG2_ERROR_FATAL; |
792 goto failed; | 767 goto failed; |
793 } | 768 } |
794 m_pStream->alignByte(); | 769 m_pStream->alignByte(); |
795 m_pStream->offset(2); | 770 m_pStream->offset(2); |
796 } else { | 771 } else { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
980 if ((cSBHUFFFS == 2) || (cSBHUFFRDW == 2) || (cSBHUFFRDH == 2) || | 955 if ((cSBHUFFFS == 2) || (cSBHUFFRDW == 2) || (cSBHUFFRDH == 2) || |
981 (cSBHUFFRDX == 2) || (cSBHUFFRDY == 2)) { | 956 (cSBHUFFRDX == 2) || (cSBHUFFRDY == 2)) { |
982 m_pModule->JBig2_Error( | 957 m_pModule->JBig2_Error( |
983 "text region segment : SBHUFFFS=2 or SBHUFFRDW=2 or " | 958 "text region segment : SBHUFFFS=2 or SBHUFFRDW=2 or " |
984 "SBHUFFRDH=2 or SBHUFFRDX=2 or SBHUFFRDY=2 is not permitted"); | 959 "SBHUFFRDH=2 or SBHUFFRDX=2 or SBHUFFRDY=2 is not permitted"); |
985 nRet = JBIG2_ERROR_FATAL; | 960 nRet = JBIG2_ERROR_FATAL; |
986 goto failed; | 961 goto failed; |
987 } | 962 } |
988 nIndex = 0; | 963 nIndex = 0; |
989 if (cSBHUFFFS == 0) { | 964 if (cSBHUFFFS == 0) { |
990 JBIG2_ALLOC(Table_B6, CJBig2_HuffmanTable(HuffmanTable_B6, | 965 Table_B6 = new CJBig2_HuffmanTable( |
991 sizeof(HuffmanTable_B6) / | 966 HuffmanTable_B6, sizeof(HuffmanTable_B6) / sizeof(JBig2TableLine), |
992 sizeof(JBig2TableLine), | 967 HuffmanTable_HTOOB_B6); |
993 HuffmanTable_HTOOB_B6)); | |
994 pTRD->SBHUFFFS = Table_B6; | 968 pTRD->SBHUFFFS = Table_B6; |
995 } else if (cSBHUFFFS == 1) { | 969 } else if (cSBHUFFFS == 1) { |
996 JBIG2_ALLOC(Table_B7, CJBig2_HuffmanTable(HuffmanTable_B7, | 970 Table_B7 = new CJBig2_HuffmanTable( |
997 sizeof(HuffmanTable_B7) / | 971 HuffmanTable_B7, sizeof(HuffmanTable_B7) / sizeof(JBig2TableLine), |
998 sizeof(JBig2TableLine), | 972 HuffmanTable_HTOOB_B7); |
999 HuffmanTable_HTOOB_B7)); | |
1000 pTRD->SBHUFFFS = Table_B7; | 973 pTRD->SBHUFFFS = Table_B7; |
1001 } else { | 974 } else { |
1002 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 975 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
1003 if (!pSeg) { | 976 if (!pSeg) { |
1004 m_pModule->JBig2_Error( | 977 m_pModule->JBig2_Error( |
1005 "text region segment : SBHUFFFS can't find user supplied table"); | 978 "text region segment : SBHUFFFS can't find user supplied table"); |
1006 nRet = JBIG2_ERROR_FATAL; | 979 nRet = JBIG2_ERROR_FATAL; |
1007 goto failed; | 980 goto failed; |
1008 } | 981 } |
1009 pTRD->SBHUFFFS = pSeg->m_Result.ht; | 982 pTRD->SBHUFFFS = pSeg->m_Result.ht; |
1010 } | 983 } |
1011 if (cSBHUFFDS == 0) { | 984 if (cSBHUFFDS == 0) { |
1012 JBIG2_ALLOC(Table_B8, CJBig2_HuffmanTable(HuffmanTable_B8, | 985 Table_B8 = new CJBig2_HuffmanTable( |
1013 sizeof(HuffmanTable_B8) / | 986 HuffmanTable_B8, sizeof(HuffmanTable_B8) / sizeof(JBig2TableLine), |
1014 sizeof(JBig2TableLine), | 987 HuffmanTable_HTOOB_B8); |
1015 HuffmanTable_HTOOB_B8)); | |
1016 pTRD->SBHUFFDS = Table_B8; | 988 pTRD->SBHUFFDS = Table_B8; |
1017 } else if (cSBHUFFDS == 1) { | 989 } else if (cSBHUFFDS == 1) { |
1018 JBIG2_ALLOC(Table_B9, CJBig2_HuffmanTable(HuffmanTable_B9, | 990 Table_B9 = new CJBig2_HuffmanTable( |
1019 sizeof(HuffmanTable_B9) / | 991 HuffmanTable_B9, sizeof(HuffmanTable_B9) / sizeof(JBig2TableLine), |
1020 sizeof(JBig2TableLine), | 992 HuffmanTable_HTOOB_B9); |
1021 HuffmanTable_HTOOB_B9)); | |
1022 pTRD->SBHUFFDS = Table_B9; | 993 pTRD->SBHUFFDS = Table_B9; |
1023 } else if (cSBHUFFDS == 2) { | 994 } else if (cSBHUFFDS == 2) { |
1024 JBIG2_ALLOC(Table_B10, CJBig2_HuffmanTable(HuffmanTable_B10, | 995 Table_B10 = new CJBig2_HuffmanTable( |
1025 sizeof(HuffmanTable_B10) / | 996 HuffmanTable_B10, sizeof(HuffmanTable_B10) / sizeof(JBig2TableLine), |
1026 sizeof(JBig2TableLine), | 997 HuffmanTable_HTOOB_B10); |
1027 HuffmanTable_HTOOB_B10)); | |
1028 pTRD->SBHUFFDS = Table_B10; | 998 pTRD->SBHUFFDS = Table_B10; |
1029 } else { | 999 } else { |
1030 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 1000 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
1031 if (!pSeg) { | 1001 if (!pSeg) { |
1032 m_pModule->JBig2_Error( | 1002 m_pModule->JBig2_Error( |
1033 "text region segment : SBHUFFDS can't find user supplied table"); | 1003 "text region segment : SBHUFFDS can't find user supplied table"); |
1034 nRet = JBIG2_ERROR_FATAL; | 1004 nRet = JBIG2_ERROR_FATAL; |
1035 goto failed; | 1005 goto failed; |
1036 } | 1006 } |
1037 pTRD->SBHUFFDS = pSeg->m_Result.ht; | 1007 pTRD->SBHUFFDS = pSeg->m_Result.ht; |
1038 } | 1008 } |
1039 if (cSBHUFFDT == 0) { | 1009 if (cSBHUFFDT == 0) { |
1040 JBIG2_ALLOC(Table_B11, CJBig2_HuffmanTable(HuffmanTable_B11, | 1010 Table_B11 = new CJBig2_HuffmanTable( |
1041 sizeof(HuffmanTable_B11) / | 1011 HuffmanTable_B11, sizeof(HuffmanTable_B11) / sizeof(JBig2TableLine), |
1042 sizeof(JBig2TableLine), | 1012 HuffmanTable_HTOOB_B11); |
1043 HuffmanTable_HTOOB_B11)); | |
1044 pTRD->SBHUFFDT = Table_B11; | 1013 pTRD->SBHUFFDT = Table_B11; |
1045 } else if (cSBHUFFDT == 1) { | 1014 } else if (cSBHUFFDT == 1) { |
1046 JBIG2_ALLOC(Table_B12, CJBig2_HuffmanTable(HuffmanTable_B12, | 1015 Table_B12 = new CJBig2_HuffmanTable( |
1047 sizeof(HuffmanTable_B12) / | 1016 HuffmanTable_B12, sizeof(HuffmanTable_B12) / sizeof(JBig2TableLine), |
1048 sizeof(JBig2TableLine), | 1017 HuffmanTable_HTOOB_B12); |
1049 HuffmanTable_HTOOB_B12)); | |
1050 pTRD->SBHUFFDT = Table_B12; | 1018 pTRD->SBHUFFDT = Table_B12; |
1051 } else if (cSBHUFFDT == 2) { | 1019 } else if (cSBHUFFDT == 2) { |
1052 JBIG2_ALLOC(Table_B13, CJBig2_HuffmanTable(HuffmanTable_B13, | 1020 Table_B13 = new CJBig2_HuffmanTable( |
1053 sizeof(HuffmanTable_B13) / | 1021 HuffmanTable_B13, sizeof(HuffmanTable_B13) / sizeof(JBig2TableLine), |
1054 sizeof(JBig2TableLine), | 1022 HuffmanTable_HTOOB_B13); |
1055 HuffmanTable_HTOOB_B13)); | |
1056 pTRD->SBHUFFDT = Table_B13; | 1023 pTRD->SBHUFFDT = Table_B13; |
1057 } else { | 1024 } else { |
1058 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 1025 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
1059 if (!pSeg) { | 1026 if (!pSeg) { |
1060 m_pModule->JBig2_Error( | 1027 m_pModule->JBig2_Error( |
1061 "text region segment : SBHUFFDT can't find user supplied table"); | 1028 "text region segment : SBHUFFDT can't find user supplied table"); |
1062 nRet = JBIG2_ERROR_FATAL; | 1029 nRet = JBIG2_ERROR_FATAL; |
1063 goto failed; | 1030 goto failed; |
1064 } | 1031 } |
1065 pTRD->SBHUFFDT = pSeg->m_Result.ht; | 1032 pTRD->SBHUFFDT = pSeg->m_Result.ht; |
1066 } | 1033 } |
1067 if (cSBHUFFRDW == 0) { | 1034 if (cSBHUFFRDW == 0) { |
1068 JBIG2_ALLOC(Table_B14, CJBig2_HuffmanTable(HuffmanTable_B14, | 1035 Table_B14 = new CJBig2_HuffmanTable( |
1069 sizeof(HuffmanTable_B14) / | 1036 HuffmanTable_B14, sizeof(HuffmanTable_B14) / sizeof(JBig2TableLine), |
1070 sizeof(JBig2TableLine), | 1037 HuffmanTable_HTOOB_B14); |
1071 HuffmanTable_HTOOB_B14)); | |
1072 pTRD->SBHUFFRDW = Table_B14; | 1038 pTRD->SBHUFFRDW = Table_B14; |
1073 } else if (cSBHUFFRDW == 1) { | 1039 } else if (cSBHUFFRDW == 1) { |
1074 JBIG2_ALLOC(Table_B15, CJBig2_HuffmanTable(HuffmanTable_B15, | 1040 Table_B15 = new CJBig2_HuffmanTable( |
1075 sizeof(HuffmanTable_B15) / | 1041 HuffmanTable_B15, sizeof(HuffmanTable_B15) / sizeof(JBig2TableLine), |
1076 sizeof(JBig2TableLine), | 1042 HuffmanTable_HTOOB_B15); |
1077 HuffmanTable_HTOOB_B15)); | |
1078 pTRD->SBHUFFRDW = Table_B15; | 1043 pTRD->SBHUFFRDW = Table_B15; |
1079 } else { | 1044 } else { |
1080 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 1045 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
1081 if (!pSeg) { | 1046 if (!pSeg) { |
1082 m_pModule->JBig2_Error( | 1047 m_pModule->JBig2_Error( |
1083 "text region segment : SBHUFFRDW can't find user supplied table"); | 1048 "text region segment : SBHUFFRDW can't find user supplied table"); |
1084 nRet = JBIG2_ERROR_FATAL; | 1049 nRet = JBIG2_ERROR_FATAL; |
1085 goto failed; | 1050 goto failed; |
1086 } | 1051 } |
1087 pTRD->SBHUFFRDW = pSeg->m_Result.ht; | 1052 pTRD->SBHUFFRDW = pSeg->m_Result.ht; |
1088 } | 1053 } |
1089 if (cSBHUFFRDH == 0) { | 1054 if (cSBHUFFRDH == 0) { |
1090 if (!Table_B14) { | 1055 if (!Table_B14) { |
1091 JBIG2_ALLOC(Table_B14, CJBig2_HuffmanTable(HuffmanTable_B14, | 1056 Table_B14 = new CJBig2_HuffmanTable( |
1092 sizeof(HuffmanTable_B14) / | 1057 HuffmanTable_B14, sizeof(HuffmanTable_B14) / sizeof(JBig2TableLine), |
1093 sizeof(JBig2TableLine), | 1058 HuffmanTable_HTOOB_B14); |
1094 HuffmanTable_HTOOB_B14)); | |
1095 } | 1059 } |
1096 pTRD->SBHUFFRDH = Table_B14; | 1060 pTRD->SBHUFFRDH = Table_B14; |
1097 } else if (cSBHUFFRDH == 1) { | 1061 } else if (cSBHUFFRDH == 1) { |
1098 if (!Table_B15) { | 1062 if (!Table_B15) { |
1099 JBIG2_ALLOC(Table_B15, CJBig2_HuffmanTable(HuffmanTable_B15, | 1063 Table_B15 = new CJBig2_HuffmanTable( |
1100 sizeof(HuffmanTable_B15) / | 1064 HuffmanTable_B15, sizeof(HuffmanTable_B15) / sizeof(JBig2TableLine), |
1101 sizeof(JBig2TableLine), | 1065 HuffmanTable_HTOOB_B15); |
1102 HuffmanTable_HTOOB_B15)); | |
1103 } | 1066 } |
1104 pTRD->SBHUFFRDH = Table_B15; | 1067 pTRD->SBHUFFRDH = Table_B15; |
1105 } else { | 1068 } else { |
1106 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 1069 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
1107 if (!pSeg) { | 1070 if (!pSeg) { |
1108 m_pModule->JBig2_Error( | 1071 m_pModule->JBig2_Error( |
1109 "text region segment : SBHUFFRDH can't find user supplied table"); | 1072 "text region segment : SBHUFFRDH can't find user supplied table"); |
1110 nRet = JBIG2_ERROR_FATAL; | 1073 nRet = JBIG2_ERROR_FATAL; |
1111 goto failed; | 1074 goto failed; |
1112 } | 1075 } |
1113 pTRD->SBHUFFRDH = pSeg->m_Result.ht; | 1076 pTRD->SBHUFFRDH = pSeg->m_Result.ht; |
1114 } | 1077 } |
1115 if (cSBHUFFRDX == 0) { | 1078 if (cSBHUFFRDX == 0) { |
1116 if (!Table_B14) { | 1079 if (!Table_B14) { |
1117 JBIG2_ALLOC(Table_B14, CJBig2_HuffmanTable(HuffmanTable_B14, | 1080 Table_B14 = new CJBig2_HuffmanTable( |
1118 sizeof(HuffmanTable_B14) / | 1081 HuffmanTable_B14, sizeof(HuffmanTable_B14) / sizeof(JBig2TableLine), |
1119 sizeof(JBig2TableLine), | 1082 HuffmanTable_HTOOB_B14); |
1120 HuffmanTable_HTOOB_B14)); | |
1121 } | 1083 } |
1122 pTRD->SBHUFFRDX = Table_B14; | 1084 pTRD->SBHUFFRDX = Table_B14; |
1123 } else if (cSBHUFFRDX == 1) { | 1085 } else if (cSBHUFFRDX == 1) { |
1124 if (!Table_B15) { | 1086 if (!Table_B15) { |
1125 JBIG2_ALLOC(Table_B15, CJBig2_HuffmanTable(HuffmanTable_B15, | 1087 Table_B15 = new CJBig2_HuffmanTable( |
1126 sizeof(HuffmanTable_B15) / | 1088 HuffmanTable_B15, sizeof(HuffmanTable_B15) / sizeof(JBig2TableLine), |
1127 sizeof(JBig2TableLine), | 1089 HuffmanTable_HTOOB_B15); |
1128 HuffmanTable_HTOOB_B15)); | |
1129 } | 1090 } |
1130 pTRD->SBHUFFRDX = Table_B15; | 1091 pTRD->SBHUFFRDX = Table_B15; |
1131 } else { | 1092 } else { |
1132 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 1093 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
1133 if (!pSeg) { | 1094 if (!pSeg) { |
1134 m_pModule->JBig2_Error( | 1095 m_pModule->JBig2_Error( |
1135 "text region segment : SBHUFFRDX can't find user supplied table"); | 1096 "text region segment : SBHUFFRDX can't find user supplied table"); |
1136 nRet = JBIG2_ERROR_FATAL; | 1097 nRet = JBIG2_ERROR_FATAL; |
1137 goto failed; | 1098 goto failed; |
1138 } | 1099 } |
1139 pTRD->SBHUFFRDX = pSeg->m_Result.ht; | 1100 pTRD->SBHUFFRDX = pSeg->m_Result.ht; |
1140 } | 1101 } |
1141 if (cSBHUFFRDY == 0) { | 1102 if (cSBHUFFRDY == 0) { |
1142 if (!Table_B14) { | 1103 if (!Table_B14) { |
1143 JBIG2_ALLOC(Table_B14, CJBig2_HuffmanTable(HuffmanTable_B14, | 1104 Table_B14 = new CJBig2_HuffmanTable( |
1144 sizeof(HuffmanTable_B14) / | 1105 HuffmanTable_B14, sizeof(HuffmanTable_B14) / sizeof(JBig2TableLine), |
1145 sizeof(JBig2TableLine), | 1106 HuffmanTable_HTOOB_B14); |
1146 HuffmanTable_HTOOB_B14)); | |
1147 } | 1107 } |
1148 pTRD->SBHUFFRDY = Table_B14; | 1108 pTRD->SBHUFFRDY = Table_B14; |
1149 } else if (cSBHUFFRDY == 1) { | 1109 } else if (cSBHUFFRDY == 1) { |
1150 if (!Table_B15) { | 1110 if (!Table_B15) { |
1151 JBIG2_ALLOC(Table_B15, CJBig2_HuffmanTable(HuffmanTable_B15, | 1111 Table_B15 = new CJBig2_HuffmanTable( |
1152 sizeof(HuffmanTable_B15) / | 1112 HuffmanTable_B15, sizeof(HuffmanTable_B15) / sizeof(JBig2TableLine), |
1153 sizeof(JBig2TableLine), | 1113 HuffmanTable_HTOOB_B15); |
1154 HuffmanTable_HTOOB_B15)); | |
1155 } | 1114 } |
1156 pTRD->SBHUFFRDY = Table_B15; | 1115 pTRD->SBHUFFRDY = Table_B15; |
1157 } else { | 1116 } else { |
1158 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 1117 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
1159 if (!pSeg) { | 1118 if (!pSeg) { |
1160 m_pModule->JBig2_Error( | 1119 m_pModule->JBig2_Error( |
1161 "text region segment : SBHUFFRDY can't find user supplied table"); | 1120 "text region segment : SBHUFFRDY can't find user supplied table"); |
1162 nRet = JBIG2_ERROR_FATAL; | 1121 nRet = JBIG2_ERROR_FATAL; |
1163 goto failed; | 1122 goto failed; |
1164 } | 1123 } |
1165 pTRD->SBHUFFRDY = pSeg->m_Result.ht; | 1124 pTRD->SBHUFFRDY = pSeg->m_Result.ht; |
1166 } | 1125 } |
1167 if (cSBHUFFRSIZE == 0) { | 1126 if (cSBHUFFRSIZE == 0) { |
1168 JBIG2_ALLOC(Table_B1, CJBig2_HuffmanTable(HuffmanTable_B1, | 1127 Table_B1 = new CJBig2_HuffmanTable( |
1169 sizeof(HuffmanTable_B1) / | 1128 HuffmanTable_B1, sizeof(HuffmanTable_B1) / sizeof(JBig2TableLine), |
1170 sizeof(JBig2TableLine), | 1129 HuffmanTable_HTOOB_B1); |
1171 HuffmanTable_HTOOB_B1)); | |
1172 pTRD->SBHUFFRSIZE = Table_B1; | 1130 pTRD->SBHUFFRSIZE = Table_B1; |
1173 } else { | 1131 } else { |
1174 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 1132 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
1175 if (!pSeg) { | 1133 if (!pSeg) { |
1176 m_pModule->JBig2_Error( | 1134 m_pModule->JBig2_Error( |
1177 "text region segment : SBHUFFRSIZE can't find user supplied table"); | 1135 "text region segment : SBHUFFRSIZE can't find user supplied table"); |
1178 nRet = JBIG2_ERROR_FATAL; | 1136 nRet = JBIG2_ERROR_FATAL; |
1179 goto failed; | 1137 goto failed; |
1180 } | 1138 } |
1181 pTRD->SBHUFFRSIZE = pSeg->m_Result.ht; | 1139 pTRD->SBHUFFRSIZE = pSeg->m_Result.ht; |
1182 } | 1140 } |
1183 } | 1141 } |
1184 if (pTRD->SBREFINE == 1) { | 1142 if (pTRD->SBREFINE == 1) { |
1185 dwTemp = pTRD->SBRTEMPLATE ? 1 << 10 : 1 << 13; | 1143 dwTemp = pTRD->SBRTEMPLATE ? 1 << 10 : 1 << 13; |
1186 grContext = | 1144 grContext = |
1187 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); | 1145 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); |
1188 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1146 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1189 } | 1147 } |
1190 if (pTRD->SBHUFF == 0) { | 1148 if (pTRD->SBHUFF == 0) { |
1191 JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(m_pStream)); | 1149 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
1192 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1150 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1193 pSegment->m_Result.im = pTRD->decode_Arith(pArithDecoder, grContext); | 1151 pSegment->m_Result.im = pTRD->decode_Arith(pArithDecoder, grContext); |
1194 delete pArithDecoder; | 1152 delete pArithDecoder; |
1195 if (pSegment->m_Result.im == NULL) { | 1153 if (pSegment->m_Result.im == NULL) { |
1196 nRet = JBIG2_ERROR_FATAL; | 1154 nRet = JBIG2_ERROR_FATAL; |
1197 goto failed; | 1155 goto failed; |
1198 } | 1156 } |
1199 m_pStream->alignByte(); | 1157 m_pStream->alignByte(); |
1200 m_pStream->offset(2); | 1158 m_pStream->offset(2); |
1201 } else { | 1159 } else { |
1202 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1160 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1203 pSegment->m_Result.im = pTRD->decode_Huffman(m_pStream, grContext); | 1161 pSegment->m_Result.im = pTRD->decode_Huffman(m_pStream, grContext); |
1204 if (pSegment->m_Result.im == NULL) { | 1162 if (pSegment->m_Result.im == NULL) { |
1205 nRet = JBIG2_ERROR_FATAL; | 1163 nRet = JBIG2_ERROR_FATAL; |
1206 goto failed; | 1164 goto failed; |
1207 } | 1165 } |
1208 m_pStream->alignByte(); | 1166 m_pStream->alignByte(); |
1209 } | 1167 } |
1210 if (pSegment->m_cFlags.s.type != 4) { | 1168 if (pSegment->m_cFlags.s.type != 4) { |
1211 if (!m_bBufSpecified) { | 1169 if (!m_bBufSpecified) { |
1212 JBig2PageInfo* pPageInfo = m_pPageInfoList->getLast(); | 1170 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1213 if ((pPageInfo->m_bIsStriped == 1) && | 1171 if ((pPageInfo->m_bIsStriped == 1) && |
1214 (ri.y + ri.height > m_pPage->m_nHeight)) { | 1172 (ri.y + ri.height > m_pPage->m_nHeight)) { |
1215 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1173 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); |
1216 } | 1174 } |
1217 } | 1175 } |
1218 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, | 1176 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, |
1219 (JBig2ComposeOp)(ri.flags & 0x03)); | 1177 (JBig2ComposeOp)(ri.flags & 0x03)); |
1220 delete pSegment->m_Result.im; | 1178 delete pSegment->m_Result.im; |
1221 pSegment->m_Result.im = NULL; | 1179 pSegment->m_Result.im = NULL; |
1222 } | 1180 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1292 } | 1250 } |
1293 pPDD->HDMMR = cFlags & 0x01; | 1251 pPDD->HDMMR = cFlags & 0x01; |
1294 pPDD->HDTEMPLATE = (cFlags >> 1) & 0x03; | 1252 pPDD->HDTEMPLATE = (cFlags >> 1) & 0x03; |
1295 pSegment->m_nResultType = JBIG2_PATTERN_DICT_POINTER; | 1253 pSegment->m_nResultType = JBIG2_PATTERN_DICT_POINTER; |
1296 if (pPDD->HDMMR == 0) { | 1254 if (pPDD->HDMMR == 0) { |
1297 dwTemp = | 1255 dwTemp = |
1298 pPDD->HDTEMPLATE == 0 ? 65536 : pPDD->HDTEMPLATE == 1 ? 8192 : 1024; | 1256 pPDD->HDTEMPLATE == 0 ? 65536 : pPDD->HDTEMPLATE == 1 ? 8192 : 1024; |
1299 gbContext = | 1257 gbContext = |
1300 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); | 1258 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); |
1301 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1259 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1302 JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(m_pStream)); | 1260 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
1303 pSegment->m_Result.pd = | 1261 pSegment->m_Result.pd = |
1304 pPDD->decode_Arith(pArithDecoder, gbContext, pPause); | 1262 pPDD->decode_Arith(pArithDecoder, gbContext, pPause); |
1305 delete pArithDecoder; | 1263 delete pArithDecoder; |
1306 if (pSegment->m_Result.pd == NULL) { | 1264 if (pSegment->m_Result.pd == NULL) { |
1307 m_pModule->JBig2_Free(gbContext); | 1265 m_pModule->JBig2_Free(gbContext); |
1308 nRet = JBIG2_ERROR_FATAL; | 1266 nRet = JBIG2_ERROR_FATAL; |
1309 goto failed; | 1267 goto failed; |
1310 } | 1268 } |
1311 m_pModule->JBig2_Free(gbContext); | 1269 m_pModule->JBig2_Free(gbContext); |
1312 m_pStream->alignByte(); | 1270 m_pStream->alignByte(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1378 pHRD->HNUMPATS = pPatternDict->NUMPATS; | 1336 pHRD->HNUMPATS = pPatternDict->NUMPATS; |
1379 pHRD->HPATS = pPatternDict->HDPATS; | 1337 pHRD->HPATS = pPatternDict->HDPATS; |
1380 pHRD->HPW = pPatternDict->HDPATS[0]->m_nWidth; | 1338 pHRD->HPW = pPatternDict->HDPATS[0]->m_nWidth; |
1381 pHRD->HPH = pPatternDict->HDPATS[0]->m_nHeight; | 1339 pHRD->HPH = pPatternDict->HDPATS[0]->m_nHeight; |
1382 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1340 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1383 if (pHRD->HMMR == 0) { | 1341 if (pHRD->HMMR == 0) { |
1384 dwTemp = pHRD->HTEMPLATE == 0 ? 65536 : pHRD->HTEMPLATE == 1 ? 8192 : 1024; | 1342 dwTemp = pHRD->HTEMPLATE == 0 ? 65536 : pHRD->HTEMPLATE == 1 ? 8192 : 1024; |
1385 gbContext = | 1343 gbContext = |
1386 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); | 1344 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); |
1387 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1345 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1388 JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(m_pStream)); | 1346 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
1389 pSegment->m_Result.im = | 1347 pSegment->m_Result.im = |
1390 pHRD->decode_Arith(pArithDecoder, gbContext, pPause); | 1348 pHRD->decode_Arith(pArithDecoder, gbContext, pPause); |
1391 delete pArithDecoder; | 1349 delete pArithDecoder; |
1392 if (pSegment->m_Result.im == NULL) { | 1350 if (pSegment->m_Result.im == NULL) { |
1393 m_pModule->JBig2_Free(gbContext); | 1351 m_pModule->JBig2_Free(gbContext); |
1394 nRet = JBIG2_ERROR_FATAL; | 1352 nRet = JBIG2_ERROR_FATAL; |
1395 goto failed; | 1353 goto failed; |
1396 } | 1354 } |
1397 m_pModule->JBig2_Free(gbContext); | 1355 m_pModule->JBig2_Free(gbContext); |
1398 m_pStream->alignByte(); | 1356 m_pStream->alignByte(); |
1399 m_pStream->offset(2); | 1357 m_pStream->offset(2); |
1400 } else { | 1358 } else { |
1401 pSegment->m_Result.im = pHRD->decode_MMR(m_pStream, pPause); | 1359 pSegment->m_Result.im = pHRD->decode_MMR(m_pStream, pPause); |
1402 if (pSegment->m_Result.im == NULL) { | 1360 if (pSegment->m_Result.im == NULL) { |
1403 nRet = JBIG2_ERROR_FATAL; | 1361 nRet = JBIG2_ERROR_FATAL; |
1404 goto failed; | 1362 goto failed; |
1405 } | 1363 } |
1406 m_pStream->alignByte(); | 1364 m_pStream->alignByte(); |
1407 } | 1365 } |
1408 if (pSegment->m_cFlags.s.type != 20) { | 1366 if (pSegment->m_cFlags.s.type != 20) { |
1409 if (!m_bBufSpecified) { | 1367 if (!m_bBufSpecified) { |
1410 JBig2PageInfo* pPageInfo = m_pPageInfoList->getLast(); | 1368 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1411 if ((pPageInfo->m_bIsStriped == 1) && | 1369 if ((pPageInfo->m_bIsStriped == 1) && |
1412 (ri.y + ri.height > m_pPage->m_nHeight)) { | 1370 (ri.y + ri.height > m_pPage->m_nHeight)) { |
1413 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1371 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); |
1414 } | 1372 } |
1415 } | 1373 } |
1416 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, | 1374 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, |
1417 (JBig2ComposeOp)(ri.flags & 0x03)); | 1375 (JBig2ComposeOp)(ri.flags & 0x03)); |
1418 delete pSegment->m_Result.im; | 1376 delete pSegment->m_Result.im; |
1419 pSegment->m_Result.im = NULL; | 1377 pSegment->m_Result.im = NULL; |
1420 } | 1378 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1474 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1432 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1475 if (m_pGRD->MMR == 0) { | 1433 if (m_pGRD->MMR == 0) { |
1476 dwTemp = | 1434 dwTemp = |
1477 m_pGRD->GBTEMPLATE == 0 ? 65536 : m_pGRD->GBTEMPLATE == 1 ? 8192 : 1024; | 1435 m_pGRD->GBTEMPLATE == 0 ? 65536 : m_pGRD->GBTEMPLATE == 1 ? 8192 : 1024; |
1478 if (m_gbContext == NULL) { | 1436 if (m_gbContext == NULL) { |
1479 m_gbContext = (JBig2ArithCtx*)m_pModule->JBig2_Malloc( | 1437 m_gbContext = (JBig2ArithCtx*)m_pModule->JBig2_Malloc( |
1480 sizeof(JBig2ArithCtx) * dwTemp); | 1438 sizeof(JBig2ArithCtx) * dwTemp); |
1481 JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1439 JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1482 } | 1440 } |
1483 if (m_pArithDecoder == NULL) { | 1441 if (m_pArithDecoder == NULL) { |
1484 JBIG2_ALLOC(m_pArithDecoder, CJBig2_ArithDecoder(m_pStream)); | 1442 m_pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
1485 m_ProcessiveStatus = m_pGRD->Start_decode_Arith( | 1443 m_ProcessiveStatus = m_pGRD->Start_decode_Arith( |
1486 &pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause); | 1444 &pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause); |
1487 } else { | 1445 } else { |
1488 m_ProcessiveStatus = m_pGRD->Continue_decode(pPause); | 1446 m_ProcessiveStatus = m_pGRD->Continue_decode(pPause); |
1489 } | 1447 } |
1490 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 1448 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
1491 if (pSegment->m_cFlags.s.type != 36) { | 1449 if (pSegment->m_cFlags.s.type != 36) { |
1492 if (!m_bBufSpecified) { | 1450 if (!m_bBufSpecified) { |
1493 JBig2PageInfo* pPageInfo = m_pPageInfoList->getLast(); | 1451 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1494 if ((pPageInfo->m_bIsStriped == 1) && | 1452 if ((pPageInfo->m_bIsStriped == 1) && |
1495 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { | 1453 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { |
1496 m_pPage->expand(m_ri.y + m_ri.height, | 1454 m_pPage->expand(m_ri.y + m_ri.height, |
1497 (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1455 (pPageInfo->m_cFlags & 4) ? 1 : 0); |
1498 } | 1456 } |
1499 } | 1457 } |
1500 FX_RECT Rect = m_pGRD->GetReplaceRect(); | 1458 FX_RECT Rect = m_pGRD->GetReplaceRect(); |
1501 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, | 1459 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, |
1502 pSegment->m_Result.im, | 1460 pSegment->m_Result.im, |
1503 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); | 1461 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); |
(...skipping 21 matching lines...) Expand all Loading... | |
1525 m_pGRD->Continue_decode(pPause); | 1483 m_pGRD->Continue_decode(pPause); |
1526 } | 1484 } |
1527 if (pSegment->m_Result.im == NULL) { | 1485 if (pSegment->m_Result.im == NULL) { |
1528 nRet = JBIG2_ERROR_FATAL; | 1486 nRet = JBIG2_ERROR_FATAL; |
1529 goto failed; | 1487 goto failed; |
1530 } | 1488 } |
1531 m_pStream->alignByte(); | 1489 m_pStream->alignByte(); |
1532 } | 1490 } |
1533 if (pSegment->m_cFlags.s.type != 36) { | 1491 if (pSegment->m_cFlags.s.type != 36) { |
1534 if (!m_bBufSpecified) { | 1492 if (!m_bBufSpecified) { |
1535 JBig2PageInfo* pPageInfo = m_pPageInfoList->getLast(); | 1493 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1536 if ((pPageInfo->m_bIsStriped == 1) && | 1494 if ((pPageInfo->m_bIsStriped == 1) && |
1537 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { | 1495 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { |
1538 m_pPage->expand(m_ri.y + m_ri.height, | 1496 m_pPage->expand(m_ri.y + m_ri.height, |
1539 (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1497 (pPageInfo->m_cFlags & 4) ? 1 : 0); |
1540 } | 1498 } |
1541 } | 1499 } |
1542 FX_RECT Rect = m_pGRD->GetReplaceRect(); | 1500 FX_RECT Rect = m_pGRD->GetReplaceRect(); |
1543 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, | 1501 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, |
1544 pSegment->m_Result.im, | 1502 pSegment->m_Result.im, |
1545 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); | 1503 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1612 pGRRD->GRREFERENCE = pSeg->m_Result.im; | 1570 pGRRD->GRREFERENCE = pSeg->m_Result.im; |
1613 } else { | 1571 } else { |
1614 pGRRD->GRREFERENCE = m_pPage; | 1572 pGRRD->GRREFERENCE = m_pPage; |
1615 } | 1573 } |
1616 pGRRD->GRREFERENCEDX = 0; | 1574 pGRRD->GRREFERENCEDX = 0; |
1617 pGRRD->GRREFERENCEDY = 0; | 1575 pGRRD->GRREFERENCEDY = 0; |
1618 dwTemp = pGRRD->GRTEMPLATE ? 1 << 10 : 1 << 13; | 1576 dwTemp = pGRRD->GRTEMPLATE ? 1 << 10 : 1 << 13; |
1619 grContext = | 1577 grContext = |
1620 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); | 1578 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); |
1621 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1579 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
1622 JBIG2_ALLOC(pArithDecoder, CJBig2_ArithDecoder(m_pStream)); | 1580 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
1623 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1581 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
1624 pSegment->m_Result.im = pGRRD->decode(pArithDecoder, grContext); | 1582 pSegment->m_Result.im = pGRRD->decode(pArithDecoder, grContext); |
1625 delete pArithDecoder; | 1583 delete pArithDecoder; |
1626 if (pSegment->m_Result.im == NULL) { | 1584 if (pSegment->m_Result.im == NULL) { |
1627 m_pModule->JBig2_Free(grContext); | 1585 m_pModule->JBig2_Free(grContext); |
1628 nRet = JBIG2_ERROR_FATAL; | 1586 nRet = JBIG2_ERROR_FATAL; |
1629 goto failed; | 1587 goto failed; |
1630 } | 1588 } |
1631 m_pModule->JBig2_Free(grContext); | 1589 m_pModule->JBig2_Free(grContext); |
1632 m_pStream->alignByte(); | 1590 m_pStream->alignByte(); |
1633 m_pStream->offset(2); | 1591 m_pStream->offset(2); |
1634 if (pSegment->m_cFlags.s.type != 40) { | 1592 if (pSegment->m_cFlags.s.type != 40) { |
1635 if (!m_bBufSpecified) { | 1593 if (!m_bBufSpecified) { |
1636 JBig2PageInfo* pPageInfo = m_pPageInfoList->getLast(); | 1594 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
1637 if ((pPageInfo->m_bIsStriped == 1) && | 1595 if ((pPageInfo->m_bIsStriped == 1) && |
1638 (ri.y + ri.height > m_pPage->m_nHeight)) { | 1596 (ri.y + ri.height > m_pPage->m_nHeight)) { |
1639 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1597 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); |
1640 } | 1598 } |
1641 } | 1599 } |
1642 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, | 1600 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, |
1643 (JBig2ComposeOp)(ri.flags & 0x03)); | 1601 (JBig2ComposeOp)(ri.flags & 0x03)); |
1644 delete pSegment->m_Result.im; | 1602 delete pSegment->m_Result.im; |
1645 pSegment->m_Result.im = NULL; | 1603 pSegment->m_Result.im = NULL; |
1646 } | 1604 } |
1647 delete pGRRD; | 1605 delete pGRRD; |
1648 return JBIG2_SUCCESS; | 1606 return JBIG2_SUCCESS; |
1649 failed: | 1607 failed: |
1650 delete pGRRD; | 1608 delete pGRRD; |
1651 return nRet; | 1609 return nRet; |
1652 } | 1610 } |
1653 int32_t CJBig2_Context::parseTable(CJBig2_Segment* pSegment) { | 1611 int32_t CJBig2_Context::parseTable(CJBig2_Segment* pSegment) { |
1654 pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER; | 1612 pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER; |
1655 JBIG2_ALLOC(pSegment->m_Result.ht, CJBig2_HuffmanTable(m_pStream)); | 1613 pSegment->m_Result.ht = new CJBig2_HuffmanTable(m_pStream); |
1656 if (!pSegment->m_Result.ht->isOK()) { | 1614 if (!pSegment->m_Result.ht->isOK()) { |
1657 delete pSegment->m_Result.ht; | 1615 delete pSegment->m_Result.ht; |
1658 pSegment->m_Result.ht = NULL; | 1616 pSegment->m_Result.ht = NULL; |
1659 return JBIG2_ERROR_FATAL; | 1617 return JBIG2_ERROR_FATAL; |
1660 } | 1618 } |
1661 m_pStream->alignByte(); | 1619 m_pStream->alignByte(); |
1662 return JBIG2_SUCCESS; | 1620 return JBIG2_SUCCESS; |
1663 } | 1621 } |
1664 int32_t CJBig2_Context::parseRegionInfo(JBig2RegionInfo* pRI) { | 1622 int32_t CJBig2_Context::parseRegionInfo(JBig2RegionInfo* pRI) { |
1665 if ((m_pStream->readInteger((FX_DWORD*)&pRI->width) != 0) || | 1623 if ((m_pStream->readInteger((FX_DWORD*)&pRI->width) != 0) || |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1817 SBSYMCODES[CURTEMP].code = CURCODE; | 1775 SBSYMCODES[CURTEMP].code = CURCODE; |
1818 CURCODE = CURCODE + 1; | 1776 CURCODE = CURCODE + 1; |
1819 } | 1777 } |
1820 CURTEMP = CURTEMP + 1; | 1778 CURTEMP = CURTEMP + 1; |
1821 } | 1779 } |
1822 CURLEN = CURLEN + 1; | 1780 CURLEN = CURLEN + 1; |
1823 } | 1781 } |
1824 m_pModule->JBig2_Free(LENCOUNT); | 1782 m_pModule->JBig2_Free(LENCOUNT); |
1825 m_pModule->JBig2_Free(FIRSTCODE); | 1783 m_pModule->JBig2_Free(FIRSTCODE); |
1826 } | 1784 } |
OLD | NEW |