| 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 "../../../include/fpdfapi/fpdf_module.h" | 9 #include "../../../include/fpdfapi/fpdf_module.h" |
| 10 #include "../../../include/fpdfapi/fpdf_page.h" | 10 #include "../../../include/fpdfapi/fpdf_page.h" |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 if (pData[(bitpos + i) / 8] & (1 << (7 - (bitpos + i) % 8))) { | 456 if (pData[(bitpos + i) / 8] & (1 << (7 - (bitpos + i) % 8))) { |
| 457 result |= 1 << (nbits - i - 1); | 457 result |= 1 << (nbits - i - 1); |
| 458 } | 458 } |
| 459 return result; | 459 return result; |
| 460 } | 460 } |
| 461 typedef struct { | 461 typedef struct { |
| 462 FX_FLOAT encode_max, encode_min; | 462 FX_FLOAT encode_max, encode_min; |
| 463 int sizes; | 463 int sizes; |
| 464 } SampleEncodeInfo; | 464 } SampleEncodeInfo; |
| 465 typedef struct { FX_FLOAT decode_max, decode_min; } SampleDecodeInfo; | 465 typedef struct { FX_FLOAT decode_max, decode_min; } SampleDecodeInfo; |
| 466 |
| 466 class CPDF_SampledFunc : public CPDF_Function { | 467 class CPDF_SampledFunc : public CPDF_Function { |
| 467 public: | 468 public: |
| 468 CPDF_SampledFunc(); | 469 CPDF_SampledFunc(); |
| 469 virtual ~CPDF_SampledFunc(); | 470 ~CPDF_SampledFunc() override; |
| 470 virtual FX_BOOL v_Init(CPDF_Object* pObj); | 471 |
| 471 virtual FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const; | 472 // CPDF_Function |
| 473 FX_BOOL v_Init(CPDF_Object* pObj) override; |
| 474 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; |
| 475 |
| 472 SampleEncodeInfo* m_pEncodeInfo; | 476 SampleEncodeInfo* m_pEncodeInfo; |
| 473 SampleDecodeInfo* m_pDecodeInfo; | 477 SampleDecodeInfo* m_pDecodeInfo; |
| 474 FX_DWORD m_nBitsPerSample; | 478 FX_DWORD m_nBitsPerSample; |
| 475 FX_DWORD m_SampleMax; | 479 FX_DWORD m_SampleMax; |
| 476 CPDF_StreamAcc* m_pSampleStream; | 480 CPDF_StreamAcc* m_pSampleStream; |
| 477 }; | 481 }; |
| 482 |
| 478 CPDF_SampledFunc::CPDF_SampledFunc() { | 483 CPDF_SampledFunc::CPDF_SampledFunc() { |
| 479 m_pSampleStream = NULL; | 484 m_pSampleStream = NULL; |
| 480 m_pEncodeInfo = NULL; | 485 m_pEncodeInfo = NULL; |
| 481 m_pDecodeInfo = NULL; | 486 m_pDecodeInfo = NULL; |
| 482 } | 487 } |
| 483 CPDF_SampledFunc::~CPDF_SampledFunc() { | 488 CPDF_SampledFunc::~CPDF_SampledFunc() { |
| 484 delete m_pSampleStream; | 489 delete m_pSampleStream; |
| 485 if (m_pEncodeInfo) { | 490 if (m_pEncodeInfo) { |
| 486 FX_Free(m_pEncodeInfo); | 491 FX_Free(m_pEncodeInfo); |
| 487 } | 492 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 encoded += (encoded_input[i] - index[i]) * | 618 encoded += (encoded_input[i] - index[i]) * |
| 614 ((FX_FLOAT)sample1 - (FX_FLOAT)sample); | 619 ((FX_FLOAT)sample1 - (FX_FLOAT)sample); |
| 615 } | 620 } |
| 616 } | 621 } |
| 617 results[j] = PDF_Interpolate(encoded, 0, (FX_FLOAT)m_SampleMax, | 622 results[j] = PDF_Interpolate(encoded, 0, (FX_FLOAT)m_SampleMax, |
| 618 m_pDecodeInfo[j].decode_min, | 623 m_pDecodeInfo[j].decode_min, |
| 619 m_pDecodeInfo[j].decode_max); | 624 m_pDecodeInfo[j].decode_max); |
| 620 } | 625 } |
| 621 return TRUE; | 626 return TRUE; |
| 622 } | 627 } |
| 628 |
| 623 class CPDF_PSFunc : public CPDF_Function { | 629 class CPDF_PSFunc : public CPDF_Function { |
| 624 public: | 630 public: |
| 625 virtual FX_BOOL v_Init(CPDF_Object* pObj); | 631 // CPDF_Function |
| 626 virtual FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const; | 632 FX_BOOL v_Init(CPDF_Object* pObj) override; |
| 633 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; |
| 634 |
| 627 CPDF_PSEngine m_PS; | 635 CPDF_PSEngine m_PS; |
| 628 }; | 636 }; |
| 637 |
| 629 FX_BOOL CPDF_PSFunc::v_Init(CPDF_Object* pObj) { | 638 FX_BOOL CPDF_PSFunc::v_Init(CPDF_Object* pObj) { |
| 630 CPDF_Stream* pStream = (CPDF_Stream*)pObj; | 639 CPDF_Stream* pStream = (CPDF_Stream*)pObj; |
| 631 CPDF_StreamAcc acc; | 640 CPDF_StreamAcc acc; |
| 632 acc.LoadAllData(pStream, FALSE); | 641 acc.LoadAllData(pStream, FALSE); |
| 633 return m_PS.Parse((const FX_CHAR*)acc.GetData(), acc.GetSize()); | 642 return m_PS.Parse((const FX_CHAR*)acc.GetData(), acc.GetSize()); |
| 634 } | 643 } |
| 635 FX_BOOL CPDF_PSFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { | 644 FX_BOOL CPDF_PSFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { |
| 636 CPDF_PSEngine& PS = (CPDF_PSEngine&)m_PS; | 645 CPDF_PSEngine& PS = (CPDF_PSEngine&)m_PS; |
| 637 PS.Reset(); | 646 PS.Reset(); |
| 638 int i; | 647 int i; |
| 639 for (i = 0; i < m_nInputs; i++) { | 648 for (i = 0; i < m_nInputs; i++) { |
| 640 PS.Push(inputs[i]); | 649 PS.Push(inputs[i]); |
| 641 } | 650 } |
| 642 PS.Execute(); | 651 PS.Execute(); |
| 643 if (PS.GetStackSize() < m_nOutputs) { | 652 if (PS.GetStackSize() < m_nOutputs) { |
| 644 return FALSE; | 653 return FALSE; |
| 645 } | 654 } |
| 646 for (i = 0; i < m_nOutputs; i++) { | 655 for (i = 0; i < m_nOutputs; i++) { |
| 647 results[m_nOutputs - i - 1] = PS.Pop(); | 656 results[m_nOutputs - i - 1] = PS.Pop(); |
| 648 } | 657 } |
| 649 return TRUE; | 658 return TRUE; |
| 650 } | 659 } |
| 660 |
| 651 class CPDF_ExpIntFunc : public CPDF_Function { | 661 class CPDF_ExpIntFunc : public CPDF_Function { |
| 652 public: | 662 public: |
| 653 CPDF_ExpIntFunc(); | 663 CPDF_ExpIntFunc(); |
| 654 virtual ~CPDF_ExpIntFunc(); | 664 ~CPDF_ExpIntFunc() override; |
| 655 virtual FX_BOOL v_Init(CPDF_Object* pObj); | 665 |
| 656 virtual FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const; | 666 // CPDF_Function |
| 667 FX_BOOL v_Init(CPDF_Object* pObj) override; |
| 668 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; |
| 669 |
| 657 FX_FLOAT m_Exponent; | 670 FX_FLOAT m_Exponent; |
| 658 FX_FLOAT* m_pBeginValues; | 671 FX_FLOAT* m_pBeginValues; |
| 659 FX_FLOAT* m_pEndValues; | 672 FX_FLOAT* m_pEndValues; |
| 660 int m_nOrigOutputs; | 673 int m_nOrigOutputs; |
| 661 }; | 674 }; |
| 675 |
| 662 CPDF_ExpIntFunc::CPDF_ExpIntFunc() { | 676 CPDF_ExpIntFunc::CPDF_ExpIntFunc() { |
| 663 m_pBeginValues = NULL; | 677 m_pBeginValues = NULL; |
| 664 m_pEndValues = NULL; | 678 m_pEndValues = NULL; |
| 665 } | 679 } |
| 666 CPDF_ExpIntFunc::~CPDF_ExpIntFunc() { | 680 CPDF_ExpIntFunc::~CPDF_ExpIntFunc() { |
| 667 if (m_pBeginValues) { | 681 if (m_pBeginValues) { |
| 668 FX_Free(m_pBeginValues); | 682 FX_Free(m_pBeginValues); |
| 669 } | 683 } |
| 670 if (m_pEndValues) { | 684 if (m_pEndValues) { |
| 671 FX_Free(m_pEndValues); | 685 FX_Free(m_pEndValues); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 701 FX_BOOL CPDF_ExpIntFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { | 715 FX_BOOL CPDF_ExpIntFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { |
| 702 for (int i = 0; i < m_nInputs; i++) | 716 for (int i = 0; i < m_nInputs; i++) |
| 703 for (int j = 0; j < m_nOrigOutputs; j++) { | 717 for (int j = 0; j < m_nOrigOutputs; j++) { |
| 704 results[i * m_nOrigOutputs + j] = | 718 results[i * m_nOrigOutputs + j] = |
| 705 m_pBeginValues[j] + | 719 m_pBeginValues[j] + |
| 706 (FX_FLOAT)FXSYS_pow(inputs[i], m_Exponent) * | 720 (FX_FLOAT)FXSYS_pow(inputs[i], m_Exponent) * |
| 707 (m_pEndValues[j] - m_pBeginValues[j]); | 721 (m_pEndValues[j] - m_pBeginValues[j]); |
| 708 } | 722 } |
| 709 return TRUE; | 723 return TRUE; |
| 710 } | 724 } |
| 725 |
| 711 class CPDF_StitchFunc : public CPDF_Function { | 726 class CPDF_StitchFunc : public CPDF_Function { |
| 712 public: | 727 public: |
| 713 CPDF_StitchFunc(); | 728 CPDF_StitchFunc(); |
| 714 virtual ~CPDF_StitchFunc(); | 729 ~CPDF_StitchFunc() override; |
| 715 virtual FX_BOOL v_Init(CPDF_Object* pObj); | 730 |
| 716 virtual FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const; | 731 // CPDF_Function |
| 732 FX_BOOL v_Init(CPDF_Object* pObj) override; |
| 733 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; |
| 734 |
| 717 int m_nSubs; | 735 int m_nSubs; |
| 718 CPDF_Function** m_pSubFunctions; | 736 CPDF_Function** m_pSubFunctions; |
| 719 FX_FLOAT* m_pBounds; | 737 FX_FLOAT* m_pBounds; |
| 720 FX_FLOAT* m_pEncode; | 738 FX_FLOAT* m_pEncode; |
| 721 }; | 739 }; |
| 740 |
| 722 CPDF_StitchFunc::CPDF_StitchFunc() { | 741 CPDF_StitchFunc::CPDF_StitchFunc() { |
| 723 m_nSubs = 0; | 742 m_nSubs = 0; |
| 724 m_pSubFunctions = NULL; | 743 m_pSubFunctions = NULL; |
| 725 m_pBounds = NULL; | 744 m_pBounds = NULL; |
| 726 m_pEncode = NULL; | 745 m_pEncode = NULL; |
| 727 } | 746 } |
| 728 CPDF_StitchFunc::~CPDF_StitchFunc() { | 747 CPDF_StitchFunc::~CPDF_StitchFunc() { |
| 729 for (int i = 0; i < m_nSubs; i++) | 748 for (int i = 0; i < m_nSubs; i++) |
| 730 delete m_pSubFunctions[i]; | 749 delete m_pSubFunctions[i]; |
| 731 if (m_pSubFunctions) { | 750 if (m_pSubFunctions) { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 for (int i = 0; i < m_nOutputs; i++) { | 929 for (int i = 0; i < m_nOutputs; i++) { |
| 911 if (results[i] < m_pRanges[i * 2]) { | 930 if (results[i] < m_pRanges[i * 2]) { |
| 912 results[i] = m_pRanges[i * 2]; | 931 results[i] = m_pRanges[i * 2]; |
| 913 } else if (results[i] > m_pRanges[i * 2 + 1]) { | 932 } else if (results[i] > m_pRanges[i * 2 + 1]) { |
| 914 results[i] = m_pRanges[i * 2 + 1]; | 933 results[i] = m_pRanges[i * 2 + 1]; |
| 915 } | 934 } |
| 916 } | 935 } |
| 917 } | 936 } |
| 918 return TRUE; | 937 return TRUE; |
| 919 } | 938 } |
| OLD | NEW |