Package com.itextpdf.kernel.pdf.function
Class PdfType0Function
- java.lang.Object
-
- com.itextpdf.kernel.pdf.PdfObjectWrapper<T>
-
- com.itextpdf.kernel.pdf.function.AbstractPdfFunction<PdfStream>
-
- com.itextpdf.kernel.pdf.function.PdfType0Function
-
- All Implemented Interfaces:
IPdfFunction
public class PdfType0Function extends AbstractPdfFunction<PdfStream>
-
-
Field Summary
Fields Modifier and Type Field Description private int
bitsPerSample
private double[]
decode
private long
decodeLimit
private double[][]
derivatives
private int[]
encode
private java.lang.String
errorMessage
private boolean
isValidated
private int
order
private int
outputDimension
private AbstractSampleExtractor
sampleExtractor
private byte[]
samples
private int[]
size
-
Constructor Summary
Constructors Constructor Description PdfType0Function(double[] domain, int[] size, double[] range, int order, int[] encode, double[] decode, int bitsPerSample, byte[] samples)
PdfType0Function(double[] domain, int[] size, double[] range, int order, int bitsPerSample, byte[] samples)
PdfType0Function(float[] domain, int[] size, float[] range, int order, int bitsPerSample, byte[] samples)
PdfType0Function(PdfStream pdfObject)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description double[]
calculate(double[] input)
Calculates one set of input components to one set of output components.private static double
calculateCubicInterpolationFormula(double x, double f0, double f1, double f2, double f3)
Interpolates function by cubic interpolation formula using function values at neighbouring points.private static double
calculateCubicSplineFormula(double x, double f0, double f1, double d0, double d1)
Interpolates function by cubic spline formula using function and its second derivative values at neighbouring points.private double[]
calculateCubicSplineFormula(double x, int position)
private static double
calculateLinearInterpolationFormula(double x, double f0, double f1)
Interpolates function by linear interpolation formula using function values at neighbouring points.private void
calculateSecondDerivatives()
Calculates second derivatives at each interpolation point by sweep method with 3-diagonal matrix.boolean
checkCompatibilityWithColorSpace(PdfColorSpace alternateSpace)
Chacks wether the output of the function matches in components with the passed by color space.private double
decode(long x, int dim)
Decode sampled value.(package private) static double
encode(double normal, int encodeMin, int encodeMax)
Encode normalized input value.double[]
getDecode()
private int[]
getDefaultEncoding()
int[]
getEncode()
(package private) static int[]
getFloor(double[] normal, int[] encode)
Calculates floor sample coordinates for the normalized input array.(package private) static double
getFloorWeight(double normal, int encodeMin, int encodeMax)
Calculates normalized distance from input value to the nearest left interpolation point.(package private) static double[]
getFloorWeights(double[] normal, int[] encode)
Calculated component-by-component normalized distances from input array to the nearest left interpolation point.private int[]
getInputDimensionSteps()
Gets a minimal distance between samples of same dimension in samples table for each dimension.int
getOrder()
(package private) static int
getSamplePosition(int[] sample, int[] size)
Maps sample coordinates to linear position in samples table.int[]
getSize()
private double
getValue(int dim, int pos)
Calculates function decoded values.private void
initializeEncoding(int[] encode)
private void
initializeEncoding(PdfArray encodeObj)
private double[]
interpolate(double[] normal, int[] floor)
private double[]
interpolateByCubicSpline(double normal, int position)
private double
interpolateOrder1(double[] x, int floorPosition, int[] steps, int inDim, int outDim)
private double
interpolateOrder3(double[] x, int[] floor, int floorPosition, int[] steps, int inDim, int outDim)
private boolean
isInvalid()
void
setDecode(double[] decode)
void
setDomain(double[] domain)
The valid input domain, input will be clipped to this domain contains a min max pair per input component.void
setEncode(int[] encode)
private void
setErrorMessage(java.lang.String message)
void
setOrder(int order)
void
setRange(double[] range)
the valid output range, output will be clipped to this range contains a min max pair per output component.void
setSize(int[] size)
(package private) static double[]
specialSweepMethod(double[] f)
Solves the system of linear equations by sweep method where the matrix is 3-diagonal.-
Methods inherited from class com.itextpdf.kernel.pdf.function.AbstractPdfFunction
calculateFromByteArray, calculateFromByteArray, clip, clipInput, clipOutput, convertFloatArrayToDoubleArray, getAsPdfObject, getDomain, getFunctionType, getInputSize, getOutputSize, getRange, isWrappedObjectMustBeIndirect, normalize
-
Methods inherited from class com.itextpdf.kernel.pdf.PdfObjectWrapper
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, flush, getPdfObject, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
-
-
-
-
Field Detail
-
size
private int[] size
-
order
private int order
-
encode
private int[] encode
-
decode
private double[] decode
-
bitsPerSample
private int bitsPerSample
-
sampleExtractor
private AbstractSampleExtractor sampleExtractor
-
samples
private byte[] samples
-
outputDimension
private int outputDimension
-
decodeLimit
private long decodeLimit
-
isValidated
private boolean isValidated
-
errorMessage
private java.lang.String errorMessage
-
derivatives
private double[][] derivatives
-
-
Constructor Detail
-
PdfType0Function
public PdfType0Function(PdfStream pdfObject)
-
PdfType0Function
public PdfType0Function(double[] domain, int[] size, double[] range, int order, int bitsPerSample, byte[] samples)
-
PdfType0Function
public PdfType0Function(float[] domain, int[] size, float[] range, int order, int bitsPerSample, byte[] samples)
-
PdfType0Function
public PdfType0Function(double[] domain, int[] size, double[] range, int order, int[] encode, double[] decode, int bitsPerSample, byte[] samples)
-
-
Method Detail
-
getOrder
public int getOrder()
-
setOrder
public void setOrder(int order)
-
getSize
public int[] getSize()
-
setSize
public void setSize(int[] size)
-
getEncode
public int[] getEncode()
-
setEncode
public void setEncode(int[] encode)
-
getDecode
public double[] getDecode()
-
setDecode
public void setDecode(double[] decode)
-
checkCompatibilityWithColorSpace
public boolean checkCompatibilityWithColorSpace(PdfColorSpace alternateSpace)
Description copied from class:AbstractPdfFunction
Chacks wether the output of the function matches in components with the passed by color space.- Specified by:
checkCompatibilityWithColorSpace
in interfaceIPdfFunction
- Overrides:
checkCompatibilityWithColorSpace
in classAbstractPdfFunction<PdfStream>
- Parameters:
alternateSpace
- The color space to verify against- Returns:
- True when compatible
-
setDomain
public void setDomain(double[] domain)
Description copied from class:AbstractPdfFunction
The valid input domain, input will be clipped to this domain contains a min max pair per input component.(see ISO-320001 Table 38)
- Specified by:
setDomain
in interfaceIPdfFunction
- Overrides:
setDomain
in classAbstractPdfFunction<PdfStream>
- Parameters:
domain
- the new set of limits
-
setRange
public void setRange(double[] range)
Description copied from class:AbstractPdfFunction
the valid output range, output will be clipped to this range contains a min max pair per output component.(see ISO-320001 Table 38)
- Specified by:
setRange
in interfaceIPdfFunction
- Overrides:
setRange
in classAbstractPdfFunction<PdfStream>
- Parameters:
range
- the new set of limts
-
calculate
public double[] calculate(double[] input)
Description copied from interface:IPdfFunction
Calculates one set of input components to one set of output components.- Parameters:
input
- The input values size must containIPdfFunction.getInputSize()
items- Returns:
- an array the size of
IPdfFunction.getOutputSize()
items containing the result
-
encode
static double encode(double normal, int encodeMin, int encodeMax)
Encode normalized input value.- Parameters:
normal
- input normalized valueencodeMin
- encode min valueencodeMax
- encode max value- Returns:
- encoded value
-
getFloor
static int[] getFloor(double[] normal, int[] encode)
Calculates floor sample coordinates for the normalized input array.- Parameters:
normal
- input array normalized to domainencode
- encode mapping- Returns:
- encoded sample coordinates of the nearest left interpolation point
-
getSamplePosition
static int getSamplePosition(int[] sample, int[] size)
Maps sample coordinates to linear position in samples table.- Parameters:
sample
- sample encoded coordinatessize
- number of samples in each input dimension- Returns:
- position in samples table
-
getFloorWeights
static double[] getFloorWeights(double[] normal, int[] encode)
Calculated component-by-component normalized distances from input array to the nearest left interpolation point. Input array shall be normalized to domain- Parameters:
normal
- input array normalized to domainencode
- encode mapping- Returns:
- component-by-component normalized distances from input array to the nearest left interpolation point
-
getFloorWeight
static double getFloorWeight(double normal, int encodeMin, int encodeMax)
Calculates normalized distance from input value to the nearest left interpolation point. Input value shall be normalized to domain component- Parameters:
normal
- input value normalized to domain componentencodeMin
- encode min valueencodeMax
- encode max value- Returns:
- normalized distance from input value to the nearest left interpolation point
-
specialSweepMethod
static double[] specialSweepMethod(double[] f)
Solves the system of linear equations by sweep method where the matrix is 3-diagonal. Main diagonal elements are 4, lower and upper diagonals: 1.x[0] = 0, x[0] + 4*x[1] + x[2] = f[0], x[1] + 4*x[2] + x[3] = f[1], ... x[n-1] + 4*x[n] + x[n+1] = f[n-1], x[n] = 0
- Parameters:
f
- right hand side- Returns:
- solution, first and last values are zeroes
-
initializeEncoding
private void initializeEncoding(PdfArray encodeObj)
-
initializeEncoding
private void initializeEncoding(int[] encode)
-
getDefaultEncoding
private int[] getDefaultEncoding()
-
interpolate
private double[] interpolate(double[] normal, int[] floor)
-
interpolateOrder1
private double interpolateOrder1(double[] x, int floorPosition, int[] steps, int inDim, int outDim)
-
interpolateOrder3
private double interpolateOrder3(double[] x, int[] floor, int floorPosition, int[] steps, int inDim, int outDim)
-
interpolateByCubicSpline
private double[] interpolateByCubicSpline(double normal, int position)
-
calculateCubicSplineFormula
private double[] calculateCubicSplineFormula(double x, int position)
-
calculateSecondDerivatives
private void calculateSecondDerivatives()
Calculates second derivatives at each interpolation point by sweep method with 3-diagonal matrix.
-
getValue
private double getValue(int dim, int pos)
Calculates function decoded values.Function values are stored sequentially in samples table. For a function with multidimensional input (more than one input variables), the sample values in the first dimension vary fastest, and the values in the last dimension vary slowest. Order example for size array [4, 4, 4]: f(0,0,0), f(1,0,0), f(2,0,0), f(3,0,0), f(0,1,0), f(1,1,0), ..., f(3,3,0), f(3,3,1), f(3,3,2), f(3,3,3). For example in this case f(1,1,0) has position 5. If the function has multiple output values each value shall occupy bitsPerSample bits and stored sequentially as well.
- Parameters:
dim
- output dimension coordinate (values from [0, ..., outputDimension - 1])pos
- position in samples table- Returns:
- function decoded value
-
getInputDimensionSteps
private int[] getInputDimensionSteps()
Gets a minimal distance between samples of same dimension in samples table for each dimension.- Returns:
- for each dimension a minimal distance between samples of same dimension in samples table
-
decode
private double decode(long x, int dim)
Decode sampled value.- Parameters:
x
- sampled valuedim
- output dimension coordinate (values from [0, ..., outputDimension - 1])- Returns:
- decoded value
-
setErrorMessage
private void setErrorMessage(java.lang.String message)
-
isInvalid
private boolean isInvalid()
-
calculateLinearInterpolationFormula
private static double calculateLinearInterpolationFormula(double x, double f0, double f1)
Interpolates function by linear interpolation formula using function values at neighbouring points.- Parameters:
x
- input normalized to [0, 1] by neighbouring pointsf0
- function value at the left neighbouring pointf1
- function value at the right neighbouring point- Returns:
- function value obtained by linear interpolation
-
calculateCubicInterpolationFormula
private static double calculateCubicInterpolationFormula(double x, double f0, double f1, double f2, double f3)
Interpolates function by cubic interpolation formula using function values at neighbouring points.- Parameters:
x
- input normalized to [0, 1] by neighbouring pointsf0
- function value at the next to left neighbouring pointf1
- function value at the left neighbouring pointf2
- function value at the right neighbouring pointf3
- function value at the next to right neighbouring point- Returns:
- function value obtained by cubic interpolation
-
calculateCubicSplineFormula
private static double calculateCubicSplineFormula(double x, double f0, double f1, double d0, double d1)
Interpolates function by cubic spline formula using function and its second derivative values at neighbouring points.- Parameters:
x
- input normalized to [0, 1] by neighbouring pointsf0
- function value in the left neighbouring pointf1
- function value in the right neighbouring pointd0
- second derivative value in the left neighbouring pointd1
- second derivative value in the right neighbouring point- Returns:
- function value interpolated by cubic spline formula
-
-