Search in sources :

Example 1 with Interpolation

use of lucee.runtime.img.interpolation.Interpolation in project Lucee by lucee.

the class ImageResizer method resize.

public static BufferedImage resize(BufferedImage image, int columns, int rows, int interpolation, double blur) throws ExpressionException {
    if (columns == 0 || rows == 0)
        throw new ExpressionException("invalid size for image");
    BufferedImage resizeImage = ImageUtil.createBufferedImage(image, columns, rows);
    Interpolation inter = getInterpolation(interpolation);
    double xFactor = (double) columns / (double) image.getWidth();
    double scale = blur * Math.max(1.0 / xFactor, 1.0);
    double xSupport = Math.max(scale * inter.getSupport(), 0.5);
    double yFactor = (double) rows / (double) image.getHeight();
    scale = blur * Math.max(1.0 / yFactor, 1.0);
    double ySupport = Math.max(scale * inter.getSupport(), 0.5);
    double support = Math.max(xSupport, ySupport);
    if (support < inter.getSupport())
        support = inter.getSupport();
    ContributionInfo[] contribution = new ContributionInfo[(int) support * 2 + 3];
    for (int cloop = 0; cloop < (int) support * 2 + 3; cloop++) contribution[cloop] = new ContributionInfo();
    int status;
    if (columns * (image.getHeight() + rows) < rows * (image.getWidth() + columns)) {
        BufferedImage sourceImage = ImageUtil.createBufferedImage(image, columns, image.getHeight());
        status = horizontal(image, sourceImage, xFactor, inter, blur, contribution);
        status |= vertical(sourceImage, resizeImage, yFactor, inter, blur, contribution);
    } else {
        BufferedImage sourceImage = ImageUtil.createBufferedImage(image, image.getWidth(), rows);
        status = vertical(image, sourceImage, yFactor, inter, blur, contribution);
        status |= horizontal(sourceImage, resizeImage, xFactor, inter, blur, contribution);
    }
    if (status == 0)
        throw new ExpressionException("can't resize image");
    return resizeImage;
}
Also used : Interpolation(lucee.runtime.img.interpolation.Interpolation) ExpressionException(lucee.runtime.exp.ExpressionException) BufferedImage(java.awt.image.BufferedImage)

Aggregations

BufferedImage (java.awt.image.BufferedImage)1 ExpressionException (lucee.runtime.exp.ExpressionException)1 Interpolation (lucee.runtime.img.interpolation.Interpolation)1