in src/main/java/org/apache/pdfbox/jbig2/image/Resizer.java [366:428]
public void resize(final Object src, final Rectangle srcBounds, final Object dst,
Rectangle dstBounds, Filter xFilter, Filter yFilter)
{
/*
* find scale of filter in a space (source space) when minifying, source scale=1/scale, but when magnifying,
* source scale=1
*/
ParameterizedFilter xFilterParameterized = new ParameterizedFilter(xFilter, mappingX.scale);
ParameterizedFilter yFilterParameterized = new ParameterizedFilter(yFilter, mappingY.scale);
/* find valid destination window (transformed source + support margin) */
final Rectangle dstRegion = new Rectangle();
final int x1 = Utils
.ceil(mappingX.srcToDst(srcBounds.x - xFilterParameterized.support) + EPSILON);
final int y1 = Utils
.ceil(mappingY.srcToDst(srcBounds.y - yFilterParameterized.support) + EPSILON);
final int x2 = Utils.floor(
mappingX.srcToDst(srcBounds.x + srcBounds.width + xFilterParameterized.support)
- EPSILON);
final int y2 = Utils.floor(
mappingY.srcToDst(srcBounds.y + srcBounds.height + yFilterParameterized.support)
- EPSILON);
dstRegion.setFrameFromDiagonal(x1, y1, x2, y2);
if (dstBounds.x < dstRegion.x || dstBounds.getMaxX() > dstRegion.getMaxX()
|| dstBounds.y < dstRegion.y || dstBounds.getMaxY() > dstRegion.getMaxY())
{
/* requested destination window lies outside the valid destination, so clip destination */
dstBounds = dstBounds.intersection(dstRegion);
}
if (srcBounds.isEmpty() || dstBounds.width <= 0 || dstBounds.height <= 0)
{
return;
}
/* check for high-level simplifications of filter */
xFilterParameterized = simplifyFilter(xFilterParameterized, mappingX.scale,
mappingX.offset);
yFilterParameterized = simplifyFilter(yFilterParameterized, mappingY.scale,
mappingY.offset);
/*
* decide which filtering order (x->y or y->x) is faster for this mapping by counting convolution multiplies
*/
final boolean orderXY = order != Order.AUTO ? order == Order.XY
: dstBounds.width * (srcBounds.height * xFilterParameterized.width
+ dstBounds.height * yFilterParameterized.width) < dstBounds.height
* (dstBounds.width * xFilterParameterized.width
+ srcBounds.width * yFilterParameterized.width);
// choose most efficient filtering order
if (orderXY)
{
resizeXfirst(src, srcBounds, dst, dstBounds, xFilterParameterized,
yFilterParameterized);
}
else
{
resizeYfirst(src, srcBounds, dst, dstBounds, xFilterParameterized,
yFilterParameterized);
}
}