Chromium Code Reviews| 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 "core/fpdfapi/render/render_int.h" | 7 #include "core/fpdfapi/render/render_int.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "core/fpdfapi/cpdf_modulemgr.h" | 13 #include "core/fpdfapi/cpdf_modulemgr.h" |
| 14 #include "core/fpdfapi/page/cpdf_docpagedata.h" | 14 #include "core/fpdfapi/page/cpdf_docpagedata.h" |
| 15 #include "core/fpdfapi/page/cpdf_image.h" | 15 #include "core/fpdfapi/page/cpdf_image.h" |
| 16 #include "core/fpdfapi/page/cpdf_imageobject.h" | 16 #include "core/fpdfapi/page/cpdf_imageobject.h" |
| 17 #include "core/fpdfapi/parser/cpdf_array.h" | 17 #include "core/fpdfapi/parser/cpdf_array.h" |
| 18 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 18 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 19 #include "core/fpdfapi/parser/cpdf_document.h" | 19 #include "core/fpdfapi/parser/cpdf_document.h" |
| 20 #include "core/fpdfapi/parser/fpdf_parser_decode.h" | |
| 20 #include "core/fpdfapi/render/cpdf_pagerendercache.h" | 21 #include "core/fpdfapi/render/cpdf_pagerendercache.h" |
| 21 #include "core/fpdfapi/render/cpdf_renderstatus.h" | 22 #include "core/fpdfapi/render/cpdf_renderstatus.h" |
| 22 #include "core/fxcodec/fx_codec.h" | 23 #include "core/fxcodec/fx_codec.h" |
| 23 #include "core/fxcrt/fx_safe_types.h" | 24 #include "core/fxcrt/fx_safe_types.h" |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 unsigned int GetBits8(const uint8_t* pData, uint64_t bitpos, size_t nbits) { | 28 unsigned int GetBits8(const uint8_t* pData, uint64_t bitpos, size_t nbits) { |
| 28 ASSERT(nbits == 1 || nbits == 2 || nbits == 4 || nbits == 8 || nbits == 16); | 29 ASSERT(nbits == 1 || nbits == 2 || nbits == 4 || nbits == 8 || nbits == 16); |
| 29 ASSERT((bitpos & (nbits - 1)) == 0); | 30 ASSERT((bitpos & (nbits - 1)) == 0); |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 506 pCompData[i].m_ColorKeyMin = std::max(min_num, 0); | 507 pCompData[i].m_ColorKeyMin = std::max(min_num, 0); |
| 507 pCompData[i].m_ColorKeyMax = std::min(max_num, max_data); | 508 pCompData[i].m_ColorKeyMax = std::min(max_num, max_data); |
| 508 } | 509 } |
| 509 } | 510 } |
| 510 bColorKey = true; | 511 bColorKey = true; |
| 511 } | 512 } |
| 512 } | 513 } |
| 513 return pCompData; | 514 return pCompData; |
| 514 } | 515 } |
| 515 | 516 |
| 516 CCodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder( | |
|
Tom Sepez
2016/12/13 19:21:20
Note: same thing moved to header, sheesh.
| |
| 517 const uint8_t* src_buf, | |
| 518 uint32_t src_size, | |
| 519 int width, | |
| 520 int height, | |
| 521 const CPDF_Dictionary* pParams); | |
| 522 | |
| 523 CCodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder( | |
| 524 const uint8_t* src_buf, | |
| 525 uint32_t src_size, | |
| 526 int width, | |
| 527 int height, | |
| 528 int nComps, | |
| 529 int bpc, | |
| 530 const CPDF_Dictionary* pParams); | |
| 531 | |
| 532 int CPDF_DIBSource::CreateDecoder() { | 517 int CPDF_DIBSource::CreateDecoder() { |
| 533 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); | 518 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); |
| 534 if (decoder.IsEmpty()) | 519 if (decoder.IsEmpty()) |
| 535 return 1; | 520 return 1; |
| 536 | 521 |
| 537 if (m_bDoBpcCheck && m_bpc == 0) | 522 if (m_bDoBpcCheck && m_bpc == 0) |
| 538 return 0; | 523 return 0; |
| 539 | 524 |
| 540 if (decoder == "JPXDecode") { | 525 if (decoder == "JPXDecode") { |
| 541 LoadJpxBitmap(); | 526 LoadJpxBitmap(); |
| 542 return m_pCachedBitmap ? 1 : 0; | 527 return m_pCachedBitmap ? 1 : 0; |
| 543 } | 528 } |
| 544 if (decoder == "JBIG2Decode") { | 529 if (decoder == "JBIG2Decode") { |
| 545 m_pCachedBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); | 530 m_pCachedBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); |
| 546 if (!m_pCachedBitmap->Create( | 531 if (!m_pCachedBitmap->Create( |
| 547 m_Width, m_Height, m_bImageMask ? FXDIB_1bppMask : FXDIB_1bppRgb)) { | 532 m_Width, m_Height, m_bImageMask ? FXDIB_1bppMask : FXDIB_1bppRgb)) { |
| 548 m_pCachedBitmap.reset(); | 533 m_pCachedBitmap.reset(); |
| 549 return 0; | 534 return 0; |
| 550 } | 535 } |
| 551 m_Status = 1; | 536 m_Status = 1; |
| 552 return 2; | 537 return 2; |
| 553 } | 538 } |
| 554 | 539 |
| 555 const uint8_t* src_data = m_pStreamAcc->GetData(); | 540 const uint8_t* src_data = m_pStreamAcc->GetData(); |
| 556 uint32_t src_size = m_pStreamAcc->GetSize(); | 541 uint32_t src_size = m_pStreamAcc->GetSize(); |
| 557 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam(); | 542 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam(); |
| 558 if (decoder == "CCITTFaxDecode") { | 543 if (decoder == "CCITTFaxDecode") { |
| 559 m_pDecoder.reset(FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, | 544 m_pDecoder = FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, m_Height, |
| 560 m_Height, pParams)); | 545 pParams); |
| 561 } else if (decoder == "FlateDecode") { | 546 } else if (decoder == "FlateDecode") { |
| 562 m_pDecoder.reset(FPDFAPI_CreateFlateDecoder( | 547 m_pDecoder = FPDFAPI_CreateFlateDecoder( |
| 563 src_data, src_size, m_Width, m_Height, m_nComponents, m_bpc, pParams)); | 548 src_data, src_size, m_Width, m_Height, m_nComponents, m_bpc, pParams); |
| 564 } else if (decoder == "RunLengthDecode") { | 549 } else if (decoder == "RunLengthDecode") { |
| 565 m_pDecoder.reset(CPDF_ModuleMgr::Get() | 550 m_pDecoder = CPDF_ModuleMgr::Get() |
| 566 ->GetCodecModule() | 551 ->GetCodecModule() |
| 567 ->GetBasicModule() | 552 ->GetBasicModule() |
| 568 ->CreateRunLengthDecoder(src_data, src_size, m_Width, | 553 ->CreateRunLengthDecoder(src_data, src_size, m_Width, |
| 569 m_Height, m_nComponents, | 554 m_Height, m_nComponents, m_bpc); |
| 570 m_bpc)); | |
| 571 } else if (decoder == "DCTDecode") { | 555 } else if (decoder == "DCTDecode") { |
| 572 m_pDecoder.reset(CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( | 556 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( |
| 573 src_data, src_size, m_Width, m_Height, m_nComponents, | 557 src_data, src_size, m_Width, m_Height, m_nComponents, |
| 574 !pParams || pParams->GetIntegerFor("ColorTransform", 1))); | 558 !pParams || pParams->GetIntegerFor("ColorTransform", 1)); |
| 575 if (!m_pDecoder) { | 559 if (!m_pDecoder) { |
| 576 bool bTransform = false; | 560 bool bTransform = false; |
| 577 int comps; | 561 int comps; |
| 578 int bpc; | 562 int bpc; |
| 579 CCodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModule(); | 563 CCodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModule(); |
| 580 if (pJpegModule->LoadInfo(src_data, src_size, &m_Width, &m_Height, &comps, | 564 if (pJpegModule->LoadInfo(src_data, src_size, &m_Width, &m_Height, &comps, |
| 581 &bpc, &bTransform)) { | 565 &bpc, &bTransform)) { |
| 582 if (m_nComponents != static_cast<uint32_t>(comps)) { | 566 if (m_nComponents != static_cast<uint32_t>(comps)) { |
| 583 FX_Free(m_pCompData); | 567 FX_Free(m_pCompData); |
| 584 m_pCompData = nullptr; | 568 m_pCompData = nullptr; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 616 } | 600 } |
| 617 } else { | 601 } else { |
| 618 if (m_Family == PDFCS_LAB && m_nComponents != 3) | 602 if (m_Family == PDFCS_LAB && m_nComponents != 3) |
| 619 return 0; | 603 return 0; |
| 620 } | 604 } |
| 621 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey); | 605 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey); |
| 622 if (!m_pCompData) | 606 if (!m_pCompData) |
| 623 return 0; | 607 return 0; |
| 624 } | 608 } |
| 625 m_bpc = bpc; | 609 m_bpc = bpc; |
| 626 m_pDecoder.reset(CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( | 610 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( |
| 627 src_data, src_size, m_Width, m_Height, m_nComponents, bTransform)); | 611 src_data, src_size, m_Width, m_Height, m_nComponents, bTransform); |
| 628 } | 612 } |
| 629 } | 613 } |
| 630 } | 614 } |
| 631 if (!m_pDecoder) | 615 if (!m_pDecoder) |
| 632 return 0; | 616 return 0; |
| 633 | 617 |
| 634 FX_SAFE_UINT32 requested_pitch = | 618 FX_SAFE_UINT32 requested_pitch = |
| 635 CalculatePitch8(m_bpc, m_nComponents, m_Width); | 619 CalculatePitch8(m_bpc, m_nComponents, m_Width); |
| 636 if (!requested_pitch.IsValid()) | 620 if (!requested_pitch.IsValid()) |
| 637 return 0; | 621 return 0; |
| (...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1486 *pDestPixel++ = FXARGB_G(argb); | 1470 *pDestPixel++ = FXARGB_G(argb); |
| 1487 *pDestPixel = FXARGB_R(argb); | 1471 *pDestPixel = FXARGB_R(argb); |
| 1488 } | 1472 } |
| 1489 } | 1473 } |
| 1490 } | 1474 } |
| 1491 | 1475 |
| 1492 bool CPDF_DIBSource::TransMask() const { | 1476 bool CPDF_DIBSource::TransMask() const { |
| 1493 return m_bLoadMask && m_GroupFamily == PDFCS_DEVICECMYK && | 1477 return m_bLoadMask && m_GroupFamily == PDFCS_DEVICECMYK && |
| 1494 m_Family == PDFCS_DEVICECMYK; | 1478 m_Family == PDFCS_DEVICECMYK; |
| 1495 } | 1479 } |
| OLD | NEW |