| 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 <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include "../../../../third_party/base/numerics/safe_conversions_impl.h" | 9 #include "../../../../third_party/base/numerics/safe_conversions_impl.h" |
| 10 #include "../../../include/fpdfapi/fpdf_module.h" | 10 #include "../../../include/fpdfapi/fpdf_module.h" |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 m_pSampleStream = NULL; | 484 m_pSampleStream = NULL; |
| 485 m_pEncodeInfo = NULL; | 485 m_pEncodeInfo = NULL; |
| 486 m_pDecodeInfo = NULL; | 486 m_pDecodeInfo = NULL; |
| 487 } | 487 } |
| 488 CPDF_SampledFunc::~CPDF_SampledFunc() { | 488 CPDF_SampledFunc::~CPDF_SampledFunc() { |
| 489 delete m_pSampleStream; | 489 delete m_pSampleStream; |
| 490 FX_Free(m_pEncodeInfo); | 490 FX_Free(m_pEncodeInfo); |
| 491 FX_Free(m_pDecodeInfo); | 491 FX_Free(m_pDecodeInfo); |
| 492 } | 492 } |
| 493 FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) { | 493 FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) { |
| 494 if (pObj->GetType() != PDFOBJ_STREAM) { | 494 CPDF_Stream* pStream = pObj->AsStream(); |
| 495 return FALSE; | 495 if (!pStream) |
| 496 } | 496 return false; |
| 497 CPDF_Stream* pStream = (CPDF_Stream*)pObj; | 497 |
| 498 CPDF_Dictionary* pDict = pStream->GetDict(); | 498 CPDF_Dictionary* pDict = pStream->GetDict(); |
| 499 CPDF_Array* pSize = pDict->GetArray(FX_BSTRC("Size")); | 499 CPDF_Array* pSize = pDict->GetArray(FX_BSTRC("Size")); |
| 500 CPDF_Array* pEncode = pDict->GetArray(FX_BSTRC("Encode")); | 500 CPDF_Array* pEncode = pDict->GetArray(FX_BSTRC("Encode")); |
| 501 CPDF_Array* pDecode = pDict->GetArray(FX_BSTRC("Decode")); | 501 CPDF_Array* pDecode = pDict->GetArray(FX_BSTRC("Decode")); |
| 502 m_nBitsPerSample = pDict->GetInteger(FX_BSTRC("BitsPerSample")); | 502 m_nBitsPerSample = pDict->GetInteger(FX_BSTRC("BitsPerSample")); |
| 503 if (m_nBitsPerSample > 32) { | 503 if (m_nBitsPerSample > 32) { |
| 504 return FALSE; | 504 return FALSE; |
| 505 } | 505 } |
| 506 m_SampleMax = 0xffffffff >> (32 - m_nBitsPerSample); | 506 m_SampleMax = 0xffffffff >> (32 - m_nBitsPerSample); |
| 507 m_pSampleStream = new CPDF_StreamAcc; | 507 m_pSampleStream = new CPDF_StreamAcc; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 class CPDF_PSFunc : public CPDF_Function { | 625 class CPDF_PSFunc : public CPDF_Function { |
| 626 public: | 626 public: |
| 627 // CPDF_Function | 627 // CPDF_Function |
| 628 FX_BOOL v_Init(CPDF_Object* pObj) override; | 628 FX_BOOL v_Init(CPDF_Object* pObj) override; |
| 629 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; | 629 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; |
| 630 | 630 |
| 631 CPDF_PSEngine m_PS; | 631 CPDF_PSEngine m_PS; |
| 632 }; | 632 }; |
| 633 | 633 |
| 634 FX_BOOL CPDF_PSFunc::v_Init(CPDF_Object* pObj) { | 634 FX_BOOL CPDF_PSFunc::v_Init(CPDF_Object* pObj) { |
| 635 CPDF_Stream* pStream = (CPDF_Stream*)pObj; | 635 CPDF_Stream* pStream = pObj->AsStream(); |
| 636 CPDF_StreamAcc acc; | 636 CPDF_StreamAcc acc; |
| 637 acc.LoadAllData(pStream, FALSE); | 637 acc.LoadAllData(pStream, FALSE); |
| 638 return m_PS.Parse((const FX_CHAR*)acc.GetData(), acc.GetSize()); | 638 return m_PS.Parse((const FX_CHAR*)acc.GetData(), acc.GetSize()); |
| 639 } | 639 } |
| 640 FX_BOOL CPDF_PSFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { | 640 FX_BOOL CPDF_PSFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { |
| 641 CPDF_PSEngine& PS = (CPDF_PSEngine&)m_PS; | 641 CPDF_PSEngine& PS = (CPDF_PSEngine&)m_PS; |
| 642 PS.Reset(); | 642 PS.Reset(); |
| 643 int i; | 643 int i; |
| 644 for (i = 0; i < m_nInputs; i++) { | 644 for (i = 0; i < m_nInputs; i++) { |
| 645 PS.Push(inputs[i]); | 645 PS.Push(inputs[i]); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 int nresults; | 807 int nresults; |
| 808 m_pSubFunctions[i]->Call(&input, m_nInputs, outputs, nresults); | 808 m_pSubFunctions[i]->Call(&input, m_nInputs, outputs, nresults); |
| 809 return TRUE; | 809 return TRUE; |
| 810 } | 810 } |
| 811 CPDF_Function* CPDF_Function::Load(CPDF_Object* pFuncObj) { | 811 CPDF_Function* CPDF_Function::Load(CPDF_Object* pFuncObj) { |
| 812 if (pFuncObj == NULL) { | 812 if (pFuncObj == NULL) { |
| 813 return NULL; | 813 return NULL; |
| 814 } | 814 } |
| 815 CPDF_Function* pFunc = NULL; | 815 CPDF_Function* pFunc = NULL; |
| 816 int type; | 816 int type; |
| 817 if (pFuncObj->GetType() == PDFOBJ_STREAM) { | 817 if (CPDF_Stream* pStream = pFuncObj->AsStream()) { |
| 818 type = ((CPDF_Stream*)pFuncObj) | 818 type = pStream->GetDict()->GetInteger(FX_BSTRC("FunctionType")); |
| 819 ->GetDict() | |
| 820 ->GetInteger(FX_BSTRC("FunctionType")); | |
| 821 } else if (CPDF_Dictionary* pDict = pFuncObj->AsDictionary()) { | 819 } else if (CPDF_Dictionary* pDict = pFuncObj->AsDictionary()) { |
| 822 type = pDict->GetInteger(FX_BSTRC("FunctionType")); | 820 type = pDict->GetInteger(FX_BSTRC("FunctionType")); |
| 823 } else { | 821 } else { |
| 824 return NULL; | 822 return NULL; |
| 825 } | 823 } |
| 826 if (type == 0) { | 824 if (type == 0) { |
| 827 pFunc = new CPDF_SampledFunc; | 825 pFunc = new CPDF_SampledFunc; |
| 828 } else if (type == 2) { | 826 } else if (type == 2) { |
| 829 pFunc = new CPDF_ExpIntFunc; | 827 pFunc = new CPDF_ExpIntFunc; |
| 830 } else if (type == 3) { | 828 } else if (type == 3) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 842 } | 840 } |
| 843 CPDF_Function::CPDF_Function() { | 841 CPDF_Function::CPDF_Function() { |
| 844 m_pDomains = NULL; | 842 m_pDomains = NULL; |
| 845 m_pRanges = NULL; | 843 m_pRanges = NULL; |
| 846 } | 844 } |
| 847 CPDF_Function::~CPDF_Function() { | 845 CPDF_Function::~CPDF_Function() { |
| 848 FX_Free(m_pDomains); | 846 FX_Free(m_pDomains); |
| 849 FX_Free(m_pRanges); | 847 FX_Free(m_pRanges); |
| 850 } | 848 } |
| 851 FX_BOOL CPDF_Function::Init(CPDF_Object* pObj) { | 849 FX_BOOL CPDF_Function::Init(CPDF_Object* pObj) { |
| 852 CPDF_Dictionary* pDict; | 850 CPDF_Stream* pStream = pObj->AsStream(); |
| 853 if (pObj->GetType() == PDFOBJ_STREAM) { | 851 CPDF_Dictionary* pDict = pStream ? pStream->GetDict() : pObj->AsDictionary(); |
| 854 pDict = ((CPDF_Stream*)pObj)->GetDict(); | 852 |
| 855 } else { | |
| 856 pDict = pObj->AsDictionary(); | |
| 857 } | |
| 858 CPDF_Array* pDomains = pDict->GetArray(FX_BSTRC("Domain")); | 853 CPDF_Array* pDomains = pDict->GetArray(FX_BSTRC("Domain")); |
| 859 if (pDomains == NULL) { | 854 if (!pDomains) |
| 860 return FALSE; | 855 return FALSE; |
| 861 } | 856 |
| 862 m_nInputs = pDomains->GetCount() / 2; | 857 m_nInputs = pDomains->GetCount() / 2; |
| 863 if (m_nInputs == 0) { | 858 if (m_nInputs == 0) |
| 864 return FALSE; | 859 return FALSE; |
| 865 } | 860 |
| 866 m_pDomains = FX_Alloc2D(FX_FLOAT, m_nInputs, 2); | 861 m_pDomains = FX_Alloc2D(FX_FLOAT, m_nInputs, 2); |
| 867 for (int i = 0; i < m_nInputs * 2; i++) { | 862 for (int i = 0; i < m_nInputs * 2; i++) { |
| 868 m_pDomains[i] = pDomains->GetFloat(i); | 863 m_pDomains[i] = pDomains->GetFloat(i); |
| 869 } | 864 } |
| 870 CPDF_Array* pRanges = pDict->GetArray(FX_BSTRC("Range")); | 865 CPDF_Array* pRanges = pDict->GetArray(FX_BSTRC("Range")); |
| 871 m_nOutputs = 0; | 866 m_nOutputs = 0; |
| 872 if (pRanges) { | 867 if (pRanges) { |
| 873 m_nOutputs = pRanges->GetCount() / 2; | 868 m_nOutputs = pRanges->GetCount() / 2; |
| 874 m_pRanges = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); | 869 m_pRanges = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); |
| 875 for (int i = 0; i < m_nOutputs * 2; i++) { | 870 for (int i = 0; i < m_nOutputs * 2; i++) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 for (int i = 0; i < m_nOutputs; i++) { | 904 for (int i = 0; i < m_nOutputs; i++) { |
| 910 if (results[i] < m_pRanges[i * 2]) { | 905 if (results[i] < m_pRanges[i * 2]) { |
| 911 results[i] = m_pRanges[i * 2]; | 906 results[i] = m_pRanges[i * 2]; |
| 912 } else if (results[i] > m_pRanges[i * 2 + 1]) { | 907 } else if (results[i] > m_pRanges[i * 2 + 1]) { |
| 913 results[i] = m_pRanges[i * 2 + 1]; | 908 results[i] = m_pRanges[i * 2 + 1]; |
| 914 } | 909 } |
| 915 } | 910 } |
| 916 } | 911 } |
| 917 return TRUE; | 912 return TRUE; |
| 918 } | 913 } |
| OLD | NEW |