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

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

Issue 1326953006: Remove CJBig2_Object, CJBig2_Module, and friends. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 5 years, 3 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
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 <list> 7 #include <list>
8 #include "JBig2_Context.h" 8 #include "JBig2_Context.h"
9 9
10 // 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
11 // 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,
12 // 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
13 // 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
14 // list keeps track of the freshness of entries, with freshest ones 14 // list keeps track of the freshness of entries, with freshest ones
15 // 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
16 // difference for typical JBIG2 documents. 16 // difference for typical JBIG2 documents.
17 const int kSymbolDictCacheMaxSize = 2; 17 const int kSymbolDictCacheMaxSize = 2;
18 18
19 CJBig2_Context* CJBig2_Context::CreateContext( 19 CJBig2_Context* CJBig2_Context::CreateContext(
20 CJBig2_Module* pModule,
21 uint8_t* pGlobalData, 20 uint8_t* pGlobalData,
22 FX_DWORD dwGlobalLength, 21 FX_DWORD dwGlobalLength,
23 uint8_t* pData, 22 uint8_t* pData,
24 FX_DWORD dwLength, 23 FX_DWORD dwLength,
25 int32_t nStreamType, 24 int32_t nStreamType,
26 std::list<CJBig2_CachePair>* pSymbolDictCache, 25 std::list<CJBig2_CachePair>* pSymbolDictCache,
27 IFX_Pause* pPause) { 26 IFX_Pause* pPause) {
28 return new (pModule) 27 return new CJBig2_Context(pGlobalData, dwGlobalLength, pData, dwLength,
29 CJBig2_Context(pGlobalData, dwGlobalLength, pData, dwLength, nStreamType, 28 nStreamType, pSymbolDictCache, pPause);
30 pSymbolDictCache, pPause);
31 } 29 }
32 void CJBig2_Context::DestroyContext(CJBig2_Context* pContext) { 30 void CJBig2_Context::DestroyContext(CJBig2_Context* pContext) {
33 delete pContext; 31 delete pContext;
34 } 32 }
35 CJBig2_Context::CJBig2_Context(uint8_t* pGlobalData, 33 CJBig2_Context::CJBig2_Context(uint8_t* pGlobalData,
36 FX_DWORD dwGlobalLength, 34 FX_DWORD dwGlobalLength,
37 uint8_t* pData, 35 uint8_t* pData,
38 FX_DWORD dwLength, 36 FX_DWORD dwLength,
39 int32_t nStreamType, 37 int32_t nStreamType,
40 std::list<CJBig2_CachePair>* pSymbolDictCache, 38 std::list<CJBig2_CachePair>* pSymbolDictCache,
41 IFX_Pause* pPause) { 39 IFX_Pause* pPause) {
42 if (pGlobalData && (dwGlobalLength > 0)) { 40 if (pGlobalData && (dwGlobalLength > 0)) {
43 JBIG2_ALLOC(m_pGlobalContext, 41 m_pGlobalContext =
44 CJBig2_Context(NULL, 0, pGlobalData, dwGlobalLength, 42 new CJBig2_Context(NULL, 0, pGlobalData, dwGlobalLength,
45 JBIG2_EMBED_STREAM, pSymbolDictCache, pPause)); 43 JBIG2_EMBED_STREAM, pSymbolDictCache, pPause);
46 } else { 44 } else {
47 m_pGlobalContext = NULL; 45 m_pGlobalContext = NULL;
48 } 46 }
49 m_pStream = new CJBig2_BitStream(pData, dwLength); 47 m_pStream = new CJBig2_BitStream(pData, dwLength);
50 m_nStreamType = nStreamType; 48 m_nStreamType = nStreamType;
51 m_nState = JBIG2_OUT_OF_PAGE; 49 m_nState = JBIG2_OUT_OF_PAGE;
52 m_pPage = NULL; 50 m_pPage = NULL;
53 m_bBufSpecified = FALSE; 51 m_bBufSpecified = FALSE;
54 m_pPause = pPause; 52 m_pPause = pPause;
55 m_nSegmentDecoded = 0; 53 m_nSegmentDecoded = 0;
56 m_PauseStep = 10; 54 m_PauseStep = 10;
57 m_pArithDecoder = NULL; 55 m_pArithDecoder = NULL;
58 m_pGRD = NULL; 56 m_pGRD = NULL;
59 m_gbContext = NULL; 57 m_gbContext = NULL;
60 m_dwOffset = 0; 58 m_dwOffset = 0;
61 m_ProcessiveStatus = FXCODEC_STATUS_FRAME_READY; 59 m_ProcessiveStatus = FXCODEC_STATUS_FRAME_READY;
62 m_pSymbolDictCache = pSymbolDictCache; 60 m_pSymbolDictCache = pSymbolDictCache;
63 } 61 }
64 CJBig2_Context::~CJBig2_Context() { 62 CJBig2_Context::~CJBig2_Context() {
65 delete m_pArithDecoder; 63 delete m_pArithDecoder;
66 m_pArithDecoder = NULL; 64 m_pArithDecoder = NULL;
67 delete m_pGRD; 65 delete m_pGRD;
68 m_pGRD = NULL; 66 m_pGRD = NULL;
69 if (m_gbContext) { 67 FX_Free(m_gbContext);
70 m_pModule->JBig2_Free(m_gbContext);
71 }
72 m_gbContext = NULL; 68 m_gbContext = NULL;
73 delete m_pGlobalContext; 69 delete m_pGlobalContext;
74 m_pGlobalContext = NULL; 70 m_pGlobalContext = NULL;
75 if (m_bBufSpecified) { 71 if (m_bBufSpecified) {
76 delete m_pPage; 72 delete m_pPage;
77 } 73 }
78 m_pPage = NULL; 74 m_pPage = NULL;
79 delete m_pStream; 75 delete m_pStream;
80 m_pStream = NULL; 76 m_pStream = NULL;
81 } 77 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 if (m_pGlobalContext) { 208 if (m_pGlobalContext) {
213 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); 209 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause);
214 if (nRet != JBIG2_SUCCESS) { 210 if (nRet != JBIG2_SUCCESS) {
215 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; 211 m_ProcessiveStatus = FXCODEC_STATUS_ERROR;
216 return nRet; 212 return nRet;
217 } 213 }
218 } 214 }
219 m_bFirstPage = TRUE; 215 m_bFirstPage = TRUE;
220 m_PauseStep = 0; 216 m_PauseStep = 0;
221 delete m_pPage; 217 delete m_pPage;
222 JBIG2_ALLOC(m_pPage, CJBig2_Image(width, height, stride, pBuf)); 218 m_pPage = new CJBig2_Image(width, height, stride, pBuf);
223 m_bBufSpecified = TRUE; 219 m_bBufSpecified = TRUE;
224 if (m_pPage && pPause && pPause->NeedToPauseNow()) { 220 if (m_pPage && pPause && pPause->NeedToPauseNow()) {
225 m_PauseStep = 1; 221 m_PauseStep = 1;
226 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; 222 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE;
227 return nRet; 223 return nRet;
228 } 224 }
229 int ret = Continue(pPause); 225 int ret = Continue(pPause);
230 return ret; 226 return ret;
231 } 227 }
232 int32_t CJBig2_Context::Continue(IFX_Pause* pPause) { 228 int32_t CJBig2_Context::Continue(IFX_Pause* pPause) {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 if (m_pStream->read1Byte(&cTemp) != 0) { 348 if (m_pStream->read1Byte(&cTemp) != 0) {
353 goto failed; 349 goto failed;
354 } 350 }
355 pSegment->m_nReferred_to_segment_count = cTemp >> 5; 351 pSegment->m_nReferred_to_segment_count = cTemp >> 5;
356 dwTemp = 5 + 1; 352 dwTemp = 5 + 1;
357 } 353 }
358 cSSize = 354 cSSize =
359 pSegment->m_dwNumber > 65536 ? 4 : pSegment->m_dwNumber > 256 ? 2 : 1; 355 pSegment->m_dwNumber > 65536 ? 4 : pSegment->m_dwNumber > 256 ? 2 : 1;
360 cPSize = pSegment->m_cFlags.s.page_association_size ? 4 : 1; 356 cPSize = pSegment->m_cFlags.s.page_association_size ? 4 : 1;
361 if (pSegment->m_nReferred_to_segment_count) { 357 if (pSegment->m_nReferred_to_segment_count) {
362 pSegment->m_pReferred_to_segment_numbers = 358 pSegment->m_pReferred_to_segment_numbers = (FX_DWORD*)FX_Alloc2D(
Tom Sepez 2015/09/04 01:26:47 Hmm. I think we can use a lower "D" allocator and
Lei Zhang 2015/09/04 21:34:59 Sure. This was all straight up JBig2_Malloc2 -> FX
363 (FX_DWORD*)m_pModule->JBig2_Malloc2( 359 uint8_t, sizeof(FX_DWORD), pSegment->m_nReferred_to_segment_count);
364 sizeof(FX_DWORD), pSegment->m_nReferred_to_segment_count);
365 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { 360 for (int32_t i = 0; i < pSegment->m_nReferred_to_segment_count; i++) {
366 switch (cSSize) { 361 switch (cSSize) {
367 case 1: 362 case 1:
368 if (m_pStream->read1Byte(&cTemp) != 0) { 363 if (m_pStream->read1Byte(&cTemp) != 0) {
369 goto failed; 364 goto failed;
370 } 365 }
371 pSegment->m_pReferred_to_segment_numbers[i] = cTemp; 366 pSegment->m_pReferred_to_segment_numbers[i] = cTemp;
372 break; 367 break;
373 case 2: 368 case 2:
374 if (m_pStream->readShortInteger(&wTemp) != 0) { 369 if (m_pStream->readShortInteger(&wTemp) != 0) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 } 463 }
469 pPageInfo->m_bIsStriped = ((wTemp >> 15) & 1) ? 1 : 0; 464 pPageInfo->m_bIsStriped = ((wTemp >> 15) & 1) ? 1 : 0;
470 pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff; 465 pPageInfo->m_wMaxStripeSize = wTemp & 0x7fff;
471 if ((pPageInfo->m_dwHeight == 0xffffffff) && 466 if ((pPageInfo->m_dwHeight == 0xffffffff) &&
472 (pPageInfo->m_bIsStriped != TRUE)) { 467 (pPageInfo->m_bIsStriped != TRUE)) {
473 pPageInfo->m_bIsStriped = TRUE; 468 pPageInfo->m_bIsStriped = TRUE;
474 } 469 }
475 if (!m_bBufSpecified) { 470 if (!m_bBufSpecified) {
476 delete m_pPage; 471 delete m_pPage;
477 if (pPageInfo->m_dwHeight == 0xffffffff) { 472 if (pPageInfo->m_dwHeight == 0xffffffff) {
478 JBIG2_ALLOC(m_pPage, CJBig2_Image(pPageInfo->m_dwWidth, 473 m_pPage = new CJBig2_Image(pPageInfo->m_dwWidth,
479 pPageInfo->m_wMaxStripeSize)); 474 pPageInfo->m_wMaxStripeSize);
480 } else { 475 } else {
481 JBIG2_ALLOC(m_pPage, CJBig2_Image(pPageInfo->m_dwWidth, 476 m_pPage =
482 pPageInfo->m_dwHeight)); 477 new CJBig2_Image(pPageInfo->m_dwWidth, pPageInfo->m_dwHeight);
483 } 478 }
484 } 479 }
485 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0); 480 m_pPage->fill((pPageInfo->m_cFlags & 4) ? 1 : 0);
486 m_PageInfoList.push_back(pPageInfo.release()); 481 m_PageInfoList.push_back(pPageInfo.release());
487 m_nState = JBIG2_IN_PAGE; 482 m_nState = JBIG2_IN_PAGE;
488 } break; 483 } break;
489 case 49: 484 case 49:
490 m_nState = JBIG2_OUT_OF_PAGE; 485 m_nState = JBIG2_OUT_OF_PAGE;
491 return JBIG2_END_OF_PAGE; 486 return JBIG2_END_OF_PAGE;
492 break; 487 break;
(...skipping 23 matching lines...) Expand all
516 IFX_Pause* pPause) { 511 IFX_Pause* pPause) {
517 FX_DWORD dwTemp; 512 FX_DWORD dwTemp;
518 FX_WORD wFlags; 513 FX_WORD wFlags;
519 uint8_t cSDHUFFDH, cSDHUFFDW, cSDHUFFBMSIZE, cSDHUFFAGGINST; 514 uint8_t cSDHUFFDH, cSDHUFFDW, cSDHUFFBMSIZE, cSDHUFFAGGINST;
520 CJBig2_HuffmanTable *Table_B1 = NULL, *Table_B2 = NULL, *Table_B3 = NULL, 515 CJBig2_HuffmanTable *Table_B1 = NULL, *Table_B2 = NULL, *Table_B3 = NULL,
521 *Table_B4 = NULL, *Table_B5 = NULL; 516 *Table_B4 = NULL, *Table_B5 = NULL;
522 int32_t i, nIndex, nRet; 517 int32_t i, nIndex, nRet;
523 CJBig2_Segment *pSeg = NULL, *pLRSeg = NULL; 518 CJBig2_Segment *pSeg = NULL, *pLRSeg = NULL;
524 FX_BOOL bUsed; 519 FX_BOOL bUsed;
525 CJBig2_Image** SDINSYMS = NULL; 520 CJBig2_Image** SDINSYMS = NULL;
526 CJBig2_SDDProc* pSymbolDictDecoder;
527 JBig2ArithCtx *gbContext = NULL, *grContext = NULL; 521 JBig2ArithCtx *gbContext = NULL, *grContext = NULL;
528 CJBig2_ArithDecoder* pArithDecoder; 522 CJBig2_ArithDecoder* pArithDecoder;
529 JBIG2_ALLOC(pSymbolDictDecoder, CJBig2_SDDProc()); 523 CJBig2_SDDProc* pSymbolDictDecoder = new CJBig2_SDDProc();
530 uint8_t* key = pSegment->m_pData; 524 uint8_t* key = pSegment->m_pData;
531 FX_BOOL cache_hit = false; 525 FX_BOOL cache_hit = false;
532 if (m_pStream->readShortInteger(&wFlags) != 0) { 526 if (m_pStream->readShortInteger(&wFlags) != 0) {
533 nRet = JBIG2_ERROR_TOO_SHORT; 527 nRet = JBIG2_ERROR_TOO_SHORT;
534 goto failed; 528 goto failed;
535 } 529 }
536 pSymbolDictDecoder->SDHUFF = wFlags & 0x0001; 530 pSymbolDictDecoder->SDHUFF = wFlags & 0x0001;
537 pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001; 531 pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001;
538 pSymbolDictDecoder->SDTEMPLATE = (wFlags >> 10) & 0x0003; 532 pSymbolDictDecoder->SDTEMPLATE = (wFlags >> 10) & 0x0003;
539 pSymbolDictDecoder->SDRTEMPLATE = (wFlags >> 12) & 0x0003; 533 pSymbolDictDecoder->SDRTEMPLATE = (wFlags >> 12) & 0x0003;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { 577 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) {
584 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); 578 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]);
585 if (pSeg->m_cFlags.s.type == 0) { 579 if (pSeg->m_cFlags.s.type == 0) {
586 pSymbolDictDecoder->SDNUMINSYMS += pSeg->m_Result.sd->SDNUMEXSYMS; 580 pSymbolDictDecoder->SDNUMINSYMS += pSeg->m_Result.sd->SDNUMEXSYMS;
587 pLRSeg = pSeg; 581 pLRSeg = pSeg;
588 } 582 }
589 } 583 }
590 if (pSymbolDictDecoder->SDNUMINSYMS == 0) { 584 if (pSymbolDictDecoder->SDNUMINSYMS == 0) {
591 SDINSYMS = NULL; 585 SDINSYMS = NULL;
592 } else { 586 } else {
593 SDINSYMS = (CJBig2_Image**)m_pModule->JBig2_Malloc2( 587 SDINSYMS = (CJBig2_Image**)FX_Alloc2D(uint8_t, sizeof(CJBig2_Image*),
594 sizeof(CJBig2_Image*), pSymbolDictDecoder->SDNUMINSYMS); 588 pSymbolDictDecoder->SDNUMINSYMS);
595 dwTemp = 0; 589 dwTemp = 0;
596 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { 590 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) {
597 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); 591 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]);
598 if (pSeg->m_cFlags.s.type == 0) { 592 if (pSeg->m_cFlags.s.type == 0) {
599 JBIG2_memcpy(SDINSYMS + dwTemp, pSeg->m_Result.sd->SDEXSYMS, 593 JBIG2_memcpy(SDINSYMS + dwTemp, pSeg->m_Result.sd->SDEXSYMS,
600 pSeg->m_Result.sd->SDNUMEXSYMS * sizeof(CJBig2_Image*)); 594 pSeg->m_Result.sd->SDNUMEXSYMS * sizeof(CJBig2_Image*));
601 dwTemp += pSeg->m_Result.sd->SDNUMEXSYMS; 595 dwTemp += pSeg->m_Result.sd->SDNUMEXSYMS;
602 } 596 }
603 } 597 }
604 } 598 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 } 668 }
675 pSymbolDictDecoder->SDHUFFAGGINST = pSeg->m_Result.ht; 669 pSymbolDictDecoder->SDHUFFAGGINST = pSeg->m_Result.ht;
676 } 670 }
677 } 671 }
678 } 672 }
679 if ((wFlags & 0x0100) && pLRSeg && pLRSeg->m_Result.sd->m_bContextRetained) { 673 if ((wFlags & 0x0100) && pLRSeg && pLRSeg->m_Result.sd->m_bContextRetained) {
680 if (pSymbolDictDecoder->SDHUFF == 0) { 674 if (pSymbolDictDecoder->SDHUFF == 0) {
681 dwTemp = pSymbolDictDecoder->SDTEMPLATE == 0 675 dwTemp = pSymbolDictDecoder->SDTEMPLATE == 0
682 ? 65536 676 ? 65536
683 : pSymbolDictDecoder->SDTEMPLATE == 1 ? 8192 : 1024; 677 : pSymbolDictDecoder->SDTEMPLATE == 1 ? 8192 : 1024;
684 gbContext = (JBig2ArithCtx*)m_pModule->JBig2_Malloc2( 678 gbContext =
685 sizeof(JBig2ArithCtx), dwTemp); 679 (JBig2ArithCtx*)FX_Alloc2D(uint8_t, sizeof(JBig2ArithCtx), dwTemp);
686 JBIG2_memcpy(gbContext, pLRSeg->m_Result.sd->m_gbContext, 680 JBIG2_memcpy(gbContext, pLRSeg->m_Result.sd->m_gbContext,
687 sizeof(JBig2ArithCtx) * dwTemp); 681 sizeof(JBig2ArithCtx) * dwTemp);
688 } 682 }
689 if (pSymbolDictDecoder->SDREFAGG == 1) { 683 if (pSymbolDictDecoder->SDREFAGG == 1) {
690 dwTemp = pSymbolDictDecoder->SDRTEMPLATE ? 1 << 10 : 1 << 13; 684 dwTemp = pSymbolDictDecoder->SDRTEMPLATE ? 1 << 10 : 1 << 13;
691 grContext = (JBig2ArithCtx*)m_pModule->JBig2_Malloc2( 685 grContext =
692 sizeof(JBig2ArithCtx), dwTemp); 686 (JBig2ArithCtx*)FX_Alloc2D(uint8_t, sizeof(JBig2ArithCtx), dwTemp);
693 JBIG2_memcpy(grContext, pLRSeg->m_Result.sd->m_grContext, 687 JBIG2_memcpy(grContext, pLRSeg->m_Result.sd->m_grContext,
694 sizeof(JBig2ArithCtx) * dwTemp); 688 sizeof(JBig2ArithCtx) * dwTemp);
695 } 689 }
696 } else { 690 } else {
697 if (pSymbolDictDecoder->SDHUFF == 0) { 691 if (pSymbolDictDecoder->SDHUFF == 0) {
698 dwTemp = pSymbolDictDecoder->SDTEMPLATE == 0 692 dwTemp = pSymbolDictDecoder->SDTEMPLATE == 0
699 ? 65536 693 ? 65536
700 : pSymbolDictDecoder->SDTEMPLATE == 1 ? 8192 : 1024; 694 : pSymbolDictDecoder->SDTEMPLATE == 1 ? 8192 : 1024;
701 gbContext = (JBig2ArithCtx*)m_pModule->JBig2_Malloc2( 695 gbContext =
702 sizeof(JBig2ArithCtx), dwTemp); 696 (JBig2ArithCtx*)FX_Alloc2D(uint8_t, sizeof(JBig2ArithCtx), dwTemp);
703 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); 697 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp);
704 } 698 }
705 if (pSymbolDictDecoder->SDREFAGG == 1) { 699 if (pSymbolDictDecoder->SDREFAGG == 1) {
706 dwTemp = pSymbolDictDecoder->SDRTEMPLATE ? 1 << 10 : 1 << 13; 700 dwTemp = pSymbolDictDecoder->SDRTEMPLATE ? 1 << 10 : 1 << 13;
707 grContext = (JBig2ArithCtx*)m_pModule->JBig2_Malloc2( 701 grContext =
708 sizeof(JBig2ArithCtx), dwTemp); 702 (JBig2ArithCtx*)FX_Alloc2D(uint8_t, sizeof(JBig2ArithCtx), dwTemp);
709 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); 703 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp);
710 } 704 }
711 } 705 }
712 pSegment->m_nResultType = JBIG2_SYMBOL_DICT_POINTER; 706 pSegment->m_nResultType = JBIG2_SYMBOL_DICT_POINTER;
713 for (std::list<CJBig2_CachePair>::iterator it = m_pSymbolDictCache->begin(); 707 for (std::list<CJBig2_CachePair>::iterator it = m_pSymbolDictCache->begin();
714 it != m_pSymbolDictCache->end(); ++it) { 708 it != m_pSymbolDictCache->end(); ++it) {
715 if (it->first == key) { 709 if (it->first == key) {
716 pSegment->m_Result.sd = it->second->DeepCopy(); 710 pSegment->m_Result.sd = it->second->DeepCopy();
717 m_pSymbolDictCache->push_front(*it); 711 m_pSymbolDictCache->push_front(*it);
718 m_pSymbolDictCache->erase(it); 712 m_pSymbolDictCache->erase(it);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 pSegment->m_Result.sd->m_gbContext = gbContext; 750 pSegment->m_Result.sd->m_gbContext = gbContext;
757 } 751 }
758 if (pSymbolDictDecoder->SDREFAGG == 1) { 752 if (pSymbolDictDecoder->SDREFAGG == 1) {
759 pSegment->m_Result.sd->m_grContext = grContext; 753 pSegment->m_Result.sd->m_grContext = grContext;
760 } 754 }
761 bUsed = TRUE; 755 bUsed = TRUE;
762 } else { 756 } else {
763 bUsed = FALSE; 757 bUsed = FALSE;
764 } 758 }
765 delete pSymbolDictDecoder; 759 delete pSymbolDictDecoder;
766 if (SDINSYMS) { 760 FX_Free(SDINSYMS);
767 m_pModule->JBig2_Free(SDINSYMS);
768 }
769 delete Table_B1; 761 delete Table_B1;
770 delete Table_B2; 762 delete Table_B2;
771 delete Table_B3; 763 delete Table_B3;
772 delete Table_B4; 764 delete Table_B4;
773 delete Table_B5; 765 delete Table_B5;
774 if (bUsed == FALSE) { 766 if (bUsed == FALSE) {
775 if (gbContext) { 767 FX_Free(gbContext);
776 m_pModule->JBig2_Free(gbContext); 768 FX_Free(grContext);
777 }
778 if (grContext) {
779 m_pModule->JBig2_Free(grContext);
780 }
781 } 769 }
782 return JBIG2_SUCCESS; 770 return JBIG2_SUCCESS;
783 failed: 771 failed:
784 delete pSymbolDictDecoder; 772 delete pSymbolDictDecoder;
785 if (SDINSYMS) { 773 FX_Free(SDINSYMS);
786 m_pModule->JBig2_Free(SDINSYMS);
787 }
788 delete Table_B1; 774 delete Table_B1;
789 delete Table_B2; 775 delete Table_B2;
790 delete Table_B3; 776 delete Table_B3;
791 delete Table_B4; 777 delete Table_B4;
792 delete Table_B5; 778 delete Table_B5;
793 if (gbContext) { 779 FX_Free(gbContext);
794 m_pModule->JBig2_Free(gbContext); 780 FX_Free(grContext);
795 }
796 if (grContext) {
797 m_pModule->JBig2_Free(grContext);
798 }
799 return nRet; 781 return nRet;
800 } 782 }
801 783
802 int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { 784 int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
803 FX_DWORD dwTemp; 785 FX_DWORD dwTemp;
804 FX_WORD wFlags; 786 FX_WORD wFlags;
805 int32_t i, nIndex, nRet; 787 int32_t i, nIndex, nRet;
806 JBig2RegionInfo ri; 788 JBig2RegionInfo ri;
807 CJBig2_Segment* pSeg; 789 CJBig2_Segment* pSeg;
808 CJBig2_Image** SBSYMS = NULL; 790 CJBig2_Image** SBSYMS = NULL;
809 JBig2HuffmanCode* SBSYMCODES = NULL; 791 JBig2HuffmanCode* SBSYMCODES = NULL;
810 uint8_t cSBHUFFFS, cSBHUFFDS, cSBHUFFDT, cSBHUFFRDW, cSBHUFFRDH, cSBHUFFRDX, 792 uint8_t cSBHUFFFS, cSBHUFFDS, cSBHUFFDT, cSBHUFFRDW, cSBHUFFRDH, cSBHUFFRDX,
811 cSBHUFFRDY, cSBHUFFRSIZE; 793 cSBHUFFRDY, cSBHUFFRSIZE;
812 CJBig2_HuffmanTable *Table_B1 = NULL, *Table_B6 = NULL, *Table_B7 = NULL, 794 CJBig2_HuffmanTable *Table_B1 = NULL, *Table_B6 = NULL, *Table_B7 = NULL,
813 *Table_B8 = NULL, *Table_B9 = NULL, *Table_B10 = NULL, 795 *Table_B8 = NULL, *Table_B9 = NULL, *Table_B10 = NULL,
814 *Table_B11 = NULL, *Table_B12 = NULL, *Table_B13 = NULL, 796 *Table_B11 = NULL, *Table_B12 = NULL, *Table_B13 = NULL,
815 *Table_B14 = NULL, *Table_B15 = NULL; 797 *Table_B14 = NULL, *Table_B15 = NULL;
816 JBig2ArithCtx* grContext = NULL; 798 JBig2ArithCtx* grContext = NULL;
817 CJBig2_ArithDecoder* pArithDecoder; 799 CJBig2_ArithDecoder* pArithDecoder;
818 CJBig2_TRDProc* pTRD; 800 CJBig2_TRDProc* pTRD = new CJBig2_TRDProc();
819 JBIG2_ALLOC(pTRD, CJBig2_TRDProc());
820 if ((parseRegionInfo(&ri) != JBIG2_SUCCESS) || 801 if ((parseRegionInfo(&ri) != JBIG2_SUCCESS) ||
821 (m_pStream->readShortInteger(&wFlags) != 0)) { 802 (m_pStream->readShortInteger(&wFlags) != 0)) {
822 nRet = JBIG2_ERROR_TOO_SHORT; 803 nRet = JBIG2_ERROR_TOO_SHORT;
823 goto failed; 804 goto failed;
824 } 805 }
825 pTRD->SBW = ri.width; 806 pTRD->SBW = ri.width;
826 pTRD->SBH = ri.height; 807 pTRD->SBH = ri.height;
827 pTRD->SBHUFF = wFlags & 0x0001; 808 pTRD->SBHUFF = wFlags & 0x0001;
828 pTRD->SBREFINE = (wFlags >> 1) & 0x0001; 809 pTRD->SBREFINE = (wFlags >> 1) & 0x0001;
829 dwTemp = (wFlags >> 2) & 0x0003; 810 dwTemp = (wFlags >> 2) & 0x0003;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 } 851 }
871 } 852 }
872 pTRD->SBNUMSYMS = 0; 853 pTRD->SBNUMSYMS = 0;
873 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { 854 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) {
874 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); 855 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]);
875 if (pSeg->m_cFlags.s.type == 0) { 856 if (pSeg->m_cFlags.s.type == 0) {
876 pTRD->SBNUMSYMS += pSeg->m_Result.sd->SDNUMEXSYMS; 857 pTRD->SBNUMSYMS += pSeg->m_Result.sd->SDNUMEXSYMS;
877 } 858 }
878 } 859 }
879 if (pTRD->SBNUMSYMS > 0) { 860 if (pTRD->SBNUMSYMS > 0) {
880 SBSYMS = (CJBig2_Image**)m_pModule->JBig2_Malloc2(sizeof(CJBig2_Image*), 861 SBSYMS = (CJBig2_Image**)FX_Alloc2D(uint8_t, sizeof(CJBig2_Image*),
881 pTRD->SBNUMSYMS); 862 pTRD->SBNUMSYMS);
882 dwTemp = 0; 863 dwTemp = 0;
883 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { 864 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) {
884 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); 865 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]);
885 if (pSeg->m_cFlags.s.type == 0) { 866 if (pSeg->m_cFlags.s.type == 0) {
886 JBIG2_memcpy(SBSYMS + dwTemp, pSeg->m_Result.sd->SDEXSYMS, 867 JBIG2_memcpy(SBSYMS + dwTemp, pSeg->m_Result.sd->SDEXSYMS,
887 pSeg->m_Result.sd->SDNUMEXSYMS * sizeof(CJBig2_Image*)); 868 pSeg->m_Result.sd->SDNUMEXSYMS * sizeof(CJBig2_Image*));
888 dwTemp += pSeg->m_Result.sd->SDNUMEXSYMS; 869 dwTemp += pSeg->m_Result.sd->SDNUMEXSYMS;
889 } 870 }
890 } 871 }
891 pTRD->SBSYMS = SBSYMS; 872 pTRD->SBSYMS = SBSYMS;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 if (!pSeg) { 1053 if (!pSeg) {
1073 nRet = JBIG2_ERROR_FATAL; 1054 nRet = JBIG2_ERROR_FATAL;
1074 goto failed; 1055 goto failed;
1075 } 1056 }
1076 pTRD->SBHUFFRSIZE = pSeg->m_Result.ht; 1057 pTRD->SBHUFFRSIZE = pSeg->m_Result.ht;
1077 } 1058 }
1078 } 1059 }
1079 if (pTRD->SBREFINE == 1) { 1060 if (pTRD->SBREFINE == 1) {
1080 dwTemp = pTRD->SBRTEMPLATE ? 1 << 10 : 1 << 13; 1061 dwTemp = pTRD->SBRTEMPLATE ? 1 << 10 : 1 << 13;
1081 grContext = 1062 grContext =
1082 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); 1063 (JBig2ArithCtx*)FX_Alloc2D(uint8_t, sizeof(JBig2ArithCtx), dwTemp);
1083 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); 1064 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp);
1084 } 1065 }
1085 if (pTRD->SBHUFF == 0) { 1066 if (pTRD->SBHUFF == 0) {
1086 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); 1067 pArithDecoder = new CJBig2_ArithDecoder(m_pStream);
1087 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; 1068 pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
1088 pSegment->m_Result.im = pTRD->decode_Arith(pArithDecoder, grContext); 1069 pSegment->m_Result.im = pTRD->decode_Arith(pArithDecoder, grContext);
1089 delete pArithDecoder; 1070 delete pArithDecoder;
1090 if (pSegment->m_Result.im == NULL) { 1071 if (pSegment->m_Result.im == NULL) {
1091 nRet = JBIG2_ERROR_FATAL; 1072 nRet = JBIG2_ERROR_FATAL;
1092 goto failed; 1073 goto failed;
(...skipping 16 matching lines...) Expand all
1109 (ri.y + ri.height > m_pPage->m_nHeight)) { 1090 (ri.y + ri.height > m_pPage->m_nHeight)) {
1110 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); 1091 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0);
1111 } 1092 }
1112 } 1093 }
1113 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, 1094 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im,
1114 (JBig2ComposeOp)(ri.flags & 0x03)); 1095 (JBig2ComposeOp)(ri.flags & 0x03));
1115 delete pSegment->m_Result.im; 1096 delete pSegment->m_Result.im;
1116 pSegment->m_Result.im = NULL; 1097 pSegment->m_Result.im = NULL;
1117 } 1098 }
1118 delete pTRD; 1099 delete pTRD;
1119 if (SBSYMS) { 1100 FX_Free(SBSYMS);
1120 m_pModule->JBig2_Free(SBSYMS); 1101 FX_Free(SBSYMCODES);
1121 } 1102 FX_Free(grContext);
1122 if (SBSYMCODES) {
1123 m_pModule->JBig2_Free(SBSYMCODES);
1124 }
1125 if (grContext) {
1126 m_pModule->JBig2_Free(grContext);
1127 }
1128 delete Table_B1; 1103 delete Table_B1;
1129 delete Table_B6; 1104 delete Table_B6;
1130 delete Table_B7; 1105 delete Table_B7;
1131 delete Table_B8; 1106 delete Table_B8;
1132 delete Table_B9; 1107 delete Table_B9;
1133 delete Table_B10; 1108 delete Table_B10;
1134 delete Table_B11; 1109 delete Table_B11;
1135 delete Table_B12; 1110 delete Table_B12;
1136 delete Table_B13; 1111 delete Table_B13;
1137 delete Table_B14; 1112 delete Table_B14;
1138 delete Table_B15; 1113 delete Table_B15;
1139 return JBIG2_SUCCESS; 1114 return JBIG2_SUCCESS;
1140 failed: 1115 failed:
1141 delete pTRD; 1116 delete pTRD;
1142 if (SBSYMS) { 1117 FX_Free(SBSYMS);
1143 m_pModule->JBig2_Free(SBSYMS); 1118 FX_Free(SBSYMCODES);
1144 } 1119 FX_Free(grContext);
1145 if (SBSYMCODES) {
1146 m_pModule->JBig2_Free(SBSYMCODES);
1147 }
1148 if (grContext) {
1149 m_pModule->JBig2_Free(grContext);
1150 }
1151 delete Table_B1; 1120 delete Table_B1;
1152 delete Table_B6; 1121 delete Table_B6;
1153 delete Table_B7; 1122 delete Table_B7;
1154 delete Table_B8; 1123 delete Table_B8;
1155 delete Table_B9; 1124 delete Table_B9;
1156 delete Table_B10; 1125 delete Table_B10;
1157 delete Table_B11; 1126 delete Table_B11;
1158 delete Table_B12; 1127 delete Table_B12;
1159 delete Table_B13; 1128 delete Table_B13;
1160 delete Table_B14; 1129 delete Table_B14;
1161 delete Table_B15; 1130 delete Table_B15;
1162 return nRet; 1131 return nRet;
1163 } 1132 }
1164 1133
1165 int32_t CJBig2_Context::parsePatternDict(CJBig2_Segment* pSegment, 1134 int32_t CJBig2_Context::parsePatternDict(CJBig2_Segment* pSegment,
1166 IFX_Pause* pPause) { 1135 IFX_Pause* pPause) {
1167 FX_DWORD dwTemp; 1136 FX_DWORD dwTemp;
1168 uint8_t cFlags; 1137 uint8_t cFlags;
1169 JBig2ArithCtx* gbContext; 1138 JBig2ArithCtx* gbContext;
1170 CJBig2_ArithDecoder* pArithDecoder; 1139 CJBig2_ArithDecoder* pArithDecoder;
1171 CJBig2_PDDProc* pPDD;
1172 int32_t nRet; 1140 int32_t nRet;
1173 JBIG2_ALLOC(pPDD, CJBig2_PDDProc()); 1141 CJBig2_PDDProc* pPDD = new CJBig2_PDDProc();
1174 if ((m_pStream->read1Byte(&cFlags) != 0) || 1142 if ((m_pStream->read1Byte(&cFlags) != 0) ||
1175 (m_pStream->read1Byte(&pPDD->HDPW) != 0) || 1143 (m_pStream->read1Byte(&pPDD->HDPW) != 0) ||
1176 (m_pStream->read1Byte(&pPDD->HDPH) != 0) || 1144 (m_pStream->read1Byte(&pPDD->HDPH) != 0) ||
1177 (m_pStream->readInteger(&pPDD->GRAYMAX) != 0)) { 1145 (m_pStream->readInteger(&pPDD->GRAYMAX) != 0)) {
1178 nRet = JBIG2_ERROR_TOO_SHORT; 1146 nRet = JBIG2_ERROR_TOO_SHORT;
1179 goto failed; 1147 goto failed;
1180 } 1148 }
1181 if (pPDD->GRAYMAX > JBIG2_MAX_PATTERN_INDEX) { 1149 if (pPDD->GRAYMAX > JBIG2_MAX_PATTERN_INDEX) {
1182 nRet = JBIG2_ERROR_LIMIT; 1150 nRet = JBIG2_ERROR_LIMIT;
1183 goto failed; 1151 goto failed;
1184 } 1152 }
1185 pPDD->HDMMR = cFlags & 0x01; 1153 pPDD->HDMMR = cFlags & 0x01;
1186 pPDD->HDTEMPLATE = (cFlags >> 1) & 0x03; 1154 pPDD->HDTEMPLATE = (cFlags >> 1) & 0x03;
1187 pSegment->m_nResultType = JBIG2_PATTERN_DICT_POINTER; 1155 pSegment->m_nResultType = JBIG2_PATTERN_DICT_POINTER;
1188 if (pPDD->HDMMR == 0) { 1156 if (pPDD->HDMMR == 0) {
1189 dwTemp = 1157 dwTemp =
1190 pPDD->HDTEMPLATE == 0 ? 65536 : pPDD->HDTEMPLATE == 1 ? 8192 : 1024; 1158 pPDD->HDTEMPLATE == 0 ? 65536 : pPDD->HDTEMPLATE == 1 ? 8192 : 1024;
1191 gbContext = 1159 gbContext =
1192 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); 1160 (JBig2ArithCtx*)FX_Alloc2D(uint8_t, sizeof(JBig2ArithCtx), dwTemp);
1193 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); 1161 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp);
1194 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); 1162 pArithDecoder = new CJBig2_ArithDecoder(m_pStream);
1195 pSegment->m_Result.pd = 1163 pSegment->m_Result.pd =
1196 pPDD->decode_Arith(pArithDecoder, gbContext, pPause); 1164 pPDD->decode_Arith(pArithDecoder, gbContext, pPause);
1197 delete pArithDecoder; 1165 delete pArithDecoder;
1198 if (pSegment->m_Result.pd == NULL) { 1166 if (pSegment->m_Result.pd == NULL) {
1199 m_pModule->JBig2_Free(gbContext); 1167 FX_Free(gbContext);
1200 nRet = JBIG2_ERROR_FATAL; 1168 nRet = JBIG2_ERROR_FATAL;
1201 goto failed; 1169 goto failed;
1202 } 1170 }
1203 m_pModule->JBig2_Free(gbContext); 1171 FX_Free(gbContext);
1204 m_pStream->alignByte(); 1172 m_pStream->alignByte();
1205 m_pStream->offset(2); 1173 m_pStream->offset(2);
1206 } else { 1174 } else {
1207 pSegment->m_Result.pd = pPDD->decode_MMR(m_pStream, pPause); 1175 pSegment->m_Result.pd = pPDD->decode_MMR(m_pStream, pPause);
1208 if (pSegment->m_Result.pd == NULL) { 1176 if (pSegment->m_Result.pd == NULL) {
1209 nRet = JBIG2_ERROR_FATAL; 1177 nRet = JBIG2_ERROR_FATAL;
1210 goto failed; 1178 goto failed;
1211 } 1179 }
1212 m_pStream->alignByte(); 1180 m_pStream->alignByte();
1213 } 1181 }
1214 delete pPDD; 1182 delete pPDD;
1215 return JBIG2_SUCCESS; 1183 return JBIG2_SUCCESS;
1216 failed: 1184 failed:
1217 delete pPDD; 1185 delete pPDD;
1218 return nRet; 1186 return nRet;
1219 } 1187 }
1220 int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, 1188 int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment,
1221 IFX_Pause* pPause) { 1189 IFX_Pause* pPause) {
1222 FX_DWORD dwTemp; 1190 FX_DWORD dwTemp;
1223 uint8_t cFlags; 1191 uint8_t cFlags;
1224 JBig2RegionInfo ri; 1192 JBig2RegionInfo ri;
1225 CJBig2_Segment* pSeg; 1193 CJBig2_Segment* pSeg;
1226 CJBig2_PatternDict* pPatternDict; 1194 CJBig2_PatternDict* pPatternDict;
1227 JBig2ArithCtx* gbContext; 1195 JBig2ArithCtx* gbContext;
1228 CJBig2_ArithDecoder* pArithDecoder; 1196 CJBig2_ArithDecoder* pArithDecoder;
1229 CJBig2_HTRDProc* pHRD;
1230 int32_t nRet; 1197 int32_t nRet;
1231 JBIG2_ALLOC(pHRD, CJBig2_HTRDProc()); 1198 CJBig2_HTRDProc* pHRD = new CJBig2_HTRDProc();
1232 if ((parseRegionInfo(&ri) != JBIG2_SUCCESS) || 1199 if ((parseRegionInfo(&ri) != JBIG2_SUCCESS) ||
1233 (m_pStream->read1Byte(&cFlags) != 0) || 1200 (m_pStream->read1Byte(&cFlags) != 0) ||
1234 (m_pStream->readInteger(&pHRD->HGW) != 0) || 1201 (m_pStream->readInteger(&pHRD->HGW) != 0) ||
1235 (m_pStream->readInteger(&pHRD->HGH) != 0) || 1202 (m_pStream->readInteger(&pHRD->HGH) != 0) ||
1236 (m_pStream->readInteger((FX_DWORD*)&pHRD->HGX) != 0) || 1203 (m_pStream->readInteger((FX_DWORD*)&pHRD->HGX) != 0) ||
1237 (m_pStream->readInteger((FX_DWORD*)&pHRD->HGY) != 0) || 1204 (m_pStream->readInteger((FX_DWORD*)&pHRD->HGY) != 0) ||
1238 (m_pStream->readShortInteger(&pHRD->HRX) != 0) || 1205 (m_pStream->readShortInteger(&pHRD->HRX) != 0) ||
1239 (m_pStream->readShortInteger(&pHRD->HRY) != 0)) { 1206 (m_pStream->readShortInteger(&pHRD->HRY) != 0)) {
1240 nRet = JBIG2_ERROR_TOO_SHORT; 1207 nRet = JBIG2_ERROR_TOO_SHORT;
1241 goto failed; 1208 goto failed;
(...skipping 20 matching lines...) Expand all
1262 goto failed; 1229 goto failed;
1263 } 1230 }
1264 pHRD->HNUMPATS = pPatternDict->NUMPATS; 1231 pHRD->HNUMPATS = pPatternDict->NUMPATS;
1265 pHRD->HPATS = pPatternDict->HDPATS; 1232 pHRD->HPATS = pPatternDict->HDPATS;
1266 pHRD->HPW = pPatternDict->HDPATS[0]->m_nWidth; 1233 pHRD->HPW = pPatternDict->HDPATS[0]->m_nWidth;
1267 pHRD->HPH = pPatternDict->HDPATS[0]->m_nHeight; 1234 pHRD->HPH = pPatternDict->HDPATS[0]->m_nHeight;
1268 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; 1235 pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
1269 if (pHRD->HMMR == 0) { 1236 if (pHRD->HMMR == 0) {
1270 dwTemp = pHRD->HTEMPLATE == 0 ? 65536 : pHRD->HTEMPLATE == 1 ? 8192 : 1024; 1237 dwTemp = pHRD->HTEMPLATE == 0 ? 65536 : pHRD->HTEMPLATE == 1 ? 8192 : 1024;
1271 gbContext = 1238 gbContext =
1272 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); 1239 (JBig2ArithCtx*)FX_Alloc2D(uint8_t, sizeof(JBig2ArithCtx), dwTemp);
1273 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); 1240 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp);
1274 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); 1241 pArithDecoder = new CJBig2_ArithDecoder(m_pStream);
1275 pSegment->m_Result.im = 1242 pSegment->m_Result.im =
1276 pHRD->decode_Arith(pArithDecoder, gbContext, pPause); 1243 pHRD->decode_Arith(pArithDecoder, gbContext, pPause);
1277 delete pArithDecoder; 1244 delete pArithDecoder;
1278 if (pSegment->m_Result.im == NULL) { 1245 if (pSegment->m_Result.im == NULL) {
1279 m_pModule->JBig2_Free(gbContext); 1246 FX_Free(gbContext);
1280 nRet = JBIG2_ERROR_FATAL; 1247 nRet = JBIG2_ERROR_FATAL;
1281 goto failed; 1248 goto failed;
1282 } 1249 }
1283 m_pModule->JBig2_Free(gbContext); 1250 FX_Free(gbContext);
1284 m_pStream->alignByte(); 1251 m_pStream->alignByte();
1285 m_pStream->offset(2); 1252 m_pStream->offset(2);
1286 } else { 1253 } else {
1287 pSegment->m_Result.im = pHRD->decode_MMR(m_pStream, pPause); 1254 pSegment->m_Result.im = pHRD->decode_MMR(m_pStream, pPause);
1288 if (pSegment->m_Result.im == NULL) { 1255 if (pSegment->m_Result.im == NULL) {
1289 nRet = JBIG2_ERROR_FATAL; 1256 nRet = JBIG2_ERROR_FATAL;
1290 goto failed; 1257 goto failed;
1291 } 1258 }
1292 m_pStream->alignByte(); 1259 m_pStream->alignByte();
1293 } 1260 }
(...skipping 16 matching lines...) Expand all
1310 delete pHRD; 1277 delete pHRD;
1311 return nRet; 1278 return nRet;
1312 } 1279 }
1313 1280
1314 int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, 1281 int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment,
1315 IFX_Pause* pPause) { 1282 IFX_Pause* pPause) {
1316 FX_DWORD dwTemp; 1283 FX_DWORD dwTemp;
1317 uint8_t cFlags; 1284 uint8_t cFlags;
1318 int32_t i, nRet; 1285 int32_t i, nRet;
1319 if (m_pGRD == NULL) { 1286 if (m_pGRD == NULL) {
1320 JBIG2_ALLOC(m_pGRD, CJBig2_GRDProc()); 1287 m_pGRD = new CJBig2_GRDProc();
1321 if ((parseRegionInfo(&m_ri) != JBIG2_SUCCESS) || 1288 if ((parseRegionInfo(&m_ri) != JBIG2_SUCCESS) ||
1322 (m_pStream->read1Byte(&cFlags) != 0)) { 1289 (m_pStream->read1Byte(&cFlags) != 0)) {
1323 nRet = JBIG2_ERROR_TOO_SHORT; 1290 nRet = JBIG2_ERROR_TOO_SHORT;
1324 goto failed; 1291 goto failed;
1325 } 1292 }
1326 if (m_ri.height < 0 || m_ri.width < 0) { 1293 if (m_ri.height < 0 || m_ri.width < 0) {
1327 nRet = JBIG2_FAILED; 1294 nRet = JBIG2_FAILED;
1328 goto failed; 1295 goto failed;
1329 } 1296 }
1330 m_pGRD->GBW = m_ri.width; 1297 m_pGRD->GBW = m_ri.width;
(...skipping 18 matching lines...) Expand all
1349 } 1316 }
1350 } 1317 }
1351 } 1318 }
1352 m_pGRD->USESKIP = 0; 1319 m_pGRD->USESKIP = 0;
1353 } 1320 }
1354 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; 1321 pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
1355 if (m_pGRD->MMR == 0) { 1322 if (m_pGRD->MMR == 0) {
1356 dwTemp = 1323 dwTemp =
1357 m_pGRD->GBTEMPLATE == 0 ? 65536 : m_pGRD->GBTEMPLATE == 1 ? 8192 : 1024; 1324 m_pGRD->GBTEMPLATE == 0 ? 65536 : m_pGRD->GBTEMPLATE == 1 ? 8192 : 1024;
1358 if (m_gbContext == NULL) { 1325 if (m_gbContext == NULL) {
1359 m_gbContext = (JBig2ArithCtx*)m_pModule->JBig2_Malloc( 1326 m_gbContext =
1360 sizeof(JBig2ArithCtx) * dwTemp); 1327 (JBig2ArithCtx*)FX_Alloc2D(uint8_t, sizeof(JBig2ArithCtx), dwTemp);
1361 JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); 1328 JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp);
1362 } 1329 }
1363 if (m_pArithDecoder == NULL) { 1330 if (m_pArithDecoder == NULL) {
1364 m_pArithDecoder = new CJBig2_ArithDecoder(m_pStream); 1331 m_pArithDecoder = new CJBig2_ArithDecoder(m_pStream);
1365 m_ProcessiveStatus = m_pGRD->Start_decode_Arith( 1332 m_ProcessiveStatus = m_pGRD->Start_decode_Arith(
1366 &pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause); 1333 &pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause);
1367 } else { 1334 } else {
1368 m_ProcessiveStatus = m_pGRD->Continue_decode(pPause); 1335 m_ProcessiveStatus = m_pGRD->Continue_decode(pPause);
1369 } 1336 }
1370 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { 1337 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
1371 if (pSegment->m_cFlags.s.type != 36) { 1338 if (pSegment->m_cFlags.s.type != 36) {
1372 if (!m_bBufSpecified) { 1339 if (!m_bBufSpecified) {
1373 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); 1340 JBig2PageInfo* pPageInfo = m_PageInfoList.back();
1374 if ((pPageInfo->m_bIsStriped == 1) && 1341 if ((pPageInfo->m_bIsStriped == 1) &&
1375 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { 1342 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) {
1376 m_pPage->expand(m_ri.y + m_ri.height, 1343 m_pPage->expand(m_ri.y + m_ri.height,
1377 (pPageInfo->m_cFlags & 4) ? 1 : 0); 1344 (pPageInfo->m_cFlags & 4) ? 1 : 0);
1378 } 1345 }
1379 } 1346 }
1380 FX_RECT Rect = m_pGRD->GetReplaceRect(); 1347 FX_RECT Rect = m_pGRD->GetReplaceRect();
1381 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, 1348 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top,
1382 pSegment->m_Result.im, 1349 pSegment->m_Result.im,
1383 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); 1350 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect);
1384 } 1351 }
1385 return JBIG2_SUCCESS; 1352 return JBIG2_SUCCESS;
1386 } else { 1353 } else {
1387 delete m_pArithDecoder; 1354 delete m_pArithDecoder;
1388 m_pArithDecoder = NULL; 1355 m_pArithDecoder = NULL;
1389 if (pSegment->m_Result.im == NULL) { 1356 if (pSegment->m_Result.im == NULL) {
1390 m_pModule->JBig2_Free(m_gbContext); 1357 FX_Free(m_gbContext);
1391 nRet = JBIG2_ERROR_FATAL; 1358 nRet = JBIG2_ERROR_FATAL;
1392 m_gbContext = NULL; 1359 m_gbContext = NULL;
1393 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; 1360 m_ProcessiveStatus = FXCODEC_STATUS_ERROR;
1394 goto failed; 1361 goto failed;
1395 } 1362 }
1396 m_pModule->JBig2_Free(m_gbContext); 1363 FX_Free(m_gbContext);
1397 m_gbContext = NULL; 1364 m_gbContext = NULL;
1398 m_pStream->alignByte(); 1365 m_pStream->alignByte();
1399 m_pStream->offset(2); 1366 m_pStream->offset(2);
1400 } 1367 }
1401 } else { 1368 } else {
1402 FXCODEC_STATUS status = 1369 FXCODEC_STATUS status =
1403 m_pGRD->Start_decode_MMR(&pSegment->m_Result.im, m_pStream, pPause); 1370 m_pGRD->Start_decode_MMR(&pSegment->m_Result.im, m_pStream, pPause);
1404 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { 1371 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
1405 m_pGRD->Continue_decode(pPause); 1372 m_pGRD->Continue_decode(pPause);
1406 } 1373 }
(...skipping 28 matching lines...) Expand all
1435 return nRet; 1402 return nRet;
1436 } 1403 }
1437 1404
1438 int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { 1405 int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) {
1439 FX_DWORD dwTemp; 1406 FX_DWORD dwTemp;
1440 JBig2RegionInfo ri; 1407 JBig2RegionInfo ri;
1441 CJBig2_Segment* pSeg; 1408 CJBig2_Segment* pSeg;
1442 int32_t i, nRet; 1409 int32_t i, nRet;
1443 uint8_t cFlags; 1410 uint8_t cFlags;
1444 JBig2ArithCtx* grContext; 1411 JBig2ArithCtx* grContext;
1445 CJBig2_GRRDProc* pGRRD;
1446 CJBig2_ArithDecoder* pArithDecoder; 1412 CJBig2_ArithDecoder* pArithDecoder;
1447 JBIG2_ALLOC(pGRRD, CJBig2_GRRDProc()); 1413 CJBig2_GRRDProc* pGRRD = new CJBig2_GRRDProc();
1448 if ((parseRegionInfo(&ri) != JBIG2_SUCCESS) || 1414 if ((parseRegionInfo(&ri) != JBIG2_SUCCESS) ||
1449 (m_pStream->read1Byte(&cFlags) != 0)) { 1415 (m_pStream->read1Byte(&cFlags) != 0)) {
1450 nRet = JBIG2_ERROR_TOO_SHORT; 1416 nRet = JBIG2_ERROR_TOO_SHORT;
1451 goto failed; 1417 goto failed;
1452 } 1418 }
1453 pGRRD->GRW = ri.width; 1419 pGRRD->GRW = ri.width;
1454 pGRRD->GRH = ri.height; 1420 pGRRD->GRH = ri.height;
1455 pGRRD->GRTEMPLATE = cFlags & 0x01; 1421 pGRRD->GRTEMPLATE = cFlags & 0x01;
1456 pGRRD->TPGRON = (cFlags >> 1) & 0x01; 1422 pGRRD->TPGRON = (cFlags >> 1) & 0x01;
1457 if (pGRRD->GRTEMPLATE == 0) { 1423 if (pGRRD->GRTEMPLATE == 0) {
(...skipping 22 matching lines...) Expand all
1480 goto failed; 1446 goto failed;
1481 } 1447 }
1482 pGRRD->GRREFERENCE = pSeg->m_Result.im; 1448 pGRRD->GRREFERENCE = pSeg->m_Result.im;
1483 } else { 1449 } else {
1484 pGRRD->GRREFERENCE = m_pPage; 1450 pGRRD->GRREFERENCE = m_pPage;
1485 } 1451 }
1486 pGRRD->GRREFERENCEDX = 0; 1452 pGRRD->GRREFERENCEDX = 0;
1487 pGRRD->GRREFERENCEDY = 0; 1453 pGRRD->GRREFERENCEDY = 0;
1488 dwTemp = pGRRD->GRTEMPLATE ? 1 << 10 : 1 << 13; 1454 dwTemp = pGRRD->GRTEMPLATE ? 1 << 10 : 1 << 13;
1489 grContext = 1455 grContext =
1490 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); 1456 (JBig2ArithCtx*)FX_Alloc2D(uint8_t, sizeof(JBig2ArithCtx), dwTemp);
1491 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); 1457 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp);
1492 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); 1458 pArithDecoder = new CJBig2_ArithDecoder(m_pStream);
1493 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; 1459 pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
1494 pSegment->m_Result.im = pGRRD->decode(pArithDecoder, grContext); 1460 pSegment->m_Result.im = pGRRD->decode(pArithDecoder, grContext);
1495 delete pArithDecoder; 1461 delete pArithDecoder;
1496 if (pSegment->m_Result.im == NULL) { 1462 if (pSegment->m_Result.im == NULL) {
1497 m_pModule->JBig2_Free(grContext); 1463 FX_Free(grContext);
1498 nRet = JBIG2_ERROR_FATAL; 1464 nRet = JBIG2_ERROR_FATAL;
1499 goto failed; 1465 goto failed;
1500 } 1466 }
1501 m_pModule->JBig2_Free(grContext); 1467 FX_Free(grContext);
1502 m_pStream->alignByte(); 1468 m_pStream->alignByte();
1503 m_pStream->offset(2); 1469 m_pStream->offset(2);
1504 if (pSegment->m_cFlags.s.type != 40) { 1470 if (pSegment->m_cFlags.s.type != 40) {
1505 if (!m_bBufSpecified) { 1471 if (!m_bBufSpecified) {
1506 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); 1472 JBig2PageInfo* pPageInfo = m_PageInfoList.back();
1507 if ((pPageInfo->m_bIsStriped == 1) && 1473 if ((pPageInfo->m_bIsStriped == 1) &&
1508 (ri.y + ri.height > m_pPage->m_nHeight)) { 1474 (ri.y + ri.height > m_pPage->m_nHeight)) {
1509 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); 1475 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0);
1510 } 1476 }
1511 } 1477 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 JBig2HuffmanCode* SBSYMCODES; 1513 JBig2HuffmanCode* SBSYMCODES;
1548 int32_t runcodes[35]; 1514 int32_t runcodes[35];
1549 int32_t runcodes_len[35]; 1515 int32_t runcodes_len[35];
1550 int32_t runcode; 1516 int32_t runcode;
1551 int32_t i; 1517 int32_t i;
1552 int32_t j; 1518 int32_t j;
1553 int32_t nVal; 1519 int32_t nVal;
1554 int32_t nBits; 1520 int32_t nBits;
1555 int32_t run; 1521 int32_t run;
1556 FX_DWORD nTemp; 1522 FX_DWORD nTemp;
1557 SBSYMCODES = (JBig2HuffmanCode*)m_pModule->JBig2_Malloc2( 1523 SBSYMCODES = (JBig2HuffmanCode*)FX_Alloc2D(uint8_t, sizeof(JBig2HuffmanCode),
1558 sizeof(JBig2HuffmanCode), SBNUMSYMS); 1524 SBNUMSYMS);
1559 for (i = 0; i < 35; i++) { 1525 for (i = 0; i < 35; i++) {
1560 if (pStream->readNBits(4, &runcodes_len[i]) != 0) { 1526 if (pStream->readNBits(4, &runcodes_len[i]) != 0) {
1561 goto failed; 1527 goto failed;
1562 } 1528 }
1563 } 1529 }
1564 huffman_assign_code(runcodes, runcodes_len, 35); 1530 huffman_assign_code(runcodes, runcodes_len, 35);
1565 i = 0; 1531 i = 0;
1566 while (i < (int)SBNUMSYMS) { 1532 while (i < (int)SBNUMSYMS) {
1567 nVal = 0; 1533 nVal = 0;
1568 nBits = 0; 1534 nBits = 0;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 } 1579 }
1614 } 1580 }
1615 i += run; 1581 i += run;
1616 } else { 1582 } else {
1617 i++; 1583 i++;
1618 } 1584 }
1619 } 1585 }
1620 huffman_assign_code(SBSYMCODES, SBNUMSYMS); 1586 huffman_assign_code(SBSYMCODES, SBNUMSYMS);
1621 return SBSYMCODES; 1587 return SBSYMCODES;
1622 failed: 1588 failed:
1623 m_pModule->JBig2_Free(SBSYMCODES); 1589 FX_Free(SBSYMCODES);
1624 return NULL; 1590 return NULL;
1625 } 1591 }
1626 void CJBig2_Context::huffman_assign_code(int* CODES, int* PREFLEN, int NTEMP) { 1592 void CJBig2_Context::huffman_assign_code(int* CODES, int* PREFLEN, int NTEMP) {
1627 int CURLEN, LENMAX, CURCODE, CURTEMP, i; 1593 int CURLEN, LENMAX, CURCODE, CURTEMP, i;
1628 int* LENCOUNT; 1594 int* LENCOUNT;
1629 int* FIRSTCODE; 1595 int* FIRSTCODE;
1630 LENMAX = 0; 1596 LENMAX = 0;
1631 for (i = 0; i < NTEMP; i++) { 1597 for (i = 0; i < NTEMP; i++) {
1632 if (PREFLEN[i] > LENMAX) { 1598 if (PREFLEN[i] > LENMAX) {
1633 LENMAX = PREFLEN[i]; 1599 LENMAX = PREFLEN[i];
1634 } 1600 }
1635 } 1601 }
1636 LENCOUNT = (int*)m_pModule->JBig2_Malloc2(sizeof(int), (LENMAX + 1)); 1602 LENCOUNT = (int*)FX_Alloc2D(uint8_t, sizeof(int), (LENMAX + 1));
1637 JBIG2_memset(LENCOUNT, 0, sizeof(int) * (LENMAX + 1)); 1603 JBIG2_memset(LENCOUNT, 0, sizeof(int) * (LENMAX + 1));
1638 FIRSTCODE = (int*)m_pModule->JBig2_Malloc2(sizeof(int), (LENMAX + 1)); 1604 FIRSTCODE = (int*)FX_Alloc2D(uint8_t, sizeof(int), (LENMAX + 1));
1639 for (i = 0; i < NTEMP; i++) { 1605 for (i = 0; i < NTEMP; i++) {
1640 LENCOUNT[PREFLEN[i]]++; 1606 LENCOUNT[PREFLEN[i]]++;
1641 } 1607 }
1642 CURLEN = 1; 1608 CURLEN = 1;
1643 FIRSTCODE[0] = 0; 1609 FIRSTCODE[0] = 0;
1644 LENCOUNT[0] = 0; 1610 LENCOUNT[0] = 0;
1645 while (CURLEN <= LENMAX) { 1611 while (CURLEN <= LENMAX) {
1646 FIRSTCODE[CURLEN] = (FIRSTCODE[CURLEN - 1] + LENCOUNT[CURLEN - 1]) << 1; 1612 FIRSTCODE[CURLEN] = (FIRSTCODE[CURLEN - 1] + LENCOUNT[CURLEN - 1]) << 1;
1647 CURCODE = FIRSTCODE[CURLEN]; 1613 CURCODE = FIRSTCODE[CURLEN];
1648 CURTEMP = 0; 1614 CURTEMP = 0;
1649 while (CURTEMP < NTEMP) { 1615 while (CURTEMP < NTEMP) {
1650 if (PREFLEN[CURTEMP] == CURLEN) { 1616 if (PREFLEN[CURTEMP] == CURLEN) {
1651 CODES[CURTEMP] = CURCODE; 1617 CODES[CURTEMP] = CURCODE;
1652 CURCODE = CURCODE + 1; 1618 CURCODE = CURCODE + 1;
1653 } 1619 }
1654 CURTEMP = CURTEMP + 1; 1620 CURTEMP = CURTEMP + 1;
1655 } 1621 }
1656 CURLEN = CURLEN + 1; 1622 CURLEN = CURLEN + 1;
1657 } 1623 }
1658 m_pModule->JBig2_Free(LENCOUNT); 1624 FX_Free(LENCOUNT);
1659 m_pModule->JBig2_Free(FIRSTCODE); 1625 FX_Free(FIRSTCODE);
1660 } 1626 }
1661 void CJBig2_Context::huffman_assign_code(JBig2HuffmanCode* SBSYMCODES, 1627 void CJBig2_Context::huffman_assign_code(JBig2HuffmanCode* SBSYMCODES,
1662 int NTEMP) { 1628 int NTEMP) {
1663 int CURLEN, LENMAX, CURCODE, CURTEMP, i; 1629 int CURLEN, LENMAX, CURCODE, CURTEMP, i;
1664 int* LENCOUNT; 1630 int* LENCOUNT;
1665 int* FIRSTCODE; 1631 int* FIRSTCODE;
1666 LENMAX = 0; 1632 LENMAX = 0;
1667 for (i = 0; i < NTEMP; i++) { 1633 for (i = 0; i < NTEMP; i++) {
1668 if (SBSYMCODES[i].codelen > LENMAX) { 1634 if (SBSYMCODES[i].codelen > LENMAX) {
1669 LENMAX = SBSYMCODES[i].codelen; 1635 LENMAX = SBSYMCODES[i].codelen;
1670 } 1636 }
1671 } 1637 }
1672 LENCOUNT = (int*)m_pModule->JBig2_Malloc2(sizeof(int), (LENMAX + 1)); 1638 LENCOUNT = (int*)FX_Alloc2D(uint8_t, sizeof(int), (LENMAX + 1));
1673 JBIG2_memset(LENCOUNT, 0, sizeof(int) * (LENMAX + 1)); 1639 JBIG2_memset(LENCOUNT, 0, sizeof(int) * (LENMAX + 1));
1674 FIRSTCODE = (int*)m_pModule->JBig2_Malloc2(sizeof(int), (LENMAX + 1)); 1640 FIRSTCODE = (int*)FX_Alloc2D(uint8_t, sizeof(int), (LENMAX + 1));
1675 for (i = 0; i < NTEMP; i++) { 1641 for (i = 0; i < NTEMP; i++) {
1676 LENCOUNT[SBSYMCODES[i].codelen]++; 1642 LENCOUNT[SBSYMCODES[i].codelen]++;
1677 } 1643 }
1678 CURLEN = 1; 1644 CURLEN = 1;
1679 FIRSTCODE[0] = 0; 1645 FIRSTCODE[0] = 0;
1680 LENCOUNT[0] = 0; 1646 LENCOUNT[0] = 0;
1681 while (CURLEN <= LENMAX) { 1647 while (CURLEN <= LENMAX) {
1682 FIRSTCODE[CURLEN] = (FIRSTCODE[CURLEN - 1] + LENCOUNT[CURLEN - 1]) << 1; 1648 FIRSTCODE[CURLEN] = (FIRSTCODE[CURLEN - 1] + LENCOUNT[CURLEN - 1]) << 1;
1683 CURCODE = FIRSTCODE[CURLEN]; 1649 CURCODE = FIRSTCODE[CURLEN];
1684 CURTEMP = 0; 1650 CURTEMP = 0;
1685 while (CURTEMP < NTEMP) { 1651 while (CURTEMP < NTEMP) {
1686 if (SBSYMCODES[CURTEMP].codelen == CURLEN) { 1652 if (SBSYMCODES[CURTEMP].codelen == CURLEN) {
1687 SBSYMCODES[CURTEMP].code = CURCODE; 1653 SBSYMCODES[CURTEMP].code = CURCODE;
1688 CURCODE = CURCODE + 1; 1654 CURCODE = CURCODE + 1;
1689 } 1655 }
1690 CURTEMP = CURTEMP + 1; 1656 CURTEMP = CURTEMP + 1;
1691 } 1657 }
1692 CURLEN = CURLEN + 1; 1658 CURLEN = CURLEN + 1;
1693 } 1659 }
1694 m_pModule->JBig2_Free(LENCOUNT); 1660 FX_Free(LENCOUNT);
1695 m_pModule->JBig2_Free(FIRSTCODE); 1661 FX_Free(FIRSTCODE);
1696 } 1662 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698