OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
| 7 #include "JBig2_Context.h" |
| 8 |
7 #include <list> | 9 #include <list> |
8 #include "JBig2_Context.h" | 10 |
| 11 #include "JBig2_GrdProc.h" |
| 12 #include "JBig2_GrrdProc.h" |
| 13 #include "JBig2_HtrdProc.h" |
| 14 #include "JBig2_PddProc.h" |
| 15 #include "JBig2_SddProc.h" |
| 16 #include "JBig2_TrdProc.h" |
9 | 17 |
10 // Implement a very small least recently used (LRU) cache. It is very | 18 // 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, | 19 // 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 | 20 // 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 | 21 // again. We key off of the memory location of the dictionary. The |
14 // list keeps track of the freshness of entries, with freshest ones | 22 // 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 | 23 // at the front. Even a tiny cache size like 2 makes a dramatic |
16 // difference for typical JBIG2 documents. | 24 // difference for typical JBIG2 documents. |
17 const int kSymbolDictCacheMaxSize = 2; | 25 static const int kSymbolDictCacheMaxSize = 2; |
18 | 26 |
19 CJBig2_Context* CJBig2_Context::CreateContext( | 27 CJBig2_Context* CJBig2_Context::CreateContext( |
20 const uint8_t* pGlobalData, | 28 const uint8_t* pGlobalData, |
21 FX_DWORD dwGlobalLength, | 29 FX_DWORD dwGlobalLength, |
22 const uint8_t* pData, | 30 const uint8_t* pData, |
23 FX_DWORD dwLength, | 31 FX_DWORD dwLength, |
24 int32_t nStreamType, | 32 int32_t nStreamType, |
25 std::list<CJBig2_CachePair>* pSymbolDictCache, | 33 std::list<CJBig2_CachePair>* pSymbolDictCache, |
26 IFX_Pause* pPause) { | 34 IFX_Pause* pPause) { |
27 return new CJBig2_Context(pGlobalData, dwGlobalLength, pData, dwLength, | 35 return new CJBig2_Context(pGlobalData, dwGlobalLength, pData, dwLength, |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 break; | 498 break; |
491 } | 499 } |
492 return JBIG2_SUCCESS; | 500 return JBIG2_SUCCESS; |
493 } | 501 } |
494 | 502 |
495 int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment, | 503 int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment, |
496 IFX_Pause* pPause) { | 504 IFX_Pause* pPause) { |
497 FX_DWORD dwTemp; | 505 FX_DWORD dwTemp; |
498 FX_WORD wFlags; | 506 FX_WORD wFlags; |
499 uint8_t cSDHUFFDH, cSDHUFFDW, cSDHUFFBMSIZE, cSDHUFFAGGINST; | 507 uint8_t cSDHUFFDH, cSDHUFFDW, cSDHUFFBMSIZE, cSDHUFFAGGINST; |
500 CJBig2_HuffmanTable *Table_B1 = NULL, *Table_B2 = NULL, *Table_B3 = NULL, | 508 CJBig2_HuffmanTable* Table_B1 = nullptr; |
501 *Table_B4 = NULL, *Table_B5 = NULL; | 509 CJBig2_HuffmanTable* Table_B2 = nullptr; |
| 510 CJBig2_HuffmanTable* Table_B3 = nullptr; |
| 511 CJBig2_HuffmanTable* Table_B4 = nullptr; |
| 512 CJBig2_HuffmanTable* Table_B5 = nullptr; |
502 int32_t i, nIndex, nRet; | 513 int32_t i, nIndex, nRet; |
503 CJBig2_Segment *pSeg = NULL, *pLRSeg = NULL; | 514 CJBig2_Segment* pSeg = nullptr; |
| 515 CJBig2_Segment* pLRSeg = nullptr; |
504 FX_BOOL bUsed; | 516 FX_BOOL bUsed; |
505 CJBig2_Image** SDINSYMS = NULL; | 517 CJBig2_Image** SDINSYMS = nullptr; |
506 JBig2ArithCtx *gbContext = NULL, *grContext = NULL; | 518 JBig2ArithCtx* gbContext = nullptr; |
| 519 JBig2ArithCtx* grContext = nullptr; |
507 CJBig2_ArithDecoder* pArithDecoder; | 520 CJBig2_ArithDecoder* pArithDecoder; |
508 CJBig2_SDDProc* pSymbolDictDecoder = new CJBig2_SDDProc(); | 521 CJBig2_SDDProc* pSymbolDictDecoder = new CJBig2_SDDProc(); |
509 const uint8_t* key = pSegment->m_pData; | 522 const uint8_t* key = pSegment->m_pData; |
510 FX_BOOL cache_hit = false; | 523 FX_BOOL cache_hit = false; |
511 if (m_pStream->readShortInteger(&wFlags) != 0) { | 524 if (m_pStream->readShortInteger(&wFlags) != 0) { |
512 nRet = JBIG2_ERROR_TOO_SHORT; | 525 nRet = JBIG2_ERROR_TOO_SHORT; |
513 goto failed; | 526 goto failed; |
514 } | 527 } |
515 pSymbolDictDecoder->SDHUFF = wFlags & 0x0001; | 528 pSymbolDictDecoder->SDHUFF = wFlags & 0x0001; |
516 pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001; | 529 pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001; |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 FX_Free(grContext); | 773 FX_Free(grContext); |
761 return nRet; | 774 return nRet; |
762 } | 775 } |
763 | 776 |
764 int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { | 777 int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { |
765 FX_DWORD dwTemp; | 778 FX_DWORD dwTemp; |
766 FX_WORD wFlags; | 779 FX_WORD wFlags; |
767 int32_t i, nIndex, nRet; | 780 int32_t i, nIndex, nRet; |
768 JBig2RegionInfo ri; | 781 JBig2RegionInfo ri; |
769 CJBig2_Segment* pSeg; | 782 CJBig2_Segment* pSeg; |
770 CJBig2_Image** SBSYMS = NULL; | 783 CJBig2_Image** SBSYMS = nullptr; |
771 JBig2HuffmanCode* SBSYMCODES = NULL; | 784 JBig2HuffmanCode* SBSYMCODES = nullptr; |
772 uint8_t cSBHUFFFS, cSBHUFFDS, cSBHUFFDT, cSBHUFFRDW, cSBHUFFRDH, cSBHUFFRDX, | 785 uint8_t cSBHUFFFS, cSBHUFFDS, cSBHUFFDT, cSBHUFFRDW, cSBHUFFRDH, cSBHUFFRDX, |
773 cSBHUFFRDY, cSBHUFFRSIZE; | 786 cSBHUFFRDY, cSBHUFFRSIZE; |
774 CJBig2_HuffmanTable *Table_B1 = NULL, *Table_B6 = NULL, *Table_B7 = NULL, | 787 CJBig2_HuffmanTable* Table_B1 = nullptr; |
775 *Table_B8 = NULL, *Table_B9 = NULL, *Table_B10 = NULL, | 788 CJBig2_HuffmanTable* Table_B6 = nullptr; |
776 *Table_B11 = NULL, *Table_B12 = NULL, *Table_B13 = NULL, | 789 CJBig2_HuffmanTable* Table_B7 = nullptr; |
777 *Table_B14 = NULL, *Table_B15 = NULL; | 790 CJBig2_HuffmanTable* Table_B8 = nullptr; |
778 JBig2ArithCtx* grContext = NULL; | 791 CJBig2_HuffmanTable* Table_B9 = nullptr; |
| 792 CJBig2_HuffmanTable* Table_B10 = nullptr; |
| 793 CJBig2_HuffmanTable* Table_B11 = nullptr; |
| 794 CJBig2_HuffmanTable* Table_B12 = nullptr; |
| 795 CJBig2_HuffmanTable* Table_B13 = nullptr; |
| 796 CJBig2_HuffmanTable* Table_B14 = nullptr; |
| 797 CJBig2_HuffmanTable* Table_B15 = nullptr; |
| 798 JBig2ArithCtx* grContext = nullptr; |
779 CJBig2_ArithDecoder* pArithDecoder; | 799 CJBig2_ArithDecoder* pArithDecoder; |
780 CJBig2_TRDProc* pTRD = new CJBig2_TRDProc(); | 800 CJBig2_TRDProc* pTRD = new CJBig2_TRDProc(); |
781 if ((parseRegionInfo(&ri) != JBIG2_SUCCESS) || | 801 if ((parseRegionInfo(&ri) != JBIG2_SUCCESS) || |
782 (m_pStream->readShortInteger(&wFlags) != 0)) { | 802 (m_pStream->readShortInteger(&wFlags) != 0)) { |
783 nRet = JBIG2_ERROR_TOO_SHORT; | 803 nRet = JBIG2_ERROR_TOO_SHORT; |
784 goto failed; | 804 goto failed; |
785 } | 805 } |
786 pTRD->SBW = ri.width; | 806 pTRD->SBW = ri.width; |
787 pTRD->SBH = ri.height; | 807 pTRD->SBH = ri.height; |
788 pTRD->SBHUFF = wFlags & 0x0001; | 808 pTRD->SBHUFF = wFlags & 0x0001; |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1626 SBSYMCODES[CURTEMP].code = CURCODE; | 1646 SBSYMCODES[CURTEMP].code = CURCODE; |
1627 CURCODE = CURCODE + 1; | 1647 CURCODE = CURCODE + 1; |
1628 } | 1648 } |
1629 CURTEMP = CURTEMP + 1; | 1649 CURTEMP = CURTEMP + 1; |
1630 } | 1650 } |
1631 CURLEN = CURLEN + 1; | 1651 CURLEN = CURLEN + 1; |
1632 } | 1652 } |
1633 FX_Free(LENCOUNT); | 1653 FX_Free(LENCOUNT); |
1634 FX_Free(FIRSTCODE); | 1654 FX_Free(FIRSTCODE); |
1635 } | 1655 } |
OLD | NEW |