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

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

Issue 1252613002: FX_BOOL considered harmful. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual edits. Created 5 years, 5 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
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 <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"
11 #include "../../../include/fxcrt/fx_safe_types.h" 11 #include "../../../include/fxcrt/fx_safe_types.h"
12 #include "../../../third_party/base/numerics/safe_conversions_impl.h" 12 #include "../../../third_party/base/numerics/safe_conversions_impl.h"
13 #include "pageint.h" 13 #include "pageint.h"
14 14
15 class CPDF_PSEngine; 15 class CPDF_PSEngine;
16 typedef enum {PSOP_ADD, PSOP_SUB, PSOP_MUL, PSOP_DIV, PSOP_IDIV, PSOP_MOD, 16 typedef enum {PSOP_ADD, PSOP_SUB, PSOP_MUL, PSOP_DIV, PSOP_IDIV, PSOP_MOD,
17 PSOP_NEG, PSOP_ABS, PSOP_CEILING, PSOP_FLOOR, PSOP_ROUND, PSOP_TRU NCATE, 17 PSOP_NEG, PSOP_ABS, PSOP_CEILING, PSOP_FLOOR, PSOP_ROUND, PSOP_TRU NCATE,
18 PSOP_SQRT, PSOP_SIN, PSOP_COS, PSOP_ATAN, PSOP_EXP, PSOP_LN, PSOP_ LOG, 18 PSOP_SQRT, PSOP_SIN, PSOP_COS, PSOP_ATAN, PSOP_EXP, PSOP_LN, PSOP_ LOG,
19 PSOP_CVI, PSOP_CVR, PSOP_EQ, PSOP_NE, PSOP_GT, PSOP_GE, PSOP_LT, P SOP_LE, 19 PSOP_CVI, PSOP_CVR, PSOP_EQ, PSOP_NE, PSOP_GT, PSOP_GE, PSOP_LT, P SOP_LE,
20 PSOP_AND, PSOP_OR, PSOP_XOR, PSOP_NOT, PSOP_BITSHIFT, PSOP_TRUE, P SOP_FALSE, 20 PSOP_AND, PSOP_OR, PSOP_XOR, PSOP_NOT, PSOP_BITSHIFT, PSOP_TRUE, P SOP_FALSE,
21 PSOP_IF, PSOP_IFELSE, PSOP_POP, PSOP_EXCH, PSOP_DUP, PSOP_COPY, 21 PSOP_IF, PSOP_IFELSE, PSOP_POP, PSOP_EXCH, PSOP_DUP, PSOP_COPY,
22 PSOP_INDEX, PSOP_ROLL, PSOP_PROC, PSOP_CONST 22 PSOP_INDEX, PSOP_ROLL, PSOP_PROC, PSOP_CONST
23 } PDF_PSOP; 23 } PDF_PSOP;
24 class CPDF_PSProc 24 class CPDF_PSProc
25 { 25 {
26 public: 26 public:
27 ~CPDF_PSProc(); 27 ~CPDF_PSProc();
28 FX_BOOL» Parse(CPDF_SimpleParser& parser); 28 bool» Parse(CPDF_SimpleParser& parser);
29 FX_BOOL» Execute(CPDF_PSEngine* pEngine); 29 bool» Execute(CPDF_PSEngine* pEngine);
30 CFX_PtrArray m_Operators; 30 CFX_PtrArray m_Operators;
31 }; 31 };
32 #define PSENGINE_STACKSIZE 100 32 #define PSENGINE_STACKSIZE 100
33 class CPDF_PSEngine 33 class CPDF_PSEngine
34 { 34 {
35 public: 35 public:
36 CPDF_PSEngine(); 36 CPDF_PSEngine();
37 ~CPDF_PSEngine(); 37 ~CPDF_PSEngine();
38 FX_BOOL» Parse(const FX_CHAR* string, int size); 38 bool» Parse(const FX_CHAR* string, int size);
39 FX_BOOL» Execute() 39 bool» Execute()
40 { 40 {
41 return m_MainProc.Execute(this); 41 return m_MainProc.Execute(this);
42 } 42 }
43 FX_BOOL» DoOperator(PDF_PSOP op); 43 bool» DoOperator(PDF_PSOP op);
44 void Reset() 44 void Reset()
45 { 45 {
46 m_StackCount = 0; 46 m_StackCount = 0;
47 } 47 }
48 void Push(FX_FLOAT value); 48 void Push(FX_FLOAT value);
49 void Push(int value) 49 void Push(int value)
50 { 50 {
51 Push((FX_FLOAT)value); 51 Push((FX_FLOAT)value);
52 } 52 }
53 FX_FLOAT Pop(); 53 FX_FLOAT Pop();
(...skipping 12 matching lines...) Expand all
66 for (int i = 0; i < size; i ++) { 66 for (int i = 0; i < size; i ++) {
67 if (m_Operators[i] == (void*)PSOP_PROC) { 67 if (m_Operators[i] == (void*)PSOP_PROC) {
68 delete (CPDF_PSProc*)m_Operators[i + 1]; 68 delete (CPDF_PSProc*)m_Operators[i + 1];
69 i ++; 69 i ++;
70 } else if (m_Operators[i] == (void*)PSOP_CONST) { 70 } else if (m_Operators[i] == (void*)PSOP_CONST) {
71 FX_Free((FX_FLOAT*)m_Operators[i + 1]); 71 FX_Free((FX_FLOAT*)m_Operators[i + 1]);
72 i ++; 72 i ++;
73 } 73 }
74 } 74 }
75 } 75 }
76 FX_BOOL CPDF_PSProc::Execute(CPDF_PSEngine* pEngine) 76 bool CPDF_PSProc::Execute(CPDF_PSEngine* pEngine)
77 { 77 {
78 int size = m_Operators.GetSize(); 78 int size = m_Operators.GetSize();
79 for (int i = 0; i < size; i ++) { 79 for (int i = 0; i < size; i ++) {
80 PDF_PSOP op = (PDF_PSOP)(uintptr_t)m_Operators[i]; 80 PDF_PSOP op = (PDF_PSOP)(uintptr_t)m_Operators[i];
81 if (op == PSOP_PROC) { 81 if (op == PSOP_PROC) {
82 i ++; 82 i ++;
83 } else if (op == PSOP_CONST) { 83 } else if (op == PSOP_CONST) {
84 pEngine->Push(*(FX_FLOAT*)m_Operators[i + 1]); 84 pEngine->Push(*(FX_FLOAT*)m_Operators[i + 1]);
85 i ++; 85 i ++;
86 } else if (op == PSOP_IF) { 86 } else if (op == PSOP_IF) {
87 if (i < 2 || m_Operators[i - 2] != (void*)PSOP_PROC) { 87 if (i < 2 || m_Operators[i - 2] != (void*)PSOP_PROC) {
88 return FALSE; 88 return false;
89 } 89 }
90 if ((int)pEngine->Pop()) { 90 if ((int)pEngine->Pop()) {
91 ((CPDF_PSProc*)m_Operators[i - 1])->Execute(pEngine); 91 ((CPDF_PSProc*)m_Operators[i - 1])->Execute(pEngine);
92 } 92 }
93 } else if (op == PSOP_IFELSE) { 93 } else if (op == PSOP_IFELSE) {
94 if (i < 4 || m_Operators[i - 2] != (void*)PSOP_PROC || 94 if (i < 4 || m_Operators[i - 2] != (void*)PSOP_PROC ||
95 m_Operators[i - 4] != (void*)PSOP_PROC) { 95 m_Operators[i - 4] != (void*)PSOP_PROC) {
96 return FALSE; 96 return false;
97 } 97 }
98 if ((int)pEngine->Pop()) { 98 if ((int)pEngine->Pop()) {
99 ((CPDF_PSProc*)m_Operators[i - 3])->Execute(pEngine); 99 ((CPDF_PSProc*)m_Operators[i - 3])->Execute(pEngine);
100 } else { 100 } else {
101 ((CPDF_PSProc*)m_Operators[i - 1])->Execute(pEngine); 101 ((CPDF_PSProc*)m_Operators[i - 1])->Execute(pEngine);
102 } 102 }
103 } else { 103 } else {
104 pEngine->DoOperator(op); 104 pEngine->DoOperator(op);
105 } 105 }
106 } 106 }
107 return TRUE; 107 return true;
108 } 108 }
109 CPDF_PSEngine::CPDF_PSEngine() 109 CPDF_PSEngine::CPDF_PSEngine()
110 { 110 {
111 m_StackCount = 0; 111 m_StackCount = 0;
112 } 112 }
113 CPDF_PSEngine::~CPDF_PSEngine() 113 CPDF_PSEngine::~CPDF_PSEngine()
114 { 114 {
115 } 115 }
116 void CPDF_PSEngine::Push(FX_FLOAT v) 116 void CPDF_PSEngine::Push(FX_FLOAT v)
117 { 117 {
(...skipping 20 matching lines...) Expand all
138 {"cos", PSOP_COS}, {"atan", PSOP_ATAN}, {"exp", PSOP_EXP}, {"ln", PSOP_LN}, 138 {"cos", PSOP_COS}, {"atan", PSOP_ATAN}, {"exp", PSOP_EXP}, {"ln", PSOP_LN},
139 {"log", PSOP_LOG}, {"cvi", PSOP_CVI}, {"cvr", PSOP_CVR}, {"eq", PSOP_EQ}, 139 {"log", PSOP_LOG}, {"cvi", PSOP_CVI}, {"cvr", PSOP_CVR}, {"eq", PSOP_EQ},
140 {"ne", PSOP_NE}, {"gt", PSOP_GT}, {"ge", PSOP_GE}, {"lt", PSOP_LT}, 140 {"ne", PSOP_NE}, {"gt", PSOP_GT}, {"ge", PSOP_GE}, {"lt", PSOP_LT},
141 {"le", PSOP_LE}, {"and", PSOP_AND}, {"or", PSOP_OR}, {"xor", PSOP_XOR}, 141 {"le", PSOP_LE}, {"and", PSOP_AND}, {"or", PSOP_OR}, {"xor", PSOP_XOR},
142 {"not", PSOP_NOT}, {"bitshift", PSOP_BITSHIFT}, {"true", PSOP_TRUE}, 142 {"not", PSOP_NOT}, {"bitshift", PSOP_BITSHIFT}, {"true", PSOP_TRUE},
143 {"false", PSOP_FALSE}, {"if", PSOP_IF}, {"ifelse", PSOP_IFELSE}, 143 {"false", PSOP_FALSE}, {"if", PSOP_IF}, {"ifelse", PSOP_IFELSE},
144 {"pop", PSOP_POP}, {"exch", PSOP_EXCH}, {"dup", PSOP_DUP}, 144 {"pop", PSOP_POP}, {"exch", PSOP_EXCH}, {"dup", PSOP_DUP},
145 {"copy", PSOP_COPY}, {"index", PSOP_INDEX}, {"roll", PSOP_ROLL}, 145 {"copy", PSOP_COPY}, {"index", PSOP_INDEX}, {"roll", PSOP_ROLL},
146 {NULL, PSOP_PROC} 146 {NULL, PSOP_PROC}
147 }; 147 };
148 FX_BOOL CPDF_PSEngine::Parse(const FX_CHAR* string, int size) 148 bool CPDF_PSEngine::Parse(const FX_CHAR* string, int size)
149 { 149 {
150 CPDF_SimpleParser parser((uint8_t*)string, size); 150 CPDF_SimpleParser parser((uint8_t*)string, size);
151 CFX_ByteStringC word = parser.GetWord(); 151 CFX_ByteStringC word = parser.GetWord();
152 if (word != FX_BSTRC("{")) { 152 if (word != FX_BSTRC("{")) {
153 return FALSE; 153 return false;
154 } 154 }
155 return m_MainProc.Parse(parser); 155 return m_MainProc.Parse(parser);
156 } 156 }
157 FX_BOOL CPDF_PSProc::Parse(CPDF_SimpleParser& parser) 157 bool CPDF_PSProc::Parse(CPDF_SimpleParser& parser)
158 { 158 {
159 while (1) { 159 while (1) {
160 CFX_ByteStringC word = parser.GetWord(); 160 CFX_ByteStringC word = parser.GetWord();
161 if (word.IsEmpty()) { 161 if (word.IsEmpty()) {
162 return FALSE; 162 return false;
163 } 163 }
164 if (word == FX_BSTRC("}")) { 164 if (word == FX_BSTRC("}")) {
165 return TRUE; 165 return true;
166 } 166 }
167 if (word == FX_BSTRC("{")) { 167 if (word == FX_BSTRC("{")) {
168 CPDF_PSProc* pProc = new CPDF_PSProc; 168 CPDF_PSProc* pProc = new CPDF_PSProc;
169 m_Operators.Add((void*)PSOP_PROC); 169 m_Operators.Add((void*)PSOP_PROC);
170 m_Operators.Add(pProc); 170 m_Operators.Add(pProc);
171 if (!pProc->Parse(parser)) { 171 if (!pProc->Parse(parser)) {
172 return FALSE; 172 return false;
173 } 173 }
174 } else { 174 } else {
175 int i = 0; 175 int i = 0;
176 while (_PDF_PSOpNames[i].name) { 176 while (_PDF_PSOpNames[i].name) {
177 if (word == CFX_ByteStringC(_PDF_PSOpNames[i].name)) { 177 if (word == CFX_ByteStringC(_PDF_PSOpNames[i].name)) {
178 m_Operators.Add((void*)_PDF_PSOpNames[i].op); 178 m_Operators.Add((void*)_PDF_PSOpNames[i].op);
179 break; 179 break;
180 } 180 }
181 i ++; 181 i ++;
182 } 182 }
183 if (_PDF_PSOpNames[i].name == NULL) { 183 if (_PDF_PSOpNames[i].name == NULL) {
184 FX_FLOAT* pd = FX_Alloc(FX_FLOAT, 1); 184 FX_FLOAT* pd = FX_Alloc(FX_FLOAT, 1);
185 *pd = FX_atof(word); 185 *pd = FX_atof(word);
186 m_Operators.Add((void*)PSOP_CONST); 186 m_Operators.Add((void*)PSOP_CONST);
187 m_Operators.Add(pd); 187 m_Operators.Add(pd);
188 } 188 }
189 } 189 }
190 } 190 }
191 } 191 }
192 #define PI 3.1415926535897932384626433832795f 192 #define PI 3.1415926535897932384626433832795f
193 FX_BOOL CPDF_PSEngine::DoOperator(PDF_PSOP op) 193 bool CPDF_PSEngine::DoOperator(PDF_PSOP op)
194 { 194 {
195 int i1, i2; 195 int i1, i2;
196 FX_FLOAT d1, d2; 196 FX_FLOAT d1, d2;
197 switch (op) { 197 switch (op) {
198 case PSOP_ADD: 198 case PSOP_ADD:
199 d1 = Pop(); 199 d1 = Pop();
200 d2 = Pop(); 200 d2 = Pop();
201 Push(d1 + d2); 201 Push(d1 + d2);
202 break; 202 break;
203 case PSOP_SUB: 203 case PSOP_SUB:
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 for (ii = 0; ii < n - 1; ii ++) { 411 for (ii = 0; ii < n - 1; ii ++) {
412 m_Stack[m_StackCount - ii - 1] = m_Stack[m_StackCoun t - ii - 2]; 412 m_Stack[m_StackCount - ii - 1] = m_Stack[m_StackCoun t - ii - 2];
413 } 413 }
414 m_Stack[m_StackCount - ii - 1] = last; 414 m_Stack[m_StackCount - ii - 1] = last;
415 } 415 }
416 break; 416 break;
417 } 417 }
418 default: 418 default:
419 break; 419 break;
420 } 420 }
421 return TRUE; 421 return true;
422 } 422 }
423 static FX_FLOAT PDF_Interpolate(FX_FLOAT x, FX_FLOAT xmin, FX_FLOAT xmax, FX_FLO AT ymin, FX_FLOAT ymax) 423 static FX_FLOAT PDF_Interpolate(FX_FLOAT x, FX_FLOAT xmin, FX_FLOAT xmax, FX_FLO AT ymin, FX_FLOAT ymax)
424 { 424 {
425 return ((x - xmin) * (ymax - ymin) / (xmax - xmin)) + ymin; 425 return ((x - xmin) * (ymax - ymin) / (xmax - xmin)) + ymin;
426 } 426 }
427 static FX_DWORD _GetBits32(const uint8_t* pData, int bitpos, int nbits) 427 static FX_DWORD _GetBits32(const uint8_t* pData, int bitpos, int nbits)
428 { 428 {
429 int result = 0; 429 int result = 0;
430 for (int i = 0; i < nbits; i ++) 430 for (int i = 0; i < nbits; i ++)
431 if (pData[(bitpos + i) / 8] & (1 << (7 - (bitpos + i) % 8))) { 431 if (pData[(bitpos + i) / 8] & (1 << (7 - (bitpos + i) % 8))) {
432 result |= 1 << (nbits - i - 1); 432 result |= 1 << (nbits - i - 1);
433 } 433 }
434 return result; 434 return result;
435 } 435 }
436 typedef struct { 436 typedef struct {
437 FX_FLOAT encode_max, encode_min; 437 FX_FLOAT encode_max, encode_min;
438 int sizes; 438 int sizes;
439 } SampleEncodeInfo; 439 } SampleEncodeInfo;
440 typedef struct { 440 typedef struct {
441 FX_FLOAT decode_max, decode_min; 441 FX_FLOAT decode_max, decode_min;
442 } SampleDecodeInfo; 442 } SampleDecodeInfo;
443 class CPDF_SampledFunc : public CPDF_Function 443 class CPDF_SampledFunc : public CPDF_Function
444 { 444 {
445 public: 445 public:
446 CPDF_SampledFunc(); 446 CPDF_SampledFunc();
447 virtual ~CPDF_SampledFunc(); 447 virtual ~CPDF_SampledFunc();
448 virtual FX_BOOL» » v_Init(CPDF_Object* pObj); 448 virtual bool» » v_Init(CPDF_Object* pObj);
449 virtual FX_BOOL» » v_Call(FX_FLOAT* inputs, FX_FLOAT* results) cons t; 449 virtual bool» » v_Call(FX_FLOAT* inputs, FX_FLOAT* results) cons t;
450 SampleEncodeInfo* m_pEncodeInfo; 450 SampleEncodeInfo* m_pEncodeInfo;
451 SampleDecodeInfo* m_pDecodeInfo; 451 SampleDecodeInfo* m_pDecodeInfo;
452 FX_DWORD m_nBitsPerSample; 452 FX_DWORD m_nBitsPerSample;
453 FX_DWORD m_SampleMax; 453 FX_DWORD m_SampleMax;
454 CPDF_StreamAcc* m_pSampleStream; 454 CPDF_StreamAcc* m_pSampleStream;
455 }; 455 };
456 CPDF_SampledFunc::CPDF_SampledFunc() 456 CPDF_SampledFunc::CPDF_SampledFunc()
457 { 457 {
458 m_pSampleStream = NULL; 458 m_pSampleStream = NULL;
459 m_pEncodeInfo = NULL; 459 m_pEncodeInfo = NULL;
460 m_pDecodeInfo = NULL; 460 m_pDecodeInfo = NULL;
461 } 461 }
462 CPDF_SampledFunc::~CPDF_SampledFunc() 462 CPDF_SampledFunc::~CPDF_SampledFunc()
463 { 463 {
464 delete m_pSampleStream; 464 delete m_pSampleStream;
465 if (m_pEncodeInfo) { 465 if (m_pEncodeInfo) {
466 FX_Free(m_pEncodeInfo); 466 FX_Free(m_pEncodeInfo);
467 } 467 }
468 if (m_pDecodeInfo) { 468 if (m_pDecodeInfo) {
469 FX_Free(m_pDecodeInfo); 469 FX_Free(m_pDecodeInfo);
470 } 470 }
471 } 471 }
472 FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) 472 bool CPDF_SampledFunc::v_Init(CPDF_Object* pObj)
473 { 473 {
474 if (pObj->GetType() != PDFOBJ_STREAM) { 474 if (pObj->GetType() != PDFOBJ_STREAM) {
475 return FALSE; 475 return false;
476 } 476 }
477 CPDF_Stream* pStream = (CPDF_Stream*)pObj; 477 CPDF_Stream* pStream = (CPDF_Stream*)pObj;
478 CPDF_Dictionary* pDict = pStream->GetDict(); 478 CPDF_Dictionary* pDict = pStream->GetDict();
479 CPDF_Array* pSize = pDict->GetArray(FX_BSTRC("Size")); 479 CPDF_Array* pSize = pDict->GetArray(FX_BSTRC("Size"));
480 CPDF_Array* pEncode = pDict->GetArray(FX_BSTRC("Encode")); 480 CPDF_Array* pEncode = pDict->GetArray(FX_BSTRC("Encode"));
481 CPDF_Array* pDecode = pDict->GetArray(FX_BSTRC("Decode")); 481 CPDF_Array* pDecode = pDict->GetArray(FX_BSTRC("Decode"));
482 m_nBitsPerSample = pDict->GetInteger(FX_BSTRC("BitsPerSample")); 482 m_nBitsPerSample = pDict->GetInteger(FX_BSTRC("BitsPerSample"));
483 if (m_nBitsPerSample > 32) { 483 if (m_nBitsPerSample > 32) {
484 return FALSE; 484 return false;
485 } 485 }
486 m_SampleMax = 0xffffffff >> (32 - m_nBitsPerSample); 486 m_SampleMax = 0xffffffff >> (32 - m_nBitsPerSample);
487 m_pSampleStream = new CPDF_StreamAcc; 487 m_pSampleStream = new CPDF_StreamAcc;
488 m_pSampleStream->LoadAllData(pStream, FALSE); 488 m_pSampleStream->LoadAllData(pStream, false);
489 m_pEncodeInfo = FX_Alloc(SampleEncodeInfo, m_nInputs); 489 m_pEncodeInfo = FX_Alloc(SampleEncodeInfo, m_nInputs);
490 FX_SAFE_DWORD nTotalSampleBits = 1; 490 FX_SAFE_DWORD nTotalSampleBits = 1;
491 for (int i = 0; i < m_nInputs; i ++) { 491 for (int i = 0; i < m_nInputs; i ++) {
492 m_pEncodeInfo[i].sizes = pSize ? pSize->GetInteger(i) : 0; 492 m_pEncodeInfo[i].sizes = pSize ? pSize->GetInteger(i) : 0;
493 if (!pSize && i == 0) { 493 if (!pSize && i == 0) {
494 m_pEncodeInfo[i].sizes = pDict->GetInteger(FX_BSTRC("Size")); 494 m_pEncodeInfo[i].sizes = pDict->GetInteger(FX_BSTRC("Size"));
495 } 495 }
496 nTotalSampleBits *= m_pEncodeInfo[i].sizes; 496 nTotalSampleBits *= m_pEncodeInfo[i].sizes;
497 if (pEncode) { 497 if (pEncode) {
498 m_pEncodeInfo[i].encode_min = pEncode->GetFloat(i * 2); 498 m_pEncodeInfo[i].encode_min = pEncode->GetFloat(i * 2);
499 m_pEncodeInfo[i].encode_max = pEncode->GetFloat(i * 2 + 1); 499 m_pEncodeInfo[i].encode_max = pEncode->GetFloat(i * 2 + 1);
500 } else { 500 } else {
501 m_pEncodeInfo[i].encode_min = 0; 501 m_pEncodeInfo[i].encode_min = 0;
502 if (m_pEncodeInfo[i].sizes == 1) { 502 if (m_pEncodeInfo[i].sizes == 1) {
503 m_pEncodeInfo[i].encode_max = 1; 503 m_pEncodeInfo[i].encode_max = 1;
504 } else { 504 } else {
505 m_pEncodeInfo[i].encode_max = (FX_FLOAT)m_pEncodeInfo[i].sizes - 1; 505 m_pEncodeInfo[i].encode_max = (FX_FLOAT)m_pEncodeInfo[i].sizes - 1;
506 } 506 }
507 } 507 }
508 } 508 }
509 nTotalSampleBits *= m_nBitsPerSample; 509 nTotalSampleBits *= m_nBitsPerSample;
510 nTotalSampleBits *= m_nOutputs; 510 nTotalSampleBits *= m_nOutputs;
511 FX_SAFE_DWORD nTotalSampleBytes = nTotalSampleBits; 511 FX_SAFE_DWORD nTotalSampleBytes = nTotalSampleBits;
512 nTotalSampleBytes += 7; 512 nTotalSampleBytes += 7;
513 nTotalSampleBytes /= 8; 513 nTotalSampleBytes /= 8;
514 if (!nTotalSampleBytes.IsValid() || 514 if (!nTotalSampleBytes.IsValid() ||
515 nTotalSampleBytes.ValueOrDie() == 0 || 515 nTotalSampleBytes.ValueOrDie() == 0 ||
516 nTotalSampleBytes.ValueOrDie() > m_pSampleStream->GetSize()) { 516 nTotalSampleBytes.ValueOrDie() > m_pSampleStream->GetSize()) {
517 return FALSE; 517 return false;
518 } 518 }
519 m_pDecodeInfo = FX_Alloc(SampleDecodeInfo, m_nOutputs); 519 m_pDecodeInfo = FX_Alloc(SampleDecodeInfo, m_nOutputs);
520 for (int i = 0; i < m_nOutputs; i ++) { 520 for (int i = 0; i < m_nOutputs; i ++) {
521 if (pDecode) { 521 if (pDecode) {
522 m_pDecodeInfo[i].decode_min = pDecode->GetFloat(2 * i); 522 m_pDecodeInfo[i].decode_min = pDecode->GetFloat(2 * i);
523 m_pDecodeInfo[i].decode_max = pDecode->GetFloat(2 * i + 1); 523 m_pDecodeInfo[i].decode_max = pDecode->GetFloat(2 * i + 1);
524 } else { 524 } else {
525 m_pDecodeInfo[i].decode_min = m_pRanges[i * 2]; 525 m_pDecodeInfo[i].decode_min = m_pRanges[i * 2];
526 m_pDecodeInfo[i].decode_max = m_pRanges[i * 2 + 1]; 526 m_pDecodeInfo[i].decode_max = m_pRanges[i * 2 + 1];
527 } 527 }
528 } 528 }
529 return TRUE; 529 return true;
530 } 530 }
531 FX_BOOL CPDF_SampledFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const 531 bool CPDF_SampledFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const
532 { 532 {
533 int pos = 0; 533 int pos = 0;
534 CFX_FixedBufGrow<FX_FLOAT, 16> encoded_input_buf(m_nInputs); 534 CFX_FixedBufGrow<FX_FLOAT, 16> encoded_input_buf(m_nInputs);
535 FX_FLOAT* encoded_input = encoded_input_buf; 535 FX_FLOAT* encoded_input = encoded_input_buf;
536 CFX_FixedBufGrow<int, 32> int_buf(m_nInputs * 2); 536 CFX_FixedBufGrow<int, 32> int_buf(m_nInputs * 2);
537 int* index = int_buf; 537 int* index = int_buf;
538 int* blocksize = index + m_nInputs; 538 int* blocksize = index + m_nInputs;
539 for (int i = 0; i < m_nInputs; i ++) { 539 for (int i = 0; i < m_nInputs; i ++) {
540 if (i == 0) { 540 if (i == 0) {
541 blocksize[i] = 1; 541 blocksize[i] = 1;
542 } else { 542 } else {
543 blocksize[i] = blocksize[i - 1] * m_pEncodeInfo[i - 1].sizes; 543 blocksize[i] = blocksize[i - 1] * m_pEncodeInfo[i - 1].sizes;
544 } 544 }
545 encoded_input[i] = PDF_Interpolate(inputs[i], m_pDomains[i * 2], m_pDoma ins[i * 2 + 1], 545 encoded_input[i] = PDF_Interpolate(inputs[i], m_pDomains[i * 2], m_pDoma ins[i * 2 + 1],
546 m_pEncodeInfo[i].encode_min, m_pEncod eInfo[i].encode_max); 546 m_pEncodeInfo[i].encode_min, m_pEncod eInfo[i].encode_max);
547 index[i] = (int)encoded_input[i]; 547 index[i] = (int)encoded_input[i];
548 if (index[i] < 0) { 548 if (index[i] < 0) {
549 index[i] = 0; 549 index[i] = 0;
550 } else if (index[i] > m_pEncodeInfo[i].sizes - 1) { 550 } else if (index[i] > m_pEncodeInfo[i].sizes - 1) {
551 index[i] = m_pEncodeInfo[i].sizes - 1; 551 index[i] = m_pEncodeInfo[i].sizes - 1;
552 } 552 }
553 pos += index[i] * blocksize[i]; 553 pos += index[i] * blocksize[i];
554 } 554 }
555 FX_SAFE_INT32 bits_to_output = m_nOutputs; 555 FX_SAFE_INT32 bits_to_output = m_nOutputs;
556 bits_to_output *= m_nBitsPerSample; 556 bits_to_output *= m_nBitsPerSample;
557 if (!bits_to_output.IsValid()) { 557 if (!bits_to_output.IsValid()) {
558 return FALSE; 558 return false;
559 } 559 }
560 FX_SAFE_INT32 bitpos = pos; 560 FX_SAFE_INT32 bitpos = pos;
561 bitpos *= bits_to_output.ValueOrDie(); 561 bitpos *= bits_to_output.ValueOrDie();
562 if (!bitpos.IsValid()) { 562 if (!bitpos.IsValid()) {
563 return FALSE; 563 return false;
564 } 564 }
565 FX_SAFE_INT32 range_check = bitpos; 565 FX_SAFE_INT32 range_check = bitpos;
566 range_check += bits_to_output.ValueOrDie(); 566 range_check += bits_to_output.ValueOrDie();
567 if (!range_check.IsValid()) { 567 if (!range_check.IsValid()) {
568 return FALSE; 568 return false;
569 } 569 }
570 const uint8_t* pSampleData = m_pSampleStream->GetData(); 570 const uint8_t* pSampleData = m_pSampleStream->GetData();
571 if (!pSampleData) { 571 if (!pSampleData) {
572 return FALSE; 572 return false;
573 } 573 }
574 for (int j = 0; j < m_nOutputs; j ++) { 574 for (int j = 0; j < m_nOutputs; j ++) {
575 FX_DWORD sample = _GetBits32(pSampleData, bitpos.ValueOrDie() + j * m_nB itsPerSample, m_nBitsPerSample); 575 FX_DWORD sample = _GetBits32(pSampleData, bitpos.ValueOrDie() + j * m_nB itsPerSample, m_nBitsPerSample);
576 FX_FLOAT encoded = (FX_FLOAT)sample; 576 FX_FLOAT encoded = (FX_FLOAT)sample;
577 for (int i = 0; i < m_nInputs; i ++) { 577 for (int i = 0; i < m_nInputs; i ++) {
578 if (index[i] == m_pEncodeInfo[i].sizes - 1) { 578 if (index[i] == m_pEncodeInfo[i].sizes - 1) {
579 if (index[i] == 0) { 579 if (index[i] == 0) {
580 encoded = encoded_input[i] * (FX_FLOAT)sample; 580 encoded = encoded_input[i] * (FX_FLOAT)sample;
581 } 581 }
582 } else { 582 } else {
583 FX_SAFE_INT32 bitpos2 = blocksize[i]; 583 FX_SAFE_INT32 bitpos2 = blocksize[i];
584 bitpos2 += pos; 584 bitpos2 += pos;
585 bitpos2 *= m_nOutputs; 585 bitpos2 *= m_nOutputs;
586 bitpos2 += j; 586 bitpos2 += j;
587 bitpos2 *= m_nBitsPerSample; 587 bitpos2 *= m_nBitsPerSample;
588 if (!bitpos2.IsValid()) { 588 if (!bitpos2.IsValid()) {
589 return FALSE; 589 return false;
590 } 590 }
591 FX_DWORD sample1 = _GetBits32(pSampleData, bitpos2.ValueOrDie(), m_nBitsPerSample); 591 FX_DWORD sample1 = _GetBits32(pSampleData, bitpos2.ValueOrDie(), m_nBitsPerSample);
592 encoded += (encoded_input[i] - index[i]) * ((FX_FLOAT)sample1 - (FX_FLOAT)sample); 592 encoded += (encoded_input[i] - index[i]) * ((FX_FLOAT)sample1 - (FX_FLOAT)sample);
593 } 593 }
594 } 594 }
595 results[j] = PDF_Interpolate(encoded, 0, (FX_FLOAT)m_SampleMax, 595 results[j] = PDF_Interpolate(encoded, 0, (FX_FLOAT)m_SampleMax,
596 m_pDecodeInfo[j].decode_min, m_pDecodeInfo[ j].decode_max); 596 m_pDecodeInfo[j].decode_min, m_pDecodeInfo[ j].decode_max);
597 } 597 }
598 return TRUE; 598 return true;
599 } 599 }
600 class CPDF_PSFunc : public CPDF_Function 600 class CPDF_PSFunc : public CPDF_Function
601 { 601 {
602 public: 602 public:
603 virtual FX_BOOL» » v_Init(CPDF_Object* pObj); 603 virtual bool» » v_Init(CPDF_Object* pObj);
604 virtual FX_BOOL» » v_Call(FX_FLOAT* inputs, FX_FLOAT* results) cons t; 604 virtual bool» » v_Call(FX_FLOAT* inputs, FX_FLOAT* results) cons t;
605 CPDF_PSEngine m_PS; 605 CPDF_PSEngine m_PS;
606 }; 606 };
607 FX_BOOL CPDF_PSFunc::v_Init(CPDF_Object* pObj) 607 bool CPDF_PSFunc::v_Init(CPDF_Object* pObj)
608 { 608 {
609 CPDF_Stream* pStream = (CPDF_Stream*)pObj; 609 CPDF_Stream* pStream = (CPDF_Stream*)pObj;
610 CPDF_StreamAcc acc; 610 CPDF_StreamAcc acc;
611 acc.LoadAllData(pStream, FALSE); 611 acc.LoadAllData(pStream, false);
612 return m_PS.Parse((const FX_CHAR*)acc.GetData(), acc.GetSize()); 612 return m_PS.Parse((const FX_CHAR*)acc.GetData(), acc.GetSize());
613 } 613 }
614 FX_BOOL CPDF_PSFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const 614 bool CPDF_PSFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const
615 { 615 {
616 CPDF_PSEngine& PS = (CPDF_PSEngine&)m_PS; 616 CPDF_PSEngine& PS = (CPDF_PSEngine&)m_PS;
617 PS.Reset(); 617 PS.Reset();
618 int i; 618 int i;
619 for (i = 0; i < m_nInputs; i ++) { 619 for (i = 0; i < m_nInputs; i ++) {
620 PS.Push(inputs[i]); 620 PS.Push(inputs[i]);
621 } 621 }
622 PS.Execute(); 622 PS.Execute();
623 if (PS.GetStackSize() < m_nOutputs) { 623 if (PS.GetStackSize() < m_nOutputs) {
624 return FALSE; 624 return false;
625 } 625 }
626 for (i = 0; i < m_nOutputs; i ++) { 626 for (i = 0; i < m_nOutputs; i ++) {
627 results[m_nOutputs - i - 1] = PS.Pop(); 627 results[m_nOutputs - i - 1] = PS.Pop();
628 } 628 }
629 return TRUE; 629 return true;
630 } 630 }
631 class CPDF_ExpIntFunc : public CPDF_Function 631 class CPDF_ExpIntFunc : public CPDF_Function
632 { 632 {
633 public: 633 public:
634 CPDF_ExpIntFunc(); 634 CPDF_ExpIntFunc();
635 virtual ~CPDF_ExpIntFunc(); 635 virtual ~CPDF_ExpIntFunc();
636 virtual FX_BOOL» » v_Init(CPDF_Object* pObj); 636 virtual bool» » v_Init(CPDF_Object* pObj);
637 virtual FX_BOOL» » v_Call(FX_FLOAT* inputs, FX_FLOAT* results) cons t; 637 virtual bool» » v_Call(FX_FLOAT* inputs, FX_FLOAT* results) cons t;
638 FX_FLOAT m_Exponent; 638 FX_FLOAT m_Exponent;
639 FX_FLOAT* m_pBeginValues; 639 FX_FLOAT* m_pBeginValues;
640 FX_FLOAT* m_pEndValues; 640 FX_FLOAT* m_pEndValues;
641 int m_nOrigOutputs; 641 int m_nOrigOutputs;
642 }; 642 };
643 CPDF_ExpIntFunc::CPDF_ExpIntFunc() 643 CPDF_ExpIntFunc::CPDF_ExpIntFunc()
644 { 644 {
645 m_pBeginValues = NULL; 645 m_pBeginValues = NULL;
646 m_pEndValues = NULL; 646 m_pEndValues = NULL;
647 } 647 }
648 CPDF_ExpIntFunc::~CPDF_ExpIntFunc() 648 CPDF_ExpIntFunc::~CPDF_ExpIntFunc()
649 { 649 {
650 if (m_pBeginValues) { 650 if (m_pBeginValues) {
651 FX_Free(m_pBeginValues); 651 FX_Free(m_pBeginValues);
652 } 652 }
653 if (m_pEndValues) { 653 if (m_pEndValues) {
654 FX_Free(m_pEndValues); 654 FX_Free(m_pEndValues);
655 } 655 }
656 } 656 }
657 FX_BOOL CPDF_ExpIntFunc::v_Init(CPDF_Object* pObj) 657 bool CPDF_ExpIntFunc::v_Init(CPDF_Object* pObj)
658 { 658 {
659 CPDF_Dictionary* pDict = pObj->GetDict(); 659 CPDF_Dictionary* pDict = pObj->GetDict();
660 if (pDict == NULL) { 660 if (pDict == NULL) {
661 return FALSE; 661 return false;
662 } 662 }
663 CPDF_Array* pArray0 = pDict->GetArray(FX_BSTRC("C0")); 663 CPDF_Array* pArray0 = pDict->GetArray(FX_BSTRC("C0"));
664 if (m_nOutputs == 0) { 664 if (m_nOutputs == 0) {
665 m_nOutputs = 1; 665 m_nOutputs = 1;
666 if (pArray0) { 666 if (pArray0) {
667 m_nOutputs = pArray0->GetCount(); 667 m_nOutputs = pArray0->GetCount();
668 } 668 }
669 } 669 }
670 CPDF_Array* pArray1 = pDict->GetArray(FX_BSTRC("C1")); 670 CPDF_Array* pArray1 = pDict->GetArray(FX_BSTRC("C1"));
671 m_pBeginValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); 671 m_pBeginValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2);
672 m_pEndValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); 672 m_pEndValues = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2);
673 for (int i = 0; i < m_nOutputs; i ++) { 673 for (int i = 0; i < m_nOutputs; i ++) {
674 m_pBeginValues[i] = pArray0 ? pArray0->GetFloat(i) : 0.0f; 674 m_pBeginValues[i] = pArray0 ? pArray0->GetFloat(i) : 0.0f;
675 m_pEndValues[i] = pArray1 ? pArray1->GetFloat(i) : 1.0f; 675 m_pEndValues[i] = pArray1 ? pArray1->GetFloat(i) : 1.0f;
676 } 676 }
677 m_Exponent = pDict->GetFloat(FX_BSTRC("N")); 677 m_Exponent = pDict->GetFloat(FX_BSTRC("N"));
678 m_nOrigOutputs = m_nOutputs; 678 m_nOrigOutputs = m_nOutputs;
679 if (m_nOutputs && m_nInputs > INT_MAX / m_nOutputs) { 679 if (m_nOutputs && m_nInputs > INT_MAX / m_nOutputs) {
680 return FALSE; 680 return false;
681 } 681 }
682 m_nOutputs *= m_nInputs; 682 m_nOutputs *= m_nInputs;
683 return TRUE; 683 return true;
684 } 684 }
685 FX_BOOL CPDF_ExpIntFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const 685 bool CPDF_ExpIntFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* results) const
686 { 686 {
687 for (int i = 0; i < m_nInputs; i ++) 687 for (int i = 0; i < m_nInputs; i ++)
688 for (int j = 0; j < m_nOrigOutputs; j ++) { 688 for (int j = 0; j < m_nOrigOutputs; j ++) {
689 results[i * m_nOrigOutputs + j] = m_pBeginValues[j] + (FX_FLOAT)FXSY S_pow(inputs[i], m_Exponent) * 689 results[i * m_nOrigOutputs + j] = m_pBeginValues[j] + (FX_FLOAT)FXSY S_pow(inputs[i], m_Exponent) *
690 (m_pEndValues[j] - m_pBeginValues[ j]); 690 (m_pEndValues[j] - m_pBeginValues[ j]);
691 } 691 }
692 return TRUE; 692 return true;
693 } 693 }
694 class CPDF_StitchFunc : public CPDF_Function 694 class CPDF_StitchFunc : public CPDF_Function
695 { 695 {
696 public: 696 public:
697 CPDF_StitchFunc(); 697 CPDF_StitchFunc();
698 virtual ~CPDF_StitchFunc(); 698 virtual ~CPDF_StitchFunc();
699 virtual FX_BOOL» » v_Init(CPDF_Object* pObj); 699 virtual bool» » v_Init(CPDF_Object* pObj);
700 virtual FX_BOOL» » v_Call(FX_FLOAT* inputs, FX_FLOAT* results) cons t; 700 virtual bool» » v_Call(FX_FLOAT* inputs, FX_FLOAT* results) cons t;
701 int m_nSubs; 701 int m_nSubs;
702 CPDF_Function** m_pSubFunctions; 702 CPDF_Function** m_pSubFunctions;
703 FX_FLOAT* m_pBounds; 703 FX_FLOAT* m_pBounds;
704 FX_FLOAT* m_pEncode; 704 FX_FLOAT* m_pEncode;
705 }; 705 };
706 CPDF_StitchFunc::CPDF_StitchFunc() 706 CPDF_StitchFunc::CPDF_StitchFunc()
707 { 707 {
708 m_nSubs = 0; 708 m_nSubs = 0;
709 m_pSubFunctions = NULL; 709 m_pSubFunctions = NULL;
710 m_pBounds = NULL; 710 m_pBounds = NULL;
711 m_pEncode = NULL; 711 m_pEncode = NULL;
712 } 712 }
713 CPDF_StitchFunc::~CPDF_StitchFunc() 713 CPDF_StitchFunc::~CPDF_StitchFunc()
714 { 714 {
715 for (int i = 0; i < m_nSubs; i ++) 715 for (int i = 0; i < m_nSubs; i ++)
716 delete m_pSubFunctions[i]; 716 delete m_pSubFunctions[i];
717 if (m_pSubFunctions) { 717 if (m_pSubFunctions) {
718 FX_Free(m_pSubFunctions); 718 FX_Free(m_pSubFunctions);
719 } 719 }
720 if (m_pBounds) { 720 if (m_pBounds) {
721 FX_Free(m_pBounds); 721 FX_Free(m_pBounds);
722 } 722 }
723 if (m_pEncode) { 723 if (m_pEncode) {
724 FX_Free(m_pEncode); 724 FX_Free(m_pEncode);
725 } 725 }
726 } 726 }
727 FX_BOOL CPDF_StitchFunc::v_Init(CPDF_Object* pObj) 727 bool CPDF_StitchFunc::v_Init(CPDF_Object* pObj)
728 { 728 {
729 CPDF_Dictionary* pDict = pObj->GetDict(); 729 CPDF_Dictionary* pDict = pObj->GetDict();
730 if (pDict == NULL) { 730 if (pDict == NULL) {
731 return FALSE; 731 return false;
732 } 732 }
733 CPDF_Array* pArray = pDict->GetArray(FX_BSTRC("Functions")); 733 CPDF_Array* pArray = pDict->GetArray(FX_BSTRC("Functions"));
734 if (pArray == NULL) { 734 if (pArray == NULL) {
735 return FALSE; 735 return false;
736 } 736 }
737 m_nSubs = pArray->GetCount(); 737 m_nSubs = pArray->GetCount();
738 if (m_nSubs == 0) { 738 if (m_nSubs == 0) {
739 return FALSE; 739 return false;
740 } 740 }
741 m_pSubFunctions = FX_Alloc(CPDF_Function*, m_nSubs); 741 m_pSubFunctions = FX_Alloc(CPDF_Function*, m_nSubs);
742 m_nOutputs = 0; 742 m_nOutputs = 0;
743 int i; 743 int i;
744 for (i = 0; i < m_nSubs; i ++) { 744 for (i = 0; i < m_nSubs; i ++) {
745 CPDF_Object* pSub = pArray->GetElementValue(i); 745 CPDF_Object* pSub = pArray->GetElementValue(i);
746 if (pSub == pObj) { 746 if (pSub == pObj) {
747 return FALSE; 747 return false;
748 } 748 }
749 m_pSubFunctions[i] = CPDF_Function::Load(pSub); 749 m_pSubFunctions[i] = CPDF_Function::Load(pSub);
750 if (m_pSubFunctions[i] == NULL) { 750 if (m_pSubFunctions[i] == NULL) {
751 return FALSE; 751 return false;
752 } 752 }
753 if (m_pSubFunctions[i]->CountOutputs() > m_nOutputs) { 753 if (m_pSubFunctions[i]->CountOutputs() > m_nOutputs) {
754 m_nOutputs = m_pSubFunctions[i]->CountOutputs(); 754 m_nOutputs = m_pSubFunctions[i]->CountOutputs();
755 } 755 }
756 } 756 }
757 m_pBounds = FX_Alloc(FX_FLOAT, m_nSubs + 1); 757 m_pBounds = FX_Alloc(FX_FLOAT, m_nSubs + 1);
758 m_pBounds[0] = m_pDomains[0]; 758 m_pBounds[0] = m_pDomains[0];
759 pArray = pDict->GetArray(FX_BSTRC("Bounds")); 759 pArray = pDict->GetArray(FX_BSTRC("Bounds"));
760 if (pArray == NULL) { 760 if (pArray == NULL) {
761 return FALSE; 761 return false;
762 } 762 }
763 for (i = 0; i < m_nSubs - 1; i ++) { 763 for (i = 0; i < m_nSubs - 1; i ++) {
764 m_pBounds[i + 1] = pArray->GetFloat(i); 764 m_pBounds[i + 1] = pArray->GetFloat(i);
765 } 765 }
766 m_pBounds[m_nSubs] = m_pDomains[1]; 766 m_pBounds[m_nSubs] = m_pDomains[1];
767 m_pEncode = FX_Alloc2D(FX_FLOAT, m_nSubs, 2); 767 m_pEncode = FX_Alloc2D(FX_FLOAT, m_nSubs, 2);
768 pArray = pDict->GetArray(FX_BSTRC("Encode")); 768 pArray = pDict->GetArray(FX_BSTRC("Encode"));
769 if (pArray == NULL) { 769 if (pArray == NULL) {
770 return FALSE; 770 return false;
771 } 771 }
772 for (i = 0; i < m_nSubs * 2; i ++) { 772 for (i = 0; i < m_nSubs * 2; i ++) {
773 m_pEncode[i] = pArray->GetFloat(i); 773 m_pEncode[i] = pArray->GetFloat(i);
774 } 774 }
775 return TRUE; 775 return true;
776 } 776 }
777 FX_BOOL CPDF_StitchFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* outputs) const 777 bool CPDF_StitchFunc::v_Call(FX_FLOAT* inputs, FX_FLOAT* outputs) const
778 { 778 {
779 FX_FLOAT input = inputs[0]; 779 FX_FLOAT input = inputs[0];
780 int i; 780 int i;
781 for (i = 0; i < m_nSubs - 1; i ++) 781 for (i = 0; i < m_nSubs - 1; i ++)
782 if (input < m_pBounds[i + 1]) { 782 if (input < m_pBounds[i + 1]) {
783 break; 783 break;
784 } 784 }
785 if (m_pSubFunctions[i] == NULL) { 785 if (m_pSubFunctions[i] == NULL) {
786 return FALSE; 786 return false;
787 } 787 }
788 input = PDF_Interpolate(input, m_pBounds[i], m_pBounds[i + 1], m_pEncode[i * 2], m_pEncode[i * 2 + 1]); 788 input = PDF_Interpolate(input, m_pBounds[i], m_pBounds[i + 1], m_pEncode[i * 2], m_pEncode[i * 2 + 1]);
789 int nresults; 789 int nresults;
790 m_pSubFunctions[i]->Call(&input, m_nInputs, outputs, nresults); 790 m_pSubFunctions[i]->Call(&input, m_nInputs, outputs, nresults);
791 return TRUE; 791 return true;
792 } 792 }
793 CPDF_Function* CPDF_Function::Load(CPDF_Object* pFuncObj) 793 CPDF_Function* CPDF_Function::Load(CPDF_Object* pFuncObj)
794 { 794 {
795 if (pFuncObj == NULL) { 795 if (pFuncObj == NULL) {
796 return NULL; 796 return NULL;
797 } 797 }
798 CPDF_Function* pFunc = NULL; 798 CPDF_Function* pFunc = NULL;
799 int type; 799 int type;
800 if (pFuncObj->GetType() == PDFOBJ_STREAM) { 800 if (pFuncObj->GetType() == PDFOBJ_STREAM) {
801 type = ((CPDF_Stream*)pFuncObj)->GetDict()->GetInteger(FX_BSTRC("Functio nType")); 801 type = ((CPDF_Stream*)pFuncObj)->GetDict()->GetInteger(FX_BSTRC("Functio nType"));
(...skipping 28 matching lines...) Expand all
830 { 830 {
831 if (m_pDomains) { 831 if (m_pDomains) {
832 FX_Free(m_pDomains); 832 FX_Free(m_pDomains);
833 m_pDomains = NULL; 833 m_pDomains = NULL;
834 } 834 }
835 if (m_pRanges) { 835 if (m_pRanges) {
836 FX_Free(m_pRanges); 836 FX_Free(m_pRanges);
837 m_pRanges = NULL; 837 m_pRanges = NULL;
838 } 838 }
839 } 839 }
840 FX_BOOL CPDF_Function::Init(CPDF_Object* pObj) 840 bool CPDF_Function::Init(CPDF_Object* pObj)
841 { 841 {
842 CPDF_Dictionary* pDict; 842 CPDF_Dictionary* pDict;
843 if (pObj->GetType() == PDFOBJ_STREAM) { 843 if (pObj->GetType() == PDFOBJ_STREAM) {
844 pDict = ((CPDF_Stream*)pObj)->GetDict(); 844 pDict = ((CPDF_Stream*)pObj)->GetDict();
845 } else { 845 } else {
846 pDict = (CPDF_Dictionary*)pObj; 846 pDict = (CPDF_Dictionary*)pObj;
847 } 847 }
848 CPDF_Array* pDomains = pDict->GetArray(FX_BSTRC("Domain")); 848 CPDF_Array* pDomains = pDict->GetArray(FX_BSTRC("Domain"));
849 if (pDomains == NULL) { 849 if (pDomains == NULL) {
850 return FALSE; 850 return false;
851 } 851 }
852 m_nInputs = pDomains->GetCount() / 2; 852 m_nInputs = pDomains->GetCount() / 2;
853 if (m_nInputs == 0) { 853 if (m_nInputs == 0) {
854 return FALSE; 854 return false;
855 } 855 }
856 m_pDomains = FX_Alloc2D(FX_FLOAT, m_nInputs, 2); 856 m_pDomains = FX_Alloc2D(FX_FLOAT, m_nInputs, 2);
857 for (int i = 0; i < m_nInputs * 2; i ++) { 857 for (int i = 0; i < m_nInputs * 2; i ++) {
858 m_pDomains[i] = pDomains->GetFloat(i); 858 m_pDomains[i] = pDomains->GetFloat(i);
859 } 859 }
860 CPDF_Array* pRanges = pDict->GetArray(FX_BSTRC("Range")); 860 CPDF_Array* pRanges = pDict->GetArray(FX_BSTRC("Range"));
861 m_nOutputs = 0; 861 m_nOutputs = 0;
862 if (pRanges) { 862 if (pRanges) {
863 m_nOutputs = pRanges->GetCount() / 2; 863 m_nOutputs = pRanges->GetCount() / 2;
864 m_pRanges = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2); 864 m_pRanges = FX_Alloc2D(FX_FLOAT, m_nOutputs, 2);
865 for (int i = 0; i < m_nOutputs * 2; i ++) { 865 for (int i = 0; i < m_nOutputs * 2; i ++) {
866 m_pRanges[i] = pRanges->GetFloat(i); 866 m_pRanges[i] = pRanges->GetFloat(i);
867 } 867 }
868 } 868 }
869 FX_DWORD old_outputs = m_nOutputs; 869 FX_DWORD old_outputs = m_nOutputs;
870 if (!v_Init(pObj)) { 870 if (!v_Init(pObj)) {
871 return FALSE; 871 return false;
872 } 872 }
873 if (m_pRanges && m_nOutputs > (int)old_outputs) { 873 if (m_pRanges && m_nOutputs > (int)old_outputs) {
874 m_pRanges = FX_Realloc(FX_FLOAT, m_pRanges, m_nOutputs * 2); 874 m_pRanges = FX_Realloc(FX_FLOAT, m_pRanges, m_nOutputs * 2);
875 if (m_pRanges) { 875 if (m_pRanges) {
876 FXSYS_memset(m_pRanges + (old_outputs * 2), 0, sizeof(FX_FLOAT) * (m _nOutputs - old_outputs) * 2); 876 FXSYS_memset(m_pRanges + (old_outputs * 2), 0, sizeof(FX_FLOAT) * (m _nOutputs - old_outputs) * 2);
877 } 877 }
878 } 878 }
879 return TRUE; 879 return true;
880 } 880 }
881 FX_BOOL CPDF_Function::Call(FX_FLOAT* inputs, int ninputs, FX_FLOAT* results, in t& nresults) const 881 bool CPDF_Function::Call(FX_FLOAT* inputs, int ninputs, FX_FLOAT* results, int& nresults) const
882 { 882 {
883 if (m_nInputs != ninputs) { 883 if (m_nInputs != ninputs) {
884 return FALSE; 884 return false;
885 } 885 }
886 nresults = m_nOutputs; 886 nresults = m_nOutputs;
887 for (int i = 0; i < m_nInputs; i ++) { 887 for (int i = 0; i < m_nInputs; i ++) {
888 if (inputs[i] < m_pDomains[i * 2]) { 888 if (inputs[i] < m_pDomains[i * 2]) {
889 inputs[i] = m_pDomains[i * 2]; 889 inputs[i] = m_pDomains[i * 2];
890 } else if (inputs[i] > m_pDomains[i * 2 + 1]) { 890 } else if (inputs[i] > m_pDomains[i * 2 + 1]) {
891 inputs[i] = m_pDomains[i * 2] + 1; 891 inputs[i] = m_pDomains[i * 2] + 1;
892 } 892 }
893 } 893 }
894 v_Call(inputs, results); 894 v_Call(inputs, results);
895 if (m_pRanges) { 895 if (m_pRanges) {
896 for (int i = 0; i < m_nOutputs; i ++) { 896 for (int i = 0; i < m_nOutputs; i ++) {
897 if (results[i] < m_pRanges[i * 2]) { 897 if (results[i] < m_pRanges[i * 2]) {
898 results[i] = m_pRanges[i * 2]; 898 results[i] = m_pRanges[i * 2];
899 } else if (results[i] > m_pRanges[i * 2 + 1]) { 899 } else if (results[i] > m_pRanges[i * 2 + 1]) {
900 results[i] = m_pRanges[i * 2 + 1]; 900 results[i] = m_pRanges[i * 2 + 1];
901 } 901 }
902 } 902 }
903 } 903 }
904 return TRUE; 904 return true;
905 } 905 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp ('k') | core/src/fpdfapi/fpdf_page/fpdf_page_graph_state.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698