Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Side by Side Diff: core/fpdfapi/fpdf_page/fpdf_page_func.cpp

Issue 1870463002: flesh out gradient shaders (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: address comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_page/pageint.h » ('j') | core/fpdfapi/fpdf_page/pageint.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 class CPDF_PSFunc : public CPDF_Function {
501 public: 496 public:
502 CPDF_SampledFunc();
503 ~CPDF_SampledFunc() override;
504
505 // CPDF_Function 497 // CPDF_Function
498 CPDF_PSFunc() : CPDF_Function(Type::kType4PostScript) {}
Tom Sepez 2016/04/11 16:41:49 nit: ctor should come before this comment, which i
caryclark 2016/04/11 20:41:51 Done.
506 FX_BOOL v_Init(CPDF_Object* pObj) override; 499 FX_BOOL v_Init(CPDF_Object* pObj) override;
507 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override; 500 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override;
508 501
509 SampleEncodeInfo* m_pEncodeInfo; 502 CPDF_PSEngine m_PS;
Tom Sepez 2016/04/11 16:41:49 nit: can this be private or protected?
caryclark 2016/04/11 20:41:51 Done.
510 SampleDecodeInfo* m_pDecodeInfo;
511 uint32_t m_nBitsPerSample;
512 uint32_t m_SampleMax;
513 CPDF_StreamAcc* m_pSampleStream;
514 }; 503 };
515 504
505 FX_BOOL CPDF_PSFunc::v_Init(CPDF_Object* pObj) {
506 CPDF_Stream* pStream = pObj->AsStream();
Tom Sepez 2016/04/11 16:41:49 nit: local not needed since it is only used once.
caryclark 2016/04/11 20:41:51 Done.
507 CPDF_StreamAcc acc;
508 acc.LoadAllData(pStream, FALSE);
509 return m_PS.Parse((const FX_CHAR*)acc.GetData(), acc.GetSize());
Tom Sepez 2016/04/11 16:41:49 nit: reinterpret_cast<const FX_CHAR*>
caryclark 2016/04/11 20:41:51 Done.
510 }
511 FX_BOOL CPDF_PSFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const {
Tom Sepez 2016/04/11 16:41:49 nit: blank line here.
caryclark 2016/04/11 20:41:51 Done.
512 CPDF_PSEngine& PS = (CPDF_PSEngine&)m_PS;
Tom Sepez 2016/04/11 16:41:49 nit: this isn't buying us anything over just using
caryclark 2016/04/11 20:41:51 v_Call is a const function; PS.Reset() for instanc
513 PS.Reset();
514 for (uint32_t i = 0; i < m_nInputs; i++)
515 PS.Push(inputs[i]);
516 PS.Execute();
517 if (PS.GetStackSize() < m_nOutputs)
518 return FALSE;
519 for (uint32_t i = 0; i < m_nOutputs; i++)
520 results[m_nOutputs - i - 1] = PS.Pop();
521 return TRUE;
522 }
523
524 } // namespace
dsinclair 2016/04/11 16:17:45 Hm, did this make the namespace section smaller? I
caryclark 2016/04/11 16:26:33 There were two namespace blocks. Now there is one.
525
516 CPDF_SampledFunc::CPDF_SampledFunc() : CPDF_Function(Type::kType0Sampled) { 526 CPDF_SampledFunc::CPDF_SampledFunc() : CPDF_Function(Type::kType0Sampled) {
517 m_pSampleStream = NULL; 527 m_pSampleStream = NULL;
518 m_pEncodeInfo = NULL; 528 m_pEncodeInfo = NULL;
519 m_pDecodeInfo = NULL; 529 m_pDecodeInfo = NULL;
520 } 530 }
521 531
522 CPDF_SampledFunc::~CPDF_SampledFunc() { 532 CPDF_SampledFunc::~CPDF_SampledFunc() {
523 delete m_pSampleStream; 533 delete m_pSampleStream;
524 FX_Free(m_pEncodeInfo); 534 FX_Free(m_pEncodeInfo);
525 FX_Free(m_pDecodeInfo); 535 FX_Free(m_pDecodeInfo);
526 } 536 }
537
527 FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) { 538 FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) {
528 CPDF_Stream* pStream = pObj->AsStream(); 539 CPDF_Stream* pStream = pObj->AsStream();
529 if (!pStream) 540 if (!pStream)
530 return false; 541 return false;
531 542
532 CPDF_Dictionary* pDict = pStream->GetDict(); 543 CPDF_Dictionary* pDict = pStream->GetDict();
533 CPDF_Array* pSize = pDict->GetArrayBy("Size"); 544 CPDF_Array* pSize = pDict->GetArrayBy("Size");
534 CPDF_Array* pEncode = pDict->GetArrayBy("Encode"); 545 CPDF_Array* pEncode = pDict->GetArrayBy("Encode");
535 CPDF_Array* pDecode = pDict->GetArrayBy("Decode"); 546 CPDF_Array* pDecode = pDict->GetArrayBy("Decode");
536 m_nBitsPerSample = pDict->GetIntegerBy("BitsPerSample"); 547 m_nBitsPerSample = pDict->GetIntegerBy("BitsPerSample");
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 if (pDecode) { 583 if (pDecode) {
573 m_pDecodeInfo[i].decode_min = pDecode->GetFloatAt(2 * i); 584 m_pDecodeInfo[i].decode_min = pDecode->GetFloatAt(2 * i);
574 m_pDecodeInfo[i].decode_max = pDecode->GetFloatAt(2 * i + 1); 585 m_pDecodeInfo[i].decode_max = pDecode->GetFloatAt(2 * i + 1);
575 } else { 586 } else {
576 m_pDecodeInfo[i].decode_min = m_pRanges[i * 2]; 587 m_pDecodeInfo[i].decode_min = m_pRanges[i * 2];
577 m_pDecodeInfo[i].decode_max = m_pRanges[i * 2 + 1]; 588 m_pDecodeInfo[i].decode_max = m_pRanges[i * 2 + 1];
578 } 589 }
579 } 590 }
580 return TRUE; 591 return TRUE;
581 } 592 }
593
582 FX_BOOL CPDF_SampledFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const { 594 FX_BOOL CPDF_SampledFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const {
583 int pos = 0; 595 int pos = 0;
584 CFX_FixedBufGrow<FX_FLOAT, 16> encoded_input_buf(m_nInputs); 596 CFX_FixedBufGrow<FX_FLOAT, 16> encoded_input_buf(m_nInputs);
585 FX_FLOAT* encoded_input = encoded_input_buf; 597 FX_FLOAT* encoded_input = encoded_input_buf;
586 CFX_FixedBufGrow<int, 32> int_buf(m_nInputs * 2); 598 CFX_FixedBufGrow<int, 32> int_buf(m_nInputs * 2);
587 int* index = int_buf; 599 int* index = int_buf;
588 int* blocksize = index + m_nInputs; 600 int* blocksize = index + m_nInputs;
589 for (uint32_t i = 0; i < m_nInputs; i++) { 601 for (uint32_t i = 0; i < m_nInputs; i++) {
590 if (i == 0) 602 if (i == 0)
591 blocksize[i] = 1; 603 blocksize[i] = 1;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 ((FX_FLOAT)sample1 - (FX_FLOAT)sample); 655 ((FX_FLOAT)sample1 - (FX_FLOAT)sample);
644 } 656 }
645 } 657 }
646 results[j] = PDF_Interpolate(encoded, 0, (FX_FLOAT)m_SampleMax, 658 results[j] = PDF_Interpolate(encoded, 0, (FX_FLOAT)m_SampleMax,
647 m_pDecodeInfo[j].decode_min, 659 m_pDecodeInfo[j].decode_min,
648 m_pDecodeInfo[j].decode_max); 660 m_pDecodeInfo[j].decode_max);
649 } 661 }
650 return TRUE; 662 return TRUE;
651 } 663 }
652 664
653 class CPDF_PSFunc : public CPDF_Function {
654 public:
655 // CPDF_Function
656 CPDF_PSFunc() : CPDF_Function(Type::kType4PostScript) {}
657 FX_BOOL v_Init(CPDF_Object* pObj) override;
658 FX_BOOL v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const override;
659
660 CPDF_PSEngine m_PS;
661 };
662
663 FX_BOOL CPDF_PSFunc::v_Init(CPDF_Object* pObj) {
664 CPDF_Stream* pStream = pObj->AsStream();
665 CPDF_StreamAcc acc;
666 acc.LoadAllData(pStream, FALSE);
667 return m_PS.Parse((const FX_CHAR*)acc.GetData(), acc.GetSize());
668 }
669 FX_BOOL CPDF_PSFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const {
670 CPDF_PSEngine& PS = (CPDF_PSEngine&)m_PS;
671 PS.Reset();
672 for (uint32_t i = 0; i < m_nInputs; i++)
673 PS.Push(inputs[i]);
674 PS.Execute();
675 if (PS.GetStackSize() < m_nOutputs)
676 return FALSE;
677 for (uint32_t i = 0; i < m_nOutputs; i++)
678 results[m_nOutputs - i - 1] = PS.Pop();
679 return TRUE;
680 }
681
682 } // namespace
683
684 CPDF_ExpIntFunc::CPDF_ExpIntFunc() 665 CPDF_ExpIntFunc::CPDF_ExpIntFunc()
685 : CPDF_Function(Type::kType2ExpotentialInterpolation) { 666 : CPDF_Function(Type::kType2ExpotentialInterpolation) {
686 m_pBeginValues = NULL; 667 m_pBeginValues = NULL;
687 m_pEndValues = NULL; 668 m_pEndValues = NULL;
688 } 669 }
689 670
690 CPDF_ExpIntFunc::~CPDF_ExpIntFunc() { 671 CPDF_ExpIntFunc::~CPDF_ExpIntFunc() {
691 FX_Free(m_pBeginValues); 672 FX_Free(m_pBeginValues);
692 FX_Free(m_pEndValues); 673 FX_Free(m_pEndValues);
693 } 674 }
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 if (m_pRanges) { 886 if (m_pRanges) {
906 for (uint32_t i = 0; i < m_nOutputs; i++) { 887 for (uint32_t i = 0; i < m_nOutputs; i++) {
907 if (results[i] < m_pRanges[i * 2]) 888 if (results[i] < m_pRanges[i * 2])
908 results[i] = m_pRanges[i * 2]; 889 results[i] = m_pRanges[i * 2];
909 else if (results[i] > m_pRanges[i * 2 + 1]) 890 else if (results[i] > m_pRanges[i * 2 + 1])
910 results[i] = m_pRanges[i * 2 + 1]; 891 results[i] = m_pRanges[i * 2 + 1];
911 } 892 }
912 } 893 }
913 return TRUE; 894 return TRUE;
914 } 895 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_page/pageint.h » ('j') | core/fpdfapi/fpdf_page/pageint.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698