use of org.apache.pdfbox.pdmodel.common.PDRange in project pdfbox by apache.
the class PDFunctionType0 method getDecodeForParameter.
/**
* Get the decode for the input parameter.
*
* @param paramNum The function parameter number.
*
* @return The decode parameter range or null if none is set.
*/
public PDRange getDecodeForParameter(int paramNum) {
PDRange retval = null;
COSArray decodeValues = getDecodeValues();
if (decodeValues != null && decodeValues.size() >= paramNum * 2 + 1) {
retval = new PDRange(decodeValues, paramNum);
}
return retval;
}
use of org.apache.pdfbox.pdmodel.common.PDRange in project pdfbox by apache.
the class PDFunctionType0 method getEncodeForParameter.
/**
* Get the encode for the input parameter.
*
* @param paramNum The function parameter number.
*
* @return The encode parameter range or null if none is set.
*/
public PDRange getEncodeForParameter(int paramNum) {
PDRange retval = null;
COSArray encodeValues = getEncodeValues();
if (encodeValues != null && encodeValues.size() >= paramNum * 2 + 1) {
retval = new PDRange(encodeValues, paramNum);
}
return retval;
}
use of org.apache.pdfbox.pdmodel.common.PDRange in project pdfbox by apache.
the class PDFunctionType3 method eval.
/**
* {@inheritDoc}
*/
@Override
public float[] eval(float[] input) throws IOException {
// This function is known as a "stitching" function. Based on the input, it decides which child function to call.
// All functions in the array are 1-value-input functions
// See PDF Reference section 3.9.3.
PDFunction function = null;
float x = input[0];
PDRange domain = getDomainForInput(0);
// clip input value to domain
x = clipToRange(x, domain.getMin(), domain.getMax());
if (functionsArray == null) {
COSArray ar = getFunctions();
functionsArray = new PDFunction[ar.size()];
for (int i = 0; i < ar.size(); ++i) {
functionsArray[i] = PDFunction.create(ar.getObject(i));
}
}
if (functionsArray.length == 1) {
// This doesn't make sense but it may happen ...
function = functionsArray[0];
PDRange encRange = getEncodeForParameter(0);
x = interpolate(x, domain.getMin(), domain.getMax(), encRange.getMin(), encRange.getMax());
} else {
if (boundsValues == null) {
boundsValues = getBounds().toFloatArray();
}
int boundsSize = boundsValues.length;
// create a combined array containing the domain and the bounds values
// domain.min, bounds[0], bounds[1], ...., bounds[boundsSize-1], domain.max
float[] partitionValues = new float[boundsSize + 2];
int partitionValuesSize = partitionValues.length;
partitionValues[0] = domain.getMin();
partitionValues[partitionValuesSize - 1] = domain.getMax();
System.arraycopy(boundsValues, 0, partitionValues, 1, boundsSize);
// find the partition
for (int i = 0; i < partitionValuesSize - 1; i++) {
if (x >= partitionValues[i] && (x < partitionValues[i + 1] || (i == partitionValuesSize - 2 && Float.compare(x, partitionValues[i + 1]) == 0))) {
function = functionsArray[i];
PDRange encRange = getEncodeForParameter(i);
x = interpolate(x, partitionValues[i], partitionValues[i + 1], encRange.getMin(), encRange.getMax());
break;
}
}
if (function == null) {
throw new IOException("partition not found in type 3 function");
}
}
float[] functionValues = new float[] { x };
// calculate the output values using the chosen function
float[] functionResult = function.eval(functionValues);
// clip to range if available
return clipToRange(functionResult);
}
use of org.apache.pdfbox.pdmodel.common.PDRange in project pdfbox by apache.
the class PDFunctionType4 method eval.
/**
* {@inheritDoc}
*/
@Override
public float[] eval(float[] input) throws IOException {
// Setup the input values
ExecutionContext context = new ExecutionContext(OPERATORS);
for (int i = 0; i < input.length; i++) {
PDRange domain = getDomainForInput(i);
float value = clipToRange(input[i], domain.getMin(), domain.getMax());
context.getStack().push(value);
}
// Execute the type 4 function.
instructions.execute(context);
// Extract the output values
int numberOfOutputValues = getNumberOfOutputParameters();
int numberOfActualOutputValues = context.getStack().size();
if (numberOfActualOutputValues < numberOfOutputValues) {
throw new IllegalStateException("The type 4 function returned " + numberOfActualOutputValues + " values but the Range entry indicates that " + numberOfOutputValues + " values be returned.");
}
float[] outputValues = new float[numberOfOutputValues];
for (int i = numberOfOutputValues - 1; i >= 0; i--) {
PDRange range = getRangeForOutput(i);
outputValues[i] = context.popReal();
outputValues[i] = clipToRange(outputValues[i], range.getMin(), range.getMax());
}
// Return the resulting array
return outputValues;
}
use of org.apache.pdfbox.pdmodel.common.PDRange in project pdfbox by apache.
the class PDLab method getDefaultDecode.
@Override
public float[] getDefaultDecode(int bitsPerComponent) {
PDRange a = getARange();
PDRange b = getBRange();
return new float[] { 0, 100, a.getMin(), a.getMax(), b.getMin(), b.getMax() };
}
Aggregations