| 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 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 FX_BOOL v_Init(CPDF_Object* pObj) override; | 513 FX_BOOL v_Init(CPDF_Object* pObj) override; |
| 514 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; | 514 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; |
| 515 | 515 |
| 516 SampleEncodeInfo* m_pEncodeInfo; | 516 SampleEncodeInfo* m_pEncodeInfo; |
| 517 SampleDecodeInfo* m_pDecodeInfo; | 517 SampleDecodeInfo* m_pDecodeInfo; |
| 518 FX_DWORD m_nBitsPerSample; | 518 FX_DWORD m_nBitsPerSample; |
| 519 FX_DWORD m_SampleMax; | 519 FX_DWORD m_SampleMax; |
| 520 CPDF_StreamAcc* m_pSampleStream; | 520 CPDF_StreamAcc* m_pSampleStream; |
| 521 }; | 521 }; |
| 522 | 522 |
| 523 CPDF_SampledFunc::CPDF_SampledFunc() { | 523 CPDF_SampledFunc::CPDF_SampledFunc() : CPDF_Function(Type::kType0Sampled) { |
| 524 m_pSampleStream = NULL; | 524 m_pSampleStream = NULL; |
| 525 m_pEncodeInfo = NULL; | 525 m_pEncodeInfo = NULL; |
| 526 m_pDecodeInfo = NULL; | 526 m_pDecodeInfo = NULL; |
| 527 } | 527 } |
| 528 |
| 528 CPDF_SampledFunc::~CPDF_SampledFunc() { | 529 CPDF_SampledFunc::~CPDF_SampledFunc() { |
| 529 delete m_pSampleStream; | 530 delete m_pSampleStream; |
| 530 FX_Free(m_pEncodeInfo); | 531 FX_Free(m_pEncodeInfo); |
| 531 FX_Free(m_pDecodeInfo); | 532 FX_Free(m_pDecodeInfo); |
| 532 } | 533 } |
| 533 FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) { | 534 FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) { |
| 534 CPDF_Stream* pStream = pObj->AsStream(); | 535 CPDF_Stream* pStream = pObj->AsStream(); |
| 535 if (!pStream) | 536 if (!pStream) |
| 536 return false; | 537 return false; |
| 537 | 538 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 results[j] = PDF_Interpolate(encoded, 0, (FX_FLOAT)m_SampleMax, | 659 results[j] = PDF_Interpolate(encoded, 0, (FX_FLOAT)m_SampleMax, |
| 659 m_pDecodeInfo[j].decode_min, | 660 m_pDecodeInfo[j].decode_min, |
| 660 m_pDecodeInfo[j].decode_max); | 661 m_pDecodeInfo[j].decode_max); |
| 661 } | 662 } |
| 662 return TRUE; | 663 return TRUE; |
| 663 } | 664 } |
| 664 | 665 |
| 665 class CPDF_PSFunc : public CPDF_Function { | 666 class CPDF_PSFunc : public CPDF_Function { |
| 666 public: | 667 public: |
| 667 // CPDF_Function | 668 // CPDF_Function |
| 669 CPDF_PSFunc() : CPDF_Function(Type::kType4PostScript) {} |
| 668 FX_BOOL v_Init(CPDF_Object* pObj) override; | 670 FX_BOOL v_Init(CPDF_Object* pObj) override; |
| 669 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; | 671 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; |
| 670 | 672 |
| 671 CPDF_PSEngine m_PS; | 673 CPDF_PSEngine m_PS; |
| 672 }; | 674 }; |
| 673 | 675 |
| 674 FX_BOOL CPDF_PSFunc::v_Init(CPDF_Object* pObj) { | 676 FX_BOOL CPDF_PSFunc::v_Init(CPDF_Object* pObj) { |
| 675 CPDF_Stream* pStream = pObj->AsStream(); | 677 CPDF_Stream* pStream = pObj->AsStream(); |
| 676 CPDF_StreamAcc acc; | 678 CPDF_StreamAcc acc; |
| 677 acc.LoadAllData(pStream, FALSE); | 679 acc.LoadAllData(pStream, FALSE); |
| 678 return m_PS.Parse((const FX_CHAR*)acc.GetData(), acc.GetSize()); | 680 return m_PS.Parse((const FX_CHAR*)acc.GetData(), acc.GetSize()); |
| 679 } | 681 } |
| 680 FX_BOOL CPDF_PSFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { | 682 FX_BOOL CPDF_PSFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { |
| 681 CPDF_PSEngine& PS = (CPDF_PSEngine&)m_PS; | 683 CPDF_PSEngine& PS = (CPDF_PSEngine&)m_PS; |
| 682 PS.Reset(); | 684 PS.Reset(); |
| 683 int i; | 685 int i; |
| 684 for (i = 0; i < m_nInputs; i++) { | 686 for (i = 0; i < m_nInputs; i++) { |
| 685 PS.Push(inputs[i]); | 687 PS.Push(inputs[i]); |
| 686 } | 688 } |
| 687 PS.Execute(); | 689 PS.Execute(); |
| 688 if (PS.GetStackSize() < m_nOutputs) { | 690 if (PS.GetStackSize() < m_nOutputs) { |
| 689 return FALSE; | 691 return FALSE; |
| 690 } | 692 } |
| 691 for (i = 0; i < m_nOutputs; i++) { | 693 for (i = 0; i < m_nOutputs; i++) { |
| 692 results[m_nOutputs - i - 1] = PS.Pop(); | 694 results[m_nOutputs - i - 1] = PS.Pop(); |
| 693 } | 695 } |
| 694 return TRUE; | 696 return TRUE; |
| 695 } | 697 } |
| 696 | 698 |
| 697 class CPDF_ExpIntFunc : public CPDF_Function { | 699 } // namespace |
| 698 public: | |
| 699 CPDF_ExpIntFunc(); | |
| 700 ~CPDF_ExpIntFunc() override; | |
| 701 | 700 |
| 702 // CPDF_Function | 701 CPDF_ExpIntFunc::CPDF_ExpIntFunc() |
| 703 FX_BOOL v_Init(CPDF_Object* pObj) override; | 702 : CPDF_Function(Type::kType2ExpotentialInterpolation) { |
| 704 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; | |
| 705 | |
| 706 FX_FLOAT m_Exponent; | |
| 707 FX_FLOAT* m_pBeginValues; | |
| 708 FX_FLOAT* m_pEndValues; | |
| 709 int m_nOrigOutputs; | |
| 710 }; | |
| 711 | |
| 712 CPDF_ExpIntFunc::CPDF_ExpIntFunc() { | |
| 713 m_pBeginValues = NULL; | 703 m_pBeginValues = NULL; |
| 714 m_pEndValues = NULL; | 704 m_pEndValues = NULL; |
| 715 } | 705 } |
| 706 |
| 716 CPDF_ExpIntFunc::~CPDF_ExpIntFunc() { | 707 CPDF_ExpIntFunc::~CPDF_ExpIntFunc() { |
| 717 FX_Free(m_pBeginValues); | 708 FX_Free(m_pBeginValues); |
| 718 FX_Free(m_pEndValues); | 709 FX_Free(m_pEndValues); |
| 719 } | 710 } |
| 720 FX_BOOL CPDF_ExpIntFunc::v_Init(CPDF_Object* pObj) { | 711 FX_BOOL CPDF_ExpIntFunc::v_Init(CPDF_Object* pObj) { |
| 721 CPDF_Dictionary* pDict = pObj->GetDict(); | 712 CPDF_Dictionary* pDict = pObj->GetDict(); |
| 722 if (!pDict) { | 713 if (!pDict) { |
| 723 return FALSE; | 714 return FALSE; |
| 724 } | 715 } |
| 725 CPDF_Array* pArray0 = pDict->GetArrayBy("C0"); | 716 CPDF_Array* pArray0 = pDict->GetArrayBy("C0"); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 748 for (int i = 0; i < m_nInputs; i++) | 739 for (int i = 0; i < m_nInputs; i++) |
| 749 for (int j = 0; j < m_nOrigOutputs; j++) { | 740 for (int j = 0; j < m_nOrigOutputs; j++) { |
| 750 results[i * m_nOrigOutputs + j] = | 741 results[i * m_nOrigOutputs + j] = |
| 751 m_pBeginValues[j] + | 742 m_pBeginValues[j] + |
| 752 (FX_FLOAT)FXSYS_pow(inputs[i], m_Exponent) * | 743 (FX_FLOAT)FXSYS_pow(inputs[i], m_Exponent) * |
| 753 (m_pEndValues[j] - m_pBeginValues[j]); | 744 (m_pEndValues[j] - m_pBeginValues[j]); |
| 754 } | 745 } |
| 755 return TRUE; | 746 return TRUE; |
| 756 } | 747 } |
| 757 | 748 |
| 758 class CPDF_StitchFunc : public CPDF_Function { | 749 CPDF_StitchFunc::CPDF_StitchFunc() : CPDF_Function(Type::kType3Stitching) { |
| 759 public: | |
| 760 CPDF_StitchFunc(); | |
| 761 ~CPDF_StitchFunc() override; | |
| 762 | |
| 763 // CPDF_Function | |
| 764 FX_BOOL v_Init(CPDF_Object* pObj) override; | |
| 765 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; | |
| 766 | |
| 767 std::vector<CPDF_Function*> m_pSubFunctions; | |
| 768 FX_FLOAT* m_pBounds; | |
| 769 FX_FLOAT* m_pEncode; | |
| 770 | |
| 771 static const int kRequiredNumInputs = 1; | |
| 772 }; | |
| 773 | |
| 774 CPDF_StitchFunc::CPDF_StitchFunc() { | |
| 775 m_pBounds = NULL; | 750 m_pBounds = NULL; |
| 776 m_pEncode = NULL; | 751 m_pEncode = NULL; |
| 777 } | 752 } |
| 753 |
| 778 CPDF_StitchFunc::~CPDF_StitchFunc() { | 754 CPDF_StitchFunc::~CPDF_StitchFunc() { |
| 779 for (auto& sub : m_pSubFunctions) { | 755 for (auto& sub : m_pSubFunctions) { |
| 780 delete sub; | 756 delete sub; |
| 781 } | 757 } |
| 782 FX_Free(m_pBounds); | 758 FX_Free(m_pBounds); |
| 783 FX_Free(m_pEncode); | 759 FX_Free(m_pEncode); |
| 784 } | 760 } |
| 785 FX_BOOL CPDF_StitchFunc::v_Init(CPDF_Object* pObj) { | 761 FX_BOOL CPDF_StitchFunc::v_Init(CPDF_Object* pObj) { |
| 786 CPDF_Dictionary* pDict = pObj->GetDict(); | 762 CPDF_Dictionary* pDict = pObj->GetDict(); |
| 787 if (!pDict) { | 763 if (!pDict) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 if (!m_pSubFunctions[i]) { | 828 if (!m_pSubFunctions[i]) { |
| 853 return FALSE; | 829 return FALSE; |
| 854 } | 830 } |
| 855 input = PDF_Interpolate(input, m_pBounds[i], m_pBounds[i + 1], | 831 input = PDF_Interpolate(input, m_pBounds[i], m_pBounds[i + 1], |
| 856 m_pEncode[i * 2], m_pEncode[i * 2 + 1]); | 832 m_pEncode[i * 2], m_pEncode[i * 2 + 1]); |
| 857 int nresults; | 833 int nresults; |
| 858 m_pSubFunctions[i]->Call(&input, kRequiredNumInputs, outputs, nresults); | 834 m_pSubFunctions[i]->Call(&input, kRequiredNumInputs, outputs, nresults); |
| 859 return TRUE; | 835 return TRUE; |
| 860 } | 836 } |
| 861 | 837 |
| 862 } // namespace | |
| 863 | |
| 864 CPDF_Function* CPDF_Function::Load(CPDF_Object* pFuncObj) { | 838 CPDF_Function* CPDF_Function::Load(CPDF_Object* pFuncObj) { |
| 865 if (!pFuncObj) { | 839 if (!pFuncObj) { |
| 866 return NULL; | 840 return NULL; |
| 867 } | 841 } |
| 868 CPDF_Function* pFunc = NULL; | |
| 869 int type; | 842 int type; |
| 870 if (CPDF_Stream* pStream = pFuncObj->AsStream()) { | 843 if (CPDF_Stream* pStream = pFuncObj->AsStream()) { |
| 871 type = pStream->GetDict()->GetIntegerBy("FunctionType"); | 844 type = pStream->GetDict()->GetIntegerBy("FunctionType"); |
| 872 } else if (CPDF_Dictionary* pDict = pFuncObj->AsDictionary()) { | 845 } else if (CPDF_Dictionary* pDict = pFuncObj->AsDictionary()) { |
| 873 type = pDict->GetIntegerBy("FunctionType"); | 846 type = pDict->GetIntegerBy("FunctionType"); |
| 874 } else { | 847 } else { |
| 875 return NULL; | 848 return NULL; |
| 876 } | 849 } |
| 850 CPDF_Function* pFunc = NULL; |
| 877 if (type == 0) { | 851 if (type == 0) { |
| 878 pFunc = new CPDF_SampledFunc; | 852 pFunc = new CPDF_SampledFunc(); |
| 879 } else if (type == 2) { | 853 } else if (type == 2) { |
| 880 pFunc = new CPDF_ExpIntFunc; | 854 pFunc = new CPDF_ExpIntFunc(); |
| 881 } else if (type == 3) { | 855 } else if (type == 3) { |
| 882 pFunc = new CPDF_StitchFunc; | 856 pFunc = new CPDF_StitchFunc(); |
| 883 } else if (type == 4) { | 857 } else if (type == 4) { |
| 884 pFunc = new CPDF_PSFunc; | 858 pFunc = new CPDF_PSFunc(); |
| 885 } else { | 859 } else { |
| 886 return NULL; | 860 return NULL; |
| 887 } | 861 } |
| 888 if (!pFunc->Init(pFuncObj)) { | 862 if (!pFunc->Init(pFuncObj)) { |
| 889 delete pFunc; | 863 delete pFunc; |
| 890 return NULL; | 864 return NULL; |
| 891 } | 865 } |
| 892 return pFunc; | 866 return pFunc; |
| 893 } | 867 } |
| 894 CPDF_Function::CPDF_Function() { | 868 |
| 869 CPDF_Function::CPDF_Function(Type type) : m_Type(type) { |
| 895 m_pDomains = NULL; | 870 m_pDomains = NULL; |
| 896 m_pRanges = NULL; | 871 m_pRanges = NULL; |
| 897 } | 872 } |
| 873 |
| 898 CPDF_Function::~CPDF_Function() { | 874 CPDF_Function::~CPDF_Function() { |
| 899 FX_Free(m_pDomains); | 875 FX_Free(m_pDomains); |
| 900 FX_Free(m_pRanges); | 876 FX_Free(m_pRanges); |
| 901 } | 877 } |
| 902 FX_BOOL CPDF_Function::Init(CPDF_Object* pObj) { | 878 FX_BOOL CPDF_Function::Init(CPDF_Object* pObj) { |
| 903 CPDF_Stream* pStream = pObj->AsStream(); | 879 CPDF_Stream* pStream = pObj->AsStream(); |
| 904 CPDF_Dictionary* pDict = pStream ? pStream->GetDict() : pObj->AsDictionary(); | 880 CPDF_Dictionary* pDict = pStream ? pStream->GetDict() : pObj->AsDictionary(); |
| 905 | 881 |
| 906 CPDF_Array* pDomains = pDict->GetArrayBy("Domain"); | 882 CPDF_Array* pDomains = pDict->GetArrayBy("Domain"); |
| 907 if (!pDomains) | 883 if (!pDomains) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 for (int i = 0; i < m_nOutputs; i++) { | 933 for (int i = 0; i < m_nOutputs; i++) { |
| 958 if (results[i] < m_pRanges[i * 2]) { | 934 if (results[i] < m_pRanges[i * 2]) { |
| 959 results[i] = m_pRanges[i * 2]; | 935 results[i] = m_pRanges[i * 2]; |
| 960 } else if (results[i] > m_pRanges[i * 2 + 1]) { | 936 } else if (results[i] > m_pRanges[i * 2 + 1]) { |
| 961 results[i] = m_pRanges[i * 2 + 1]; | 937 results[i] = m_pRanges[i * 2 + 1]; |
| 962 } | 938 } |
| 963 } | 939 } |
| 964 } | 940 } |
| 965 return TRUE; | 941 return TRUE; |
| 966 } | 942 } |
| OLD | NEW |