| 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 "../../../include/fxge/fx_ge.h" | 7 #include "../../../include/fxge/fx_ge.h" |
| 8 #include "../../../include/fxcodec/fx_codec.h" | 8 #include "../../../include/fxcodec/fx_codec.h" |
| 9 #include "../../../include/fpdfapi/fpdf_module.h" | 9 #include "../../../include/fpdfapi/fpdf_module.h" |
| 10 #include "../../../include/fpdfapi/fpdf_render.h" | 10 #include "../../../include/fpdfapi/fpdf_render.h" |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(FX_LPCBYTE src_buf, FX_DWORD sr
c_size, int width, int height, | 557 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(FX_LPCBYTE src_buf, FX_DWORD sr
c_size, int width, int height, |
| 558 const CPDF_Dictionary* pParams); | 558 const CPDF_Dictionary* pParams); |
| 559 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(FX_LPCBYTE src_buf, FX_DWORD
src_size, int width, int height, | 559 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(FX_LPCBYTE src_buf, FX_DWORD
src_size, int width, int height, |
| 560 int nComps, int bpc, const CPDF_Dictionary* pParams); | 560 int nComps, int bpc, const CPDF_Dictionary* pParams); |
| 561 int CPDF_DIBSource::CreateDecoder() | 561 int CPDF_DIBSource::CreateDecoder() |
| 562 { | 562 { |
| 563 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); | 563 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); |
| 564 if (decoder.IsEmpty()) { | 564 if (decoder.IsEmpty()) { |
| 565 return 1; | 565 return 1; |
| 566 } | 566 } |
| 567 FX_DWORD bpc = GetValidBpc(); |
| 568 if (bpc == 0) { |
| 569 return 0; |
| 570 } |
| 567 FX_LPCBYTE src_data = m_pStreamAcc->GetData(); | 571 FX_LPCBYTE src_data = m_pStreamAcc->GetData(); |
| 568 FX_DWORD src_size = m_pStreamAcc->GetSize(); | 572 FX_DWORD src_size = m_pStreamAcc->GetSize(); |
| 569 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam(); | 573 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam(); |
| 570 if (decoder == FX_BSTRC("CCITTFaxDecode")) { | 574 if (decoder == FX_BSTRC("CCITTFaxDecode")) { |
| 571 m_pDecoder = FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, m_Hei
ght, pParams); | 575 m_pDecoder = FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, m_Hei
ght, pParams); |
| 572 } else if (decoder == FX_BSTRC("DCTDecode")) { | 576 } else if (decoder == FX_BSTRC("DCTDecode")) { |
| 573 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(src_d
ata, src_size, m_Width, m_Height, | 577 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(src_d
ata, src_size, m_Width, m_Height, |
| 574 m_nComponents, pParams ? pParams->GetInteger(FX_BSTR("Color
Transform"), 1) : 1); | 578 m_nComponents, pParams ? pParams->GetInteger(FX_BSTR("Color
Transform"), 1) : 1); |
| 575 if (NULL == m_pDecoder) { | 579 if (NULL == m_pDecoder) { |
| 576 FX_BOOL bTransform = FALSE; | 580 FX_BOOL bTransform = FALSE; |
| 577 int comps, bpc; | 581 int comps, tmp_bpc; |
| 578 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModul
e(); | 582 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModul
e(); |
| 579 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, com
ps, bpc, bTransform)) { | 583 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, com
ps, tmp_bpc, bTransform)) { |
| 580 m_nComponents = comps; | 584 m_nComponents = comps; |
| 581 m_bpc = bpc; | 585 m_bpc = bpc = tmp_bpc; |
| 582 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecod
er(src_data, src_size, m_Width, m_Height, | 586 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecod
er(src_data, src_size, m_Width, m_Height, |
| 583 m_nComponents, bTransform); | 587 m_nComponents, bTransform); |
| 584 } | 588 } |
| 585 } | 589 } |
| 586 } else if (decoder == FX_BSTRC("FlateDecode")) { | 590 } else if (decoder == FX_BSTRC("FlateDecode")) { |
| 587 m_pDecoder = FPDFAPI_CreateFlateDecoder(src_data, src_size, m_Width, m_H
eight, m_nComponents, m_bpc, pParams); | 591 m_pDecoder = FPDFAPI_CreateFlateDecoder(src_data, src_size, m_Width, m_H
eight, m_nComponents, bpc, pParams); |
| 588 } else if (decoder == FX_BSTRC("JPXDecode")) { | 592 } else if (decoder == FX_BSTRC("JPXDecode")) { |
| 589 LoadJpxBitmap(); | 593 LoadJpxBitmap(); |
| 590 return m_pCachedBitmap != NULL ? 1 : 0; | 594 return m_pCachedBitmap != NULL ? 1 : 0; |
| 591 } else if (decoder == FX_BSTRC("JBIG2Decode")) { | 595 } else if (decoder == FX_BSTRC("JBIG2Decode")) { |
| 592 m_pCachedBitmap = FX_NEW CFX_DIBitmap; | 596 m_pCachedBitmap = FX_NEW CFX_DIBitmap; |
| 593 if (!m_pCachedBitmap->Create(m_Width, m_Height, m_bImageMask ? FXDIB_1bp
pMask : FXDIB_1bppRgb)) { | 597 if (!m_pCachedBitmap->Create(m_Width, m_Height, m_bImageMask ? FXDIB_1bp
pMask : FXDIB_1bppRgb)) { |
| 594 delete m_pCachedBitmap; | 598 delete m_pCachedBitmap; |
| 595 m_pCachedBitmap = NULL; | 599 m_pCachedBitmap = NULL; |
| 596 return 0; | 600 return 0; |
| 597 } | 601 } |
| 598 m_Status = 1; | 602 m_Status = 1; |
| 599 return 2; | 603 return 2; |
| 600 } else if (decoder == FX_BSTRC("RunLengthDecode")) { | 604 } else if (decoder == FX_BSTRC("RunLengthDecode")) { |
| 601 m_pDecoder = CPDF_ModuleMgr::Get()->GetCodecModule()->GetBasicModule()->
CreateRunLengthDecoder(src_data, src_size, m_Width, m_Height, m_nComponents, m_b
pc); | 605 m_pDecoder = CPDF_ModuleMgr::Get()->GetCodecModule()->GetBasicModule()->
CreateRunLengthDecoder(src_data, src_size, m_Width, m_Height, m_nComponents, bpc
); |
| 602 } | 606 } |
| 603 if (m_pDecoder) { | 607 if (m_pDecoder) { |
| 604 int requested_pitch = (m_Width * m_nComponents * m_bpc + 7) / 8; | 608 FX_SAFE_DWORD requested_pitch = bpc; |
| 605 int provided_pitch = (m_pDecoder->GetWidth() * m_pDecoder->CountComps()
* m_pDecoder->GetBPC() + 7) / 8; | 609 requested_pitch *= m_nComponents; |
| 606 if (provided_pitch < requested_pitch) { | 610 requested_pitch *= m_Width; |
| 611 requested_pitch += 7; |
| 612 requested_pitch /= 8; |
| 613 if (!requested_pitch.IsValid()) { |
| 614 return 0; |
| 615 } |
| 616 FX_SAFE_DWORD provided_pitch = m_pDecoder->GetBPC(); |
| 617 provided_pitch *= m_pDecoder->CountComps(); |
| 618 provided_pitch *= m_pDecoder->GetWidth(); |
| 619 provided_pitch += 7; |
| 620 provided_pitch /= 8; |
| 621 if (!provided_pitch.IsValid()) { |
| 622 return 0; |
| 623 } |
| 624 if (provided_pitch.ValueOrDie() < requested_pitch.ValueOrDie()) { |
| 607 return 0; | 625 return 0; |
| 608 } | 626 } |
| 609 return 1; | 627 return 1; |
| 610 } | 628 } |
| 611 return 0; | 629 return 0; |
| 612 } | 630 } |
| 613 void CPDF_DIBSource::LoadJpxBitmap() | 631 void CPDF_DIBSource::LoadJpxBitmap() |
| 614 { | 632 { |
| 615 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); | 633 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); |
| 616 if (pJpxModule == NULL) { | 634 if (pJpxModule == NULL) { |
| (...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1526 if (!m_bCached) { | 1544 if (!m_bCached) { |
| 1527 if (m_pBitmap) { | 1545 if (m_pBitmap) { |
| 1528 delete m_pBitmap; | 1546 delete m_pBitmap; |
| 1529 m_pBitmap = NULL; | 1547 m_pBitmap = NULL; |
| 1530 } | 1548 } |
| 1531 if (m_pMask) { | 1549 if (m_pMask) { |
| 1532 delete m_pMask; | 1550 delete m_pMask; |
| 1533 } | 1551 } |
| 1534 } | 1552 } |
| 1535 } | 1553 } |
| OLD | NEW |