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 "pageint.h" | 7 #include "pageint.h" |
8 | 8 |
9 #include <limits.h> | 9 #include <limits.h> |
10 | 10 |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 delete m_pSampleStream; | 493 delete m_pSampleStream; |
494 FX_Free(m_pEncodeInfo); | 494 FX_Free(m_pEncodeInfo); |
495 FX_Free(m_pDecodeInfo); | 495 FX_Free(m_pDecodeInfo); |
496 } | 496 } |
497 FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) { | 497 FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) { |
498 CPDF_Stream* pStream = pObj->AsStream(); | 498 CPDF_Stream* pStream = pObj->AsStream(); |
499 if (!pStream) | 499 if (!pStream) |
500 return false; | 500 return false; |
501 | 501 |
502 CPDF_Dictionary* pDict = pStream->GetDict(); | 502 CPDF_Dictionary* pDict = pStream->GetDict(); |
503 CPDF_Array* pSize = pDict->GetArray("Size"); | 503 CPDF_Array* pSize = pDict->GetArrayBy("Size"); |
504 CPDF_Array* pEncode = pDict->GetArray("Encode"); | 504 CPDF_Array* pEncode = pDict->GetArrayBy("Encode"); |
505 CPDF_Array* pDecode = pDict->GetArray("Decode"); | 505 CPDF_Array* pDecode = pDict->GetArrayBy("Decode"); |
506 m_nBitsPerSample = pDict->GetInteger("BitsPerSample"); | 506 m_nBitsPerSample = pDict->GetIntegerBy("BitsPerSample"); |
507 if (m_nBitsPerSample > 32) { | 507 if (m_nBitsPerSample > 32) { |
508 return FALSE; | 508 return FALSE; |
509 } | 509 } |
510 m_SampleMax = 0xffffffff >> (32 - m_nBitsPerSample); | 510 m_SampleMax = 0xffffffff >> (32 - m_nBitsPerSample); |
511 m_pSampleStream = new CPDF_StreamAcc; | 511 m_pSampleStream = new CPDF_StreamAcc; |
512 m_pSampleStream->LoadAllData(pStream, FALSE); | 512 m_pSampleStream->LoadAllData(pStream, FALSE); |
513 m_pEncodeInfo = FX_Alloc(SampleEncodeInfo, m_nInputs); | 513 m_pEncodeInfo = FX_Alloc(SampleEncodeInfo, m_nInputs); |
514 FX_SAFE_DWORD nTotalSampleBits = 1; | 514 FX_SAFE_DWORD nTotalSampleBits = 1; |
515 for (int i = 0; i < m_nInputs; i++) { | 515 for (int i = 0; i < m_nInputs; i++) { |
516 m_pEncodeInfo[i].sizes = pSize ? pSize->GetInteger(i) : 0; | 516 m_pEncodeInfo[i].sizes = pSize ? pSize->GetIntegerAt(i) : 0; |
517 if (!pSize && i == 0) { | 517 if (!pSize && i == 0) { |
518 m_pEncodeInfo[i].sizes = pDict->GetInteger("Size"); | 518 m_pEncodeInfo[i].sizes = pDict->GetIntegerBy("Size"); |
519 } | 519 } |
520 nTotalSampleBits *= m_pEncodeInfo[i].sizes; | 520 nTotalSampleBits *= m_pEncodeInfo[i].sizes; |
521 if (pEncode) { | 521 if (pEncode) { |
522 m_pEncodeInfo[i].encode_min = pEncode->GetFloat(i * 2); | 522 m_pEncodeInfo[i].encode_min = pEncode->GetFloatAt(i * 2); |
523 m_pEncodeInfo[i].encode_max = pEncode->GetFloat(i * 2 + 1); | 523 m_pEncodeInfo[i].encode_max = pEncode->GetFloatAt(i * 2 + 1); |
524 } else { | 524 } else { |
525 m_pEncodeInfo[i].encode_min = 0; | 525 m_pEncodeInfo[i].encode_min = 0; |
526 if (m_pEncodeInfo[i].sizes == 1) { | 526 if (m_pEncodeInfo[i].sizes == 1) { |
527 m_pEncodeInfo[i].encode_max = 1; | 527 m_pEncodeInfo[i].encode_max = 1; |
528 } else { | 528 } else { |
529 m_pEncodeInfo[i].encode_max = (FX_FLOAT)m_pEncodeInfo[i].sizes - 1; | 529 m_pEncodeInfo[i].encode_max = (FX_FLOAT)m_pEncodeInfo[i].sizes - 1; |
530 } | 530 } |
531 } | 531 } |
532 } | 532 } |
533 nTotalSampleBits *= m_nBitsPerSample; | 533 nTotalSampleBits *= m_nBitsPerSample; |
534 nTotalSampleBits *= m_nOutputs; | 534 nTotalSampleBits *= m_nOutputs; |
535 FX_SAFE_DWORD nTotalSampleBytes = nTotalSampleBits; | 535 FX_SAFE_DWORD nTotalSampleBytes = nTotalSampleBits; |
536 nTotalSampleBytes += 7; | 536 nTotalSampleBytes += 7; |
537 nTotalSampleBytes /= 8; | 537 nTotalSampleBytes /= 8; |
538 if (!nTotalSampleBytes.IsValid() || nTotalSampleBytes.ValueOrDie() == 0 || | 538 if (!nTotalSampleBytes.IsValid() || nTotalSampleBytes.ValueOrDie() == 0 || |
539 nTotalSampleBytes.ValueOrDie() > m_pSampleStream->GetSize()) { | 539 nTotalSampleBytes.ValueOrDie() > m_pSampleStream->GetSize()) { |
540 return FALSE; | 540 return FALSE; |
541 } | 541 } |
542 m_pDecodeInfo = FX_Alloc(SampleDecodeInfo, m_nOutputs); | 542 m_pDecodeInfo = FX_Alloc(SampleDecodeInfo, m_nOutputs); |
543 for (int i = 0; i < m_nOutputs; i++) { | 543 for (int i = 0; i < m_nOutputs; i++) { |
544 if (pDecode) { | 544 if (pDecode) { |
545 m_pDecodeInfo[i].decode_min = pDecode->GetFloat(2 * i); | 545 m_pDecodeInfo[i].decode_min = pDecode->GetFloatAt(2 * i); |
546 m_pDecodeInfo[i].decode_max = pDecode->GetFloat(2 * i + 1); | 546 m_pDecodeInfo[i].decode_max = pDecode->GetFloatAt(2 * i + 1); |
547 } else { | 547 } else { |
548 m_pDecodeInfo[i].decode_min = m_pRanges[i * 2]; | 548 m_pDecodeInfo[i].decode_min = m_pRanges[i * 2]; |
549 m_pDecodeInfo[i].decode_max = m_pRanges[i * 2 + 1]; | 549 m_pDecodeInfo[i].decode_max = m_pRanges[i * 2 + 1]; |
550 } | 550 } |
551 } | 551 } |
552 return TRUE; | 552 return TRUE; |
553 } | 553 } |
554 FX_BOOL CPDF_SampledFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { | 554 FX_BOOL CPDF_SampledFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { |
555 int pos = 0; | 555 int pos = 0; |
556 CFX_FixedBufGrow<FX_FLOAT, 16> encoded_input_buf(m_nInputs); | 556 CFX_FixedBufGrow<FX_FLOAT, 16> encoded_input_buf(m_nInputs); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 } | 679 } |
680 CPDF_ExpIntFunc::~CPDF_ExpIntFunc() { | 680 CPDF_ExpIntFunc::~CPDF_ExpIntFunc() { |
681 FX_Free(m_pBeginValues); | 681 FX_Free(m_pBeginValues); |
682 FX_Free(m_pEndValues); | 682 FX_Free(m_pEndValues); |
683 } | 683 } |
684 FX_BOOL CPDF_ExpIntFunc::v_Init(CPDF_Object* pObj) { | 684 FX_BOOL CPDF_ExpIntFunc::v_Init(CPDF_Object* pObj) { |
685 CPDF_Dictionary* pDict = pObj->GetDict(); | 685 CPDF_Dictionary* pDict = pObj->GetDict(); |
686 if (!pDict) { | 686 if (!pDict) { |
687 return FALSE; | 687 return FALSE; |
688 } | 688 } |
689 CPDF_Array* pArray0 = pDict->GetArray("C0"); | 689 CPDF_Array* pArray0 = pDict->GetArrayBy("C0"); |
690 if (m_nOutputs == 0) { | 690 if (m_nOutputs == 0) { |
691 m_nOutputs = 1; | 691 m_nOutputs = 1; |
692 if (pArray0) { | 692 if (pArray0) { |
693 m_nOutputs = pArray0->GetCount(); | 693 m_nOutputs = pArray0->GetCount(); |
694 } | 694 } |
695 } | 695 } |
696 CPDF_Array* pArray1 = pDict->GetArray("C1"); | 696 CPDF_Array* pArray1 = pDict->GetArrayBy("C1"); |
697 m_pBeginValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); | 697 m_pBeginValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); |
698 m_pEndValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); | 698 m_pEndValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); |
699 for (int i = 0; i < m_nOutputs; i++) { | 699 for (int i = 0; i < m_nOutputs; i++) { |
700 m_pBeginValues[i] = pArray0 ? pArray0->GetFloat(i) : 0.0f; | 700 m_pBeginValues[i] = pArray0 ? pArray0->GetFloatAt(i) : 0.0f; |
701 m_pEndValues[i] = pArray1 ? pArray1->GetFloat(i) : 1.0f; | 701 m_pEndValues[i] = pArray1 ? pArray1->GetFloatAt(i) : 1.0f; |
702 } | 702 } |
703 m_Exponent = pDict->GetFloat("N"); | 703 m_Exponent = pDict->GetFloatBy("N"); |
704 m_nOrigOutputs = m_nOutputs; | 704 m_nOrigOutputs = m_nOutputs; |
705 if (m_nOutputs && m_nInputs > INT_MAX / m_nOutputs) { | 705 if (m_nOutputs && m_nInputs > INT_MAX / m_nOutputs) { |
706 return FALSE; | 706 return FALSE; |
707 } | 707 } |
708 m_nOutputs *= m_nInputs; | 708 m_nOutputs *= m_nInputs; |
709 return TRUE; | 709 return TRUE; |
710 } | 710 } |
711 FX_BOOL CPDF_ExpIntFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { | 711 FX_BOOL CPDF_ExpIntFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { |
712 for (int i = 0; i < m_nInputs; i++) | 712 for (int i = 0; i < m_nInputs; i++) |
713 for (int j = 0; j < m_nOrigOutputs; j++) { | 713 for (int j = 0; j < m_nOrigOutputs; j++) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 FX_Free(m_pEncode); | 747 FX_Free(m_pEncode); |
748 } | 748 } |
749 FX_BOOL CPDF_StitchFunc::v_Init(CPDF_Object* pObj) { | 749 FX_BOOL CPDF_StitchFunc::v_Init(CPDF_Object* pObj) { |
750 CPDF_Dictionary* pDict = pObj->GetDict(); | 750 CPDF_Dictionary* pDict = pObj->GetDict(); |
751 if (!pDict) { | 751 if (!pDict) { |
752 return FALSE; | 752 return FALSE; |
753 } | 753 } |
754 if (m_nInputs != kRequiredNumInputs) { | 754 if (m_nInputs != kRequiredNumInputs) { |
755 return FALSE; | 755 return FALSE; |
756 } | 756 } |
757 CPDF_Array* pArray = pDict->GetArray("Functions"); | 757 CPDF_Array* pArray = pDict->GetArrayBy("Functions"); |
758 if (!pArray) { | 758 if (!pArray) { |
759 return FALSE; | 759 return FALSE; |
760 } | 760 } |
761 FX_DWORD nSubs = pArray->GetCount(); | 761 FX_DWORD nSubs = pArray->GetCount(); |
762 if (nSubs == 0) { | 762 if (nSubs == 0) { |
763 return FALSE; | 763 return FALSE; |
764 } | 764 } |
765 m_nOutputs = 0; | 765 m_nOutputs = 0; |
766 for (FX_DWORD i = 0; i < nSubs; i++) { | 766 for (FX_DWORD i = 0; i < nSubs; i++) { |
767 CPDF_Object* pSub = pArray->GetElementValue(i); | 767 CPDF_Object* pSub = pArray->GetElementValue(i); |
(...skipping 13 matching lines...) Expand all Loading... |
781 if (m_nOutputs) | 781 if (m_nOutputs) |
782 return FALSE; | 782 return FALSE; |
783 | 783 |
784 m_nOutputs = pFunc->CountOutputs(); | 784 m_nOutputs = pFunc->CountOutputs(); |
785 } | 785 } |
786 | 786 |
787 m_pSubFunctions.push_back(pFunc.release()); | 787 m_pSubFunctions.push_back(pFunc.release()); |
788 } | 788 } |
789 m_pBounds = FX_Alloc(FX_FLOAT, nSubs + 1); | 789 m_pBounds = FX_Alloc(FX_FLOAT, nSubs + 1); |
790 m_pBounds[0] = m_pDomains[0]; | 790 m_pBounds[0] = m_pDomains[0]; |
791 pArray = pDict->GetArray("Bounds"); | 791 pArray = pDict->GetArrayBy("Bounds"); |
792 if (!pArray) { | 792 if (!pArray) { |
793 return FALSE; | 793 return FALSE; |
794 } | 794 } |
795 for (FX_DWORD i = 0; i < nSubs - 1; i++) { | 795 for (FX_DWORD i = 0; i < nSubs - 1; i++) { |
796 m_pBounds[i + 1] = pArray->GetFloat(i); | 796 m_pBounds[i + 1] = pArray->GetFloatAt(i); |
797 } | 797 } |
798 m_pBounds[nSubs] = m_pDomains[1]; | 798 m_pBounds[nSubs] = m_pDomains[1]; |
799 m_pEncode = FX_Alloc2D(FX_FLOAT, nSubs, 2); | 799 m_pEncode = FX_Alloc2D(FX_FLOAT, nSubs, 2); |
800 pArray = pDict->GetArray("Encode"); | 800 pArray = pDict->GetArrayBy("Encode"); |
801 if (!pArray) { | 801 if (!pArray) { |
802 return FALSE; | 802 return FALSE; |
803 } | 803 } |
804 for (FX_DWORD i = 0; i < nSubs * 2; i++) { | 804 for (FX_DWORD i = 0; i < nSubs * 2; i++) { |
805 m_pEncode[i] = pArray->GetFloat(i); | 805 m_pEncode[i] = pArray->GetFloatAt(i); |
806 } | 806 } |
807 return TRUE; | 807 return TRUE; |
808 } | 808 } |
809 FX_BOOL CPDF_StitchFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* outputs) const { | 809 FX_BOOL CPDF_StitchFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* outputs) const { |
810 FX_FLOAT input = inputs[0]; | 810 FX_FLOAT input = inputs[0]; |
811 size_t i; | 811 size_t i; |
812 for (i = 0; i < m_pSubFunctions.size() - 1; i++) | 812 for (i = 0; i < m_pSubFunctions.size() - 1; i++) |
813 if (input < m_pBounds[i + 1]) { | 813 if (input < m_pBounds[i + 1]) { |
814 break; | 814 break; |
815 } | 815 } |
816 if (!m_pSubFunctions[i]) { | 816 if (!m_pSubFunctions[i]) { |
817 return FALSE; | 817 return FALSE; |
818 } | 818 } |
819 input = PDF_Interpolate(input, m_pBounds[i], m_pBounds[i + 1], | 819 input = PDF_Interpolate(input, m_pBounds[i], m_pBounds[i + 1], |
820 m_pEncode[i * 2], m_pEncode[i * 2 + 1]); | 820 m_pEncode[i * 2], m_pEncode[i * 2 + 1]); |
821 int nresults; | 821 int nresults; |
822 m_pSubFunctions[i]->Call(&input, kRequiredNumInputs, outputs, nresults); | 822 m_pSubFunctions[i]->Call(&input, kRequiredNumInputs, outputs, nresults); |
823 return TRUE; | 823 return TRUE; |
824 } | 824 } |
825 CPDF_Function* CPDF_Function::Load(CPDF_Object* pFuncObj) { | 825 CPDF_Function* CPDF_Function::Load(CPDF_Object* pFuncObj) { |
826 if (!pFuncObj) { | 826 if (!pFuncObj) { |
827 return NULL; | 827 return NULL; |
828 } | 828 } |
829 CPDF_Function* pFunc = NULL; | 829 CPDF_Function* pFunc = NULL; |
830 int type; | 830 int type; |
831 if (CPDF_Stream* pStream = pFuncObj->AsStream()) { | 831 if (CPDF_Stream* pStream = pFuncObj->AsStream()) { |
832 type = pStream->GetDict()->GetInteger("FunctionType"); | 832 type = pStream->GetDict()->GetIntegerBy("FunctionType"); |
833 } else if (CPDF_Dictionary* pDict = pFuncObj->AsDictionary()) { | 833 } else if (CPDF_Dictionary* pDict = pFuncObj->AsDictionary()) { |
834 type = pDict->GetInteger("FunctionType"); | 834 type = pDict->GetIntegerBy("FunctionType"); |
835 } else { | 835 } else { |
836 return NULL; | 836 return NULL; |
837 } | 837 } |
838 if (type == 0) { | 838 if (type == 0) { |
839 pFunc = new CPDF_SampledFunc; | 839 pFunc = new CPDF_SampledFunc; |
840 } else if (type == 2) { | 840 } else if (type == 2) { |
841 pFunc = new CPDF_ExpIntFunc; | 841 pFunc = new CPDF_ExpIntFunc; |
842 } else if (type == 3) { | 842 } else if (type == 3) { |
843 pFunc = new CPDF_StitchFunc; | 843 pFunc = new CPDF_StitchFunc; |
844 } else if (type == 4) { | 844 } else if (type == 4) { |
(...skipping 12 matching lines...) Expand all Loading... |
857 m_pRanges = NULL; | 857 m_pRanges = NULL; |
858 } | 858 } |
859 CPDF_Function::~CPDF_Function() { | 859 CPDF_Function::~CPDF_Function() { |
860 FX_Free(m_pDomains); | 860 FX_Free(m_pDomains); |
861 FX_Free(m_pRanges); | 861 FX_Free(m_pRanges); |
862 } | 862 } |
863 FX_BOOL CPDF_Function::Init(CPDF_Object* pObj) { | 863 FX_BOOL CPDF_Function::Init(CPDF_Object* pObj) { |
864 CPDF_Stream* pStream = pObj->AsStream(); | 864 CPDF_Stream* pStream = pObj->AsStream(); |
865 CPDF_Dictionary* pDict = pStream ? pStream->GetDict() : pObj->AsDictionary(); | 865 CPDF_Dictionary* pDict = pStream ? pStream->GetDict() : pObj->AsDictionary(); |
866 | 866 |
867 CPDF_Array* pDomains = pDict->GetArray("Domain"); | 867 CPDF_Array* pDomains = pDict->GetArrayBy("Domain"); |
868 if (!pDomains) | 868 if (!pDomains) |
869 return FALSE; | 869 return FALSE; |
870 | 870 |
871 m_nInputs = pDomains->GetCount() / 2; | 871 m_nInputs = pDomains->GetCount() / 2; |
872 if (m_nInputs == 0) | 872 if (m_nInputs == 0) |
873 return FALSE; | 873 return FALSE; |
874 | 874 |
875 m_pDomains = FX_Alloc2D(FX_FLOAT, m_nInputs, 2); | 875 m_pDomains = FX_Alloc2D(FX_FLOAT, m_nInputs, 2); |
876 for (int i = 0; i < m_nInputs * 2; i++) { | 876 for (int i = 0; i < m_nInputs * 2; i++) { |
877 m_pDomains[i] = pDomains->GetFloat(i); | 877 m_pDomains[i] = pDomains->GetFloatAt(i); |
878 } | 878 } |
879 CPDF_Array* pRanges = pDict->GetArray("Range"); | 879 CPDF_Array* pRanges = pDict->GetArrayBy("Range"); |
880 m_nOutputs = 0; | 880 m_nOutputs = 0; |
881 if (pRanges) { | 881 if (pRanges) { |
882 m_nOutputs = pRanges->GetCount() / 2; | 882 m_nOutputs = pRanges->GetCount() / 2; |
883 m_pRanges = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); | 883 m_pRanges = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); |
884 for (int i = 0; i < m_nOutputs * 2; i++) { | 884 for (int i = 0; i < m_nOutputs * 2; i++) { |
885 m_pRanges[i] = pRanges->GetFloat(i); | 885 m_pRanges[i] = pRanges->GetFloatAt(i); |
886 } | 886 } |
887 } | 887 } |
888 FX_DWORD old_outputs = m_nOutputs; | 888 FX_DWORD old_outputs = m_nOutputs; |
889 if (!v_Init(pObj)) { | 889 if (!v_Init(pObj)) { |
890 return FALSE; | 890 return FALSE; |
891 } | 891 } |
892 if (m_pRanges && m_nOutputs > (int)old_outputs) { | 892 if (m_pRanges && m_nOutputs > (int)old_outputs) { |
893 m_pRanges = FX_Realloc(FX_FLOAT, m_pRanges, m_nOutputs * 2); | 893 m_pRanges = FX_Realloc(FX_FLOAT, m_pRanges, m_nOutputs * 2); |
894 if (m_pRanges) { | 894 if (m_pRanges) { |
895 FXSYS_memset(m_pRanges + (old_outputs * 2), 0, | 895 FXSYS_memset(m_pRanges + (old_outputs * 2), 0, |
(...skipping 22 matching lines...) Expand all Loading... |
918 for (int i = 0; i < m_nOutputs; i++) { | 918 for (int i = 0; i < m_nOutputs; i++) { |
919 if (results[i] < m_pRanges[i * 2]) { | 919 if (results[i] < m_pRanges[i * 2]) { |
920 results[i] = m_pRanges[i * 2]; | 920 results[i] = m_pRanges[i * 2]; |
921 } else if (results[i] > m_pRanges[i * 2 + 1]) { | 921 } else if (results[i] > m_pRanges[i * 2 + 1]) { |
922 results[i] = m_pRanges[i * 2 + 1]; | 922 results[i] = m_pRanges[i * 2 + 1]; |
923 } | 923 } |
924 } | 924 } |
925 } | 925 } |
926 return TRUE; | 926 return TRUE; |
927 } | 927 } |
OLD | NEW |