| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include <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, | 20 const uint8_t* pGlobalData, |
| 21 uint8_t* pGlobalData, | |
| 22 FX_DWORD dwGlobalLength, | 21 FX_DWORD dwGlobalLength, |
| 23 uint8_t* pData, | 22 const 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(const uint8_t* pGlobalData, |
| 36 FX_DWORD dwGlobalLength, | 34 FX_DWORD dwGlobalLength, |
| 37 uint8_t* pData, | 35 const 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 Loading... |
| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 = |
| 363 (FX_DWORD*)m_pModule->JBig2_Malloc2( | 359 FX_Alloc(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 Loading... |
| 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 Loading... |
| 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 const 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; |
| 540 cSDHUFFDH = (wFlags >> 2) & 0x0003; | 534 cSDHUFFDH = (wFlags >> 2) & 0x0003; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 = FX_Alloc(CJBig2_Image*, pSymbolDictDecoder->SDNUMINSYMS); |
| 594 sizeof(CJBig2_Image*), pSymbolDictDecoder->SDNUMINSYMS); | |
| 595 dwTemp = 0; | 588 dwTemp = 0; |
| 596 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { | 589 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { |
| 597 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); | 590 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); |
| 598 if (pSeg->m_cFlags.s.type == 0) { | 591 if (pSeg->m_cFlags.s.type == 0) { |
| 599 JBIG2_memcpy(SDINSYMS + dwTemp, pSeg->m_Result.sd->SDEXSYMS, | 592 JBIG2_memcpy(SDINSYMS + dwTemp, pSeg->m_Result.sd->SDEXSYMS, |
| 600 pSeg->m_Result.sd->SDNUMEXSYMS * sizeof(CJBig2_Image*)); | 593 pSeg->m_Result.sd->SDNUMEXSYMS * sizeof(CJBig2_Image*)); |
| 601 dwTemp += pSeg->m_Result.sd->SDNUMEXSYMS; | 594 dwTemp += pSeg->m_Result.sd->SDNUMEXSYMS; |
| 602 } | 595 } |
| 603 } | 596 } |
| 604 } | 597 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 } | 667 } |
| 675 pSymbolDictDecoder->SDHUFFAGGINST = pSeg->m_Result.ht; | 668 pSymbolDictDecoder->SDHUFFAGGINST = pSeg->m_Result.ht; |
| 676 } | 669 } |
| 677 } | 670 } |
| 678 } | 671 } |
| 679 if ((wFlags & 0x0100) && pLRSeg && pLRSeg->m_Result.sd->m_bContextRetained) { | 672 if ((wFlags & 0x0100) && pLRSeg && pLRSeg->m_Result.sd->m_bContextRetained) { |
| 680 if (pSymbolDictDecoder->SDHUFF == 0) { | 673 if (pSymbolDictDecoder->SDHUFF == 0) { |
| 681 dwTemp = pSymbolDictDecoder->SDTEMPLATE == 0 | 674 dwTemp = pSymbolDictDecoder->SDTEMPLATE == 0 |
| 682 ? 65536 | 675 ? 65536 |
| 683 : pSymbolDictDecoder->SDTEMPLATE == 1 ? 8192 : 1024; | 676 : pSymbolDictDecoder->SDTEMPLATE == 1 ? 8192 : 1024; |
| 684 gbContext = (JBig2ArithCtx*)m_pModule->JBig2_Malloc2( | 677 gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
| 685 sizeof(JBig2ArithCtx), dwTemp); | |
| 686 JBIG2_memcpy(gbContext, pLRSeg->m_Result.sd->m_gbContext, | 678 JBIG2_memcpy(gbContext, pLRSeg->m_Result.sd->m_gbContext, |
| 687 sizeof(JBig2ArithCtx) * dwTemp); | 679 sizeof(JBig2ArithCtx) * dwTemp); |
| 688 } | 680 } |
| 689 if (pSymbolDictDecoder->SDREFAGG == 1) { | 681 if (pSymbolDictDecoder->SDREFAGG == 1) { |
| 690 dwTemp = pSymbolDictDecoder->SDRTEMPLATE ? 1 << 10 : 1 << 13; | 682 dwTemp = pSymbolDictDecoder->SDRTEMPLATE ? 1 << 10 : 1 << 13; |
| 691 grContext = (JBig2ArithCtx*)m_pModule->JBig2_Malloc2( | 683 grContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
| 692 sizeof(JBig2ArithCtx), dwTemp); | |
| 693 JBIG2_memcpy(grContext, pLRSeg->m_Result.sd->m_grContext, | 684 JBIG2_memcpy(grContext, pLRSeg->m_Result.sd->m_grContext, |
| 694 sizeof(JBig2ArithCtx) * dwTemp); | 685 sizeof(JBig2ArithCtx) * dwTemp); |
| 695 } | 686 } |
| 696 } else { | 687 } else { |
| 697 if (pSymbolDictDecoder->SDHUFF == 0) { | 688 if (pSymbolDictDecoder->SDHUFF == 0) { |
| 698 dwTemp = pSymbolDictDecoder->SDTEMPLATE == 0 | 689 dwTemp = pSymbolDictDecoder->SDTEMPLATE == 0 |
| 699 ? 65536 | 690 ? 65536 |
| 700 : pSymbolDictDecoder->SDTEMPLATE == 1 ? 8192 : 1024; | 691 : pSymbolDictDecoder->SDTEMPLATE == 1 ? 8192 : 1024; |
| 701 gbContext = (JBig2ArithCtx*)m_pModule->JBig2_Malloc2( | 692 gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
| 702 sizeof(JBig2ArithCtx), dwTemp); | |
| 703 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 693 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
| 704 } | 694 } |
| 705 if (pSymbolDictDecoder->SDREFAGG == 1) { | 695 if (pSymbolDictDecoder->SDREFAGG == 1) { |
| 706 dwTemp = pSymbolDictDecoder->SDRTEMPLATE ? 1 << 10 : 1 << 13; | 696 dwTemp = pSymbolDictDecoder->SDRTEMPLATE ? 1 << 10 : 1 << 13; |
| 707 grContext = (JBig2ArithCtx*)m_pModule->JBig2_Malloc2( | 697 grContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
| 708 sizeof(JBig2ArithCtx), dwTemp); | |
| 709 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 698 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
| 710 } | 699 } |
| 711 } | 700 } |
| 712 pSegment->m_nResultType = JBIG2_SYMBOL_DICT_POINTER; | 701 pSegment->m_nResultType = JBIG2_SYMBOL_DICT_POINTER; |
| 713 for (std::list<CJBig2_CachePair>::iterator it = m_pSymbolDictCache->begin(); | 702 for (std::list<CJBig2_CachePair>::iterator it = m_pSymbolDictCache->begin(); |
| 714 it != m_pSymbolDictCache->end(); ++it) { | 703 it != m_pSymbolDictCache->end(); ++it) { |
| 715 if (it->first == key) { | 704 if (it->first == key) { |
| 716 pSegment->m_Result.sd = it->second->DeepCopy(); | 705 pSegment->m_Result.sd = it->second->DeepCopy(); |
| 717 m_pSymbolDictCache->push_front(*it); | 706 m_pSymbolDictCache->push_front(*it); |
| 718 m_pSymbolDictCache->erase(it); | 707 m_pSymbolDictCache->erase(it); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 pSegment->m_Result.sd->m_gbContext = gbContext; | 745 pSegment->m_Result.sd->m_gbContext = gbContext; |
| 757 } | 746 } |
| 758 if (pSymbolDictDecoder->SDREFAGG == 1) { | 747 if (pSymbolDictDecoder->SDREFAGG == 1) { |
| 759 pSegment->m_Result.sd->m_grContext = grContext; | 748 pSegment->m_Result.sd->m_grContext = grContext; |
| 760 } | 749 } |
| 761 bUsed = TRUE; | 750 bUsed = TRUE; |
| 762 } else { | 751 } else { |
| 763 bUsed = FALSE; | 752 bUsed = FALSE; |
| 764 } | 753 } |
| 765 delete pSymbolDictDecoder; | 754 delete pSymbolDictDecoder; |
| 766 if (SDINSYMS) { | 755 FX_Free(SDINSYMS); |
| 767 m_pModule->JBig2_Free(SDINSYMS); | |
| 768 } | |
| 769 delete Table_B1; | 756 delete Table_B1; |
| 770 delete Table_B2; | 757 delete Table_B2; |
| 771 delete Table_B3; | 758 delete Table_B3; |
| 772 delete Table_B4; | 759 delete Table_B4; |
| 773 delete Table_B5; | 760 delete Table_B5; |
| 774 if (bUsed == FALSE) { | 761 if (bUsed == FALSE) { |
| 775 if (gbContext) { | 762 FX_Free(gbContext); |
| 776 m_pModule->JBig2_Free(gbContext); | 763 FX_Free(grContext); |
| 777 } | |
| 778 if (grContext) { | |
| 779 m_pModule->JBig2_Free(grContext); | |
| 780 } | |
| 781 } | 764 } |
| 782 return JBIG2_SUCCESS; | 765 return JBIG2_SUCCESS; |
| 783 failed: | 766 failed: |
| 784 delete pSymbolDictDecoder; | 767 delete pSymbolDictDecoder; |
| 785 if (SDINSYMS) { | 768 FX_Free(SDINSYMS); |
| 786 m_pModule->JBig2_Free(SDINSYMS); | |
| 787 } | |
| 788 delete Table_B1; | 769 delete Table_B1; |
| 789 delete Table_B2; | 770 delete Table_B2; |
| 790 delete Table_B3; | 771 delete Table_B3; |
| 791 delete Table_B4; | 772 delete Table_B4; |
| 792 delete Table_B5; | 773 delete Table_B5; |
| 793 if (gbContext) { | 774 FX_Free(gbContext); |
| 794 m_pModule->JBig2_Free(gbContext); | 775 FX_Free(grContext); |
| 795 } | |
| 796 if (grContext) { | |
| 797 m_pModule->JBig2_Free(grContext); | |
| 798 } | |
| 799 return nRet; | 776 return nRet; |
| 800 } | 777 } |
| 801 | 778 |
| 802 int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { | 779 int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { |
| 803 FX_DWORD dwTemp; | 780 FX_DWORD dwTemp; |
| 804 FX_WORD wFlags; | 781 FX_WORD wFlags; |
| 805 int32_t i, nIndex, nRet; | 782 int32_t i, nIndex, nRet; |
| 806 JBig2RegionInfo ri; | 783 JBig2RegionInfo ri; |
| 807 CJBig2_Segment* pSeg; | 784 CJBig2_Segment* pSeg; |
| 808 CJBig2_Image** SBSYMS = NULL; | 785 CJBig2_Image** SBSYMS = NULL; |
| 809 JBig2HuffmanCode* SBSYMCODES = NULL; | 786 JBig2HuffmanCode* SBSYMCODES = NULL; |
| 810 uint8_t cSBHUFFFS, cSBHUFFDS, cSBHUFFDT, cSBHUFFRDW, cSBHUFFRDH, cSBHUFFRDX, | 787 uint8_t cSBHUFFFS, cSBHUFFDS, cSBHUFFDT, cSBHUFFRDW, cSBHUFFRDH, cSBHUFFRDX, |
| 811 cSBHUFFRDY, cSBHUFFRSIZE; | 788 cSBHUFFRDY, cSBHUFFRSIZE; |
| 812 CJBig2_HuffmanTable *Table_B1 = NULL, *Table_B6 = NULL, *Table_B7 = NULL, | 789 CJBig2_HuffmanTable *Table_B1 = NULL, *Table_B6 = NULL, *Table_B7 = NULL, |
| 813 *Table_B8 = NULL, *Table_B9 = NULL, *Table_B10 = NULL, | 790 *Table_B8 = NULL, *Table_B9 = NULL, *Table_B10 = NULL, |
| 814 *Table_B11 = NULL, *Table_B12 = NULL, *Table_B13 = NULL, | 791 *Table_B11 = NULL, *Table_B12 = NULL, *Table_B13 = NULL, |
| 815 *Table_B14 = NULL, *Table_B15 = NULL; | 792 *Table_B14 = NULL, *Table_B15 = NULL; |
| 816 JBig2ArithCtx* grContext = NULL; | 793 JBig2ArithCtx* grContext = NULL; |
| 817 CJBig2_ArithDecoder* pArithDecoder; | 794 CJBig2_ArithDecoder* pArithDecoder; |
| 818 CJBig2_TRDProc* pTRD; | 795 CJBig2_TRDProc* pTRD = new CJBig2_TRDProc(); |
| 819 JBIG2_ALLOC(pTRD, CJBig2_TRDProc()); | |
| 820 if ((parseRegionInfo(&ri) != JBIG2_SUCCESS) || | 796 if ((parseRegionInfo(&ri) != JBIG2_SUCCESS) || |
| 821 (m_pStream->readShortInteger(&wFlags) != 0)) { | 797 (m_pStream->readShortInteger(&wFlags) != 0)) { |
| 822 nRet = JBIG2_ERROR_TOO_SHORT; | 798 nRet = JBIG2_ERROR_TOO_SHORT; |
| 823 goto failed; | 799 goto failed; |
| 824 } | 800 } |
| 825 pTRD->SBW = ri.width; | 801 pTRD->SBW = ri.width; |
| 826 pTRD->SBH = ri.height; | 802 pTRD->SBH = ri.height; |
| 827 pTRD->SBHUFF = wFlags & 0x0001; | 803 pTRD->SBHUFF = wFlags & 0x0001; |
| 828 pTRD->SBREFINE = (wFlags >> 1) & 0x0001; | 804 pTRD->SBREFINE = (wFlags >> 1) & 0x0001; |
| 829 dwTemp = (wFlags >> 2) & 0x0003; | 805 dwTemp = (wFlags >> 2) & 0x0003; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 } | 846 } |
| 871 } | 847 } |
| 872 pTRD->SBNUMSYMS = 0; | 848 pTRD->SBNUMSYMS = 0; |
| 873 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { | 849 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { |
| 874 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); | 850 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); |
| 875 if (pSeg->m_cFlags.s.type == 0) { | 851 if (pSeg->m_cFlags.s.type == 0) { |
| 876 pTRD->SBNUMSYMS += pSeg->m_Result.sd->SDNUMEXSYMS; | 852 pTRD->SBNUMSYMS += pSeg->m_Result.sd->SDNUMEXSYMS; |
| 877 } | 853 } |
| 878 } | 854 } |
| 879 if (pTRD->SBNUMSYMS > 0) { | 855 if (pTRD->SBNUMSYMS > 0) { |
| 880 SBSYMS = (CJBig2_Image**)m_pModule->JBig2_Malloc2(sizeof(CJBig2_Image*), | 856 SBSYMS = FX_Alloc(CJBig2_Image*, pTRD->SBNUMSYMS); |
| 881 pTRD->SBNUMSYMS); | |
| 882 dwTemp = 0; | 857 dwTemp = 0; |
| 883 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { | 858 for (i = 0; i < pSegment->m_nReferred_to_segment_count; i++) { |
| 884 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); | 859 pSeg = findSegmentByNumber(pSegment->m_pReferred_to_segment_numbers[i]); |
| 885 if (pSeg->m_cFlags.s.type == 0) { | 860 if (pSeg->m_cFlags.s.type == 0) { |
| 886 JBIG2_memcpy(SBSYMS + dwTemp, pSeg->m_Result.sd->SDEXSYMS, | 861 JBIG2_memcpy(SBSYMS + dwTemp, pSeg->m_Result.sd->SDEXSYMS, |
| 887 pSeg->m_Result.sd->SDNUMEXSYMS * sizeof(CJBig2_Image*)); | 862 pSeg->m_Result.sd->SDNUMEXSYMS * sizeof(CJBig2_Image*)); |
| 888 dwTemp += pSeg->m_Result.sd->SDNUMEXSYMS; | 863 dwTemp += pSeg->m_Result.sd->SDNUMEXSYMS; |
| 889 } | 864 } |
| 890 } | 865 } |
| 891 pTRD->SBSYMS = SBSYMS; | 866 pTRD->SBSYMS = SBSYMS; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); | 1046 pSeg = findReferredSegmentByTypeAndIndex(pSegment, 53, nIndex++); |
| 1072 if (!pSeg) { | 1047 if (!pSeg) { |
| 1073 nRet = JBIG2_ERROR_FATAL; | 1048 nRet = JBIG2_ERROR_FATAL; |
| 1074 goto failed; | 1049 goto failed; |
| 1075 } | 1050 } |
| 1076 pTRD->SBHUFFRSIZE = pSeg->m_Result.ht; | 1051 pTRD->SBHUFFRSIZE = pSeg->m_Result.ht; |
| 1077 } | 1052 } |
| 1078 } | 1053 } |
| 1079 if (pTRD->SBREFINE == 1) { | 1054 if (pTRD->SBREFINE == 1) { |
| 1080 dwTemp = pTRD->SBRTEMPLATE ? 1 << 10 : 1 << 13; | 1055 dwTemp = pTRD->SBRTEMPLATE ? 1 << 10 : 1 << 13; |
| 1081 grContext = | 1056 grContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
| 1082 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); | |
| 1083 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1057 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
| 1084 } | 1058 } |
| 1085 if (pTRD->SBHUFF == 0) { | 1059 if (pTRD->SBHUFF == 0) { |
| 1086 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 1060 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
| 1087 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1061 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
| 1088 pSegment->m_Result.im = pTRD->decode_Arith(pArithDecoder, grContext); | 1062 pSegment->m_Result.im = pTRD->decode_Arith(pArithDecoder, grContext); |
| 1089 delete pArithDecoder; | 1063 delete pArithDecoder; |
| 1090 if (pSegment->m_Result.im == NULL) { | 1064 if (pSegment->m_Result.im == NULL) { |
| 1091 nRet = JBIG2_ERROR_FATAL; | 1065 nRet = JBIG2_ERROR_FATAL; |
| 1092 goto failed; | 1066 goto failed; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1109 (ri.y + ri.height > m_pPage->m_nHeight)) { | 1083 (ri.y + ri.height > m_pPage->m_nHeight)) { |
| 1110 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1084 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); |
| 1111 } | 1085 } |
| 1112 } | 1086 } |
| 1113 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, | 1087 m_pPage->composeFrom(ri.x, ri.y, pSegment->m_Result.im, |
| 1114 (JBig2ComposeOp)(ri.flags & 0x03)); | 1088 (JBig2ComposeOp)(ri.flags & 0x03)); |
| 1115 delete pSegment->m_Result.im; | 1089 delete pSegment->m_Result.im; |
| 1116 pSegment->m_Result.im = NULL; | 1090 pSegment->m_Result.im = NULL; |
| 1117 } | 1091 } |
| 1118 delete pTRD; | 1092 delete pTRD; |
| 1119 if (SBSYMS) { | 1093 FX_Free(SBSYMS); |
| 1120 m_pModule->JBig2_Free(SBSYMS); | 1094 FX_Free(SBSYMCODES); |
| 1121 } | 1095 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; | 1096 delete Table_B1; |
| 1129 delete Table_B6; | 1097 delete Table_B6; |
| 1130 delete Table_B7; | 1098 delete Table_B7; |
| 1131 delete Table_B8; | 1099 delete Table_B8; |
| 1132 delete Table_B9; | 1100 delete Table_B9; |
| 1133 delete Table_B10; | 1101 delete Table_B10; |
| 1134 delete Table_B11; | 1102 delete Table_B11; |
| 1135 delete Table_B12; | 1103 delete Table_B12; |
| 1136 delete Table_B13; | 1104 delete Table_B13; |
| 1137 delete Table_B14; | 1105 delete Table_B14; |
| 1138 delete Table_B15; | 1106 delete Table_B15; |
| 1139 return JBIG2_SUCCESS; | 1107 return JBIG2_SUCCESS; |
| 1140 failed: | 1108 failed: |
| 1141 delete pTRD; | 1109 delete pTRD; |
| 1142 if (SBSYMS) { | 1110 FX_Free(SBSYMS); |
| 1143 m_pModule->JBig2_Free(SBSYMS); | 1111 FX_Free(SBSYMCODES); |
| 1144 } | 1112 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; | 1113 delete Table_B1; |
| 1152 delete Table_B6; | 1114 delete Table_B6; |
| 1153 delete Table_B7; | 1115 delete Table_B7; |
| 1154 delete Table_B8; | 1116 delete Table_B8; |
| 1155 delete Table_B9; | 1117 delete Table_B9; |
| 1156 delete Table_B10; | 1118 delete Table_B10; |
| 1157 delete Table_B11; | 1119 delete Table_B11; |
| 1158 delete Table_B12; | 1120 delete Table_B12; |
| 1159 delete Table_B13; | 1121 delete Table_B13; |
| 1160 delete Table_B14; | 1122 delete Table_B14; |
| 1161 delete Table_B15; | 1123 delete Table_B15; |
| 1162 return nRet; | 1124 return nRet; |
| 1163 } | 1125 } |
| 1164 | 1126 |
| 1165 int32_t CJBig2_Context::parsePatternDict(CJBig2_Segment* pSegment, | 1127 int32_t CJBig2_Context::parsePatternDict(CJBig2_Segment* pSegment, |
| 1166 IFX_Pause* pPause) { | 1128 IFX_Pause* pPause) { |
| 1167 FX_DWORD dwTemp; | 1129 FX_DWORD dwTemp; |
| 1168 uint8_t cFlags; | 1130 uint8_t cFlags; |
| 1169 JBig2ArithCtx* gbContext; | 1131 JBig2ArithCtx* gbContext; |
| 1170 CJBig2_ArithDecoder* pArithDecoder; | 1132 CJBig2_ArithDecoder* pArithDecoder; |
| 1171 CJBig2_PDDProc* pPDD; | |
| 1172 int32_t nRet; | 1133 int32_t nRet; |
| 1173 JBIG2_ALLOC(pPDD, CJBig2_PDDProc()); | 1134 CJBig2_PDDProc* pPDD = new CJBig2_PDDProc(); |
| 1174 if ((m_pStream->read1Byte(&cFlags) != 0) || | 1135 if ((m_pStream->read1Byte(&cFlags) != 0) || |
| 1175 (m_pStream->read1Byte(&pPDD->HDPW) != 0) || | 1136 (m_pStream->read1Byte(&pPDD->HDPW) != 0) || |
| 1176 (m_pStream->read1Byte(&pPDD->HDPH) != 0) || | 1137 (m_pStream->read1Byte(&pPDD->HDPH) != 0) || |
| 1177 (m_pStream->readInteger(&pPDD->GRAYMAX) != 0)) { | 1138 (m_pStream->readInteger(&pPDD->GRAYMAX) != 0)) { |
| 1178 nRet = JBIG2_ERROR_TOO_SHORT; | 1139 nRet = JBIG2_ERROR_TOO_SHORT; |
| 1179 goto failed; | 1140 goto failed; |
| 1180 } | 1141 } |
| 1181 if (pPDD->GRAYMAX > JBIG2_MAX_PATTERN_INDEX) { | 1142 if (pPDD->GRAYMAX > JBIG2_MAX_PATTERN_INDEX) { |
| 1182 nRet = JBIG2_ERROR_LIMIT; | 1143 nRet = JBIG2_ERROR_LIMIT; |
| 1183 goto failed; | 1144 goto failed; |
| 1184 } | 1145 } |
| 1185 pPDD->HDMMR = cFlags & 0x01; | 1146 pPDD->HDMMR = cFlags & 0x01; |
| 1186 pPDD->HDTEMPLATE = (cFlags >> 1) & 0x03; | 1147 pPDD->HDTEMPLATE = (cFlags >> 1) & 0x03; |
| 1187 pSegment->m_nResultType = JBIG2_PATTERN_DICT_POINTER; | 1148 pSegment->m_nResultType = JBIG2_PATTERN_DICT_POINTER; |
| 1188 if (pPDD->HDMMR == 0) { | 1149 if (pPDD->HDMMR == 0) { |
| 1189 dwTemp = | 1150 dwTemp = |
| 1190 pPDD->HDTEMPLATE == 0 ? 65536 : pPDD->HDTEMPLATE == 1 ? 8192 : 1024; | 1151 pPDD->HDTEMPLATE == 0 ? 65536 : pPDD->HDTEMPLATE == 1 ? 8192 : 1024; |
| 1191 gbContext = | 1152 gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
| 1192 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); | |
| 1193 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1153 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
| 1194 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 1154 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
| 1195 pSegment->m_Result.pd = | 1155 pSegment->m_Result.pd = |
| 1196 pPDD->decode_Arith(pArithDecoder, gbContext, pPause); | 1156 pPDD->decode_Arith(pArithDecoder, gbContext, pPause); |
| 1197 delete pArithDecoder; | 1157 delete pArithDecoder; |
| 1198 if (pSegment->m_Result.pd == NULL) { | 1158 if (pSegment->m_Result.pd == NULL) { |
| 1199 m_pModule->JBig2_Free(gbContext); | 1159 FX_Free(gbContext); |
| 1200 nRet = JBIG2_ERROR_FATAL; | 1160 nRet = JBIG2_ERROR_FATAL; |
| 1201 goto failed; | 1161 goto failed; |
| 1202 } | 1162 } |
| 1203 m_pModule->JBig2_Free(gbContext); | 1163 FX_Free(gbContext); |
| 1204 m_pStream->alignByte(); | 1164 m_pStream->alignByte(); |
| 1205 m_pStream->offset(2); | 1165 m_pStream->offset(2); |
| 1206 } else { | 1166 } else { |
| 1207 pSegment->m_Result.pd = pPDD->decode_MMR(m_pStream, pPause); | 1167 pSegment->m_Result.pd = pPDD->decode_MMR(m_pStream, pPause); |
| 1208 if (pSegment->m_Result.pd == NULL) { | 1168 if (pSegment->m_Result.pd == NULL) { |
| 1209 nRet = JBIG2_ERROR_FATAL; | 1169 nRet = JBIG2_ERROR_FATAL; |
| 1210 goto failed; | 1170 goto failed; |
| 1211 } | 1171 } |
| 1212 m_pStream->alignByte(); | 1172 m_pStream->alignByte(); |
| 1213 } | 1173 } |
| 1214 delete pPDD; | 1174 delete pPDD; |
| 1215 return JBIG2_SUCCESS; | 1175 return JBIG2_SUCCESS; |
| 1216 failed: | 1176 failed: |
| 1217 delete pPDD; | 1177 delete pPDD; |
| 1218 return nRet; | 1178 return nRet; |
| 1219 } | 1179 } |
| 1220 int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, | 1180 int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, |
| 1221 IFX_Pause* pPause) { | 1181 IFX_Pause* pPause) { |
| 1222 FX_DWORD dwTemp; | 1182 FX_DWORD dwTemp; |
| 1223 uint8_t cFlags; | 1183 uint8_t cFlags; |
| 1224 JBig2RegionInfo ri; | 1184 JBig2RegionInfo ri; |
| 1225 CJBig2_Segment* pSeg; | 1185 CJBig2_Segment* pSeg; |
| 1226 CJBig2_PatternDict* pPatternDict; | 1186 CJBig2_PatternDict* pPatternDict; |
| 1227 JBig2ArithCtx* gbContext; | 1187 JBig2ArithCtx* gbContext; |
| 1228 CJBig2_ArithDecoder* pArithDecoder; | 1188 CJBig2_ArithDecoder* pArithDecoder; |
| 1229 CJBig2_HTRDProc* pHRD; | |
| 1230 int32_t nRet; | 1189 int32_t nRet; |
| 1231 JBIG2_ALLOC(pHRD, CJBig2_HTRDProc()); | 1190 CJBig2_HTRDProc* pHRD = new CJBig2_HTRDProc(); |
| 1232 if ((parseRegionInfo(&ri) != JBIG2_SUCCESS) || | 1191 if ((parseRegionInfo(&ri) != JBIG2_SUCCESS) || |
| 1233 (m_pStream->read1Byte(&cFlags) != 0) || | 1192 (m_pStream->read1Byte(&cFlags) != 0) || |
| 1234 (m_pStream->readInteger(&pHRD->HGW) != 0) || | 1193 (m_pStream->readInteger(&pHRD->HGW) != 0) || |
| 1235 (m_pStream->readInteger(&pHRD->HGH) != 0) || | 1194 (m_pStream->readInteger(&pHRD->HGH) != 0) || |
| 1236 (m_pStream->readInteger((FX_DWORD*)&pHRD->HGX) != 0) || | 1195 (m_pStream->readInteger((FX_DWORD*)&pHRD->HGX) != 0) || |
| 1237 (m_pStream->readInteger((FX_DWORD*)&pHRD->HGY) != 0) || | 1196 (m_pStream->readInteger((FX_DWORD*)&pHRD->HGY) != 0) || |
| 1238 (m_pStream->readShortInteger(&pHRD->HRX) != 0) || | 1197 (m_pStream->readShortInteger(&pHRD->HRX) != 0) || |
| 1239 (m_pStream->readShortInteger(&pHRD->HRY) != 0)) { | 1198 (m_pStream->readShortInteger(&pHRD->HRY) != 0)) { |
| 1240 nRet = JBIG2_ERROR_TOO_SHORT; | 1199 nRet = JBIG2_ERROR_TOO_SHORT; |
| 1241 goto failed; | 1200 goto failed; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1261 nRet = JBIG2_ERROR_FATAL; | 1220 nRet = JBIG2_ERROR_FATAL; |
| 1262 goto failed; | 1221 goto failed; |
| 1263 } | 1222 } |
| 1264 pHRD->HNUMPATS = pPatternDict->NUMPATS; | 1223 pHRD->HNUMPATS = pPatternDict->NUMPATS; |
| 1265 pHRD->HPATS = pPatternDict->HDPATS; | 1224 pHRD->HPATS = pPatternDict->HDPATS; |
| 1266 pHRD->HPW = pPatternDict->HDPATS[0]->m_nWidth; | 1225 pHRD->HPW = pPatternDict->HDPATS[0]->m_nWidth; |
| 1267 pHRD->HPH = pPatternDict->HDPATS[0]->m_nHeight; | 1226 pHRD->HPH = pPatternDict->HDPATS[0]->m_nHeight; |
| 1268 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1227 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
| 1269 if (pHRD->HMMR == 0) { | 1228 if (pHRD->HMMR == 0) { |
| 1270 dwTemp = pHRD->HTEMPLATE == 0 ? 65536 : pHRD->HTEMPLATE == 1 ? 8192 : 1024; | 1229 dwTemp = pHRD->HTEMPLATE == 0 ? 65536 : pHRD->HTEMPLATE == 1 ? 8192 : 1024; |
| 1271 gbContext = | 1230 gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
| 1272 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); | |
| 1273 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1231 JBIG2_memset(gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
| 1274 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 1232 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
| 1275 pSegment->m_Result.im = | 1233 pSegment->m_Result.im = |
| 1276 pHRD->decode_Arith(pArithDecoder, gbContext, pPause); | 1234 pHRD->decode_Arith(pArithDecoder, gbContext, pPause); |
| 1277 delete pArithDecoder; | 1235 delete pArithDecoder; |
| 1278 if (pSegment->m_Result.im == NULL) { | 1236 if (pSegment->m_Result.im == NULL) { |
| 1279 m_pModule->JBig2_Free(gbContext); | 1237 FX_Free(gbContext); |
| 1280 nRet = JBIG2_ERROR_FATAL; | 1238 nRet = JBIG2_ERROR_FATAL; |
| 1281 goto failed; | 1239 goto failed; |
| 1282 } | 1240 } |
| 1283 m_pModule->JBig2_Free(gbContext); | 1241 FX_Free(gbContext); |
| 1284 m_pStream->alignByte(); | 1242 m_pStream->alignByte(); |
| 1285 m_pStream->offset(2); | 1243 m_pStream->offset(2); |
| 1286 } else { | 1244 } else { |
| 1287 pSegment->m_Result.im = pHRD->decode_MMR(m_pStream, pPause); | 1245 pSegment->m_Result.im = pHRD->decode_MMR(m_pStream, pPause); |
| 1288 if (pSegment->m_Result.im == NULL) { | 1246 if (pSegment->m_Result.im == NULL) { |
| 1289 nRet = JBIG2_ERROR_FATAL; | 1247 nRet = JBIG2_ERROR_FATAL; |
| 1290 goto failed; | 1248 goto failed; |
| 1291 } | 1249 } |
| 1292 m_pStream->alignByte(); | 1250 m_pStream->alignByte(); |
| 1293 } | 1251 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1310 delete pHRD; | 1268 delete pHRD; |
| 1311 return nRet; | 1269 return nRet; |
| 1312 } | 1270 } |
| 1313 | 1271 |
| 1314 int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, | 1272 int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, |
| 1315 IFX_Pause* pPause) { | 1273 IFX_Pause* pPause) { |
| 1316 FX_DWORD dwTemp; | 1274 FX_DWORD dwTemp; |
| 1317 uint8_t cFlags; | 1275 uint8_t cFlags; |
| 1318 int32_t i, nRet; | 1276 int32_t i, nRet; |
| 1319 if (m_pGRD == NULL) { | 1277 if (m_pGRD == NULL) { |
| 1320 JBIG2_ALLOC(m_pGRD, CJBig2_GRDProc()); | 1278 m_pGRD = new CJBig2_GRDProc(); |
| 1321 if ((parseRegionInfo(&m_ri) != JBIG2_SUCCESS) || | 1279 if ((parseRegionInfo(&m_ri) != JBIG2_SUCCESS) || |
| 1322 (m_pStream->read1Byte(&cFlags) != 0)) { | 1280 (m_pStream->read1Byte(&cFlags) != 0)) { |
| 1323 nRet = JBIG2_ERROR_TOO_SHORT; | 1281 nRet = JBIG2_ERROR_TOO_SHORT; |
| 1324 goto failed; | 1282 goto failed; |
| 1325 } | 1283 } |
| 1326 if (m_ri.height < 0 || m_ri.width < 0) { | 1284 if (m_ri.height < 0 || m_ri.width < 0) { |
| 1327 nRet = JBIG2_FAILED; | 1285 nRet = JBIG2_FAILED; |
| 1328 goto failed; | 1286 goto failed; |
| 1329 } | 1287 } |
| 1330 m_pGRD->GBW = m_ri.width; | 1288 m_pGRD->GBW = m_ri.width; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1349 } | 1307 } |
| 1350 } | 1308 } |
| 1351 } | 1309 } |
| 1352 m_pGRD->USESKIP = 0; | 1310 m_pGRD->USESKIP = 0; |
| 1353 } | 1311 } |
| 1354 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1312 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
| 1355 if (m_pGRD->MMR == 0) { | 1313 if (m_pGRD->MMR == 0) { |
| 1356 dwTemp = | 1314 dwTemp = |
| 1357 m_pGRD->GBTEMPLATE == 0 ? 65536 : m_pGRD->GBTEMPLATE == 1 ? 8192 : 1024; | 1315 m_pGRD->GBTEMPLATE == 0 ? 65536 : m_pGRD->GBTEMPLATE == 1 ? 8192 : 1024; |
| 1358 if (m_gbContext == NULL) { | 1316 if (m_gbContext == NULL) { |
| 1359 m_gbContext = (JBig2ArithCtx*)m_pModule->JBig2_Malloc( | 1317 m_gbContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
| 1360 sizeof(JBig2ArithCtx) * dwTemp); | |
| 1361 JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1318 JBIG2_memset(m_gbContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
| 1362 } | 1319 } |
| 1363 if (m_pArithDecoder == NULL) { | 1320 if (m_pArithDecoder == NULL) { |
| 1364 m_pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 1321 m_pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
| 1365 m_ProcessiveStatus = m_pGRD->Start_decode_Arith( | 1322 m_ProcessiveStatus = m_pGRD->Start_decode_Arith( |
| 1366 &pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause); | 1323 &pSegment->m_Result.im, m_pArithDecoder, m_gbContext, pPause); |
| 1367 } else { | 1324 } else { |
| 1368 m_ProcessiveStatus = m_pGRD->Continue_decode(pPause); | 1325 m_ProcessiveStatus = m_pGRD->Continue_decode(pPause); |
| 1369 } | 1326 } |
| 1370 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 1327 if (m_ProcessiveStatus == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
| 1371 if (pSegment->m_cFlags.s.type != 36) { | 1328 if (pSegment->m_cFlags.s.type != 36) { |
| 1372 if (!m_bBufSpecified) { | 1329 if (!m_bBufSpecified) { |
| 1373 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 1330 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
| 1374 if ((pPageInfo->m_bIsStriped == 1) && | 1331 if ((pPageInfo->m_bIsStriped == 1) && |
| 1375 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { | 1332 (m_ri.y + m_ri.height > m_pPage->m_nHeight)) { |
| 1376 m_pPage->expand(m_ri.y + m_ri.height, | 1333 m_pPage->expand(m_ri.y + m_ri.height, |
| 1377 (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1334 (pPageInfo->m_cFlags & 4) ? 1 : 0); |
| 1378 } | 1335 } |
| 1379 } | 1336 } |
| 1380 FX_RECT Rect = m_pGRD->GetReplaceRect(); | 1337 FX_RECT Rect = m_pGRD->GetReplaceRect(); |
| 1381 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, | 1338 m_pPage->composeFrom(m_ri.x + Rect.left, m_ri.y + Rect.top, |
| 1382 pSegment->m_Result.im, | 1339 pSegment->m_Result.im, |
| 1383 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); | 1340 (JBig2ComposeOp)(m_ri.flags & 0x03), &Rect); |
| 1384 } | 1341 } |
| 1385 return JBIG2_SUCCESS; | 1342 return JBIG2_SUCCESS; |
| 1386 } else { | 1343 } else { |
| 1387 delete m_pArithDecoder; | 1344 delete m_pArithDecoder; |
| 1388 m_pArithDecoder = NULL; | 1345 m_pArithDecoder = NULL; |
| 1389 if (pSegment->m_Result.im == NULL) { | 1346 if (pSegment->m_Result.im == NULL) { |
| 1390 m_pModule->JBig2_Free(m_gbContext); | 1347 FX_Free(m_gbContext); |
| 1391 nRet = JBIG2_ERROR_FATAL; | 1348 nRet = JBIG2_ERROR_FATAL; |
| 1392 m_gbContext = NULL; | 1349 m_gbContext = NULL; |
| 1393 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; | 1350 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; |
| 1394 goto failed; | 1351 goto failed; |
| 1395 } | 1352 } |
| 1396 m_pModule->JBig2_Free(m_gbContext); | 1353 FX_Free(m_gbContext); |
| 1397 m_gbContext = NULL; | 1354 m_gbContext = NULL; |
| 1398 m_pStream->alignByte(); | 1355 m_pStream->alignByte(); |
| 1399 m_pStream->offset(2); | 1356 m_pStream->offset(2); |
| 1400 } | 1357 } |
| 1401 } else { | 1358 } else { |
| 1402 FXCODEC_STATUS status = | 1359 FXCODEC_STATUS status = |
| 1403 m_pGRD->Start_decode_MMR(&pSegment->m_Result.im, m_pStream, pPause); | 1360 m_pGRD->Start_decode_MMR(&pSegment->m_Result.im, m_pStream, pPause); |
| 1404 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { | 1361 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) { |
| 1405 m_pGRD->Continue_decode(pPause); | 1362 m_pGRD->Continue_decode(pPause); |
| 1406 } | 1363 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1435 return nRet; | 1392 return nRet; |
| 1436 } | 1393 } |
| 1437 | 1394 |
| 1438 int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { | 1395 int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { |
| 1439 FX_DWORD dwTemp; | 1396 FX_DWORD dwTemp; |
| 1440 JBig2RegionInfo ri; | 1397 JBig2RegionInfo ri; |
| 1441 CJBig2_Segment* pSeg; | 1398 CJBig2_Segment* pSeg; |
| 1442 int32_t i, nRet; | 1399 int32_t i, nRet; |
| 1443 uint8_t cFlags; | 1400 uint8_t cFlags; |
| 1444 JBig2ArithCtx* grContext; | 1401 JBig2ArithCtx* grContext; |
| 1445 CJBig2_GRRDProc* pGRRD; | |
| 1446 CJBig2_ArithDecoder* pArithDecoder; | 1402 CJBig2_ArithDecoder* pArithDecoder; |
| 1447 JBIG2_ALLOC(pGRRD, CJBig2_GRRDProc()); | 1403 CJBig2_GRRDProc* pGRRD = new CJBig2_GRRDProc(); |
| 1448 if ((parseRegionInfo(&ri) != JBIG2_SUCCESS) || | 1404 if ((parseRegionInfo(&ri) != JBIG2_SUCCESS) || |
| 1449 (m_pStream->read1Byte(&cFlags) != 0)) { | 1405 (m_pStream->read1Byte(&cFlags) != 0)) { |
| 1450 nRet = JBIG2_ERROR_TOO_SHORT; | 1406 nRet = JBIG2_ERROR_TOO_SHORT; |
| 1451 goto failed; | 1407 goto failed; |
| 1452 } | 1408 } |
| 1453 pGRRD->GRW = ri.width; | 1409 pGRRD->GRW = ri.width; |
| 1454 pGRRD->GRH = ri.height; | 1410 pGRRD->GRH = ri.height; |
| 1455 pGRRD->GRTEMPLATE = cFlags & 0x01; | 1411 pGRRD->GRTEMPLATE = cFlags & 0x01; |
| 1456 pGRRD->TPGRON = (cFlags >> 1) & 0x01; | 1412 pGRRD->TPGRON = (cFlags >> 1) & 0x01; |
| 1457 if (pGRRD->GRTEMPLATE == 0) { | 1413 if (pGRRD->GRTEMPLATE == 0) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1479 nRet = JBIG2_ERROR_FATAL; | 1435 nRet = JBIG2_ERROR_FATAL; |
| 1480 goto failed; | 1436 goto failed; |
| 1481 } | 1437 } |
| 1482 pGRRD->GRREFERENCE = pSeg->m_Result.im; | 1438 pGRRD->GRREFERENCE = pSeg->m_Result.im; |
| 1483 } else { | 1439 } else { |
| 1484 pGRRD->GRREFERENCE = m_pPage; | 1440 pGRRD->GRREFERENCE = m_pPage; |
| 1485 } | 1441 } |
| 1486 pGRRD->GRREFERENCEDX = 0; | 1442 pGRRD->GRREFERENCEDX = 0; |
| 1487 pGRRD->GRREFERENCEDY = 0; | 1443 pGRRD->GRREFERENCEDY = 0; |
| 1488 dwTemp = pGRRD->GRTEMPLATE ? 1 << 10 : 1 << 13; | 1444 dwTemp = pGRRD->GRTEMPLATE ? 1 << 10 : 1 << 13; |
| 1489 grContext = | 1445 grContext = FX_Alloc(JBig2ArithCtx, dwTemp); |
| 1490 (JBig2ArithCtx*)m_pModule->JBig2_Malloc2(sizeof(JBig2ArithCtx), dwTemp); | |
| 1491 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); | 1446 JBIG2_memset(grContext, 0, sizeof(JBig2ArithCtx) * dwTemp); |
| 1492 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); | 1447 pArithDecoder = new CJBig2_ArithDecoder(m_pStream); |
| 1493 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; | 1448 pSegment->m_nResultType = JBIG2_IMAGE_POINTER; |
| 1494 pSegment->m_Result.im = pGRRD->decode(pArithDecoder, grContext); | 1449 pSegment->m_Result.im = pGRRD->decode(pArithDecoder, grContext); |
| 1495 delete pArithDecoder; | 1450 delete pArithDecoder; |
| 1496 if (pSegment->m_Result.im == NULL) { | 1451 if (pSegment->m_Result.im == NULL) { |
| 1497 m_pModule->JBig2_Free(grContext); | 1452 FX_Free(grContext); |
| 1498 nRet = JBIG2_ERROR_FATAL; | 1453 nRet = JBIG2_ERROR_FATAL; |
| 1499 goto failed; | 1454 goto failed; |
| 1500 } | 1455 } |
| 1501 m_pModule->JBig2_Free(grContext); | 1456 FX_Free(grContext); |
| 1502 m_pStream->alignByte(); | 1457 m_pStream->alignByte(); |
| 1503 m_pStream->offset(2); | 1458 m_pStream->offset(2); |
| 1504 if (pSegment->m_cFlags.s.type != 40) { | 1459 if (pSegment->m_cFlags.s.type != 40) { |
| 1505 if (!m_bBufSpecified) { | 1460 if (!m_bBufSpecified) { |
| 1506 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); | 1461 JBig2PageInfo* pPageInfo = m_PageInfoList.back(); |
| 1507 if ((pPageInfo->m_bIsStriped == 1) && | 1462 if ((pPageInfo->m_bIsStriped == 1) && |
| 1508 (ri.y + ri.height > m_pPage->m_nHeight)) { | 1463 (ri.y + ri.height > m_pPage->m_nHeight)) { |
| 1509 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); | 1464 m_pPage->expand(ri.y + ri.height, (pPageInfo->m_cFlags & 4) ? 1 : 0); |
| 1510 } | 1465 } |
| 1511 } | 1466 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1547 JBig2HuffmanCode* SBSYMCODES; | 1502 JBig2HuffmanCode* SBSYMCODES; |
| 1548 int32_t runcodes[35]; | 1503 int32_t runcodes[35]; |
| 1549 int32_t runcodes_len[35]; | 1504 int32_t runcodes_len[35]; |
| 1550 int32_t runcode; | 1505 int32_t runcode; |
| 1551 int32_t i; | 1506 int32_t i; |
| 1552 int32_t j; | 1507 int32_t j; |
| 1553 int32_t nVal; | 1508 int32_t nVal; |
| 1554 int32_t nBits; | 1509 int32_t nBits; |
| 1555 int32_t run; | 1510 int32_t run; |
| 1556 FX_DWORD nTemp; | 1511 FX_DWORD nTemp; |
| 1557 SBSYMCODES = (JBig2HuffmanCode*)m_pModule->JBig2_Malloc2( | 1512 SBSYMCODES = FX_Alloc(JBig2HuffmanCode, SBNUMSYMS); |
| 1558 sizeof(JBig2HuffmanCode), SBNUMSYMS); | |
| 1559 for (i = 0; i < 35; i++) { | 1513 for (i = 0; i < 35; i++) { |
| 1560 if (pStream->readNBits(4, &runcodes_len[i]) != 0) { | 1514 if (pStream->readNBits(4, &runcodes_len[i]) != 0) { |
| 1561 goto failed; | 1515 goto failed; |
| 1562 } | 1516 } |
| 1563 } | 1517 } |
| 1564 huffman_assign_code(runcodes, runcodes_len, 35); | 1518 huffman_assign_code(runcodes, runcodes_len, 35); |
| 1565 i = 0; | 1519 i = 0; |
| 1566 while (i < (int)SBNUMSYMS) { | 1520 while (i < (int)SBNUMSYMS) { |
| 1567 nVal = 0; | 1521 nVal = 0; |
| 1568 nBits = 0; | 1522 nBits = 0; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1613 } | 1567 } |
| 1614 } | 1568 } |
| 1615 i += run; | 1569 i += run; |
| 1616 } else { | 1570 } else { |
| 1617 i++; | 1571 i++; |
| 1618 } | 1572 } |
| 1619 } | 1573 } |
| 1620 huffman_assign_code(SBSYMCODES, SBNUMSYMS); | 1574 huffman_assign_code(SBSYMCODES, SBNUMSYMS); |
| 1621 return SBSYMCODES; | 1575 return SBSYMCODES; |
| 1622 failed: | 1576 failed: |
| 1623 m_pModule->JBig2_Free(SBSYMCODES); | 1577 FX_Free(SBSYMCODES); |
| 1624 return NULL; | 1578 return NULL; |
| 1625 } | 1579 } |
| 1626 void CJBig2_Context::huffman_assign_code(int* CODES, int* PREFLEN, int NTEMP) { | 1580 void CJBig2_Context::huffman_assign_code(int* CODES, int* PREFLEN, int NTEMP) { |
| 1627 int CURLEN, LENMAX, CURCODE, CURTEMP, i; | 1581 int CURLEN, LENMAX, CURCODE, CURTEMP, i; |
| 1628 int* LENCOUNT; | 1582 int* LENCOUNT; |
| 1629 int* FIRSTCODE; | 1583 int* FIRSTCODE; |
| 1630 LENMAX = 0; | 1584 LENMAX = 0; |
| 1631 for (i = 0; i < NTEMP; i++) { | 1585 for (i = 0; i < NTEMP; i++) { |
| 1632 if (PREFLEN[i] > LENMAX) { | 1586 if (PREFLEN[i] > LENMAX) { |
| 1633 LENMAX = PREFLEN[i]; | 1587 LENMAX = PREFLEN[i]; |
| 1634 } | 1588 } |
| 1635 } | 1589 } |
| 1636 LENCOUNT = (int*)m_pModule->JBig2_Malloc2(sizeof(int), (LENMAX + 1)); | 1590 LENCOUNT = FX_Alloc(int, LENMAX + 1); |
| 1637 JBIG2_memset(LENCOUNT, 0, sizeof(int) * (LENMAX + 1)); | 1591 JBIG2_memset(LENCOUNT, 0, sizeof(int) * (LENMAX + 1)); |
| 1638 FIRSTCODE = (int*)m_pModule->JBig2_Malloc2(sizeof(int), (LENMAX + 1)); | 1592 FIRSTCODE = FX_Alloc(int, LENMAX + 1); |
| 1639 for (i = 0; i < NTEMP; i++) { | 1593 for (i = 0; i < NTEMP; i++) { |
| 1640 LENCOUNT[PREFLEN[i]]++; | 1594 LENCOUNT[PREFLEN[i]]++; |
| 1641 } | 1595 } |
| 1642 CURLEN = 1; | 1596 CURLEN = 1; |
| 1643 FIRSTCODE[0] = 0; | 1597 FIRSTCODE[0] = 0; |
| 1644 LENCOUNT[0] = 0; | 1598 LENCOUNT[0] = 0; |
| 1645 while (CURLEN <= LENMAX) { | 1599 while (CURLEN <= LENMAX) { |
| 1646 FIRSTCODE[CURLEN] = (FIRSTCODE[CURLEN - 1] + LENCOUNT[CURLEN - 1]) << 1; | 1600 FIRSTCODE[CURLEN] = (FIRSTCODE[CURLEN - 1] + LENCOUNT[CURLEN - 1]) << 1; |
| 1647 CURCODE = FIRSTCODE[CURLEN]; | 1601 CURCODE = FIRSTCODE[CURLEN]; |
| 1648 CURTEMP = 0; | 1602 CURTEMP = 0; |
| 1649 while (CURTEMP < NTEMP) { | 1603 while (CURTEMP < NTEMP) { |
| 1650 if (PREFLEN[CURTEMP] == CURLEN) { | 1604 if (PREFLEN[CURTEMP] == CURLEN) { |
| 1651 CODES[CURTEMP] = CURCODE; | 1605 CODES[CURTEMP] = CURCODE; |
| 1652 CURCODE = CURCODE + 1; | 1606 CURCODE = CURCODE + 1; |
| 1653 } | 1607 } |
| 1654 CURTEMP = CURTEMP + 1; | 1608 CURTEMP = CURTEMP + 1; |
| 1655 } | 1609 } |
| 1656 CURLEN = CURLEN + 1; | 1610 CURLEN = CURLEN + 1; |
| 1657 } | 1611 } |
| 1658 m_pModule->JBig2_Free(LENCOUNT); | 1612 FX_Free(LENCOUNT); |
| 1659 m_pModule->JBig2_Free(FIRSTCODE); | 1613 FX_Free(FIRSTCODE); |
| 1660 } | 1614 } |
| 1661 void CJBig2_Context::huffman_assign_code(JBig2HuffmanCode* SBSYMCODES, | 1615 void CJBig2_Context::huffman_assign_code(JBig2HuffmanCode* SBSYMCODES, |
| 1662 int NTEMP) { | 1616 int NTEMP) { |
| 1663 int CURLEN, LENMAX, CURCODE, CURTEMP, i; | 1617 int CURLEN, LENMAX, CURCODE, CURTEMP, i; |
| 1664 int* LENCOUNT; | 1618 int* LENCOUNT; |
| 1665 int* FIRSTCODE; | 1619 int* FIRSTCODE; |
| 1666 LENMAX = 0; | 1620 LENMAX = 0; |
| 1667 for (i = 0; i < NTEMP; i++) { | 1621 for (i = 0; i < NTEMP; i++) { |
| 1668 if (SBSYMCODES[i].codelen > LENMAX) { | 1622 if (SBSYMCODES[i].codelen > LENMAX) { |
| 1669 LENMAX = SBSYMCODES[i].codelen; | 1623 LENMAX = SBSYMCODES[i].codelen; |
| 1670 } | 1624 } |
| 1671 } | 1625 } |
| 1672 LENCOUNT = (int*)m_pModule->JBig2_Malloc2(sizeof(int), (LENMAX + 1)); | 1626 LENCOUNT = FX_Alloc(int, (LENMAX + 1)); |
| 1673 JBIG2_memset(LENCOUNT, 0, sizeof(int) * (LENMAX + 1)); | 1627 JBIG2_memset(LENCOUNT, 0, sizeof(int) * (LENMAX + 1)); |
| 1674 FIRSTCODE = (int*)m_pModule->JBig2_Malloc2(sizeof(int), (LENMAX + 1)); | 1628 FIRSTCODE = FX_Alloc(int, (LENMAX + 1)); |
| 1675 for (i = 0; i < NTEMP; i++) { | 1629 for (i = 0; i < NTEMP; i++) { |
| 1676 LENCOUNT[SBSYMCODES[i].codelen]++; | 1630 LENCOUNT[SBSYMCODES[i].codelen]++; |
| 1677 } | 1631 } |
| 1678 CURLEN = 1; | 1632 CURLEN = 1; |
| 1679 FIRSTCODE[0] = 0; | 1633 FIRSTCODE[0] = 0; |
| 1680 LENCOUNT[0] = 0; | 1634 LENCOUNT[0] = 0; |
| 1681 while (CURLEN <= LENMAX) { | 1635 while (CURLEN <= LENMAX) { |
| 1682 FIRSTCODE[CURLEN] = (FIRSTCODE[CURLEN - 1] + LENCOUNT[CURLEN - 1]) << 1; | 1636 FIRSTCODE[CURLEN] = (FIRSTCODE[CURLEN - 1] + LENCOUNT[CURLEN - 1]) << 1; |
| 1683 CURCODE = FIRSTCODE[CURLEN]; | 1637 CURCODE = FIRSTCODE[CURLEN]; |
| 1684 CURTEMP = 0; | 1638 CURTEMP = 0; |
| 1685 while (CURTEMP < NTEMP) { | 1639 while (CURTEMP < NTEMP) { |
| 1686 if (SBSYMCODES[CURTEMP].codelen == CURLEN) { | 1640 if (SBSYMCODES[CURTEMP].codelen == CURLEN) { |
| 1687 SBSYMCODES[CURTEMP].code = CURCODE; | 1641 SBSYMCODES[CURTEMP].code = CURCODE; |
| 1688 CURCODE = CURCODE + 1; | 1642 CURCODE = CURCODE + 1; |
| 1689 } | 1643 } |
| 1690 CURTEMP = CURTEMP + 1; | 1644 CURTEMP = CURTEMP + 1; |
| 1691 } | 1645 } |
| 1692 CURLEN = CURLEN + 1; | 1646 CURLEN = CURLEN + 1; |
| 1693 } | 1647 } |
| 1694 m_pModule->JBig2_Free(LENCOUNT); | 1648 FX_Free(LENCOUNT); |
| 1695 m_pModule->JBig2_Free(FIRSTCODE); | 1649 FX_Free(FIRSTCODE); |
| 1696 } | 1650 } |
| OLD | NEW |