Package com.sun.pdfview.function
Class FunctionType0
- java.lang.Object
-
- com.sun.pdfview.function.PDFFunction
-
- com.sun.pdfview.function.FunctionType0
-
public class FunctionType0 extends PDFFunction
A sampled function maps input values to output values by interpolating along a line or cubic between two known values.
-
-
Field Summary
Fields Modifier and Type Field Description private int
bitsPerSample
the number of bits in each sampleprotected static int
CUBIC_INTERPOLATION
private float[]
decode
the optional decoding array, tells how to map output parameters to valuesprivate float[]
encode
the optional encoding array, tells how to map input parameters to valuesprotected static int
LINEAR_INTERPOLATION
the valid interpolation methodsprivate int
order
the interpolation type, from the list aboveprivate int[][]
samples
the actual samples, converted to integers.private int[]
size
the size of each input dimension, as an array of m integers-
Fields inherited from class com.sun.pdfview.function.PDFFunction
TYPE_0, TYPE_2, TYPE_3, TYPE_4
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
FunctionType0()
Creates a new instance of FunctionType0
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doFunction(float[] inputs, int inputOffset, float[] outputs, int outputOffset)
Map from m input values to n output values.protected int
getBitsPerSample()
Get the number of bits per sampleprotected float
getDecode(int i)
Get the decoding for a particular input parameterprotected float
getEncode(int i)
Get the encoding for a particular input parameterprotected int
getOrder()
Get the interpolation typeprivate float
getSample(float[] encoded, int map, int od)
Get a sample based on an array of encoded values and a control map.protected int
getSample(int[] values, int od)
Get a component for a sample given m indices and output dimension.protected int
getSize(int dimension)
Get the size of a given input dimensionstatic float
interpolate(float x, float xmin, float xmax, float ymin, float ymax)
Perform a linear interpolation.private float
multicubicInterpolate(float[] encoded, int od)
Perform a multicubic interpolationprivate float
multilinearInterpolate(float[] encoded, int od)
Perform a piecewise multilinear interpolation.protected void
parse(PDFObject obj)
Read the function information from a PDF Objectprivate int[][]
readSamples(java.nio.ByteBuffer buf)
Read the samples from the input stream.protected void
setBitsPerSample(int bits)
Set the number of bits per sampleprotected void
setDecode(float[] decode)
Set the decode arrayprotected void
setEncode(float[] encode)
Set the encode arrayprotected void
setOrder(int order)
Set the interpolation typeprotected void
setSamples(int[][] samples)
Set the table of samplesprotected void
setSize(int[] size)
Set the size of all input dimensions-
Methods inherited from class com.sun.pdfview.function.PDFFunction
calculate, calculate, getDomain, getFunction, getNumInputs, getNumOutputs, getRange, getType, setDomain, setRange
-
-
-
-
Field Detail
-
LINEAR_INTERPOLATION
protected static final int LINEAR_INTERPOLATION
the valid interpolation methods- See Also:
- Constant Field Values
-
CUBIC_INTERPOLATION
protected static final int CUBIC_INTERPOLATION
- See Also:
- Constant Field Values
-
size
private int[] size
the size of each input dimension, as an array of m integers
-
bitsPerSample
private int bitsPerSample
the number of bits in each sample
-
order
private int order
the interpolation type, from the list above
-
encode
private float[] encode
the optional encoding array, tells how to map input parameters to values
-
decode
private float[] decode
the optional decoding array, tells how to map output parameters to values
-
samples
private int[][] samples
the actual samples, converted to integers. The first index is input values (from 0 to size[m - 1] * size[m - 2] * ... * size[0]), and the second is the output dimension within the sample (from 0 to n)
-
-
Method Detail
-
parse
protected void parse(PDFObject obj) throws java.io.IOException
Read the function information from a PDF Object- Specified by:
parse
in classPDFFunction
- Throws:
java.io.IOException
-
doFunction
protected void doFunction(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.- Specified by:
doFunction
in classPDFFunction
- Parameters:
inputs
- an array of m input valuesoutputs
- an array of size n which will be filled with the output values, or null to return a new arrayinputOffset
- the offset into the inputs array to read fromoutputOffset
- the offset into the output array to write to
-
getSize
protected int getSize(int dimension)
Get the size of a given input dimension- Parameters:
dimension
- the input dimension to get the size of- Returns:
- the number of samples in the given dimension
-
setSize
protected void setSize(int[] size)
Set the size of all input dimensions
-
getBitsPerSample
protected int getBitsPerSample()
Get the number of bits per sample
-
setBitsPerSample
protected void setBitsPerSample(int bits)
Set the number of bits per sample
-
getOrder
protected int getOrder()
Get the interpolation type
-
setOrder
protected void setOrder(int order)
Set the interpolation type
-
getEncode
protected float getEncode(int i)
Get the encoding for a particular input parameter- Parameters:
i
- the index into the encoding array, which has size 2 * m. the ith entry in the array has index 2i, 2i + 1- Returns:
- the encoding value if the encoding array is set, or the default
-
setEncode
protected void setEncode(float[] encode)
Set the encode array
-
getDecode
protected float getDecode(int i)
Get the decoding for a particular input parameter- Parameters:
i
- the index into the decoding array, which has size 2 * n. the ith entry in the array has index 2i, 2i + 1- Returns:
- the decoding value if the decoding array is set, or the default
-
setDecode
protected void setDecode(float[] decode)
Set the decode array
-
getSample
protected int getSample(int[] values, int od)
Get a component for a sample given m indices and output dimension.- Parameters:
values
- an array of m values determining which sample to selectod
- the output dimension (0 - n) to get the sample in- Returns:
- the sample for the given values and index
-
setSamples
protected void setSamples(int[][] samples)
Set the table of samples
-
readSamples
private int[][] readSamples(java.nio.ByteBuffer buf)
Read the samples from the input stream. Each sample is made up of n components, each of which has length bitsPerSample bits. The samples are arranged by dimension, then range
-
multilinearInterpolate
private float multilinearInterpolate(float[] encoded, int od)
Perform a piecewise multilinear interpolation. The provides a close approximation to the standard linear interpolation, at a far lower cost, since every element is not evaluated at every iteration. Instead, a walk of the most significant axes is performed, following the algorithm desribed at: http://osl.iu.edu/~tveldhui/papers/MAScThesis/node33.html- Parameters:
encoded
- the encoded input valuesod
- the output dimension
-
multicubicInterpolate
private float multicubicInterpolate(float[] encoded, int od)
Perform a multicubic interpolation- Parameters:
encoded
- the encoded input valuesod
- the output dimension
-
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 valueymin
- the minimum y valuexmax
- the maximum x valueymax
- the maximum y value- Returns:
- the y value interpolated from the given x
-
getSample
private float getSample(float[] encoded, int map, int od)
Get a sample based on an array of encoded values and a control map. For each bit in the map, if that bit is 0 the integer below the encoded value is selected, or if the bit is 1, the interger above is selected.- Parameters:
encoded
- the encoded valuesmap
- the bit map of control valuesod
- the output dimension to read the sample for
-
-