| 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/fpdf_page/pageint.h" | 7 #include "core/fpdfapi/fpdf_page/pageint.h" |
| 8 | 8 |
| 9 #include <limits.h> | 9 #include <limits.h> |
| 10 | 10 |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 CPDF_SampledFunc::CPDF_SampledFunc() : CPDF_Function(Type::kType0Sampled) {} | 464 CPDF_SampledFunc::CPDF_SampledFunc() : CPDF_Function(Type::kType0Sampled) {} |
| 465 | 465 |
| 466 CPDF_SampledFunc::~CPDF_SampledFunc() {} | 466 CPDF_SampledFunc::~CPDF_SampledFunc() {} |
| 467 | 467 |
| 468 FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) { | 468 FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) { |
| 469 CPDF_Stream* pStream = pObj->AsStream(); | 469 CPDF_Stream* pStream = pObj->AsStream(); |
| 470 if (!pStream) | 470 if (!pStream) |
| 471 return false; | 471 return false; |
| 472 | 472 |
| 473 CPDF_Dictionary* pDict = pStream->GetDict(); | 473 CPDF_Dictionary* pDict = pStream->GetDict(); |
| 474 CPDF_Array* pSize = pDict->GetArrayBy("Size"); | 474 CPDF_Array* pSize = pDict->GetArrayFor("Size"); |
| 475 CPDF_Array* pEncode = pDict->GetArrayBy("Encode"); | 475 CPDF_Array* pEncode = pDict->GetArrayFor("Encode"); |
| 476 CPDF_Array* pDecode = pDict->GetArrayBy("Decode"); | 476 CPDF_Array* pDecode = pDict->GetArrayFor("Decode"); |
| 477 m_nBitsPerSample = pDict->GetIntegerBy("BitsPerSample"); | 477 m_nBitsPerSample = pDict->GetIntegerFor("BitsPerSample"); |
| 478 if (!IsValidBitsPerSample(m_nBitsPerSample)) | 478 if (!IsValidBitsPerSample(m_nBitsPerSample)) |
| 479 return FALSE; | 479 return FALSE; |
| 480 | 480 |
| 481 m_SampleMax = 0xffffffff >> (32 - m_nBitsPerSample); | 481 m_SampleMax = 0xffffffff >> (32 - m_nBitsPerSample); |
| 482 m_pSampleStream.reset(new CPDF_StreamAcc); | 482 m_pSampleStream.reset(new CPDF_StreamAcc); |
| 483 m_pSampleStream->LoadAllData(pStream, FALSE); | 483 m_pSampleStream->LoadAllData(pStream, FALSE); |
| 484 FX_SAFE_UINT32 nTotalSampleBits = 1; | 484 FX_SAFE_UINT32 nTotalSampleBits = 1; |
| 485 m_EncodeInfo.resize(m_nInputs); | 485 m_EncodeInfo.resize(m_nInputs); |
| 486 for (uint32_t i = 0; i < m_nInputs; i++) { | 486 for (uint32_t i = 0; i < m_nInputs; i++) { |
| 487 m_EncodeInfo[i].sizes = pSize ? pSize->GetIntegerAt(i) : 0; | 487 m_EncodeInfo[i].sizes = pSize ? pSize->GetIntegerAt(i) : 0; |
| 488 if (!pSize && i == 0) | 488 if (!pSize && i == 0) |
| 489 m_EncodeInfo[i].sizes = pDict->GetIntegerBy("Size"); | 489 m_EncodeInfo[i].sizes = pDict->GetIntegerFor("Size"); |
| 490 nTotalSampleBits *= m_EncodeInfo[i].sizes; | 490 nTotalSampleBits *= m_EncodeInfo[i].sizes; |
| 491 if (pEncode) { | 491 if (pEncode) { |
| 492 m_EncodeInfo[i].encode_min = pEncode->GetFloatAt(i * 2); | 492 m_EncodeInfo[i].encode_min = pEncode->GetFloatAt(i * 2); |
| 493 m_EncodeInfo[i].encode_max = pEncode->GetFloatAt(i * 2 + 1); | 493 m_EncodeInfo[i].encode_max = pEncode->GetFloatAt(i * 2 + 1); |
| 494 } else { | 494 } else { |
| 495 m_EncodeInfo[i].encode_min = 0; | 495 m_EncodeInfo[i].encode_min = 0; |
| 496 m_EncodeInfo[i].encode_max = | 496 m_EncodeInfo[i].encode_max = |
| 497 m_EncodeInfo[i].sizes == 1 ? 1 : (FX_FLOAT)m_EncodeInfo[i].sizes - 1; | 497 m_EncodeInfo[i].sizes == 1 ? 1 : (FX_FLOAT)m_EncodeInfo[i].sizes - 1; |
| 498 } | 498 } |
| 499 } | 499 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 | 594 |
| 595 CPDF_ExpIntFunc::~CPDF_ExpIntFunc() { | 595 CPDF_ExpIntFunc::~CPDF_ExpIntFunc() { |
| 596 FX_Free(m_pBeginValues); | 596 FX_Free(m_pBeginValues); |
| 597 FX_Free(m_pEndValues); | 597 FX_Free(m_pEndValues); |
| 598 } | 598 } |
| 599 FX_BOOL CPDF_ExpIntFunc::v_Init(CPDF_Object* pObj) { | 599 FX_BOOL CPDF_ExpIntFunc::v_Init(CPDF_Object* pObj) { |
| 600 CPDF_Dictionary* pDict = pObj->GetDict(); | 600 CPDF_Dictionary* pDict = pObj->GetDict(); |
| 601 if (!pDict) { | 601 if (!pDict) { |
| 602 return FALSE; | 602 return FALSE; |
| 603 } | 603 } |
| 604 CPDF_Array* pArray0 = pDict->GetArrayBy("C0"); | 604 CPDF_Array* pArray0 = pDict->GetArrayFor("C0"); |
| 605 if (m_nOutputs == 0) { | 605 if (m_nOutputs == 0) { |
| 606 m_nOutputs = 1; | 606 m_nOutputs = 1; |
| 607 if (pArray0) { | 607 if (pArray0) { |
| 608 m_nOutputs = pArray0->GetCount(); | 608 m_nOutputs = pArray0->GetCount(); |
| 609 } | 609 } |
| 610 } | 610 } |
| 611 CPDF_Array* pArray1 = pDict->GetArrayBy("C1"); | 611 CPDF_Array* pArray1 = pDict->GetArrayFor("C1"); |
| 612 m_pBeginValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); | 612 m_pBeginValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); |
| 613 m_pEndValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); | 613 m_pEndValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); |
| 614 for (uint32_t i = 0; i < m_nOutputs; i++) { | 614 for (uint32_t i = 0; i < m_nOutputs; i++) { |
| 615 m_pBeginValues[i] = pArray0 ? pArray0->GetFloatAt(i) : 0.0f; | 615 m_pBeginValues[i] = pArray0 ? pArray0->GetFloatAt(i) : 0.0f; |
| 616 m_pEndValues[i] = pArray1 ? pArray1->GetFloatAt(i) : 1.0f; | 616 m_pEndValues[i] = pArray1 ? pArray1->GetFloatAt(i) : 1.0f; |
| 617 } | 617 } |
| 618 m_Exponent = pDict->GetFloatBy("N"); | 618 m_Exponent = pDict->GetFloatFor("N"); |
| 619 m_nOrigOutputs = m_nOutputs; | 619 m_nOrigOutputs = m_nOutputs; |
| 620 if (m_nOutputs && m_nInputs > INT_MAX / m_nOutputs) { | 620 if (m_nOutputs && m_nInputs > INT_MAX / m_nOutputs) { |
| 621 return FALSE; | 621 return FALSE; |
| 622 } | 622 } |
| 623 m_nOutputs *= m_nInputs; | 623 m_nOutputs *= m_nInputs; |
| 624 return TRUE; | 624 return TRUE; |
| 625 } | 625 } |
| 626 FX_BOOL CPDF_ExpIntFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { | 626 FX_BOOL CPDF_ExpIntFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { |
| 627 for (uint32_t i = 0; i < m_nInputs; i++) | 627 for (uint32_t i = 0; i < m_nInputs; i++) |
| 628 for (uint32_t j = 0; j < m_nOrigOutputs; j++) { | 628 for (uint32_t j = 0; j < m_nOrigOutputs; j++) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 645 } | 645 } |
| 646 | 646 |
| 647 FX_BOOL CPDF_StitchFunc::v_Init(CPDF_Object* pObj) { | 647 FX_BOOL CPDF_StitchFunc::v_Init(CPDF_Object* pObj) { |
| 648 CPDF_Dictionary* pDict = pObj->GetDict(); | 648 CPDF_Dictionary* pDict = pObj->GetDict(); |
| 649 if (!pDict) { | 649 if (!pDict) { |
| 650 return FALSE; | 650 return FALSE; |
| 651 } | 651 } |
| 652 if (m_nInputs != kRequiredNumInputs) { | 652 if (m_nInputs != kRequiredNumInputs) { |
| 653 return FALSE; | 653 return FALSE; |
| 654 } | 654 } |
| 655 CPDF_Array* pArray = pDict->GetArrayBy("Functions"); | 655 CPDF_Array* pArray = pDict->GetArrayFor("Functions"); |
| 656 if (!pArray) { | 656 if (!pArray) { |
| 657 return FALSE; | 657 return FALSE; |
| 658 } | 658 } |
| 659 uint32_t nSubs = pArray->GetCount(); | 659 uint32_t nSubs = pArray->GetCount(); |
| 660 if (nSubs == 0) | 660 if (nSubs == 0) |
| 661 return FALSE; | 661 return FALSE; |
| 662 m_nOutputs = 0; | 662 m_nOutputs = 0; |
| 663 for (uint32_t i = 0; i < nSubs; i++) { | 663 for (uint32_t i = 0; i < nSubs; i++) { |
| 664 CPDF_Object* pSub = pArray->GetDirectObjectAt(i); | 664 CPDF_Object* pSub = pArray->GetDirectObjectAt(i); |
| 665 if (pSub == pObj) | 665 if (pSub == pObj) |
| 666 return FALSE; | 666 return FALSE; |
| 667 std::unique_ptr<CPDF_Function> pFunc(CPDF_Function::Load(pSub)); | 667 std::unique_ptr<CPDF_Function> pFunc(CPDF_Function::Load(pSub)); |
| 668 if (!pFunc) | 668 if (!pFunc) |
| 669 return FALSE; | 669 return FALSE; |
| 670 // Check that the input dimensionality is 1, and that all output | 670 // Check that the input dimensionality is 1, and that all output |
| 671 // dimensionalities are the same. | 671 // dimensionalities are the same. |
| 672 if (pFunc->CountInputs() != kRequiredNumInputs) | 672 if (pFunc->CountInputs() != kRequiredNumInputs) |
| 673 return FALSE; | 673 return FALSE; |
| 674 if (pFunc->CountOutputs() != m_nOutputs) { | 674 if (pFunc->CountOutputs() != m_nOutputs) { |
| 675 if (m_nOutputs) | 675 if (m_nOutputs) |
| 676 return FALSE; | 676 return FALSE; |
| 677 | 677 |
| 678 m_nOutputs = pFunc->CountOutputs(); | 678 m_nOutputs = pFunc->CountOutputs(); |
| 679 } | 679 } |
| 680 | 680 |
| 681 m_pSubFunctions.push_back(std::move(pFunc)); | 681 m_pSubFunctions.push_back(std::move(pFunc)); |
| 682 } | 682 } |
| 683 m_pBounds = FX_Alloc(FX_FLOAT, nSubs + 1); | 683 m_pBounds = FX_Alloc(FX_FLOAT, nSubs + 1); |
| 684 m_pBounds[0] = m_pDomains[0]; | 684 m_pBounds[0] = m_pDomains[0]; |
| 685 pArray = pDict->GetArrayBy("Bounds"); | 685 pArray = pDict->GetArrayFor("Bounds"); |
| 686 if (!pArray) | 686 if (!pArray) |
| 687 return FALSE; | 687 return FALSE; |
| 688 for (uint32_t i = 0; i < nSubs - 1; i++) | 688 for (uint32_t i = 0; i < nSubs - 1; i++) |
| 689 m_pBounds[i + 1] = pArray->GetFloatAt(i); | 689 m_pBounds[i + 1] = pArray->GetFloatAt(i); |
| 690 m_pBounds[nSubs] = m_pDomains[1]; | 690 m_pBounds[nSubs] = m_pDomains[1]; |
| 691 m_pEncode = FX_Alloc2D(FX_FLOAT, nSubs, 2); | 691 m_pEncode = FX_Alloc2D(FX_FLOAT, nSubs, 2); |
| 692 pArray = pDict->GetArrayBy("Encode"); | 692 pArray = pDict->GetArrayFor("Encode"); |
| 693 if (!pArray) | 693 if (!pArray) |
| 694 return FALSE; | 694 return FALSE; |
| 695 | 695 |
| 696 for (uint32_t i = 0; i < nSubs * 2; i++) | 696 for (uint32_t i = 0; i < nSubs * 2; i++) |
| 697 m_pEncode[i] = pArray->GetFloatAt(i); | 697 m_pEncode[i] = pArray->GetFloatAt(i); |
| 698 return TRUE; | 698 return TRUE; |
| 699 } | 699 } |
| 700 | 700 |
| 701 FX_BOOL CPDF_StitchFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* outputs) const { | 701 FX_BOOL CPDF_StitchFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* outputs) const { |
| 702 FX_FLOAT input = inputs[0]; | 702 FX_FLOAT input = inputs[0]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 713 } | 713 } |
| 714 | 714 |
| 715 // static | 715 // static |
| 716 std::unique_ptr<CPDF_Function> CPDF_Function::Load(CPDF_Object* pFuncObj) { | 716 std::unique_ptr<CPDF_Function> CPDF_Function::Load(CPDF_Object* pFuncObj) { |
| 717 std::unique_ptr<CPDF_Function> pFunc; | 717 std::unique_ptr<CPDF_Function> pFunc; |
| 718 if (!pFuncObj) | 718 if (!pFuncObj) |
| 719 return pFunc; | 719 return pFunc; |
| 720 | 720 |
| 721 int iType = -1; | 721 int iType = -1; |
| 722 if (CPDF_Stream* pStream = pFuncObj->AsStream()) | 722 if (CPDF_Stream* pStream = pFuncObj->AsStream()) |
| 723 iType = pStream->GetDict()->GetIntegerBy("FunctionType"); | 723 iType = pStream->GetDict()->GetIntegerFor("FunctionType"); |
| 724 else if (CPDF_Dictionary* pDict = pFuncObj->AsDictionary()) | 724 else if (CPDF_Dictionary* pDict = pFuncObj->AsDictionary()) |
| 725 iType = pDict->GetIntegerBy("FunctionType"); | 725 iType = pDict->GetIntegerFor("FunctionType"); |
| 726 | 726 |
| 727 Type type = IntegerToFunctionType(iType); | 727 Type type = IntegerToFunctionType(iType); |
| 728 if (type == Type::kType0Sampled) | 728 if (type == Type::kType0Sampled) |
| 729 pFunc.reset(new CPDF_SampledFunc()); | 729 pFunc.reset(new CPDF_SampledFunc()); |
| 730 else if (type == Type::kType2ExpotentialInterpolation) | 730 else if (type == Type::kType2ExpotentialInterpolation) |
| 731 pFunc.reset(new CPDF_ExpIntFunc()); | 731 pFunc.reset(new CPDF_ExpIntFunc()); |
| 732 else if (type == Type::kType3Stitching) | 732 else if (type == Type::kType3Stitching) |
| 733 pFunc.reset(new CPDF_StitchFunc()); | 733 pFunc.reset(new CPDF_StitchFunc()); |
| 734 else if (type == Type::kType4PostScript) | 734 else if (type == Type::kType4PostScript) |
| 735 pFunc.reset(new CPDF_PSFunc()); | 735 pFunc.reset(new CPDF_PSFunc()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 757 | 757 |
| 758 CPDF_Function::~CPDF_Function() { | 758 CPDF_Function::~CPDF_Function() { |
| 759 FX_Free(m_pDomains); | 759 FX_Free(m_pDomains); |
| 760 FX_Free(m_pRanges); | 760 FX_Free(m_pRanges); |
| 761 } | 761 } |
| 762 | 762 |
| 763 FX_BOOL CPDF_Function::Init(CPDF_Object* pObj) { | 763 FX_BOOL CPDF_Function::Init(CPDF_Object* pObj) { |
| 764 CPDF_Stream* pStream = pObj->AsStream(); | 764 CPDF_Stream* pStream = pObj->AsStream(); |
| 765 CPDF_Dictionary* pDict = pStream ? pStream->GetDict() : pObj->AsDictionary(); | 765 CPDF_Dictionary* pDict = pStream ? pStream->GetDict() : pObj->AsDictionary(); |
| 766 | 766 |
| 767 CPDF_Array* pDomains = pDict->GetArrayBy("Domain"); | 767 CPDF_Array* pDomains = pDict->GetArrayFor("Domain"); |
| 768 if (!pDomains) | 768 if (!pDomains) |
| 769 return FALSE; | 769 return FALSE; |
| 770 | 770 |
| 771 m_nInputs = pDomains->GetCount() / 2; | 771 m_nInputs = pDomains->GetCount() / 2; |
| 772 if (m_nInputs == 0) | 772 if (m_nInputs == 0) |
| 773 return FALSE; | 773 return FALSE; |
| 774 | 774 |
| 775 m_pDomains = FX_Alloc2D(FX_FLOAT, m_nInputs, 2); | 775 m_pDomains = FX_Alloc2D(FX_FLOAT, m_nInputs, 2); |
| 776 for (uint32_t i = 0; i < m_nInputs * 2; i++) { | 776 for (uint32_t i = 0; i < m_nInputs * 2; i++) { |
| 777 m_pDomains[i] = pDomains->GetFloatAt(i); | 777 m_pDomains[i] = pDomains->GetFloatAt(i); |
| 778 } | 778 } |
| 779 CPDF_Array* pRanges = pDict->GetArrayBy("Range"); | 779 CPDF_Array* pRanges = pDict->GetArrayFor("Range"); |
| 780 m_nOutputs = 0; | 780 m_nOutputs = 0; |
| 781 if (pRanges) { | 781 if (pRanges) { |
| 782 m_nOutputs = pRanges->GetCount() / 2; | 782 m_nOutputs = pRanges->GetCount() / 2; |
| 783 m_pRanges = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); | 783 m_pRanges = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); |
| 784 for (uint32_t i = 0; i < m_nOutputs * 2; i++) | 784 for (uint32_t i = 0; i < m_nOutputs * 2; i++) |
| 785 m_pRanges[i] = pRanges->GetFloatAt(i); | 785 m_pRanges[i] = pRanges->GetFloatAt(i); |
| 786 } | 786 } |
| 787 uint32_t old_outputs = m_nOutputs; | 787 uint32_t old_outputs = m_nOutputs; |
| 788 if (!v_Init(pObj)) | 788 if (!v_Init(pObj)) |
| 789 return FALSE; | 789 return FALSE; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 return m_Type == Type::kType2ExpotentialInterpolation | 833 return m_Type == Type::kType2ExpotentialInterpolation |
| 834 ? static_cast<const CPDF_ExpIntFunc*>(this) | 834 ? static_cast<const CPDF_ExpIntFunc*>(this) |
| 835 : nullptr; | 835 : nullptr; |
| 836 } | 836 } |
| 837 | 837 |
| 838 const CPDF_StitchFunc* CPDF_Function::ToStitchFunc() const { | 838 const CPDF_StitchFunc* CPDF_Function::ToStitchFunc() const { |
| 839 return m_Type == Type::kType3Stitching | 839 return m_Type == Type::kType3Stitching |
| 840 ? static_cast<const CPDF_StitchFunc*>(this) | 840 ? static_cast<const CPDF_StitchFunc*>(this) |
| 841 : nullptr; | 841 : nullptr; |
| 842 } | 842 } |
| OLD | NEW |