Class PdfType0Function

All Implemented Interfaces:
IPdfFunction

public class PdfType0Function extends AbstractPdfFunction<PdfStream>
  • Field Details

    • 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 String errorMessage
    • derivatives

      private double[][] derivatives
  • Constructor Details

    • 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 Details

    • 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 interface IPdfFunction
      Overrides:
      checkCompatibilityWithColorSpace in class AbstractPdfFunction<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 interface IPdfFunction
      Overrides:
      setDomain in class AbstractPdfFunction<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 interface IPdfFunction
      Overrides:
      setRange in class AbstractPdfFunction<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 contain IPdfFunction.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 value
      encodeMin - encode min value
      encodeMax - 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 domain
      encode - 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 coordinates
      size - 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 domain
      encode - 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 component
      encodeMin - encode min value
      encodeMax - 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 value
      dim - output dimension coordinate (values from [0, ..., outputDimension - 1])
      Returns:
      decoded value
    • setErrorMessage

      private void setErrorMessage(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 points
      f0 - function value at the left neighbouring point
      f1 - 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 points
      f0 - function value at the next to left neighbouring point
      f1 - function value at the left neighbouring point
      f2 - function value at the right neighbouring point
      f3 - 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 points
      f0 - function value in the left neighbouring point
      f1 - function value in the right neighbouring point
      d0 - second derivative value in the left neighbouring point
      d1 - second derivative value in the right neighbouring point
      Returns:
      function value interpolated by cubic spline formula