source: trunk/poppler/mypoppler/poppler/Function.h @ 461

Last change on this file since 461 was 277, checked in by rbri, 12 years ago

PDF plugin: Poppler library updated to version 0.12.3

File size: 6.7 KB
Line 
1//========================================================================
2//
3// Function.h
4//
5// Copyright 2001-2003 Glyph & Cog, LLC
6//
7//========================================================================
8
9//========================================================================
10//
11// Modified under the Poppler project - http://poppler.freedesktop.org
12//
13// All changes made under the Poppler project to this file are licensed
14// under GPL version 2 or later
15//
16// Copyright (C) 2009 Albert Astals Cid <aacid@kde.org>
17//
18// To see a description of the changes please see the Changelog file that
19// came with your tarball or type make ChangeLog if you are building from git
20//
21//========================================================================
22
23#ifndef FUNCTION_H
24#define FUNCTION_H
25
26#ifdef USE_GCC_PRAGMAS
27#pragma interface
28#endif
29
30#include "goo/gtypes.h"
31#include "Object.h"
32
33class Dict;
34class Stream;
35struct PSObject;
36class PSStack;
37class PopplerCache;
38
39//------------------------------------------------------------------------
40// Function
41//------------------------------------------------------------------------
42
43#define funcMaxInputs        32
44#define funcMaxOutputs       32
45#define sampledFuncMaxInputs 16
46
47class Function {
48public:
49
50  Function();
51
52  virtual ~Function();
53
54  // Construct a function.  Returns NULL if unsuccessful.
55  static Function *parse(Object *funcObj);
56
57  // Initialize the entries common to all function types.
58  GBool init(Dict *dict);
59
60  virtual Function *copy() = 0;
61
62  // Return the function type:
63  //   -1 : identity
64  //    0 : sampled
65  //    2 : exponential
66  //    3 : stitching
67  //    4 : PostScript
68  virtual int getType() = 0;
69
70  // Return size of input and output tuples.
71  int getInputSize() { return m; }
72  int getOutputSize() { return n; }
73
74  double getDomainMin(int i) { return domain[i][0]; }
75  double getDomainMax(int i) { return domain[i][1]; }
76  double getRangeMin(int i) { return range[i][0]; }
77  double getRangeMax(int i) { return range[i][1]; }
78  GBool getHasRange() { return hasRange; }
79
80  // Transform an input tuple into an output tuple.
81  virtual void transform(double *in, double *out) = 0;
82
83  virtual GBool isOk() = 0;
84
85protected:
86
87  int m, n;                     // size of input and output tuples
88  double                        // min and max values for function domain
89    domain[funcMaxInputs][2];
90  double                        // min and max values for function range
91    range[funcMaxOutputs][2];
92  GBool hasRange;               // set if range is defined
93};
94
95//------------------------------------------------------------------------
96// IdentityFunction
97//------------------------------------------------------------------------
98
99class IdentityFunction: public Function {
100public:
101
102  IdentityFunction();
103  virtual ~IdentityFunction();
104  virtual Function *copy() { return new IdentityFunction(); }
105  virtual int getType() { return -1; }
106  virtual void transform(double *in, double *out);
107  virtual GBool isOk() { return gTrue; }
108
109private:
110};
111
112//------------------------------------------------------------------------
113// SampledFunction
114//------------------------------------------------------------------------
115
116class SampledFunction: public Function {
117public:
118
119  SampledFunction(Object *funcObj, Dict *dict);
120  virtual ~SampledFunction();
121  virtual Function *copy() { return new SampledFunction(this); }
122  virtual int getType() { return 0; }
123  virtual void transform(double *in, double *out);
124  virtual GBool isOk() { return ok; }
125
126  int getSampleSize(int i) { return sampleSize[i]; }
127  double getEncodeMin(int i) { return encode[i][0]; }
128  double getEncodeMax(int i) { return encode[i][1]; }
129  double getDecodeMin(int i) { return decode[i][0]; }
130  double getDecodeMax(int i) { return decode[i][1]; }
131  double *getSamples() { return samples; }
132
133private:
134
135  SampledFunction(SampledFunction *func);
136
137  int                           // number of samples for each domain element
138    sampleSize[funcMaxInputs];
139  double                        // min and max values for domain encoder
140    encode[funcMaxInputs][2];
141  double                        // min and max values for range decoder
142    decode[funcMaxOutputs][2];
143  double                        // input multipliers
144    inputMul[funcMaxInputs];
145  int idxMul[funcMaxInputs];    // sample array index multipliers
146  double *samples;              // the samples
147  int nSamples;                 // size of the samples array
148  double *sBuf;                 // buffer for the transform function
149  GBool ok;
150};
151
152//------------------------------------------------------------------------
153// ExponentialFunction
154//------------------------------------------------------------------------
155
156class ExponentialFunction: public Function {
157public:
158
159  ExponentialFunction(Object *funcObj, Dict *dict);
160  virtual ~ExponentialFunction();
161  virtual Function *copy() { return new ExponentialFunction(this); }
162  virtual int getType() { return 2; }
163  virtual void transform(double *in, double *out);
164  virtual GBool isOk() { return ok; }
165
166  double *getC0() { return c0; }
167  double *getC1() { return c1; }
168  double getE() { return e; }
169
170private:
171
172  ExponentialFunction(ExponentialFunction *func);
173
174  double c0[funcMaxOutputs];
175  double c1[funcMaxOutputs];
176  double e;
177  GBool ok;
178};
179
180//------------------------------------------------------------------------
181// StitchingFunction
182//------------------------------------------------------------------------
183
184class StitchingFunction: public Function {
185public:
186
187  StitchingFunction(Object *funcObj, Dict *dict);
188  virtual ~StitchingFunction();
189  virtual Function *copy() { return new StitchingFunction(this); }
190  virtual int getType() { return 3; }
191  virtual void transform(double *in, double *out);
192  virtual GBool isOk() { return ok; }
193
194  int getNumFuncs() { return k; }
195  Function *getFunc(int i) { return funcs[i]; }
196  double *getBounds() { return bounds; }
197  double *getEncode() { return encode; }
198  double *getScale() { return scale; }
199
200private:
201
202  StitchingFunction(StitchingFunction *func);
203
204  int k;
205  Function **funcs;
206  double *bounds;
207  double *encode;
208  double *scale;
209  GBool ok;
210};
211
212//------------------------------------------------------------------------
213// PostScriptFunction
214//------------------------------------------------------------------------
215
216class PostScriptFunction: public Function {
217public:
218
219  PostScriptFunction(Object *funcObj, Dict *dict);
220  virtual ~PostScriptFunction();
221  virtual Function *copy() { return new PostScriptFunction(this); }
222  virtual int getType() { return 4; }
223  virtual void transform(double *in, double *out);
224  virtual GBool isOk() { return ok; }
225
226  GooString *getCodeString() { return codeString; }
227
228private:
229
230  PostScriptFunction(PostScriptFunction *func);
231  GBool parseCode(Stream *str, int *codePtr);
232  GooString *getToken(Stream *str);
233  void resizeCode(int newSize);
234  void exec(PSStack *stack, int codePtr);
235
236  GooString *codeString;
237  PSObject *code;
238  PSStack *stack;
239  int codeSize;
240  GBool ok;
241  PopplerCache *cache;
242};
243
244#endif
Note: See TracBrowser for help on using the repository browser.