public InputStream resizingFunk(InputStream in) {
ByteArrayInputStream bis = null;
try {
BufferedImage source = ImageIO.read(in);
int iw = source.getWidth(null);
int ih = source.getHeight(null);
if (iw > ih) {
int numOfTests = 10;
long[] timeArray = new long[numOfTests];
//test 1-phase Bicubic Java2D-native resize
for (int sizeIdx = 0; sizeIdx < thumbnail_sizes_w.length; sizeIdx++) {
int destWidth = thumbnail_sizes_w[sizeIdx][0];
int destHeight = thumbnail_sizes_w[sizeIdx][1];
BufferedImage result = null;
for (int testNum = 0; testNum < numOfTests; testNum++) {
long start = System.nanoTime();
result = resizeJava2DNative(source, destWidth, destHeight,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
timeArray[testNum] = System.nanoTime() - start;
}
//sort test results
Arrays.sort(timeArray);
//calculate average time except the best and the worst results
long sum = 0;
for (int i = 1; i < numOfTests - 1; i++) {
sum += timeArray[i] / 1000000;
}
//System.out.println("Average time of 1-phase Java2D-BICUBIC - [" + destWidth + "x" + destHeight + "]: " + (sum / (numOfTests - 2)) + "ms");
//writeJPEG(result, "C:\\result_java2d_" + destWidth + "_" + destHeight + ".jpg");
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(result, "jpg", out);
// Read the outputstream into the inputstream for the return value
bis = new ByteArrayInputStream(out.toByteArray());
}
} else {
int numOfTests = 10;
long[] timeArray = new long[numOfTests];
//test 1-phase Bicubic Java2D-native resize
for (int sizeIdx = 0; sizeIdx < thumbnail_sizes_h.length; sizeIdx++) {
int destWidth = thumbnail_sizes_h[sizeIdx][0];
int destHeight = thumbnail_sizes_h[sizeIdx][1];
BufferedImage result = null;
for (int testNum = 0; testNum < numOfTests; testNum++) {
long start = System.nanoTime();
result = resizeJava2DNative(source, destWidth, destHeight,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
timeArray[testNum] = System.nanoTime() - start;
}
//sort test results
Arrays.sort(timeArray);
//calculate average time except the best and the worst results
long sum = 0;
for (int i = 1; i < numOfTests - 1; i++) {
sum += timeArray[i] / 1000000;
}
System.out.println("Average time of 1-phase Java2D-BICUBIC - [" + destWidth + "x" + destHeight + "]: " + (sum / (numOfTests - 2)) + "ms");
//writeJPEG(result, "C:\\result_java2d_" + destWidth + "_" + destHeight + ".jpg");
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(result, "jpg", out);
// Read the outputstream into the inputstream for the return value
bis = new ByteArrayInputStream(out.toByteArray());
}