I grabbed the source and took a look. It turns out this resize method
is already implemented for CFIMAGE (it is in /nary/awt/image/
imageOps.java in the scaleToSize() method, which is called by the
resize() method, which is used by cfIMAGE.java).
It is exactly the same implementation method I proposed, but it looks
as if the multistep method is hardcoded into it. CFIMAGE doesn't
support setting the interpolation method it appears - it is hardcoded
to bicubic and resize() always uses the multistep method (even when it
shouldn't to be honest - it does no good at all if you are upscaling).
Anyway I basically copied the implementation from imageOps.java and
added a bit of code to set the higherQuality flag intelligently. I did
not test it but my changes are very minor (relative to the version in
imageOps). The code is below (this should be a drop-in replacement for
the existing scaleToSize() method in /naryx/tagfusion/expression/
function/image/ImageResize.java).
private BufferedImage scaleToSize(BufferedImage img, int targetWidth,
int targetHeight, Object interpolation) {
if (targetWidth == img.getWidth() && targetHeight == img.getHeight())
{
return img;
}
boolean higherQuality = (
// Set flag to use multi-step technique only if
// target size is less than 50% of the original size
// and the interpolation mode is bilinear or
(targetWidth < (int)(img.getWidth() * 0.5)) &&
(
(interpolation ==
RenderingHints.VALUE_INTERPOLATION_BILINEAR) ||
(interpolation ==
RenderingHints.VALUE_INTERPOLATION_BICUBIC)
)
);
int type = (img.getTransparency() == Transparency.OPAQUE) ?
BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
BufferedImage ret = (BufferedImage) img;
int w, h;
if (higherQuality) {
// Use multi-step technique: start with original size, then
// scale down in multiple passes with drawImage()
// until the target size is reached
w = img.getWidth();
h = img.getHeight();
} else {
// Use one-step technique: scale directly from original
// size to target size with a single drawImage() call
w = targetWidth;
h = targetHeight;
}
do {
if (higherQuality && w > targetWidth) {
w /= 2;
if (w < targetWidth) {
w = targetWidth;
}
}
if (higherQuality && h > targetHeight) {
h /= 2;
if (h < targetHeight) {
h = targetHeight;
}
}
BufferedImage tmp = new BufferedImage(w, h, type);
Graphics2D g2 = tmp.createGraphics();
g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION,
interpolation );
g2.setRenderingHint( RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY );
g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON );
g2.drawImage(ret, 0, 0, w, h, null);
g2.dispose();
ret = tmp;
} while (w != targetWidth || h != targetHeight);
return ret;
}
On Nov 27, 4:38 am, "Alan Williamson (aw2.0 cloud experts)"
<[email protected]> wrote:
> If you don't want to pull directly from SVN then you can use the nightly
> build src and do it all locally. I would recommend however you just get
> an SVN client (SmartSVN - Bing it) and your life will be easier.
--
online documentation: http://openbd.org/manual/
google+ hints/tips: https://plus.google.com/115990347459711259462
http://groups.google.com/group/openbd?hl=en