Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: core/src/fxcodec/jbig2/JBig2_Context.cpp

Issue 1172793002: Merge to XFA: Use stdint.h types throughout PDFium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxcodec/jbig2/JBig2_Context.h ('k') | core/src/fxcodec/jbig2/JBig2_Define.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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> 7 #include <map>
8 #include <list> 8 #include <list>
9 #include "JBig2_Context.h" 9 #include "JBig2_Context.h"
10 10
11 // Implement a very small least recently used (LRU) cache. It is very 11 // 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, 12 // 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 13 // 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 14 // again. We key off of the memory location of the dictionary. The
15 // list keeps track of the freshness of entries, with freshest ones 15 // 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 16 // at the front. Even a tiny cache size like 2 makes a dramatic
17 // difference for typical JBIG2 documents. 17 // difference for typical JBIG2 documents.
18 const int kSymbolDictCacheMaxSize = 2; 18 const int kSymbolDictCacheMaxSize = 2;
19 19
20 void OutputBitmap(CJBig2_Image* pImage) 20 void OutputBitmap(CJBig2_Image* pImage)
21 { 21 {
22 if(!pImage) { 22 if(!pImage) {
23 return; 23 return;
24 } 24 }
25 } 25 }
26 CJBig2_Context *CJBig2_Context::CreateContext(CJBig2_Module *pModule, FX_BYTE *p GlobalData, FX_DWORD dwGlobalLength, 26 CJBig2_Context *CJBig2_Context::CreateContext(CJBig2_Module *pModule, uint8_t *p GlobalData, FX_DWORD dwGlobalLength,
27 FX_BYTE *pData, FX_DWORD dwLength, FX_INT32 nStreamType, std::list<CJBig 2_CachePair>* pSymbolDictCache, IFX_Pause* pPause) 27 uint8_t *pData, FX_DWORD dwLength, int32_t nStreamType, std::list<CJBig2 _CachePair>* pSymbolDictCache, IFX_Pause* pPause)
28 { 28 {
29 return new(pModule)CJBig2_Context(pGlobalData, dwGlobalLength, pData, dwLeng th, nStreamType, pSymbolDictCache, pPause); 29 return new(pModule)CJBig2_Context(pGlobalData, dwGlobalLength, pData, dwLeng th, nStreamType, pSymbolDictCache, pPause);
30 } 30 }
31 void CJBig2_Context::DestroyContext(CJBig2_Context *pContext) 31 void CJBig2_Context::DestroyContext(CJBig2_Context *pContext)
32 { 32 {
33 if(pContext) { 33 if(pContext) {
34 delete pContext; 34 delete pContext;
35 } 35 }
36 } 36 }
37 CJBig2_Context::CJBig2_Context(FX_BYTE *pGlobalData, FX_DWORD dwGlobalLength, 37 CJBig2_Context::CJBig2_Context(uint8_t *pGlobalData, FX_DWORD dwGlobalLength,
38 FX_BYTE *pData, FX_DWORD dwLength, FX_INT32 nStre amType, std::list<CJBig2_CachePair>* pSymbolDictCache, IFX_Pause* pPause) 38 uint8_t *pData, FX_DWORD dwLength, int32_t nStrea mType, std::list<CJBig2_CachePair>* pSymbolDictCache, IFX_Pause* pPause)
39 { 39 {
40 if(pGlobalData && (dwGlobalLength > 0)) { 40 if(pGlobalData && (dwGlobalLength > 0)) {
41 JBIG2_ALLOC(m_pGlobalContext, CJBig2_Context(NULL, 0, pGlobalData, dwGlo balLength, 41 JBIG2_ALLOC(m_pGlobalContext, CJBig2_Context(NULL, 0, pGlobalData, dwGlo balLength,
42 JBIG2_EMBED_STREAM, pSymbolDictCache, pPause)); 42 JBIG2_EMBED_STREAM, pSymbolDictCache, pPause));
43 } else { 43 } else {
44 m_pGlobalContext = NULL; 44 m_pGlobalContext = NULL;
45 } 45 }
46 JBIG2_ALLOC(m_pStream, CJBig2_BitStream(pData, dwLength)); 46 JBIG2_ALLOC(m_pStream, CJBig2_BitStream(pData, dwLength));
47 m_nStreamType = nStreamType; 47 m_nStreamType = nStreamType;
48 m_nState = JBIG2_OUT_OF_PAGE; 48 m_nState = JBIG2_OUT_OF_PAGE;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 m_pPage = NULL; 89 m_pPage = NULL;
90 if(m_pStream) { 90 if(m_pStream) {
91 delete m_pStream; 91 delete m_pStream;
92 } 92 }
93 m_pStream = NULL; 93 m_pStream = NULL;
94 if(m_pSegmentList) { 94 if(m_pSegmentList) {
95 delete m_pSegmentList; 95 delete m_pSegmentList;
96 } 96 }
97 m_pSegmentList = NULL; 97 m_pSegmentList = NULL;
98 } 98 }
99 FX_INT32 CJBig2_Context::decodeFile(IFX_Pause* pPause) 99 int32_t CJBig2_Context::decodeFile(IFX_Pause* pPause)
100 { 100 {
101 FX_BYTE cFlags; 101 uint8_t cFlags;
102 FX_DWORD dwTemp; 102 FX_DWORD dwTemp;
103 const FX_BYTE fileID[] = {0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 0x0A}; 103 const uint8_t fileID[] = {0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 0x0A};
104 FX_INT32 nRet; 104 int32_t nRet;
105 if(m_pStream->getByteLeft() < 8) { 105 if(m_pStream->getByteLeft() < 8) {
106 m_pModule->JBig2_Error("file header too short."); 106 m_pModule->JBig2_Error("file header too short.");
107 nRet = JBIG2_ERROR_TOO_SHORT; 107 nRet = JBIG2_ERROR_TOO_SHORT;
108 goto failed; 108 goto failed;
109 } 109 }
110 if(JBIG2_memcmp(m_pStream->getPointer(), fileID, 8) != 0) { 110 if(JBIG2_memcmp(m_pStream->getPointer(), fileID, 8) != 0) {
111 m_pModule->JBig2_Error("not jbig2 file"); 111 m_pModule->JBig2_Error("not jbig2 file");
112 nRet = JBIG2_ERROR_FILE_FORMAT; 112 nRet = JBIG2_ERROR_FILE_FORMAT;
113 goto failed; 113 goto failed;
114 } 114 }
(...skipping 17 matching lines...) Expand all
132 if(cFlags & 0x01) { 132 if(cFlags & 0x01) {
133 m_nStreamType = JBIG2_SQUENTIAL_STREAM; 133 m_nStreamType = JBIG2_SQUENTIAL_STREAM;
134 return decode_SquentialOrgnazation(pPause); 134 return decode_SquentialOrgnazation(pPause);
135 } else { 135 } else {
136 m_nStreamType = JBIG2_RANDOM_STREAM; 136 m_nStreamType = JBIG2_RANDOM_STREAM;
137 return decode_RandomOrgnazation_FirstPage(pPause); 137 return decode_RandomOrgnazation_FirstPage(pPause);
138 } 138 }
139 failed: 139 failed:
140 return nRet; 140 return nRet;
141 } 141 }
142 FX_INT32 CJBig2_Context::decode_SquentialOrgnazation(IFX_Pause* pPause) 142 int32_t CJBig2_Context::decode_SquentialOrgnazation(IFX_Pause* pPause)
143 { 143 {
144 FX_INT32 nRet; 144 int32_t nRet;
145 if(m_pStream->getByteLeft() > 0) { 145 if(m_pStream->getByteLeft() > 0) {
146 while(m_pStream->getByteLeft() >= JBIG2_MIN_SEGMENT_SIZE) { 146 while(m_pStream->getByteLeft() >= JBIG2_MIN_SEGMENT_SIZE) {
147 if(m_pSegment == NULL) { 147 if(m_pSegment == NULL) {
148 JBIG2_ALLOC(m_pSegment, CJBig2_Segment()); 148 JBIG2_ALLOC(m_pSegment, CJBig2_Segment());
149 nRet = parseSegmentHeader(m_pSegment); 149 nRet = parseSegmentHeader(m_pSegment);
150 if(nRet != JBIG2_SUCCESS) { 150 if(nRet != JBIG2_SUCCESS) {
151 delete m_pSegment; 151 delete m_pSegment;
152 m_pSegment = NULL; 152 m_pSegment = NULL;
153 return nRet; 153 return nRet;
154 } 154 }
(...skipping 27 matching lines...) Expand all
182 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; 182 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
183 m_PauseStep = 2; 183 m_PauseStep = 2;
184 return JBIG2_SUCCESS; 184 return JBIG2_SUCCESS;
185 } 185 }
186 } 186 }
187 } else { 187 } else {
188 return JBIG2_END_OF_FILE; 188 return JBIG2_END_OF_FILE;
189 } 189 }
190 return JBIG2_SUCCESS; 190 return JBIG2_SUCCESS;
191 } 191 }
192 FX_INT32 CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause) 192 int32_t CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause)
193 { 193 {
194 return decode_SquentialOrgnazation(pPause); 194 return decode_SquentialOrgnazation(pPause);
195 } 195 }
196 FX_INT32 CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) 196 int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause)
197 { 197 {
198 CJBig2_Segment *pSegment; 198 CJBig2_Segment *pSegment;
199 FX_INT32 nRet; 199 int32_t nRet;
200 while(m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) { 200 while(m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) {
201 JBIG2_ALLOC(pSegment, CJBig2_Segment()); 201 JBIG2_ALLOC(pSegment, CJBig2_Segment());
202 nRet = parseSegmentHeader(pSegment); 202 nRet = parseSegmentHeader(pSegment);
203 if(nRet != JBIG2_SUCCESS) { 203 if(nRet != JBIG2_SUCCESS) {
204 delete pSegment; 204 delete pSegment;
205 return nRet; 205 return nRet;
206 } else if(pSegment->m_cFlags.s.type == 51) { 206 } else if(pSegment->m_cFlags.s.type == 51) {
207 delete pSegment; 207 delete pSegment;
208 break; 208 break;
209 } 209 }
210 m_pSegmentList->addItem(pSegment); 210 m_pSegmentList->addItem(pSegment);
211 if(pPause && m_pPause && pPause->NeedToPauseNow()) { 211 if(pPause && m_pPause && pPause->NeedToPauseNow()) {
212 m_PauseStep = 3; 212 m_PauseStep = 3;
213 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; 213 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
214 return JBIG2_SUCCESS; 214 return JBIG2_SUCCESS;
215 } 215 }
216 } 216 }
217 m_nSegmentDecoded = 0; 217 m_nSegmentDecoded = 0;
218 return decode_RandomOrgnazation(pPause); 218 return decode_RandomOrgnazation(pPause);
219 } 219 }
220 FX_INT32 CJBig2_Context::decode_RandomOrgnazation(IFX_Pause* pPause) 220 int32_t CJBig2_Context::decode_RandomOrgnazation(IFX_Pause* pPause)
221 { 221 {
222 FX_INT32 nRet; 222 int32_t nRet;
223 for(; m_nSegmentDecoded < m_pSegmentList->getLength(); m_nSegmentDecoded++) { 223 for(; m_nSegmentDecoded < m_pSegmentList->getLength(); m_nSegmentDecoded++) {
224 nRet = parseSegmentData(m_pSegmentList->getAt(m_nSegmentDecoded), pPause ); 224 nRet = parseSegmentData(m_pSegmentList->getAt(m_nSegmentDecoded), pPause );
225 if((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) { 225 if((nRet == JBIG2_END_OF_PAGE) || (nRet == JBIG2_END_OF_FILE)) {
226 break; 226 break;
227 } else if(nRet != JBIG2_SUCCESS) { 227 } else if(nRet != JBIG2_SUCCESS) {
228 return nRet; 228 return nRet;
229 } 229 }
230 if(m_pPage && pPause && pPause->NeedToPauseNow()) { 230 if(m_pPage && pPause && pPause->NeedToPauseNow()) {
231 m_PauseStep = 4; 231 m_PauseStep = 4;
232 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; 232 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
233 return JBIG2_SUCCESS; 233 return JBIG2_SUCCESS;
234 } 234 }
235 } 235 }
236 return JBIG2_SUCCESS; 236 return JBIG2_SUCCESS;
237 } 237 }
238 FX_INT32 CJBig2_Context::getFirstPage(FX_BYTE *pBuf, FX_INT32 width, FX_INT32 he ight, FX_INT32 stride, IFX_Pause* pPause) 238 int32_t CJBig2_Context::getFirstPage(uint8_t *pBuf, int32_t width, int32_t heigh t, int32_t stride, IFX_Pause* pPause)
239 { 239 {
240 FX_INT32 nRet = 0; 240 int32_t nRet = 0;
241 if(m_pGlobalContext) { 241 if(m_pGlobalContext) {
242 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); 242 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause);
243 if(nRet != JBIG2_SUCCESS) { 243 if(nRet != JBIG2_SUCCESS) {
244 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; 244 m_ProcessiveStatus = FXCODEC_STATUS_ERROR;
245 return nRet; 245 return nRet;
246 } 246 }
247 } 247 }
248 m_bFirstPage = TRUE; 248 m_bFirstPage = TRUE;
249 m_PauseStep = 0; 249 m_PauseStep = 0;
250 if(m_pPage) { 250 if(m_pPage) {
251 delete m_pPage; 251 delete m_pPage;
252 } 252 }
253 JBIG2_ALLOC(m_pPage, CJBig2_Image(width, height, stride, pBuf)); 253 JBIG2_ALLOC(m_pPage, CJBig2_Image(width, height, stride, pBuf));
254 m_bBufSpecified = TRUE; 254 m_bBufSpecified = TRUE;
255 if(m_pPage && pPause && pPause->NeedToPauseNow()) { 255 if(m_pPage && pPause && pPause->NeedToPauseNow()) {
256 m_PauseStep = 1; 256 m_PauseStep = 1;
257 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; 257 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
258 return nRet; 258 return nRet;
259 } 259 }
260 int ret = Continue(pPause); 260 int ret = Continue(pPause);
261 return ret; 261 return ret;
262 } 262 }
263 FX_INT32 CJBig2_Context::Continue(IFX_Pause* pPause) 263 int32_t CJBig2_Context::Continue(IFX_Pause* pPause)
264 { 264 {
265 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_READY; 265 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_READY;
266 FX_INT32 nRet; 266 int32_t nRet;
267 if(m_PauseStep <= 1) { 267 if(m_PauseStep <= 1) {
268 switch(m_nStreamType) { 268 switch(m_nStreamType) {
269 case JBIG2_FILE_STREAM: 269 case JBIG2_FILE_STREAM:
270 nRet = decodeFile(pPause); 270 nRet = decodeFile(pPause);
271 break; 271 break;
272 case JBIG2_SQUENTIAL_STREAM: 272 case JBIG2_SQUENTIAL_STREAM:
273 nRet = decode_SquentialOrgnazation(pPause); 273 nRet = decode_SquentialOrgnazation(pPause);
274 break; 274 break;
275 case JBIG2_RANDOM_STREAM: 275 case JBIG2_RANDOM_STREAM:
276 if(m_bFirstPage) { 276 if(m_bFirstPage) {
(...skipping 27 matching lines...) Expand all
304 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_FINISH; 304 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_FINISH;
305 return JBIG2_SUCCESS; 305 return JBIG2_SUCCESS;
306 } 306 }
307 if(nRet == JBIG2_SUCCESS) { 307 if(nRet == JBIG2_SUCCESS) {
308 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_FINISH; 308 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_FINISH;
309 } else { 309 } else {
310 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; 310 m_ProcessiveStatus = FXCODEC_STATUS_ERROR;
311 } 311 }
312 return nRet; 312 return nRet;
313 } 313 }
314 FX_INT32 CJBig2_Context::getNextPage(FX_BYTE *pBuf, FX_INT32 width, FX_INT32 hei ght, FX_INT32 stride, IFX_Pause* pPause) 314 int32_t CJBig2_Context::getNextPage(uint8_t *pBuf, int32_t width, int32_t height , int32_t stride, IFX_Pause* pPause)
315 { 315 {
316 FX_INT32 nRet = JBIG2_ERROR_STREAM_TYPE; 316 int32_t nRet = JBIG2_ERROR_STREAM_TYPE;
317 m_bFirstPage = FALSE; 317 m_bFirstPage = FALSE;
318 m_PauseStep = 0; 318 m_PauseStep = 0;
319 if(m_pPage) { 319 if(m_pPage) {
320 delete m_pPage; 320 delete m_pPage;
321 } 321 }
322 JBIG2_ALLOC(m_pPage, CJBig2_Image(width, height, stride, pBuf)); 322 JBIG2_ALLOC(m_pPage, CJBig2_Image(width, height, stride, pBuf));
323 m_bBufSpecified = TRUE; 323 m_bBufSpecified = TRUE;
324 if(m_pPage && pPause && pPause->NeedToPauseNow()) { 324 if(m_pPage && pPause && pPause->NeedToPauseNow()) {
325 m_PauseStep = 1; 325 m_PauseStep = 1;
326 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; 326 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
(...skipping 11 matching lines...) Expand all
338 nRet = decode_RandomOrgnazation(pPause); 338 nRet = decode_RandomOrgnazation(pPause);
339 break; 339 break;
340 case JBIG2_EMBED_STREAM: 340 case JBIG2_EMBED_STREAM:
341 nRet = decode_EmbedOrgnazation(pPause); 341 nRet = decode_EmbedOrgnazation(pPause);
342 break; 342 break;
343 default: 343 default:
344 return JBIG2_ERROR_STREAM_TYPE; 344 return JBIG2_ERROR_STREAM_TYPE;
345 } 345 }
346 return nRet; 346 return nRet;
347 } 347 }
348 FX_INT32 CJBig2_Context::getFirstPage(CJBig2_Image **image, IFX_Pause* pPause) 348 int32_t CJBig2_Context::getFirstPage(CJBig2_Image **image, IFX_Pause* pPause)
349 { 349 {
350 FX_INT32 nRet; 350 int32_t nRet;
351 m_bFirstPage = TRUE; 351 m_bFirstPage = TRUE;
352 m_PauseStep = 0; 352 m_PauseStep = 0;
353 if(m_pGlobalContext) { 353 if(m_pGlobalContext) {
354 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); 354 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause);
355 if(nRet != JBIG2_SUCCESS) { 355 if(nRet != JBIG2_SUCCESS) {
356 return nRet; 356 return nRet;
357 } 357 }
358 } 358 }
359 m_bBufSpecified = FALSE; 359 m_bBufSpecified = FALSE;
360 return Continue(pPause); 360 return Continue(pPause);
361 } 361 }
362 FX_INT32 CJBig2_Context::getNextPage(CJBig2_Image **image, IFX_Pause* pPause) 362 int32_t CJBig2_Context::getNextPage(CJBig2_Image **image, IFX_Pause* pPause)
363 { 363 {
364 FX_INT32 nRet; 364 int32_t nRet;
365 m_bBufSpecified = FALSE; 365 m_bBufSpecified = FALSE;
366 m_bFirstPage = FALSE; 366 m_bFirstPage = FALSE;
367 m_PauseStep = 0; 367 m_PauseStep = 0;
368 switch(m_nStreamType) { 368 switch(m_nStreamType) {
369 case JBIG2_FILE_STREAM: 369 case JBIG2_FILE_STREAM:
370 nRet = decodeFile(pPause); 370 nRet = decodeFile(pPause);
371 break; 371 break;
372 case JBIG2_SQUENTIAL_STREAM: 372 case JBIG2_SQUENTIAL_STREAM:
373 nRet = decode_SquentialOrgnazation(pPause); 373 nRet = decode_SquentialOrgnazation(pPause);
374 break; 374 break;
375 case JBIG2_RANDOM_STREAM: 375 case JBIG2_RANDOM_STREAM:
376 nRet = decode_RandomOrgnazation(pPause); 376 nRet = decode_RandomOrgnazation(pPause);
377 break; 377 break;
378 case JBIG2_EMBED_STREAM: 378 case JBIG2_EMBED_STREAM:
379 nRet = decode_EmbedOrgnazation(pPause); 379 nRet = decode_EmbedOrgnazation(pPause);
380 break; 380 break;
381 default: 381 default:
382 return JBIG2_ERROR_STREAM_TYPE; 382 return JBIG2_ERROR_STREAM_TYPE;
383 } 383 }
384 if(nRet == JBIG2_SUCCESS) { 384 if(nRet == JBIG2_SUCCESS) {
385 *image = m_pPage; 385 *image = m_pPage;
386 m_pPage = NULL; 386 m_pPage = NULL;
387 return JBIG2_SUCCESS; 387 return JBIG2_SUCCESS;
388 } 388 }
389 return nRet; 389 return nRet;
390 } 390 }
391 CJBig2_Segment *CJBig2_Context::findSegmentByNumber(FX_DWORD dwNumber) 391 CJBig2_Segment *CJBig2_Context::findSegmentByNumber(FX_DWORD dwNumber)
392 { 392 {
393 CJBig2_Segment *pSeg; 393 CJBig2_Segment *pSeg;
394 FX_INT32 i; 394 int32_t i;
395 if(m_pGlobalContext) { 395 if(m_pGlobalContext) {
396 pSeg = m_pGlobalContext->findSegmentByNumber(dwNumber); 396 pSeg = m_pGlobalContext->findSegmentByNumber(dwNumber);
397 if(pSeg) { 397 if(pSeg) {
398 return pSeg; 398 return pSeg;
399 } 399 }
400 } 400 }
401 for(i = 0; i < m_pSegmentList->getLength(); i++) { 401 for(i = 0; i < m_pSegmentList->getLength(); i++) {
402 pSeg = m_pSegmentList->getAt(i); 402 pSeg = m_pSegmentList->getAt(i);
403 if(pSeg->m_dwNumber == dwNumber) { 403 if(pSeg->m_dwNumber == dwNumber) {
404 return pSeg; 404 return pSeg;
405 } 405 }
406 } 406 }
407 return NULL; 407 return NULL;
408 } 408 }
409 CJBig2_Segment *CJBig2_Context::findReferredSegmentByTypeAndIndex(CJBig2_Segment *pSegment, 409 CJBig2_Segment *CJBig2_Context::findReferredSegmentByTypeAndIndex(CJBig2_Segment *pSegment,
410 FX_BYTE cType, FX_INT32 nIndex) 410 uint8_t cType, int32_t nIndex)
411 { 411 {
412 CJBig2_Segment *pSeg; 412 CJBig2_Segment *pSeg;
413 FX_INT32 i, count; 413 int32_t i, count;
414 count = 0; 414 count = 0;
415 for(i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { 415 for(i = 0; i < pSegment->m_nReferred_to_segment_count; i++) {
416 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); 416 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]);
417 if(pSeg && pSeg->m_cFlags.s.type == cType) { 417 if(pSeg && pSeg->m_cFlags.s.type == cType) {
418 if(count == nIndex) { 418 if(count == nIndex) {
419 return pSeg; 419 return pSeg;
420 } else { 420 } else {
421 count ++; 421 count ++;
422 } 422 }
423 } 423 }
424 } 424 }
425 return NULL; 425 return NULL;
426 } 426 }
427 FX_INT32 CJBig2_Context::parseSegmentHeader(CJBig2_Segment *pSegment) 427 int32_t CJBig2_Context::parseSegmentHeader(CJBig2_Segment *pSegment)
428 { 428 {
429 FX_BYTE cSSize, cPSize; 429 uint8_t cSSize, cPSize;
430 FX_BYTE cTemp; 430 uint8_t cTemp;
431 FX_WORD wTemp; 431 FX_WORD wTemp;
432 FX_DWORD dwTemp; 432 FX_DWORD dwTemp;
433 if((m_pStream->readInteger(&pSegment->m_dwNumber) != 0) 433 if((m_pStream->readInteger(&pSegment->m_dwNumber) != 0)
434 || (m_pStream->read1Byte(&pSegment->m_cFlags.c) != 0)) { 434 || (m_pStream->read1Byte(&pSegment->m_cFlags.c) != 0)) {
435 goto failed; 435 goto failed;
436 } 436 }
437 cTemp = m_pStream->getCurByte(); 437 cTemp = m_pStream->getCurByte();
438 if((cTemp >> 5) == 7) { 438 if((cTemp >> 5) == 7) {
439 if(m_pStream->readInteger((FX_DWORD*)&pSegment->m_nReferred_to_segment_c ount) != 0) { 439 if(m_pStream->readInteger((FX_DWORD*)&pSegment->m_nReferred_to_segment_c ount) != 0) {
440 goto failed; 440 goto failed;
441 } 441 }
442 pSegment->m_nReferred_to_segment_count &= 0x1fffffff; 442 pSegment->m_nReferred_to_segment_count &= 0x1fffffff;
443 if (pSegment->m_nReferred_to_segment_count > JBIG2_MAX_REFERRED_SEGMENT_ COUNT) { 443 if (pSegment->m_nReferred_to_segment_count > JBIG2_MAX_REFERRED_SEGMENT_ COUNT) {
444 m_pModule->JBig2_Error("Too many referred segments."); 444 m_pModule->JBig2_Error("Too many referred segments.");
445 return JBIG2_ERROR_LIMIT; 445 return JBIG2_ERROR_LIMIT;
446 } 446 }
447 dwTemp = 5 + 4 + (pSegment->m_nReferred_to_segment_count + 1) / 8; 447 dwTemp = 5 + 4 + (pSegment->m_nReferred_to_segment_count + 1) / 8;
448 } else { 448 } else {
449 if(m_pStream->read1Byte(&cTemp) != 0) { 449 if(m_pStream->read1Byte(&cTemp) != 0) {
450 goto failed; 450 goto failed;
451 } 451 }
452 pSegment->m_nReferred_to_segment_count = cTemp >> 5; 452 pSegment->m_nReferred_to_segment_count = cTemp >> 5;
453 dwTemp = 5 + 1; 453 dwTemp = 5 + 1;
454 } 454 }
455 cSSize = pSegment->m_dwNumber > 65536 ? 4 : pSegment->m_dwNumber > 256 ? 2 : 1; 455 cSSize = pSegment->m_dwNumber > 65536 ? 4 : pSegment->m_dwNumber > 256 ? 2 : 1;
456 cPSize = pSegment->m_cFlags.s.page_association_size ? 4 : 1; 456 cPSize = pSegment->m_cFlags.s.page_association_size ? 4 : 1;
457 if(pSegment->m_nReferred_to_segment_count) { 457 if(pSegment->m_nReferred_to_segment_count) {
458 pSegment->m_pReferred_to_segment_numbers = (FX_DWORD*)m_pModule->JBig2_M alloc2( 458 pSegment->m_pReferred_to_segment_numbers = (FX_DWORD*)m_pModule->JBig2_M alloc2(
459 sizeof(FX_DWORD), pSegment->m_nReferred_to_segment_count); 459 sizeof(FX_DWORD), pSegment->m_nReferred_to_segment_count);
460 for(FX_INT32 i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { 460 for(int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; i++) {
461 switch(cSSize) { 461 switch(cSSize) {
462 case 1: 462 case 1:
463 if(m_pStream->read1Byte(&cTemp) != 0) { 463 if(m_pStream->read1Byte(&cTemp) != 0) {
464 goto failed; 464 goto failed;
465 } 465 }
466 pSegment->m_pReferred_to_segment_numbers[i] = cTemp; 466 pSegment->m_pReferred_to_segment_numbers[i] = cTemp;
467 break; 467 break;
468 case 2: 468 case 2:
469 if(m_pStream->readShortInteger(&wTemp) != 0) { 469 if(m_pStream->readShortInteger(&wTemp) != 0) {
470 goto failed; 470 goto failed;
(...skipping 26 matching lines...) Expand all
497 if(m_pStream->readInteger(&pSegment->m_dwData_length) != 0) { 497 if(m_pStream->readInteger(&pSegment->m_dwData_length) != 0) {
498 goto failed; 498 goto failed;
499 } 499 }
500 pSegment->m_pData = m_pStream->getPointer(); 500 pSegment->m_pData = m_pStream->getPointer();
501 pSegment->m_State = JBIG2_SEGMENT_DATA_UNPARSED; 501 pSegment->m_State = JBIG2_SEGMENT_DATA_UNPARSED;
502 return JBIG2_SUCCESS; 502 return JBIG2_SUCCESS;
503 failed: 503 failed:
504 m_pModule->JBig2_Error("header too short."); 504 m_pModule->JBig2_Error("header too short.");
505 return JBIG2_ERROR_TOO_SHORT; 505 return JBIG2_ERROR_TOO_SHORT;
506 } 506 }
507 FX_INT32 CJBig2_Context::parseSegmentData(CJBig2_Segment *pSegment, IFX_Pause* p Pause) 507 int32_t CJBig2_Context::parseSegmentData(CJBig2_Segment *pSegment, IFX_Pause* pP ause)
508 { 508 {
509 FX_INT32 ret = ProcessiveParseSegmentData(pSegment, pPause); 509 int32_t ret = ProcessiveParseSegmentData(pSegment, pPause);
510 while(m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE && m_pStream ->getByteLeft() > 0) { 510 while(m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE && m_pStream ->getByteLeft() > 0) {
511 ret = ProcessiveParseSegmentData(pSegment, pPause); 511 ret = ProcessiveParseSegmentData(pSegment, pPause);
512 } 512 }
513 return ret; 513 return ret;
514 } 514 }
515 FX_INT32 CJBig2_Context::ProcessiveParseSegmentData(CJBig2_Segment *pSegment, IF X_Pause* pPause) 515 int32_t CJBig2_Context::ProcessiveParseSegmentData(CJBig2_Segment *pSegment, IFX _Pause* pPause)
516 { 516 {
517 switch(pSegment->m_cFlags.s.type) { 517 switch(pSegment->m_cFlags.s.type) {
518 case 0: 518 case 0:
519 return parseSymbolDict(pSegment, pPause); 519 return parseSymbolDict(pSegment, pPause);
520 case 4: 520 case 4:
521 case 6: 521 case 6:
522 case 7: 522 case 7:
523 if(m_nState == JBIG2_OUT_OF_PAGE) { 523 if(m_nState == JBIG2_OUT_OF_PAGE) {
524 goto failed2; 524 goto failed2;
525 } else { 525 } else {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 break; 606 break;
607 } 607 }
608 return JBIG2_SUCCESS; 608 return JBIG2_SUCCESS;
609 failed1: 609 failed1:
610 m_pModule->JBig2_Error("segment data too short."); 610 m_pModule->JBig2_Error("segment data too short.");
611 return JBIG2_ERROR_TOO_SHORT; 611 return JBIG2_ERROR_TOO_SHORT;
612 failed2: 612 failed2:
613 m_pModule->JBig2_Error("segment syntax error."); 613 m_pModule->JBig2_Error("segment syntax error.");
614 return JBIG2_ERROR_FETAL; 614 return JBIG2_ERROR_FETAL;
615 } 615 }
616 FX_INT32 CJBig2_Context::parseSymbolDict(CJBig2_Segment *pSegment, IFX_Pause* pP ause) 616 int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment *pSegment, IFX_Pause* pPa use)
617 { 617 {
618 FX_DWORD dwTemp; 618 FX_DWORD dwTemp;
619 FX_WORD wFlags; 619 FX_WORD wFlags;
620 FX_BYTE cSDHUFFDH, cSDHUFFDW, cSDHUFFBMSIZE, cSDHUFFAGGINST; 620 uint8_t cSDHUFFDH, cSDHUFFDW, cSDHUFFBMSIZE, cSDHUFFAGGINST;
621 CJBig2_HuffmanTable *Table_B1 = NULL, *Table_B2 = NULL, *Table_B3 = NULL, *T able_B4 = NULL, *Table_B5 = NULL; 621 CJBig2_HuffmanTable *Table_B1 = NULL, *Table_B2 = NULL, *Table_B3 = NULL, *T able_B4 = NULL, *Table_B5 = NULL;
622 FX_INT32 i, nIndex, nRet; 622 int32_t i, nIndex, nRet;
623 CJBig2_Segment *pSeg = NULL, *pLRSeg = NULL; 623 CJBig2_Segment *pSeg = NULL, *pLRSeg = NULL;
624 FX_BOOL bUsed; 624 FX_BOOL bUsed;
625 CJBig2_Image ** SDINSYMS = NULL; 625 CJBig2_Image ** SDINSYMS = NULL;
626 CJBig2_SDDProc *pSymbolDictDecoder; 626 CJBig2_SDDProc *pSymbolDictDecoder;
627 JBig2ArithCtx *gbContext = NULL, *grContext = NULL; 627 JBig2ArithCtx *gbContext = NULL, *grContext = NULL;
628 CJBig2_ArithDecoder *pArithDecoder; 628 CJBig2_ArithDecoder *pArithDecoder;
629 JBIG2_ALLOC(pSymbolDictDecoder, CJBig2_SDDProc()); 629 JBIG2_ALLOC(pSymbolDictDecoder, CJBig2_SDDProc());
630 FX_BYTE *key = pSegment->m_pData; 630 uint8_t *key = pSegment->m_pData;
631 FX_BOOL cache_hit = false; 631 FX_BOOL cache_hit = false;
632 if(m_pStream->readShortInteger(&wFlags) != 0) { 632 if(m_pStream->readShortInteger(&wFlags) != 0) {
633 m_pModule->JBig2_Error("symbol dictionary segment : data header too shor t."); 633 m_pModule->JBig2_Error("symbol dictionary segment : data header too shor t.");
634 nRet = JBIG2_ERROR_TOO_SHORT; 634 nRet = JBIG2_ERROR_TOO_SHORT;
635 goto failed; 635 goto failed;
636 } 636 }
637 pSymbolDictDecoder->SDHUFF = wFlags & 0x0001; 637 pSymbolDictDecoder->SDHUFF = wFlags & 0x0001;
638 pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001; 638 pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001;
639 pSymbolDictDecoder->SDTEMPLATE = (wFlags >> 10) & 0x0003; 639 pSymbolDictDecoder->SDTEMPLATE = (wFlags >> 10) & 0x0003;
640 pSymbolDictDecoder->SDRTEMPLATE = (wFlags >> 12) & 0x0003; 640 pSymbolDictDecoder->SDRTEMPLATE = (wFlags >> 12) & 0x0003;
641 cSDHUFFDH = (wFlags >> 2) & 0x0003; 641 cSDHUFFDH = (wFlags >> 2) & 0x0003;
642 cSDHUFFDW = (wFlags >> 4) & 0x0003; 642 cSDHUFFDW = (wFlags >> 4) & 0x0003;
643 cSDHUFFBMSIZE = (wFlags >> 6) & 0x0001; 643 cSDHUFFBMSIZE = (wFlags >> 6) & 0x0001;
644 cSDHUFFAGGINST = (wFlags >> 7) & 0x0001; 644 cSDHUFFAGGINST = (wFlags >> 7) & 0x0001;
645 if(pSymbolDictDecoder->SDHUFF == 0) { 645 if(pSymbolDictDecoder->SDHUFF == 0) {
646 if(pSymbolDictDecoder->SDTEMPLATE == 0) { 646 if(pSymbolDictDecoder->SDTEMPLATE == 0) {
647 dwTemp = 8; 647 dwTemp = 8;
648 } else { 648 } else {
649 dwTemp = 2; 649 dwTemp = 2;
650 } 650 }
651 for(i = 0; i < (FX_INT32)dwTemp; i++) { 651 for(i = 0; i < (int32_t)dwTemp; i++) {
652 if(m_pStream->read1Byte((FX_BYTE*)&pSymbolDictDecoder->SDAT[i]) != 0 ) { 652 if(m_pStream->read1Byte((uint8_t*)&pSymbolDictDecoder->SDAT[i]) != 0 ) {
653 m_pModule->JBig2_Error("symbol dictionary segment : data header too short."); 653 m_pModule->JBig2_Error("symbol dictionary segment : data header too short.");
654 nRet = JBIG2_ERROR_TOO_SHORT; 654 nRet = JBIG2_ERROR_TOO_SHORT;
655 goto failed; 655 goto failed;
656 } 656 }
657 } 657 }
658 } 658 }
659 if((pSymbolDictDecoder->SDREFAGG == 1) && (pSymbolDictDecoder->SDRTEMPLATE = = 0)) { 659 if((pSymbolDictDecoder->SDREFAGG == 1) && (pSymbolDictDecoder->SDRTEMPLATE = = 0)) {
660 for(i = 0; i < 4; i++) { 660 for(i = 0; i < 4; i++) {
661 if(m_pStream->read1Byte((FX_BYTE*)&pSymbolDictDecoder->SDRAT[i]) != 0) { 661 if(m_pStream->read1Byte((uint8_t*)&pSymbolDictDecoder->SDRAT[i]) != 0) {
662 m_pModule->JBig2_Error("symbol dictionary segment : data header too short."); 662 m_pModule->JBig2_Error("symbol dictionary segment : data header too short.");
663 nRet = JBIG2_ERROR_TOO_SHORT; 663 nRet = JBIG2_ERROR_TOO_SHORT;
664 goto failed; 664 goto failed;
665 } 665 }
666 } 666 }
667 } 667 }
668 if((m_pStream->readInteger(&pSymbolDictDecoder->SDNUMEXSYMS) != 0) 668 if((m_pStream->readInteger(&pSymbolDictDecoder->SDNUMEXSYMS) != 0)
669 || (m_pStream->readInteger(&pSymbolDictDecoder->SDNUMNEWSYMS) != 0)) { 669 || (m_pStream->readInteger(&pSymbolDictDecoder->SDNUMNEWSYMS) != 0)) {
670 m_pModule->JBig2_Error("symbol dictionary segment : data header too shor t."); 670 m_pModule->JBig2_Error("symbol dictionary segment : data header too shor t.");
671 nRet = JBIG2_ERROR_TOO_SHORT; 671 nRet = JBIG2_ERROR_TOO_SHORT;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 if(grContext) { 910 if(grContext) {
911 m_pModule->JBig2_Free(grContext); 911 m_pModule->JBig2_Free(grContext);
912 } 912 }
913 return nRet; 913 return nRet;
914 } 914 }
915 915
916 FX_BOOL CJBig2_Context::parseTextRegion(CJBig2_Segment *pSegment) 916 FX_BOOL CJBig2_Context::parseTextRegion(CJBig2_Segment *pSegment)
917 { 917 {
918 FX_DWORD dwTemp; 918 FX_DWORD dwTemp;
919 FX_WORD wFlags; 919 FX_WORD wFlags;
920 FX_INT32 i, nIndex, nRet; 920 int32_t i, nIndex, nRet;
921 JBig2RegionInfo ri; 921 JBig2RegionInfo ri;
922 CJBig2_Segment *pSeg; 922 CJBig2_Segment *pSeg;
923 CJBig2_Image **SBSYMS = NULL; 923 CJBig2_Image **SBSYMS = NULL;
924 JBig2HuffmanCode *SBSYMCODES = NULL; 924 JBig2HuffmanCode *SBSYMCODES = NULL;
925 FX_BYTE cSBHUFFFS, cSBHUFFDS, cSBHUFFDT, cSBHUFFRDW, cSBHUFFRDH, cSBHUFFRDX, cSBHUFFRDY, cSBHUFFRSIZE; 925 uint8_t cSBHUFFFS, cSBHUFFDS, cSBHUFFDT, cSBHUFFRDW, cSBHUFFRDH, cSBHUFFRDX, cSBHUFFRDY, cSBHUFFRSIZE;
926 CJBig2_HuffmanTable *Table_B1 = NULL, 926 CJBig2_HuffmanTable *Table_B1 = NULL,
927 *Table_B6 = NULL, 927 *Table_B6 = NULL,
928 *Table_B7 = NULL, 928 *Table_B7 = NULL,
929 *Table_B8 = NULL, 929 *Table_B8 = NULL,
930 *Table_B9 = NULL, 930 *Table_B9 = NULL,
931 *Table_B10 = NULL, 931 *Table_B10 = NULL,
932 *Table_B11 = NULL, 932 *Table_B11 = NULL,
933 *Table_B12 = NULL, 933 *Table_B12 = NULL,
934 *Table_B13 = NULL, 934 *Table_B13 = NULL,
935 *Table_B14 = NULL, 935 *Table_B14 = NULL,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 cSBHUFFDS = (wFlags >> 2) & 0x0003; 969 cSBHUFFDS = (wFlags >> 2) & 0x0003;
970 cSBHUFFDT = (wFlags >> 4) & 0x0003; 970 cSBHUFFDT = (wFlags >> 4) & 0x0003;
971 cSBHUFFRDW = (wFlags >> 6) & 0x0003; 971 cSBHUFFRDW = (wFlags >> 6) & 0x0003;
972 cSBHUFFRDH = (wFlags >> 8) & 0x0003; 972 cSBHUFFRDH = (wFlags >> 8) & 0x0003;
973 cSBHUFFRDX = (wFlags >> 10) & 0x0003; 973 cSBHUFFRDX = (wFlags >> 10) & 0x0003;
974 cSBHUFFRDY = (wFlags >> 12) & 0x0003; 974 cSBHUFFRDY = (wFlags >> 12) & 0x0003;
975 cSBHUFFRSIZE = (wFlags >> 14) & 0x0001; 975 cSBHUFFRSIZE = (wFlags >> 14) & 0x0001;
976 } 976 }
977 if((pTRD->SBREFINE == 1) && (pTRD->SBRTEMPLATE == 0)) { 977 if((pTRD->SBREFINE == 1) && (pTRD->SBRTEMPLATE == 0)) {
978 for(i = 0; i < 4; i++) { 978 for(i = 0; i < 4; i++) {
979 if(m_pStream->read1Byte((FX_BYTE*)&pTRD->SBRAT[i]) != 0) { 979 if(m_pStream->read1Byte((uint8_t*)&pTRD->SBRAT[i]) != 0) {
980 m_pModule->JBig2_Error("text region segment : data header too sh ort."); 980 m_pModule->JBig2_Error("text region segment : data header too sh ort.");
981 nRet = JBIG2_ERROR_TOO_SHORT; 981 nRet = JBIG2_ERROR_TOO_SHORT;
982 goto failed; 982 goto failed;
983 } 983 }
984 } 984 }
985 } 985 }
986 if(m_pStream->readInteger(&pTRD->SBNUMINSTANCES) != 0) { 986 if(m_pStream->readInteger(&pTRD->SBNUMINSTANCES) != 0) {
987 m_pModule->JBig2_Error("text region segment : data header too short."); 987 m_pModule->JBig2_Error("text region segment : data header too short.");
988 nRet = JBIG2_ERROR_TOO_SHORT; 988 nRet = JBIG2_ERROR_TOO_SHORT;
989 goto failed; 989 goto failed;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 nRet = JBIG2_ERROR_FETAL; 1025 nRet = JBIG2_ERROR_FETAL;
1026 goto failed; 1026 goto failed;
1027 } 1027 }
1028 m_pStream->alignByte(); 1028 m_pStream->alignByte();
1029 pTRD->SBSYMCODES = SBSYMCODES; 1029 pTRD->SBSYMCODES = SBSYMCODES;
1030 } else { 1030 } else {
1031 dwTemp = 0; 1031 dwTemp = 0;
1032 while((FX_DWORD)(1 << dwTemp) < pTRD->SBNUMSYMS) { 1032 while((FX_DWORD)(1 << dwTemp) < pTRD->SBNUMSYMS) {
1033 dwTemp ++; 1033 dwTemp ++;
1034 } 1034 }
1035 pTRD->SBSYMCODELEN = (FX_BYTE)dwTemp; 1035 pTRD->SBSYMCODELEN = (uint8_t)dwTemp;
1036 } 1036 }
1037 if(pTRD->SBHUFF == 1) { 1037 if(pTRD->SBHUFF == 1) {
1038 if((cSBHUFFFS == 2) || (cSBHUFFRDW == 2) || (cSBHUFFRDH == 2) 1038 if((cSBHUFFFS == 2) || (cSBHUFFRDW == 2) || (cSBHUFFRDH == 2)
1039 || (cSBHUFFRDX == 2) || (cSBHUFFRDY == 2)) { 1039 || (cSBHUFFRDX == 2) || (cSBHUFFRDY == 2)) {
1040 m_pModule->JBig2_Error("text region segment : SBHUFFFS=2 or SBHUFFRD W=2 or " 1040 m_pModule->JBig2_Error("text region segment : SBHUFFFS=2 or SBHUFFRD W=2 or "
1041 "SBHUFFRDH=2 or SBHUFFRDX=2 or SBHUFFRDY=2 is not permitted"); 1041 "SBHUFFRDH=2 or SBHUFFRDX=2 or SBHUFFRDY=2 is not permitted");
1042 nRet = JBIG2_ERROR_FETAL; 1042 nRet = JBIG2_ERROR_FETAL;
1043 goto failed; 1043 goto failed;
1044 } 1044 }
1045 nIndex = 0; 1045 nIndex = 0;
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 } 1319 }
1320 if(Table_B15) { 1320 if(Table_B15) {
1321 delete Table_B15; 1321 delete Table_B15;
1322 } 1322 }
1323 return nRet; 1323 return nRet;
1324 } 1324 }
1325 1325
1326 FX_BOOL CJBig2_Context::parsePatternDict(CJBig2_Segment *pSegment, IFX_Pause* pP ause) 1326 FX_BOOL CJBig2_Context::parsePatternDict(CJBig2_Segment *pSegment, IFX_Pause* pP ause)
1327 { 1327 {
1328 FX_DWORD dwTemp; 1328 FX_DWORD dwTemp;
1329 FX_BYTE cFlags; 1329 uint8_t cFlags;
1330 JBig2ArithCtx *gbContext; 1330 JBig2ArithCtx *gbContext;
1331 CJBig2_ArithDecoder *pArithDecoder; 1331 CJBig2_ArithDecoder *pArithDecoder;
1332 CJBig2_PDDProc *pPDD; 1332 CJBig2_PDDProc *pPDD;
1333 FX_INT32 nRet; 1333 int32_t nRet;
1334 JBIG2_ALLOC(pPDD, CJBig2_PDDProc()); 1334 JBIG2_ALLOC(pPDD, CJBig2_PDDProc());
1335 if((m_pStream->read1Byte(&cFlags) != 0) 1335 if((m_pStream->read1Byte(&cFlags) != 0)
1336 || (m_pStream->read1Byte(&pPDD->HDPW) != 0) 1336 || (m_pStream->read1Byte(&pPDD->HDPW) != 0)
1337 || (m_pStream->read1Byte(&pPDD->HDPH) != 0) 1337 || (m_pStream->read1Byte(&pPDD->HDPH) != 0)
1338 || (m_pStream->readInteger(&pPDD->GRAYMAX) != 0)) { 1338 || (m_pStream->readInteger(&pPDD->GRAYMAX) != 0)) {
1339 m_pModule->JBig2_Error("pattern dictionary segment : data header too sho rt."); 1339 m_pModule->JBig2_Error("pattern dictionary segment : data header too sho rt.");
1340 nRet = JBIG2_ERROR_TOO_SHORT; 1340 nRet = JBIG2_ERROR_TOO_SHORT;
1341 goto failed; 1341 goto failed;
1342 } 1342 }
1343 if (pPDD->GRAYMAX > JBIG2_MAX_PATTERN_INDEX) { 1343 if (pPDD->GRAYMAX > JBIG2_MAX_PATTERN_INDEX) {
(...skipping 29 matching lines...) Expand all
1373 } 1373 }
1374 delete pPDD; 1374 delete pPDD;
1375 return JBIG2_SUCCESS; 1375 return JBIG2_SUCCESS;
1376 failed: 1376 failed:
1377 delete pPDD; 1377 delete pPDD;
1378 return nRet; 1378 return nRet;
1379 } 1379 }
1380 FX_BOOL CJBig2_Context::parseHalftoneRegion(CJBig2_Segment *pSegment, IFX_Pause* pPause) 1380 FX_BOOL CJBig2_Context::parseHalftoneRegion(CJBig2_Segment *pSegment, IFX_Pause* pPause)
1381 { 1381 {
1382 FX_DWORD dwTemp; 1382 FX_DWORD dwTemp;
1383 FX_BYTE cFlags; 1383 uint8_t cFlags;
1384 JBig2RegionInfo ri; 1384 JBig2RegionInfo ri;
1385 CJBig2_Segment *pSeg; 1385 CJBig2_Segment *pSeg;
1386 CJBig2_PatternDict *pPatternDict; 1386 CJBig2_PatternDict *pPatternDict;
1387 JBig2ArithCtx *gbContext; 1387 JBig2ArithCtx *gbContext;
1388 CJBig2_ArithDecoder *pArithDecoder; 1388 CJBig2_ArithDecoder *pArithDecoder;
1389 CJBig2_HTRDProc *pHRD; 1389 CJBig2_HTRDProc *pHRD;
1390 FX_INT32 nRet; 1390 int32_t nRet;
1391 JBIG2_ALLOC(pHRD, CJBig2_HTRDProc()); 1391 JBIG2_ALLOC(pHRD, CJBig2_HTRDProc());
1392 if((parseRegionInfo(&ri) != JBIG2_SUCCESS) 1392 if((parseRegionInfo(&ri) != JBIG2_SUCCESS)
1393 || (m_pStream->read1Byte(&cFlags) != 0) 1393 || (m_pStream->read1Byte(&cFlags) != 0)
1394 || (m_pStream->readInteger(&pHRD->HGW) != 0) 1394 || (m_pStream->readInteger(&pHRD->HGW) != 0)
1395 || (m_pStream->readInteger(&pHRD->HGH) != 0) 1395 || (m_pStream->readInteger(&pHRD->HGH) != 0)
1396 || (m_pStream->readInteger((FX_DWORD*)&pHRD->HGX) != 0) 1396 || (m_pStream->readInteger((FX_DWORD*)&pHRD->HGX) != 0)
1397 || (m_pStream->readInteger((FX_DWORD*)&pHRD->HGY) != 0) 1397 || (m_pStream->readInteger((FX_DWORD*)&pHRD->HGY) != 0)
1398 || (m_pStream->readShortInteger(&pHRD->HRX) != 0) 1398 || (m_pStream->readShortInteger(&pHRD->HRX) != 0)
1399 || (m_pStream->readShortInteger(&pHRD->HRY) != 0)) { 1399 || (m_pStream->readShortInteger(&pHRD->HRY) != 0)) {
1400 m_pModule->JBig2_Error("halftone region segment : data header too short. "); 1400 m_pModule->JBig2_Error("halftone region segment : data header too short. ");
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 delete pHRD; 1467 delete pHRD;
1468 return JBIG2_SUCCESS; 1468 return JBIG2_SUCCESS;
1469 failed: 1469 failed:
1470 delete pHRD; 1470 delete pHRD;
1471 return nRet; 1471 return nRet;
1472 } 1472 }
1473 1473
1474 FX_BOOL CJBig2_Context::parseGenericRegion(CJBig2_Segment *pSegment, IFX_Pause* pPause) 1474 FX_BOOL CJBig2_Context::parseGenericRegion(CJBig2_Segment *pSegment, IFX_Pause* pPause)
1475 { 1475 {
1476 FX_DWORD dwTemp; 1476 FX_DWORD dwTemp;
1477 FX_BYTE cFlags; 1477 uint8_t cFlags;
1478 FX_INT32 i, nRet; 1478 int32_t i, nRet;
1479 if(m_pGRD == NULL) { 1479 if(m_pGRD == NULL) {
1480 JBIG2_ALLOC(m_pGRD, CJBig2_GRDProc()); 1480 JBIG2_ALLOC(m_pGRD, CJBig2_GRDProc());
1481 if((parseRegionInfo(&m_ri) != JBIG2_SUCCESS) 1481 if((parseRegionInfo(&m_ri) != JBIG2_SUCCESS)
1482 || (m_pStream->read1Byte(&cFlags) != 0)) { 1482 || (m_pStream->read1Byte(&cFlags) != 0)) {
1483 m_pModule->JBig2_Error("generic region segment : data header too sho rt."); 1483 m_pModule->JBig2_Error("generic region segment : data header too sho rt.");
1484 nRet = JBIG2_ERROR_TOO_SHORT; 1484 nRet = JBIG2_ERROR_TOO_SHORT;
1485 goto failed; 1485 goto failed;
1486 } 1486 }
1487 if (m_ri.height < 0 || m_ri.width < 0) { 1487 if (m_ri.height < 0 || m_ri.width < 0) {
1488 m_pModule->JBig2_Error("generic region segment : wrong data."); 1488 m_pModule->JBig2_Error("generic region segment : wrong data.");
1489 nRet = JBIG2_FAILED; 1489 nRet = JBIG2_FAILED;
1490 goto failed; 1490 goto failed;
1491 } 1491 }
1492 m_pGRD->GBW = m_ri.width; 1492 m_pGRD->GBW = m_ri.width;
1493 m_pGRD->GBH = m_ri.height; 1493 m_pGRD->GBH = m_ri.height;
1494 m_pGRD->MMR = cFlags & 0x01; 1494 m_pGRD->MMR = cFlags & 0x01;
1495 m_pGRD->GBTEMPLATE = (cFlags >> 1) & 0x03; 1495 m_pGRD->GBTEMPLATE = (cFlags >> 1) & 0x03;
1496 m_pGRD->TPGDON = (cFlags >> 3) & 0x01; 1496 m_pGRD->TPGDON = (cFlags >> 3) & 0x01;
1497 if(m_pGRD->MMR == 0) { 1497 if(m_pGRD->MMR == 0) {
1498 if(m_pGRD->GBTEMPLATE == 0) { 1498 if(m_pGRD->GBTEMPLATE == 0) {
1499 for(i = 0; i < 8; i++) { 1499 for(i = 0; i < 8; i++) {
1500 if(m_pStream->read1Byte((FX_BYTE*)&m_pGRD->GBAT[i]) != 0) { 1500 if(m_pStream->read1Byte((uint8_t*)&m_pGRD->GBAT[i]) != 0) {
1501 m_pModule->JBig2_Error("generic region segment : data he ader too short."); 1501 m_pModule->JBig2_Error("generic region segment : data he ader too short.");
1502 nRet = JBIG2_ERROR_TOO_SHORT; 1502 nRet = JBIG2_ERROR_TOO_SHORT;
1503 goto failed; 1503 goto failed;
1504 } 1504 }
1505 } 1505 }
1506 } else { 1506 } else {
1507 for(i = 0; i < 2; i++) { 1507 for(i = 0; i < 2; i++) {
1508 if(m_pStream->read1Byte((FX_BYTE*)&m_pGRD->GBAT[i]) != 0) { 1508 if(m_pStream->read1Byte((uint8_t*)&m_pGRD->GBAT[i]) != 0) {
1509 m_pModule->JBig2_Error("generic region segment : data he ader too short."); 1509 m_pModule->JBig2_Error("generic region segment : data he ader too short.");
1510 nRet = JBIG2_ERROR_TOO_SHORT; 1510 nRet = JBIG2_ERROR_TOO_SHORT;
1511 goto failed; 1511 goto failed;
1512 } 1512 }
1513 } 1513 }
1514 } 1514 }
1515 } 1515 }
1516 m_pGRD->USESKIP = 0; 1516 m_pGRD->USESKIP = 0;
1517 } 1517 }
1518 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; 1518 pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 delete m_pGRD; 1586 delete m_pGRD;
1587 m_pGRD = NULL; 1587 m_pGRD = NULL;
1588 return nRet; 1588 return nRet;
1589 } 1589 }
1590 1590
1591 FX_BOOL CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment *pSegment) 1591 FX_BOOL CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment *pSegment)
1592 { 1592 {
1593 FX_DWORD dwTemp; 1593 FX_DWORD dwTemp;
1594 JBig2RegionInfo ri; 1594 JBig2RegionInfo ri;
1595 CJBig2_Segment *pSeg; 1595 CJBig2_Segment *pSeg;
1596 FX_INT32 i, nRet; 1596 int32_t i, nRet;
1597 FX_BYTE cFlags; 1597 uint8_t cFlags;
1598 JBig2ArithCtx *grContext; 1598 JBig2ArithCtx *grContext;
1599 CJBig2_GRRDProc *pGRRD; 1599 CJBig2_GRRDProc *pGRRD;
1600 CJBig2_ArithDecoder *pArithDecoder; 1600 CJBig2_ArithDecoder *pArithDecoder;
1601 JBIG2_ALLOC(pGRRD, CJBig2_GRRDProc()); 1601 JBIG2_ALLOC(pGRRD, CJBig2_GRRDProc());
1602 if((parseRegionInfo(&ri) != JBIG2_SUCCESS) 1602 if((parseRegionInfo(&ri) != JBIG2_SUCCESS)
1603 || (m_pStream->read1Byte(&cFlags) != 0)) { 1603 || (m_pStream->read1Byte(&cFlags) != 0)) {
1604 m_pModule->JBig2_Error("generic refinement region segment : data header too short."); 1604 m_pModule->JBig2_Error("generic refinement region segment : data header too short.");
1605 nRet = JBIG2_ERROR_TOO_SHORT; 1605 nRet = JBIG2_ERROR_TOO_SHORT;
1606 goto failed; 1606 goto failed;
1607 } 1607 }
1608 pGRRD->GRW = ri.width; 1608 pGRRD->GRW = ri.width;
1609 pGRRD->GRH = ri.height; 1609 pGRRD->GRH = ri.height;
1610 pGRRD->GRTEMPLATE = cFlags & 0x01; 1610 pGRRD->GRTEMPLATE = cFlags & 0x01;
1611 pGRRD->TPGRON = (cFlags >> 1) & 0x01; 1611 pGRRD->TPGRON = (cFlags >> 1) & 0x01;
1612 if(pGRRD->GRTEMPLATE == 0) { 1612 if(pGRRD->GRTEMPLATE == 0) {
1613 for(i = 0; i < 4; i++) { 1613 for(i = 0; i < 4; i++) {
1614 if(m_pStream->read1Byte((FX_BYTE*)&pGRRD->GRAT[i]) != 0) { 1614 if(m_pStream->read1Byte((uint8_t*)&pGRRD->GRAT[i]) != 0) {
1615 m_pModule->JBig2_Error("generic refinement region segment : data header too short."); 1615 m_pModule->JBig2_Error("generic refinement region segment : data header too short.");
1616 nRet = JBIG2_ERROR_TOO_SHORT; 1616 nRet = JBIG2_ERROR_TOO_SHORT;
1617 goto failed; 1617 goto failed;
1618 } 1618 }
1619 } 1619 }
1620 } 1620 }
1621 pSeg = NULL; 1621 pSeg = NULL;
1622 if(pSegment->m_nReferred_to_segment_count > 0) { 1622 if(pSegment->m_nReferred_to_segment_count > 0) {
1623 for(i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { 1623 for(i = 0; i < pSegment->m_nReferred_to_segment_count; i++) {
1624 pSeg = this->findSegmentByNumber(pSegment->m_pReferred_to_segment_nu mbers[0]); 1624 pSeg = this->findSegmentByNumber(pSegment->m_pReferred_to_segment_nu mbers[0]);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER; 1680 pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER;
1681 JBIG2_ALLOC(pSegment->m_Result.ht, CJBig2_HuffmanTable(m_pStream)); 1681 JBIG2_ALLOC(pSegment->m_Result.ht, CJBig2_HuffmanTable(m_pStream));
1682 if(!pSegment->m_Result.ht->isOK()) { 1682 if(!pSegment->m_Result.ht->isOK()) {
1683 delete pSegment->m_Result.ht; 1683 delete pSegment->m_Result.ht;
1684 pSegment->m_Result.ht = NULL; 1684 pSegment->m_Result.ht = NULL;
1685 return JBIG2_ERROR_FETAL; 1685 return JBIG2_ERROR_FETAL;
1686 } 1686 }
1687 m_pStream->alignByte(); 1687 m_pStream->alignByte();
1688 return JBIG2_SUCCESS; 1688 return JBIG2_SUCCESS;
1689 } 1689 }
1690 FX_INT32 CJBig2_Context::parseRegionInfo(JBig2RegionInfo *pRI) 1690 int32_t CJBig2_Context::parseRegionInfo(JBig2RegionInfo *pRI)
1691 { 1691 {
1692 if((m_pStream->readInteger((FX_DWORD*)&pRI->width) != 0) 1692 if((m_pStream->readInteger((FX_DWORD*)&pRI->width) != 0)
1693 || (m_pStream->readInteger((FX_DWORD*)&pRI->height) != 0) 1693 || (m_pStream->readInteger((FX_DWORD*)&pRI->height) != 0)
1694 || (m_pStream->readInteger((FX_DWORD*)&pRI->x) != 0) 1694 || (m_pStream->readInteger((FX_DWORD*)&pRI->x) != 0)
1695 || (m_pStream->readInteger((FX_DWORD*)&pRI->y) != 0) 1695 || (m_pStream->readInteger((FX_DWORD*)&pRI->y) != 0)
1696 || (m_pStream->read1Byte(&pRI->flags) != 0)) { 1696 || (m_pStream->read1Byte(&pRI->flags) != 0)) {
1697 return JBIG2_ERROR_TOO_SHORT; 1697 return JBIG2_ERROR_TOO_SHORT;
1698 } 1698 }
1699 return JBIG2_SUCCESS; 1699 return JBIG2_SUCCESS;
1700 } 1700 }
1701 JBig2HuffmanCode *CJBig2_Context::decodeSymbolIDHuffmanTable(CJBig2_BitStream *p Stream, 1701 JBig2HuffmanCode *CJBig2_Context::decodeSymbolIDHuffmanTable(CJBig2_BitStream *p Stream,
1702 FX_DWORD SBNUMSYMS) 1702 FX_DWORD SBNUMSYMS)
1703 { 1703 {
1704 JBig2HuffmanCode *SBSYMCODES; 1704 JBig2HuffmanCode *SBSYMCODES;
1705 FX_INT32 runcodes[35], runcodes_len[35], runcode; 1705 int32_t runcodes[35], runcodes_len[35], runcode;
1706 FX_INT32 i, j, nTemp, nVal, nBits; 1706 int32_t i, j, nTemp, nVal, nBits;
1707 FX_INT32 run; 1707 int32_t run;
1708 SBSYMCODES = (JBig2HuffmanCode*)m_pModule->JBig2_Malloc2(sizeof(JBig2Huffman Code), SBNUMSYMS); 1708 SBSYMCODES = (JBig2HuffmanCode*)m_pModule->JBig2_Malloc2(sizeof(JBig2Huffman Code), SBNUMSYMS);
1709 for (i = 0; i < 35; i ++) { 1709 for (i = 0; i < 35; i ++) {
1710 if(pStream->readNBits(4, &runcodes_len[i]) != 0) { 1710 if(pStream->readNBits(4, &runcodes_len[i]) != 0) {
1711 goto failed; 1711 goto failed;
1712 } 1712 }
1713 } 1713 }
1714 huffman_assign_code(runcodes, runcodes_len, 35); 1714 huffman_assign_code(runcodes, runcodes_len, 35);
1715 i = 0; 1715 i = 0;
1716 while(i < (int)SBNUMSYMS) { 1716 while(i < (int)SBNUMSYMS) {
1717 nVal = 0; 1717 nVal = 0;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1838 SBSYMCODES[CURTEMP].code = CURCODE; 1838 SBSYMCODES[CURTEMP].code = CURCODE;
1839 CURCODE = CURCODE + 1; 1839 CURCODE = CURCODE + 1;
1840 } 1840 }
1841 CURTEMP = CURTEMP + 1; 1841 CURTEMP = CURTEMP + 1;
1842 } 1842 }
1843 CURLEN = CURLEN + 1; 1843 CURLEN = CURLEN + 1;
1844 } 1844 }
1845 m_pModule->JBig2_Free(LENCOUNT); 1845 m_pModule->JBig2_Free(LENCOUNT);
1846 m_pModule->JBig2_Free(FIRSTCODE); 1846 m_pModule->JBig2_Free(FIRSTCODE);
1847 } 1847 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/jbig2/JBig2_Context.h ('k') | core/src/fxcodec/jbig2/JBig2_Define.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698