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

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

Issue 1686153004: Add a class to better represent PS operations. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: address comments Created 4 years, 10 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 | no next file » | no next file with comments »
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 "pageint.h" 7 #include "core/src/fpdfapi/fpdf_page/pageint.h"
8 8
9 #include <limits.h> 9 #include <limits.h>
10 #include <math.h>
10 11
11 #include <memory> 12 #include <memory>
13 #include <utility>
12 #include <vector> 14 #include <vector>
13 15
14 #include "core/include/fpdfapi/fpdf_module.h" 16 #include "core/include/fpdfapi/fpdf_module.h"
15 #include "core/include/fpdfapi/fpdf_page.h" 17 #include "core/include/fpdfapi/fpdf_page.h"
16 #include "core/include/fxcrt/fx_safe_types.h" 18 #include "core/include/fxcrt/fx_safe_types.h"
17 #include "third_party/base/numerics/safe_conversions_impl.h" 19 #include "third_party/base/numerics/safe_conversions_impl.h"
18 20
19 class CPDF_PSEngine; 21 namespace {
20 typedef enum { 22
23 enum PDF_PSOP {
21 PSOP_ADD, 24 PSOP_ADD,
22 PSOP_SUB, 25 PSOP_SUB,
23 PSOP_MUL, 26 PSOP_MUL,
24 PSOP_DIV, 27 PSOP_DIV,
25 PSOP_IDIV, 28 PSOP_IDIV,
26 PSOP_MOD, 29 PSOP_MOD,
27 PSOP_NEG, 30 PSOP_NEG,
28 PSOP_ABS, 31 PSOP_ABS,
29 PSOP_CEILING, 32 PSOP_CEILING,
30 PSOP_FLOOR, 33 PSOP_FLOOR,
(...skipping 24 matching lines...) Expand all
55 PSOP_IF, 58 PSOP_IF,
56 PSOP_IFELSE, 59 PSOP_IFELSE,
57 PSOP_POP, 60 PSOP_POP,
58 PSOP_EXCH, 61 PSOP_EXCH,
59 PSOP_DUP, 62 PSOP_DUP,
60 PSOP_COPY, 63 PSOP_COPY,
61 PSOP_INDEX, 64 PSOP_INDEX,
62 PSOP_ROLL, 65 PSOP_ROLL,
63 PSOP_PROC, 66 PSOP_PROC,
64 PSOP_CONST 67 PSOP_CONST
65 } PDF_PSOP; 68 };
69
70 class CPDF_PSEngine;
71 class CPDF_PSProc;
72
73 class CPDF_PSOP {
Tom Sepez 2016/02/11 16:48:32 Thinking about this on the way home, are you sure
74 public:
75 enum Type { TYPE_GENERIC, TYPE_CONST, TYPE_PROC };
76
77 explicit CPDF_PSOP(PDF_PSOP op) : m_op(op) {}
78 virtual ~CPDF_PSOP() {}
79
80 virtual Type GetType() const { return TYPE_GENERIC; }
81 virtual FX_FLOAT GetFloatValue() const {
82 ASSERT(false);
83 return 0;
84 }
85 virtual CPDF_PSProc* GetProc() const {
86 ASSERT(false);
87 return nullptr;
88 }
89
90 PDF_PSOP GetOp() const { return m_op; }
91
92 private:
93 const PDF_PSOP m_op;
94 };
95
96 class CPDF_PSOP_Const : public CPDF_PSOP {
97 public:
98 explicit CPDF_PSOP_Const(FX_FLOAT value)
99 : CPDF_PSOP(PSOP_CONST), m_value(value) {}
100 ~CPDF_PSOP_Const() override {}
101
102 Type GetType() const override { return TYPE_CONST; }
103 FX_FLOAT GetFloatValue() const override { return m_value; }
104
105 private:
106 const FX_FLOAT m_value;
107 };
108
109 class CPDF_PSOP_Proc : public CPDF_PSOP {
110 public:
111 explicit CPDF_PSOP_Proc(std::unique_ptr<CPDF_PSProc> proc)
112 : CPDF_PSOP(PSOP_PROC), m_proc(std::move(proc)) {}
113 ~CPDF_PSOP_Proc() override {}
114
115 Type GetType() const override { return TYPE_PROC; }
116 CPDF_PSProc* GetProc() const override { return m_proc.get(); }
117
118 private:
119 std::unique_ptr<CPDF_PSProc> m_proc;
120 };
121
66 class CPDF_PSProc { 122 class CPDF_PSProc {
67 public: 123 public:
68 ~CPDF_PSProc(); 124 CPDF_PSProc() {}
69 FX_BOOL Parse(CPDF_SimpleParser& parser); 125 ~CPDF_PSProc() {}
126
127 FX_BOOL Parse(CPDF_SimpleParser* parser);
70 FX_BOOL Execute(CPDF_PSEngine* pEngine); 128 FX_BOOL Execute(CPDF_PSEngine* pEngine);
71 std::vector<void*> m_Operators; 129
130 private:
131 std::vector<std::unique_ptr<CPDF_PSOP>> m_Operators;
72 }; 132 };
73 #define PSENGINE_STACKSIZE 100 133
134 const size_t PSENGINE_STACKSIZE = 100;
135
74 class CPDF_PSEngine { 136 class CPDF_PSEngine {
75 public: 137 public:
76 CPDF_PSEngine(); 138 CPDF_PSEngine();
77 ~CPDF_PSEngine(); 139 ~CPDF_PSEngine();
140
78 FX_BOOL Parse(const FX_CHAR* string, int size); 141 FX_BOOL Parse(const FX_CHAR* string, int size);
79 FX_BOOL Execute() { return m_MainProc.Execute(this); } 142 FX_BOOL Execute() { return m_MainProc.Execute(this); }
80 FX_BOOL DoOperator(PDF_PSOP op); 143 FX_BOOL DoOperator(PDF_PSOP op);
81 void Reset() { m_StackCount = 0; } 144 void Reset() { m_StackCount = 0; }
82 void Push(FX_FLOAT value); 145 void Push(FX_FLOAT value);
83 void Push(int value) { Push((FX_FLOAT)value); } 146 void Push(int value) { Push((FX_FLOAT)value); }
84 FX_FLOAT Pop(); 147 FX_FLOAT Pop();
85 int GetStackSize() { return m_StackCount; } 148 int GetStackSize() const { return m_StackCount; }
86 149
87 private: 150 private:
88 FX_FLOAT m_Stack[PSENGINE_STACKSIZE]; 151 FX_FLOAT m_Stack[PSENGINE_STACKSIZE];
89 int m_StackCount; 152 int m_StackCount;
90 CPDF_PSProc m_MainProc; 153 CPDF_PSProc m_MainProc;
91 }; 154 };
92 CPDF_PSProc::~CPDF_PSProc() { 155
93 for (size_t i = 0; i < m_Operators.size(); i++) { 156 FX_BOOL CPDF_PSProc::Execute(CPDF_PSEngine* pEngine) {
94 if (m_Operators[i] == (void*)PSOP_PROC) { 157 for (size_t i = 0; i < m_Operators.size(); ++i) {
95 delete (CPDF_PSProc*)m_Operators[i + 1]; 158 const CPDF_PSOP::Type type = m_Operators[i]->GetType();
96 i++; 159 if (type == CPDF_PSOP::TYPE_PROC)
97 } else if (m_Operators[i] == (void*)PSOP_CONST) { 160 continue;
98 FX_Free((FX_FLOAT*)m_Operators[i + 1]); 161
99 i++; 162 if (type == CPDF_PSOP::TYPE_CONST) {
163 pEngine->Push(m_Operators[i]->GetFloatValue());
164 continue;
100 } 165 }
101 } 166
102 } 167 const PDF_PSOP op = m_Operators[i]->GetOp();
103 FX_BOOL CPDF_PSProc::Execute(CPDF_PSEngine* pEngine) { 168 if (op == PSOP_IF) {
104 for (size_t i = 0; i < m_Operators.size(); i++) { 169 if (i == 0 || m_Operators[i - 1]->GetType() != CPDF_PSOP::TYPE_PROC)
105 PDF_PSOP op = (PDF_PSOP)(uintptr_t)m_Operators[i]; 170 return FALSE;
106 if (op == PSOP_PROC) { 171
107 i++; 172 if (static_cast<int>(pEngine->Pop()))
108 } else if (op == PSOP_CONST) { 173 m_Operators[i - 1]->GetProc()->Execute(pEngine);
109 pEngine->Push(*(FX_FLOAT*)m_Operators[i + 1]); 174 } else if (op == PSOP_IFELSE) {
110 i++; 175 if (i < 2 || m_Operators[i - 1]->GetType() != CPDF_PSOP::TYPE_PROC ||
111 } else if (op == PSOP_IF) { 176 m_Operators[i - 2]->GetType() != CPDF_PSOP::TYPE_PROC) {
112 if (i < 2 || m_Operators[i - 2] != (void*)PSOP_PROC) {
113 return FALSE; 177 return FALSE;
114 } 178 }
115 if ((int)pEngine->Pop()) { 179 size_t offset = static_cast<int>(pEngine->Pop()) ? 2 : 1;
116 ((CPDF_PSProc*)m_Operators[i - 1])->Execute(pEngine); 180 m_Operators[i - offset]->GetProc()->Execute(pEngine);
117 }
118 } else if (op == PSOP_IFELSE) {
119 if (i < 4 || m_Operators[i - 2] != (void*)PSOP_PROC ||
120 m_Operators[i - 4] != (void*)PSOP_PROC) {
121 return FALSE;
122 }
123 if ((int)pEngine->Pop()) {
124 ((CPDF_PSProc*)m_Operators[i - 3])->Execute(pEngine);
125 } else {
126 ((CPDF_PSProc*)m_Operators[i - 1])->Execute(pEngine);
127 }
128 } else { 181 } else {
129 pEngine->DoOperator(op); 182 pEngine->DoOperator(op);
130 } 183 }
131 } 184 }
132 return TRUE; 185 return TRUE;
133 } 186 }
187
134 CPDF_PSEngine::CPDF_PSEngine() { 188 CPDF_PSEngine::CPDF_PSEngine() {
135 m_StackCount = 0; 189 m_StackCount = 0;
136 } 190 }
137 CPDF_PSEngine::~CPDF_PSEngine() {} 191 CPDF_PSEngine::~CPDF_PSEngine() {}
138 void CPDF_PSEngine::Push(FX_FLOAT v) { 192 void CPDF_PSEngine::Push(FX_FLOAT v) {
139 if (m_StackCount == 100) { 193 if (m_StackCount == PSENGINE_STACKSIZE) {
140 return; 194 return;
141 } 195 }
142 m_Stack[m_StackCount++] = v; 196 m_Stack[m_StackCount++] = v;
143 } 197 }
144 FX_FLOAT CPDF_PSEngine::Pop() { 198 FX_FLOAT CPDF_PSEngine::Pop() {
145 if (m_StackCount == 0) { 199 if (m_StackCount == 0) {
146 return 0; 200 return 0;
147 } 201 }
148 return m_Stack[--m_StackCount]; 202 return m_Stack[--m_StackCount];
149 } 203 }
150 const struct _PDF_PSOpName { 204 const struct PDF_PSOpName {
151 const FX_CHAR* name; 205 const FX_CHAR* name;
152 PDF_PSOP op; 206 PDF_PSOP op;
153 } _PDF_PSOpNames[] = {{"add", PSOP_ADD}, {"sub", PSOP_SUB}, 207 } PDF_PSOpNames[] = {{"add", PSOP_ADD}, {"sub", PSOP_SUB},
154 {"mul", PSOP_MUL}, {"div", PSOP_DIV}, 208 {"mul", PSOP_MUL}, {"div", PSOP_DIV},
155 {"idiv", PSOP_IDIV}, {"mod", PSOP_MOD}, 209 {"idiv", PSOP_IDIV}, {"mod", PSOP_MOD},
156 {"neg", PSOP_NEG}, {"abs", PSOP_ABS}, 210 {"neg", PSOP_NEG}, {"abs", PSOP_ABS},
157 {"ceiling", PSOP_CEILING}, {"floor", PSOP_FLOOR}, 211 {"ceiling", PSOP_CEILING}, {"floor", PSOP_FLOOR},
158 {"round", PSOP_ROUND}, {"truncate", PSOP_TRUNCATE}, 212 {"round", PSOP_ROUND}, {"truncate", PSOP_TRUNCATE},
159 {"sqrt", PSOP_SQRT}, {"sin", PSOP_SIN}, 213 {"sqrt", PSOP_SQRT}, {"sin", PSOP_SIN},
160 {"cos", PSOP_COS}, {"atan", PSOP_ATAN}, 214 {"cos", PSOP_COS}, {"atan", PSOP_ATAN},
161 {"exp", PSOP_EXP}, {"ln", PSOP_LN}, 215 {"exp", PSOP_EXP}, {"ln", PSOP_LN},
162 {"log", PSOP_LOG}, {"cvi", PSOP_CVI}, 216 {"log", PSOP_LOG}, {"cvi", PSOP_CVI},
163 {"cvr", PSOP_CVR}, {"eq", PSOP_EQ}, 217 {"cvr", PSOP_CVR}, {"eq", PSOP_EQ},
164 {"ne", PSOP_NE}, {"gt", PSOP_GT}, 218 {"ne", PSOP_NE}, {"gt", PSOP_GT},
165 {"ge", PSOP_GE}, {"lt", PSOP_LT}, 219 {"ge", PSOP_GE}, {"lt", PSOP_LT},
166 {"le", PSOP_LE}, {"and", PSOP_AND}, 220 {"le", PSOP_LE}, {"and", PSOP_AND},
167 {"or", PSOP_OR}, {"xor", PSOP_XOR}, 221 {"or", PSOP_OR}, {"xor", PSOP_XOR},
168 {"not", PSOP_NOT}, {"bitshift", PSOP_BITSHIFT}, 222 {"not", PSOP_NOT}, {"bitshift", PSOP_BITSHIFT},
169 {"true", PSOP_TRUE}, {"false", PSOP_FALSE}, 223 {"true", PSOP_TRUE}, {"false", PSOP_FALSE},
170 {"if", PSOP_IF}, {"ifelse", PSOP_IFELSE}, 224 {"if", PSOP_IF}, {"ifelse", PSOP_IFELSE},
171 {"pop", PSOP_POP}, {"exch", PSOP_EXCH}, 225 {"pop", PSOP_POP}, {"exch", PSOP_EXCH},
172 {"dup", PSOP_DUP}, {"copy", PSOP_COPY}, 226 {"dup", PSOP_DUP}, {"copy", PSOP_COPY},
173 {"index", PSOP_INDEX}, {"roll", PSOP_ROLL}, 227 {"index", PSOP_INDEX}, {"roll", PSOP_ROLL}};
174 {NULL, PSOP_PROC}}; 228
175 FX_BOOL CPDF_PSEngine::Parse(const FX_CHAR* string, int size) { 229 FX_BOOL CPDF_PSEngine::Parse(const FX_CHAR* string, int size) {
176 CPDF_SimpleParser parser((uint8_t*)string, size); 230 CPDF_SimpleParser parser((uint8_t*)string, size);
177 CFX_ByteStringC word = parser.GetWord(); 231 CFX_ByteStringC word = parser.GetWord();
178 if (word != "{") { 232 if (word != "{") {
179 return FALSE; 233 return FALSE;
180 } 234 }
181 return m_MainProc.Parse(parser); 235 return m_MainProc.Parse(&parser);
182 } 236 }
183 FX_BOOL CPDF_PSProc::Parse(CPDF_SimpleParser& parser) { 237 FX_BOOL CPDF_PSProc::Parse(CPDF_SimpleParser* parser) {
184 while (1) { 238 while (1) {
185 CFX_ByteStringC word = parser.GetWord(); 239 CFX_ByteStringC word = parser->GetWord();
186 if (word.IsEmpty()) { 240 if (word.IsEmpty()) {
187 return FALSE; 241 return FALSE;
188 } 242 }
189 if (word == "}") { 243 if (word == "}") {
190 return TRUE; 244 return TRUE;
191 } 245 }
192 if (word == "{") { 246 if (word == "{") {
193 CPDF_PSProc* pProc = new CPDF_PSProc; 247 std::unique_ptr<CPDF_PSProc> proc(new CPDF_PSProc);
194 m_Operators.push_back((void*)PSOP_PROC); 248 std::unique_ptr<CPDF_PSOP> op(new CPDF_PSOP_Proc(std::move(proc)));
195 m_Operators.push_back(pProc); 249 m_Operators.push_back(std::move(op));
196 if (!pProc->Parse(parser)) { 250 if (!m_Operators.back()->GetProc()->Parse(parser)) {
197 return FALSE; 251 return FALSE;
198 } 252 }
199 } else { 253 } else {
200 int i = 0; 254 bool found = false;
201 while (_PDF_PSOpNames[i].name) { 255 for (const PDF_PSOpName& op_name : PDF_PSOpNames) {
202 if (word == CFX_ByteStringC(_PDF_PSOpNames[i].name)) { 256 if (word == CFX_ByteStringC(op_name.name)) {
203 m_Operators.push_back((void*)_PDF_PSOpNames[i].op); 257 std::unique_ptr<CPDF_PSOP> op(new CPDF_PSOP(op_name.op));
258 m_Operators.push_back(std::move(op));
259 found = true;
204 break; 260 break;
205 } 261 }
206 i++;
207 } 262 }
208 if (!_PDF_PSOpNames[i].name) { 263 if (!found) {
209 FX_FLOAT* pd = FX_Alloc(FX_FLOAT, 1); 264 std::unique_ptr<CPDF_PSOP> op(new CPDF_PSOP_Const(FX_atof(word)));
210 *pd = FX_atof(word); 265 m_Operators.push_back(std::move(op));
211 m_Operators.push_back((void*)PSOP_CONST);
212 m_Operators.push_back(pd);
213 } 266 }
214 } 267 }
215 } 268 }
216 } 269 }
217 #define PI 3.1415926535897932384626433832795f 270
Tom Sepez 2016/02/11 18:18:54 Also this (from Bruce) https://randomascii.wordpre
Lei Zhang 2016/02/12 02:38:44 I added "#define _USE_MATH_DEFINES" and refuse to
Lei Zhang 2016/02/12 02:42:47 BTW, there's also FX_PI, FWLTHEME_PI, and PWL_PI.
218 FX_BOOL CPDF_PSEngine::DoOperator(PDF_PSOP op) { 271 FX_BOOL CPDF_PSEngine::DoOperator(PDF_PSOP op) {
219 int i1, i2; 272 int i1, i2;
220 FX_FLOAT d1, d2; 273 FX_FLOAT d1, d2;
221 switch (op) { 274 switch (op) {
222 case PSOP_ADD: 275 case PSOP_ADD:
223 d1 = Pop(); 276 d1 = Pop();
224 d2 = Pop(); 277 d2 = Pop();
225 Push(d1 + d2); 278 Push(d1 + d2);
226 break; 279 break;
227 case PSOP_SUB: 280 case PSOP_SUB:
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 case PSOP_TRUNCATE: 325 case PSOP_TRUNCATE:
273 i1 = (int)Pop(); 326 i1 = (int)Pop();
274 Push(i1); 327 Push(i1);
275 break; 328 break;
276 case PSOP_SQRT: 329 case PSOP_SQRT:
277 d1 = Pop(); 330 d1 = Pop();
278 Push((FX_FLOAT)FXSYS_sqrt(d1)); 331 Push((FX_FLOAT)FXSYS_sqrt(d1));
279 break; 332 break;
280 case PSOP_SIN: 333 case PSOP_SIN:
281 d1 = Pop(); 334 d1 = Pop();
282 Push((FX_FLOAT)FXSYS_sin(d1 * PI / 180.0f)); 335 Push((FX_FLOAT)FXSYS_sin(d1 * M_PI / 180.0f));
283 break; 336 break;
284 case PSOP_COS: 337 case PSOP_COS:
285 d1 = Pop(); 338 d1 = Pop();
286 Push((FX_FLOAT)FXSYS_cos(d1 * PI / 180.0f)); 339 Push((FX_FLOAT)FXSYS_cos(d1 * M_PI / 180.0f));
287 break; 340 break;
288 case PSOP_ATAN: 341 case PSOP_ATAN:
289 d2 = Pop(); 342 d2 = Pop();
290 d1 = Pop(); 343 d1 = Pop();
291 d1 = (FX_FLOAT)(FXSYS_atan2(d1, d2) * 180.0 / PI); 344 d1 = (FX_FLOAT)(FXSYS_atan2(d1, d2) * 180.0 / M_PI);
292 if (d1 < 0) { 345 if (d1 < 0) {
293 d1 += 360; 346 d1 += 360;
294 } 347 }
295 Push(d1); 348 Push(d1);
296 break; 349 break;
297 case PSOP_EXP: 350 case PSOP_EXP:
298 d2 = Pop(); 351 d2 = Pop();
299 d1 = Pop(); 352 d1 = Pop();
300 Push((FX_FLOAT)FXSYS_pow(d1, d2)); 353 Push((FX_FLOAT)FXSYS_pow(d1, d2));
301 break; 354 break;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 467 }
415 case PSOP_ROLL: { 468 case PSOP_ROLL: {
416 int j = (int)Pop(); 469 int j = (int)Pop();
417 int n = (int)Pop(); 470 int n = (int)Pop();
418 if (m_StackCount == 0) { 471 if (m_StackCount == 0) {
419 break; 472 break;
420 } 473 }
421 if (n < 0 || n > m_StackCount) { 474 if (n < 0 || n > m_StackCount) {
422 break; 475 break;
423 } 476 }
424 if (j < 0) 477 if (j < 0) {
425 for (int i = 0; i < -j; i++) { 478 for (int i = 0; i < -j; i++) {
426 FX_FLOAT first = m_Stack[m_StackCount - n]; 479 FX_FLOAT first = m_Stack[m_StackCount - n];
427 for (int ii = 0; ii < n - 1; ii++) { 480 for (int ii = 0; ii < n - 1; ii++) {
428 m_Stack[m_StackCount - n + ii] = m_Stack[m_StackCount - n + ii + 1]; 481 m_Stack[m_StackCount - n + ii] = m_Stack[m_StackCount - n + ii + 1];
429 } 482 }
430 m_Stack[m_StackCount - 1] = first; 483 m_Stack[m_StackCount - 1] = first;
431 } 484 }
432 else 485 } else {
433 for (int i = 0; i < j; i++) { 486 for (int i = 0; i < j; i++) {
434 FX_FLOAT last = m_Stack[m_StackCount - 1]; 487 FX_FLOAT last = m_Stack[m_StackCount - 1];
435 int ii; 488 int ii;
436 for (ii = 0; ii < n - 1; ii++) { 489 for (ii = 0; ii < n - 1; ii++) {
437 m_Stack[m_StackCount - ii - 1] = m_Stack[m_StackCount - ii - 2]; 490 m_Stack[m_StackCount - ii - 1] = m_Stack[m_StackCount - ii - 2];
438 } 491 }
439 m_Stack[m_StackCount - ii - 1] = last; 492 m_Stack[m_StackCount - ii - 1] = last;
440 } 493 }
494 }
441 break; 495 break;
442 } 496 }
443 default: 497 default:
444 break; 498 break;
445 } 499 }
446 return TRUE; 500 return TRUE;
447 } 501 }
448 static FX_FLOAT PDF_Interpolate(FX_FLOAT x, 502 static FX_FLOAT PDF_Interpolate(FX_FLOAT x,
Tom Sepez 2016/02/11 16:48:32 Now that we're in namespace {, don't need static.
449 FX_FLOAT xmin, 503 FX_FLOAT xmin,
450 FX_FLOAT xmax, 504 FX_FLOAT xmax,
451 FX_FLOAT ymin, 505 FX_FLOAT ymin,
452 FX_FLOAT ymax) { 506 FX_FLOAT ymax) {
453 return ((x - xmin) * (ymax - ymin) / (xmax - xmin)) + ymin; 507 return ((x - xmin) * (ymax - ymin) / (xmax - xmin)) + ymin;
454 } 508 }
455 static FX_DWORD _GetBits32(const uint8_t* pData, int bitpos, int nbits) { 509 static FX_DWORD _GetBits32(const uint8_t* pData, int bitpos, int nbits) {
Tom Sepez 2016/02/11 16:48:32 here too
456 int result = 0; 510 int result = 0;
457 for (int i = 0; i < nbits; i++) 511 for (int i = 0; i < nbits; i++)
458 if (pData[(bitpos + i) / 8] & (1 << (7 - (bitpos + i) % 8))) { 512 if (pData[(bitpos + i) / 8] & (1 << (7 - (bitpos + i) % 8))) {
459 result |= 1 << (nbits - i - 1); 513 result |= 1 << (nbits - i - 1);
460 } 514 }
461 return result; 515 return result;
462 } 516 }
463 typedef struct { 517 typedef struct {
Tom Sepez 2016/02/11 16:48:32 nit: as long as we're here, no typedef needed and
464 FX_FLOAT encode_max, encode_min; 518 FX_FLOAT encode_max, encode_min;
465 int sizes; 519 int sizes;
466 } SampleEncodeInfo; 520 } SampleEncodeInfo;
467 typedef struct { FX_FLOAT decode_max, decode_min; } SampleDecodeInfo; 521 typedef struct { FX_FLOAT decode_max, decode_min; } SampleDecodeInfo;
468 522
469 class CPDF_SampledFunc : public CPDF_Function { 523 class CPDF_SampledFunc : public CPDF_Function {
470 public: 524 public:
471 CPDF_SampledFunc(); 525 CPDF_SampledFunc();
472 ~CPDF_SampledFunc() override; 526 ~CPDF_SampledFunc() override;
473 527
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 } 867 }
814 if (!m_pSubFunctions[i]) { 868 if (!m_pSubFunctions[i]) {
815 return FALSE; 869 return FALSE;
816 } 870 }
817 input = PDF_Interpolate(input, m_pBounds[i], m_pBounds[i + 1], 871 input = PDF_Interpolate(input, m_pBounds[i], m_pBounds[i + 1],
818 m_pEncode[i * 2], m_pEncode[i * 2 + 1]); 872 m_pEncode[i * 2], m_pEncode[i * 2 + 1]);
819 int nresults; 873 int nresults;
820 m_pSubFunctions[i]->Call(&input, kRequiredNumInputs, outputs, nresults); 874 m_pSubFunctions[i]->Call(&input, kRequiredNumInputs, outputs, nresults);
821 return TRUE; 875 return TRUE;
822 } 876 }
877
878 } // namespace
879
823 CPDF_Function* CPDF_Function::Load(CPDF_Object* pFuncObj) { 880 CPDF_Function* CPDF_Function::Load(CPDF_Object* pFuncObj) {
824 if (!pFuncObj) { 881 if (!pFuncObj) {
825 return NULL; 882 return NULL;
826 } 883 }
827 CPDF_Function* pFunc = NULL; 884 CPDF_Function* pFunc = NULL;
828 int type; 885 int type;
829 if (CPDF_Stream* pStream = pFuncObj->AsStream()) { 886 if (CPDF_Stream* pStream = pFuncObj->AsStream()) {
830 type = pStream->GetDict()->GetIntegerBy("FunctionType"); 887 type = pStream->GetDict()->GetIntegerBy("FunctionType");
831 } else if (CPDF_Dictionary* pDict = pFuncObj->AsDictionary()) { 888 } else if (CPDF_Dictionary* pDict = pFuncObj->AsDictionary()) {
832 type = pDict->GetIntegerBy("FunctionType"); 889 type = pDict->GetIntegerBy("FunctionType");
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 for (int i = 0; i < m_nOutputs; i++) { 973 for (int i = 0; i < m_nOutputs; i++) {
917 if (results[i] < m_pRanges[i * 2]) { 974 if (results[i] < m_pRanges[i * 2]) {
918 results[i] = m_pRanges[i * 2]; 975 results[i] = m_pRanges[i * 2];
919 } else if (results[i] > m_pRanges[i * 2 + 1]) { 976 } else if (results[i] > m_pRanges[i * 2 + 1]) {
920 results[i] = m_pRanges[i * 2 + 1]; 977 results[i] = m_pRanges[i * 2 + 1];
921 } 978 }
922 } 979 }
923 } 980 }
924 return TRUE; 981 return TRUE;
925 } 982 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698