Chromium Code Reviews| 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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 return ((x - xmin) * (ymax - ymin) / (xmax - xmin)) + ymin; | 484 return ((x - xmin) * (ymax - ymin) / (xmax - xmin)) + ymin; |
| 485 } | 485 } |
| 486 static uint32_t _GetBits32(const uint8_t* pData, int bitpos, int nbits) { | 486 static uint32_t _GetBits32(const uint8_t* pData, int bitpos, int nbits) { |
| 487 int result = 0; | 487 int result = 0; |
| 488 for (int i = 0; i < nbits; i++) | 488 for (int i = 0; i < nbits; i++) |
| 489 if (pData[(bitpos + i) / 8] & (1 << (7 - (bitpos + i) % 8))) { | 489 if (pData[(bitpos + i) / 8] & (1 << (7 - (bitpos + i) % 8))) { |
| 490 result |= 1 << (nbits - i - 1); | 490 result |= 1 << (nbits - i - 1); |
| 491 } | 491 } |
| 492 return result; | 492 return result; |
| 493 } | 493 } |
| 494 typedef struct { | |
| 495 FX_FLOAT encode_max, encode_min; | |
| 496 int sizes; | |
| 497 } SampleEncodeInfo; | |
| 498 typedef struct { FX_FLOAT decode_max, decode_min; } SampleDecodeInfo; | |
| 499 | 494 |
| 500 class CPDF_SampledFunc : public CPDF_Function { | 495 } // namespace |
| 501 public: | |
| 502 CPDF_SampledFunc(); | |
| 503 ~CPDF_SampledFunc() override; | |
| 504 | |
| 505 // CPDF_Function | |
| 506 FX_BOOL v_Init(CPDF_Object* pObj) override; | |
| 507 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; | |
| 508 | |
| 509 SampleEncodeInfo* m_pEncodeInfo; | |
| 510 SampleDecodeInfo* m_pDecodeInfo; | |
| 511 uint32_t m_nBitsPerSample; | |
| 512 uint32_t m_SampleMax; | |
| 513 CPDF_StreamAcc* m_pSampleStream; | |
| 514 }; | |
| 515 | 496 |
| 516 CPDF_SampledFunc::CPDF_SampledFunc() : CPDF_Function(Type::kType0Sampled) { | 497 CPDF_SampledFunc::CPDF_SampledFunc() : CPDF_Function(Type::kType0Sampled) { |
| 517 m_pSampleStream = NULL; | 498 m_pSampleStream = NULL; |
| 518 m_pEncodeInfo = NULL; | 499 m_pEncodeInfo = NULL; |
| 519 m_pDecodeInfo = NULL; | 500 m_pDecodeInfo = NULL; |
| 520 } | 501 } |
| 521 | 502 |
| 522 CPDF_SampledFunc::~CPDF_SampledFunc() { | 503 CPDF_SampledFunc::~CPDF_SampledFunc() { |
| 523 delete m_pSampleStream; | 504 delete m_pSampleStream; |
| 524 FX_Free(m_pEncodeInfo); | 505 FX_Free(m_pEncodeInfo); |
| 525 FX_Free(m_pDecodeInfo); | 506 FX_Free(m_pDecodeInfo); |
| 526 } | 507 } |
| 508 | |
| 527 FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) { | 509 FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) { |
| 528 CPDF_Stream* pStream = pObj->AsStream(); | 510 CPDF_Stream* pStream = pObj->AsStream(); |
| 529 if (!pStream) | 511 if (!pStream) |
| 530 return false; | 512 return false; |
| 531 | 513 |
| 532 CPDF_Dictionary* pDict = pStream->GetDict(); | 514 CPDF_Dictionary* pDict = pStream->GetDict(); |
| 533 CPDF_Array* pSize = pDict->GetArrayBy("Size"); | 515 CPDF_Array* pSize = pDict->GetArrayBy("Size"); |
| 534 CPDF_Array* pEncode = pDict->GetArrayBy("Encode"); | 516 CPDF_Array* pEncode = pDict->GetArrayBy("Encode"); |
| 535 CPDF_Array* pDecode = pDict->GetArrayBy("Decode"); | 517 CPDF_Array* pDecode = pDict->GetArrayBy("Decode"); |
| 536 m_nBitsPerSample = pDict->GetIntegerBy("BitsPerSample"); | 518 m_nBitsPerSample = pDict->GetIntegerBy("BitsPerSample"); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 572 if (pDecode) { | 554 if (pDecode) { |
| 573 m_pDecodeInfo[i].decode_min = pDecode->GetFloatAt(2 * i); | 555 m_pDecodeInfo[i].decode_min = pDecode->GetFloatAt(2 * i); |
| 574 m_pDecodeInfo[i].decode_max = pDecode->GetFloatAt(2 * i + 1); | 556 m_pDecodeInfo[i].decode_max = pDecode->GetFloatAt(2 * i + 1); |
| 575 } else { | 557 } else { |
| 576 m_pDecodeInfo[i].decode_min = m_pRanges[i * 2]; | 558 m_pDecodeInfo[i].decode_min = m_pRanges[i * 2]; |
| 577 m_pDecodeInfo[i].decode_max = m_pRanges[i * 2 + 1]; | 559 m_pDecodeInfo[i].decode_max = m_pRanges[i * 2 + 1]; |
| 578 } | 560 } |
| 579 } | 561 } |
| 580 return TRUE; | 562 return TRUE; |
| 581 } | 563 } |
| 564 | |
| 582 FX_BOOL CPDF_SampledFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { | 565 FX_BOOL CPDF_SampledFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { |
| 583 int pos = 0; | 566 int pos = 0; |
| 584 CFX_FixedBufGrow<FX_FLOAT, 16> encoded_input_buf(m_nInputs); | 567 CFX_FixedBufGrow<FX_FLOAT, 16> encoded_input_buf(m_nInputs); |
| 585 FX_FLOAT* encoded_input = encoded_input_buf; | 568 FX_FLOAT* encoded_input = encoded_input_buf; |
| 586 CFX_FixedBufGrow<int, 32> int_buf(m_nInputs * 2); | 569 CFX_FixedBufGrow<int, 32> int_buf(m_nInputs * 2); |
| 587 int* index = int_buf; | 570 int* index = int_buf; |
| 588 int* blocksize = index + m_nInputs; | 571 int* blocksize = index + m_nInputs; |
| 589 for (uint32_t i = 0; i < m_nInputs; i++) { | 572 for (uint32_t i = 0; i < m_nInputs; i++) { |
| 590 if (i == 0) | 573 if (i == 0) |
| 591 blocksize[i] = 1; | 574 blocksize[i] = 1; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 643 ((FX_FLOAT)sample1 - (FX_FLOAT)sample); | 626 ((FX_FLOAT)sample1 - (FX_FLOAT)sample); |
| 644 } | 627 } |
| 645 } | 628 } |
| 646 results[j] = PDF_Interpolate(encoded, 0, (FX_FLOAT)m_SampleMax, | 629 results[j] = PDF_Interpolate(encoded, 0, (FX_FLOAT)m_SampleMax, |
| 647 m_pDecodeInfo[j].decode_min, | 630 m_pDecodeInfo[j].decode_min, |
| 648 m_pDecodeInfo[j].decode_max); | 631 m_pDecodeInfo[j].decode_max); |
| 649 } | 632 } |
| 650 return TRUE; | 633 return TRUE; |
| 651 } | 634 } |
| 652 | 635 |
| 636 namespace { | |
| 637 | |
| 653 class CPDF_PSFunc : public CPDF_Function { | 638 class CPDF_PSFunc : public CPDF_Function { |
|
dsinclair
2016/04/11 14:29:28
Can this be moved up into the namespace {} at the
caryclark
2016/04/11 15:01:50
Done.
| |
| 654 public: | 639 public: |
| 655 // CPDF_Function | 640 // CPDF_Function |
| 656 CPDF_PSFunc() : CPDF_Function(Type::kType4PostScript) {} | 641 CPDF_PSFunc() : CPDF_Function(Type::kType4PostScript) {} |
| 657 FX_BOOL v_Init(CPDF_Object* pObj) override; | 642 FX_BOOL v_Init(CPDF_Object* pObj) override; |
| 658 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; | 643 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; |
| 659 | 644 |
| 660 CPDF_PSEngine m_PS; | 645 CPDF_PSEngine m_PS; |
| 661 }; | 646 }; |
| 662 | 647 |
| 663 FX_BOOL CPDF_PSFunc::v_Init(CPDF_Object* pObj) { | 648 FX_BOOL CPDF_PSFunc::v_Init(CPDF_Object* pObj) { |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 905 if (m_pRanges) { | 890 if (m_pRanges) { |
| 906 for (uint32_t i = 0; i < m_nOutputs; i++) { | 891 for (uint32_t i = 0; i < m_nOutputs; i++) { |
| 907 if (results[i] < m_pRanges[i * 2]) | 892 if (results[i] < m_pRanges[i * 2]) |
| 908 results[i] = m_pRanges[i * 2]; | 893 results[i] = m_pRanges[i * 2]; |
| 909 else if (results[i] > m_pRanges[i * 2 + 1]) | 894 else if (results[i] > m_pRanges[i * 2 + 1]) |
| 910 results[i] = m_pRanges[i * 2 + 1]; | 895 results[i] = m_pRanges[i * 2 + 1]; |
| 911 } | 896 } |
| 912 } | 897 } |
| 913 return TRUE; | 898 return TRUE; |
| 914 } | 899 } |
| OLD | NEW |