| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <list> | 8 #include <list> |
| 9 #include "JBig2_Context.h" | 9 #include "JBig2_Context.h" |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 JBIG2_EMBED_STREAM, pSymbolDictCache, pPause)); | 40 JBIG2_EMBED_STREAM, pSymbolDictCache, pPause)); |
| 41 } else { | 41 } else { |
| 42 m_pGlobalContext = NULL; | 42 m_pGlobalContext = NULL; |
| 43 } | 43 } |
| 44 JBIG2_ALLOC(m_pStream, CJBig2_BitStream(pData, dwLength)); | 44 JBIG2_ALLOC(m_pStream, CJBig2_BitStream(pData, dwLength)); |
| 45 m_nStreamType = nStreamType; | 45 m_nStreamType = nStreamType; |
| 46 m_nState = JBIG2_OUT_OF_PAGE; | 46 m_nState = JBIG2_OUT_OF_PAGE; |
| 47 JBIG2_ALLOC(m_pSegmentList, CJBig2_List<CJBig2_Segment>); | 47 JBIG2_ALLOC(m_pSegmentList, CJBig2_List<CJBig2_Segment>); |
| 48 JBIG2_ALLOC(m_pPageInfoList, CJBig2_List<JBig2PageInfo>(1)); | 48 JBIG2_ALLOC(m_pPageInfoList, CJBig2_List<JBig2PageInfo>(1)); |
| 49 m_pPage = NULL; | 49 m_pPage = NULL; |
| 50 m_bBufSpecified = FALSE; | 50 m_bBufSpecified = false; |
| 51 m_pPause = pPause; | 51 m_pPause = pPause; |
| 52 m_nSegmentDecoded = 0; | 52 m_nSegmentDecoded = 0; |
| 53 m_PauseStep = 10; | 53 m_PauseStep = 10; |
| 54 m_pArithDecoder = NULL; | 54 m_pArithDecoder = NULL; |
| 55 m_pGRD = NULL; | 55 m_pGRD = NULL; |
| 56 m_gbContext = NULL; | 56 m_gbContext = NULL; |
| 57 m_pSegment = NULL; | 57 m_pSegment = NULL; |
| 58 m_dwOffset = 0; | 58 m_dwOffset = 0; |
| 59 m_ProcessiveStatus = FXCODEC_STATUS_FRAME_READY; | 59 m_ProcessiveStatus = FXCODEC_STATUS_FRAME_READY; |
| 60 m_pSymbolDictCache = pSymbolDictCache; | 60 m_pSymbolDictCache = pSymbolDictCache; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 int32_t CJBig2_Context::getFirstPage(uint8_t *pBuf, int32_t width, int32_t heigh
t, int32_t stride, IFX_Pause* pPause) | 224 int32_t CJBig2_Context::getFirstPage(uint8_t *pBuf, int32_t width, int32_t heigh
t, int32_t stride, IFX_Pause* pPause) |
| 225 { | 225 { |
| 226 int32_t nRet = 0; | 226 int32_t nRet = 0; |
| 227 if(m_pGlobalContext) { | 227 if(m_pGlobalContext) { |
| 228 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); | 228 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); |
| 229 if(nRet != JBIG2_SUCCESS) { | 229 if(nRet != JBIG2_SUCCESS) { |
| 230 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; | 230 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; |
| 231 return nRet; | 231 return nRet; |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 m_bFirstPage = TRUE; | 234 m_bFirstPage = true; |
| 235 m_PauseStep = 0; | 235 m_PauseStep = 0; |
| 236 delete m_pPage; | 236 delete m_pPage; |
| 237 JBIG2_ALLOC(m_pPage, CJBig2_Image(width, height, stride, pBuf)); | 237 JBIG2_ALLOC(m_pPage, CJBig2_Image(width, height, stride, pBuf)); |
| 238 m_bBufSpecified = TRUE; | 238 m_bBufSpecified = true; |
| 239 if(m_pPage && pPause && pPause->NeedToPauseNow()) { | 239 if(m_pPage && pPause && pPause->NeedToPauseNow()) { |
| 240 m_PauseStep = 1; | 240 m_PauseStep = 1; |
| 241 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 241 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 242 return nRet; | 242 return nRet; |
| 243 } | 243 } |
| 244 int ret = Continue(pPause); | 244 int ret = Continue(pPause); |
| 245 return ret; | 245 return ret; |
| 246 } | 246 } |
| 247 int32_t CJBig2_Context::Continue(IFX_Pause* pPause) | 247 int32_t CJBig2_Context::Continue(IFX_Pause* pPause) |
| 248 { | 248 { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 if(nRet == JBIG2_SUCCESS) { | 291 if(nRet == JBIG2_SUCCESS) { |
| 292 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_FINISH; | 292 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_FINISH; |
| 293 } else { | 293 } else { |
| 294 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; | 294 m_ProcessiveStatus = FXCODEC_STATUS_ERROR; |
| 295 } | 295 } |
| 296 return nRet; | 296 return nRet; |
| 297 } | 297 } |
| 298 int32_t CJBig2_Context::getNextPage(uint8_t *pBuf, int32_t width, int32_t height
, int32_t stride, IFX_Pause* pPause) | 298 int32_t CJBig2_Context::getNextPage(uint8_t *pBuf, int32_t width, int32_t height
, int32_t stride, IFX_Pause* pPause) |
| 299 { | 299 { |
| 300 int32_t nRet = JBIG2_ERROR_STREAM_TYPE; | 300 int32_t nRet = JBIG2_ERROR_STREAM_TYPE; |
| 301 m_bFirstPage = FALSE; | 301 m_bFirstPage = false; |
| 302 m_PauseStep = 0; | 302 m_PauseStep = 0; |
| 303 delete m_pPage; | 303 delete m_pPage; |
| 304 JBIG2_ALLOC(m_pPage, CJBig2_Image(width, height, stride, pBuf)); | 304 JBIG2_ALLOC(m_pPage, CJBig2_Image(width, height, stride, pBuf)); |
| 305 m_bBufSpecified = TRUE; | 305 m_bBufSpecified = true; |
| 306 if(m_pPage && pPause && pPause->NeedToPauseNow()) { | 306 if(m_pPage && pPause && pPause->NeedToPauseNow()) { |
| 307 m_PauseStep = 1; | 307 m_PauseStep = 1; |
| 308 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; | 308 m_ProcessiveStatus = FXCODEC_STATUS_DECODE_TOBECONTINUE; |
| 309 return nRet; | 309 return nRet; |
| 310 } | 310 } |
| 311 return Continue(pPause); | 311 return Continue(pPause); |
| 312 switch(m_nStreamType) { | 312 switch(m_nStreamType) { |
| 313 case JBIG2_FILE_STREAM: | 313 case JBIG2_FILE_STREAM: |
| 314 nRet = decodeFile(pPause); | 314 nRet = decodeFile(pPause); |
| 315 break; | 315 break; |
| 316 case JBIG2_SQUENTIAL_STREAM: | 316 case JBIG2_SQUENTIAL_STREAM: |
| 317 nRet = decode_SquentialOrgnazation(pPause); | 317 nRet = decode_SquentialOrgnazation(pPause); |
| 318 break; | 318 break; |
| 319 case JBIG2_RANDOM_STREAM: | 319 case JBIG2_RANDOM_STREAM: |
| 320 nRet = decode_RandomOrgnazation(pPause); | 320 nRet = decode_RandomOrgnazation(pPause); |
| 321 break; | 321 break; |
| 322 case JBIG2_EMBED_STREAM: | 322 case JBIG2_EMBED_STREAM: |
| 323 nRet = decode_EmbedOrgnazation(pPause); | 323 nRet = decode_EmbedOrgnazation(pPause); |
| 324 break; | 324 break; |
| 325 default: | 325 default: |
| 326 return JBIG2_ERROR_STREAM_TYPE; | 326 return JBIG2_ERROR_STREAM_TYPE; |
| 327 } | 327 } |
| 328 return nRet; | 328 return nRet; |
| 329 } | 329 } |
| 330 int32_t CJBig2_Context::getFirstPage(CJBig2_Image **image, IFX_Pause* pPause) | 330 int32_t CJBig2_Context::getFirstPage(CJBig2_Image **image, IFX_Pause* pPause) |
| 331 { | 331 { |
| 332 int32_t nRet; | 332 int32_t nRet; |
| 333 m_bFirstPage = TRUE; | 333 m_bFirstPage = true; |
| 334 m_PauseStep = 0; | 334 m_PauseStep = 0; |
| 335 if(m_pGlobalContext) { | 335 if(m_pGlobalContext) { |
| 336 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); | 336 nRet = m_pGlobalContext->decode_EmbedOrgnazation(pPause); |
| 337 if(nRet != JBIG2_SUCCESS) { | 337 if(nRet != JBIG2_SUCCESS) { |
| 338 return nRet; | 338 return nRet; |
| 339 } | 339 } |
| 340 } | 340 } |
| 341 m_bBufSpecified = FALSE; | 341 m_bBufSpecified = false; |
| 342 return Continue(pPause); | 342 return Continue(pPause); |
| 343 } | 343 } |
| 344 int32_t CJBig2_Context::getNextPage(CJBig2_Image **image, IFX_Pause* pPause) | 344 int32_t CJBig2_Context::getNextPage(CJBig2_Image **image, IFX_Pause* pPause) |
| 345 { | 345 { |
| 346 int32_t nRet; | 346 int32_t nRet; |
| 347 m_bBufSpecified = FALSE; | 347 m_bBufSpecified = false; |
| 348 m_bFirstPage = FALSE; | 348 m_bFirstPage = false; |
| 349 m_PauseStep = 0; | 349 m_PauseStep = 0; |
| 350 switch(m_nStreamType) { | 350 switch(m_nStreamType) { |
| 351 case JBIG2_FILE_STREAM: | 351 case JBIG2_FILE_STREAM: |
| 352 nRet = decodeFile(pPause); | 352 nRet = decodeFile(pPause); |
| 353 break; | 353 break; |
| 354 case JBIG2_SQUENTIAL_STREAM: | 354 case JBIG2_SQUENTIAL_STREAM: |
| 355 nRet = decode_SquentialOrgnazation(pPause); | 355 nRet = decode_SquentialOrgnazation(pPause); |
| 356 break; | 356 break; |
| 357 case JBIG2_RANDOM_STREAM: | 357 case JBIG2_RANDOM_STREAM: |
| 358 nRet = decode_RandomOrgnazation(pPause); | 358 nRet = decode_RandomOrgnazation(pPause); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 return JBIG2_ERROR_FATAL; | 594 return JBIG2_ERROR_FATAL; |
| 595 } | 595 } |
| 596 int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment *pSegment, IFX_Pause* pPa
use) | 596 int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment *pSegment, IFX_Pause* pPa
use) |
| 597 { | 597 { |
| 598 FX_DWORD dwTemp; | 598 FX_DWORD dwTemp; |
| 599 FX_WORD wFlags; | 599 FX_WORD wFlags; |
| 600 uint8_t cSDHUFFDH, cSDHUFFDW, cSDHUFFBMSIZE, cSDHUFFAGGINST; | 600 uint8_t cSDHUFFDH, cSDHUFFDW, cSDHUFFBMSIZE, cSDHUFFAGGINST; |
| 601 CJBig2_HuffmanTable *Table_B1 = NULL, *Table_B2 = NULL, *Table_B3 = NULL, *T
able_B4 = NULL, *Table_B5 = NULL; | 601 CJBig2_HuffmanTable *Table_B1 = NULL, *Table_B2 = NULL, *Table_B3 = NULL, *T
able_B4 = NULL, *Table_B5 = NULL; |
| 602 int32_t i, nIndex, nRet; | 602 int32_t i, nIndex, nRet; |
| 603 CJBig2_Segment *pSeg = NULL, *pLRSeg = NULL; | 603 CJBig2_Segment *pSeg = NULL, *pLRSeg = NULL; |
| 604 FX_BOOL bUsed; | 604 bool bUsed; |
| 605 CJBig2_Image ** SDINSYMS = NULL; | 605 CJBig2_Image ** SDINSYMS = NULL; |
| 606 CJBig2_SDDProc *pSymbolDictDecoder; | 606 CJBig2_SDDProc *pSymbolDictDecoder; |
| 607 JBig2ArithCtx *gbContext = NULL, *grContext = NULL; | 607 JBig2ArithCtx *gbContext = NULL, *grContext = NULL; |
| 608 CJBig2_ArithDecoder *pArithDecoder; | 608 CJBig2_ArithDecoder *pArithDecoder; |
| 609 JBIG2_ALLOC(pSymbolDictDecoder, CJBig2_SDDProc()); | 609 JBIG2_ALLOC(pSymbolDictDecoder, CJBig2_SDDProc()); |
| 610 uint8_t *key = pSegment->m_pData; | 610 uint8_t *key = pSegment->m_pData; |
| 611 FX_BOOL cache_hit = false; | 611 bool cache_hit = false; |
| 612 if(m_pStream->readShortInteger(&wFlags) != 0) { | 612 if(m_pStream->readShortInteger(&wFlags) != 0) { |
| 613 m_pModule->JBig2_Error("symbol dictionary segment : data header too shor
t."); | 613 m_pModule->JBig2_Error("symbol dictionary segment : data header too shor
t."); |
| 614 nRet = JBIG2_ERROR_TOO_SHORT; | 614 nRet = JBIG2_ERROR_TOO_SHORT; |
| 615 goto failed; | 615 goto failed; |
| 616 } | 616 } |
| 617 pSymbolDictDecoder->SDHUFF = wFlags & 0x0001; | 617 pSymbolDictDecoder->SDHUFF = wFlags & 0x0001; |
| 618 pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001; | 618 pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001; |
| 619 pSymbolDictDecoder->SDTEMPLATE = (wFlags >> 10) & 0x0003; | 619 pSymbolDictDecoder->SDTEMPLATE = (wFlags >> 10) & 0x0003; |
| 620 pSymbolDictDecoder->SDRTEMPLATE = (wFlags >> 12) & 0x0003; | 620 pSymbolDictDecoder->SDRTEMPLATE = (wFlags >> 12) & 0x0003; |
| 621 cSDHUFFDH = (wFlags >> 2) & 0x0003; | 621 cSDHUFFDH = (wFlags >> 2) & 0x0003; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 CJBig2_SymbolDict *value = pSegment->m_Result.sd->DeepCopy(); | 818 CJBig2_SymbolDict *value = pSegment->m_Result.sd->DeepCopy(); |
| 819 if (value && kSymbolDictCacheMaxSize > 0) { | 819 if (value && kSymbolDictCacheMaxSize > 0) { |
| 820 while (m_pSymbolDictCache->size() >= kSymbolDictCacheMaxSize) { | 820 while (m_pSymbolDictCache->size() >= kSymbolDictCacheMaxSize) { |
| 821 delete m_pSymbolDictCache->back().second; | 821 delete m_pSymbolDictCache->back().second; |
| 822 m_pSymbolDictCache->pop_back(); | 822 m_pSymbolDictCache->pop_back(); |
| 823 } | 823 } |
| 824 m_pSymbolDictCache->push_front(CJBig2_CachePair(key, value)); | 824 m_pSymbolDictCache->push_front(CJBig2_CachePair(key, value)); |
| 825 } | 825 } |
| 826 } | 826 } |
| 827 if(wFlags & 0x0200) { | 827 if(wFlags & 0x0200) { |
| 828 pSegment->m_Result.sd->m_bContextRetained = TRUE; | 828 pSegment->m_Result.sd->m_bContextRetained = true; |
| 829 if(pSymbolDictDecoder->SDHUFF == 0) { | 829 if(pSymbolDictDecoder->SDHUFF == 0) { |
| 830 pSegment->m_Result.sd->m_gbContext = gbContext; | 830 pSegment->m_Result.sd->m_gbContext = gbContext; |
| 831 } | 831 } |
| 832 if(pSymbolDictDecoder->SDREFAGG == 1) { | 832 if(pSymbolDictDecoder->SDREFAGG == 1) { |
| 833 pSegment->m_Result.sd->m_grContext = grContext; | 833 pSegment->m_Result.sd->m_grContext = grContext; |
| 834 } | 834 } |
| 835 bUsed = TRUE; | 835 bUsed = true; |
| 836 } else { | 836 } else { |
| 837 bUsed = FALSE; | 837 bUsed = false; |
| 838 } | 838 } |
| 839 delete pSymbolDictDecoder; | 839 delete pSymbolDictDecoder; |
| 840 if(SDINSYMS) { | 840 if(SDINSYMS) { |
| 841 m_pModule->JBig2_Free(SDINSYMS); | 841 m_pModule->JBig2_Free(SDINSYMS); |
| 842 } | 842 } |
| 843 delete Table_B1; | 843 delete Table_B1; |
| 844 delete Table_B2; | 844 delete Table_B2; |
| 845 delete Table_B3; | 845 delete Table_B3; |
| 846 delete Table_B4; | 846 delete Table_B4; |
| 847 delete Table_B5; | 847 delete Table_B5; |
| 848 if(bUsed == FALSE) { | 848 if(bUsed == false) { |
| 849 if(gbContext) { | 849 if(gbContext) { |
| 850 m_pModule->JBig2_Free(gbContext); | 850 m_pModule->JBig2_Free(gbContext); |
| 851 } | 851 } |
| 852 if(grContext) { | 852 if(grContext) { |
| 853 m_pModule->JBig2_Free(grContext); | 853 m_pModule->JBig2_Free(grContext); |
| 854 } | 854 } |
| 855 } | 855 } |
| 856 return JBIG2_SUCCESS; | 856 return JBIG2_SUCCESS; |
| 857 failed: | 857 failed: |
| 858 delete pSymbolDictDecoder; | 858 delete pSymbolDictDecoder; |
| (...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1760 SBSYMCODES[CURTEMP].code = CURCODE; | 1760 SBSYMCODES[CURTEMP].code = CURCODE; |
| 1761 CURCODE = CURCODE + 1; | 1761 CURCODE = CURCODE + 1; |
| 1762 } | 1762 } |
| 1763 CURTEMP = CURTEMP + 1; | 1763 CURTEMP = CURTEMP + 1; |
| 1764 } | 1764 } |
| 1765 CURLEN = CURLEN + 1; | 1765 CURLEN = CURLEN + 1; |
| 1766 } | 1766 } |
| 1767 m_pModule->JBig2_Free(LENCOUNT); | 1767 m_pModule->JBig2_Free(LENCOUNT); |
| 1768 m_pModule->JBig2_Free(FIRSTCODE); | 1768 m_pModule->JBig2_Free(FIRSTCODE); |
| 1769 } | 1769 } |
| OLD | NEW |