Class PDFFunction
java.lang.Object
org.loboevolution.pdfview.function.PDFFunction
- Direct Known Subclasses:
FunctionType0
,FunctionType2
,FunctionType3
,FunctionType4
PDF Functions are defined in the reference as Section 3.9.
A PDF function maps some set of m inputs into some set of n outputs. There are 4 types of functions:
- Type 0: Sampled functions. (PDF 1.2)
A sampled function (type 0) uses a table of sample values to define the function. Various techniques are used to interpolate values between the sample values (see Section 3.9.1, "Type 0 (Sampled) Functions"). - Type 2: Exponential Interpolation. (PDF 1.3)
An exponential interpolation function (type 2) defines a set of coefficients for an exponential function (see Section 3.9.2, "Type 2 (Exponential Interpolation) Functions"). - Type 3: Stitching functions. (PDF 1.3)
A stitching function (type 3) is a combination of other functions, partitioned across a domain (see Section 3.9.3, "Type 3 (Stitching) Functions"). - Type 4: Postscript calculations. (PDF 1.3)
A PostScript calculator function (type 4) uses operators from the PostScript language to describe an arithmetic expression (see Section 3.9.4, "Type 4 (PostScript Calculator) Functions").
The function interface contains a single method, calculate which takes an array of m floats an interprets them into an array of n floats. PDFFunctions do not have accessible constructors. Instead, use the static getFunction() method to read a functions from a PDF Object.
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
PDFFunction
(int type) Creates a new instance of PDFFunction -
Method Summary
Modifier and TypeMethodDescriptionfloat[]
calculate
(float[] inputs) Map from m input values to n output values.float[]
calculate
(float[] inputs, int inputOffset, float[] outputs, int outputOffset) Map from m input values to n output values.protected abstract void
doFunction
(float[] inputs, int inputOffset, float[] outputs, int outputOffset) Subclasses must implement this method to perform the actual function on the given set of data.protected float
getDomain
(int i) Get a component of the domain of this functionstatic PDFFunction
getFunction
(PDFObject obj) Get a PDFFunction from a PDFObjectint
Get the number of inputs, m, required by this functionint
Get the number of outputs, n, returned by this functionprotected float
getRange
(int i) Get a component of the range of this functionstatic float
interpolate
(float x, float xmin, float xmax, float ymin, float ymax) Perform a linear interpolation.protected abstract void
Read the function information from a PDF Object
-
Field Details
-
TYPE_0
public static final int TYPE_0Sampled function- See Also:
-
TYPE_2
public static final int TYPE_2Exponential interpolation function- See Also:
-
TYPE_3
public static final int TYPE_3Stitching function.- See Also:
-
TYPE_4
public static final int TYPE_4PostScript calculator function.- See Also:
-
-
Constructor Details
-
PDFFunction
protected PDFFunction(int type) Creates a new instance of PDFFunction- Parameters:
type
- aInteger
object.
-
-
Method Details
-
getFunction
Get a PDFFunction from a PDFObject- Parameters:
obj
- aPDFObject
object.- Returns:
- a
PDFFunction
object. - Throws:
IOException
- if any.
-
interpolate
public static float interpolate(float x, float xmin, float xmax, float ymin, float ymax) Perform a linear interpolation. Given a value x, and two points, (xmin, ymin), (xmax, ymax), where xmin <= x <= xmax, calculate a value y on the line from (xmin, ymin) to (xmax, ymax).- Parameters:
x
- the x value of the inputxmin
- the minimum x valuexmax
- the maximum x valueymin
- the minimum y valueymax
- the maximum y value- Returns:
- the y value interpolated from the given x
-
getNumInputs
public int getNumInputs()Get the number of inputs, m, required by this function- Returns:
- the number of input values expected by this function
-
getNumOutputs
public int getNumOutputs()Get the number of outputs, n, returned by this function- Returns:
- the number of output values this function will return
-
getDomain
protected float getDomain(int i) Get a component of the domain of this function- Parameters:
i
- the index into the domain array, which has size 2 * m. the ith entry in the array has index 2i, 2i + 1- Returns:
- the ith entry in the domain array
-
getRange
protected float getRange(int i) Get a component of the range of this function- Parameters:
i
- the index into the range array, which has size 2 * n. the ith entry in the array has index 2i, 2i + 1- Returns:
- the ith entry in the range array
-
calculate
public float[] calculate(float[] inputs) Map from m input values to n output values. The number of inputs m must be exactly one half the size of the domain. The number of outputs should match one half the size of the range.- Parameters:
inputs
- an array of >= m input values- Returns:
- the array of n output values
-
calculate
public float[] calculate(float[] inputs, int inputOffset, float[] outputs, int outputOffset) Map from m input values to n output values. The number of inputs m must be exactly one half the size of the domain. The number of outputs should match one half the size of the range.- Parameters:
inputs
- an array of >= m input valuesinputOffset
- the offset into the input array to read fromoutputs
- an array of size >= n which will be filled with the output valuesoutputOffset
- the offset into the output array to write to- Returns:
- the array of n output values
-
doFunction
protected abstract void doFunction(float[] inputs, int inputOffset, float[] outputs, int outputOffset) Subclasses must implement this method to perform the actual function on the given set of data. Note that the inputs are guaranteed to be clipped to the domain, while the outputs will be automatically clipped to the range after being returned from this function.- Parameters:
inputs
- an array ofinvalid reference
float
inputOffset
- the offset into the inputs array to read fromoutputs
- guaranteed to be at least as big asgetNumOutputs()
, but not yet clipped to domainoutputOffset
- the offset into the output array to write to
-
parse
Read the function information from a PDF Object- Parameters:
obj
- aPDFObject
object.- Throws:
IOException
- if any.
-