Fixed JPEG snapshot resizing when running on OpenJDK.

Resizing JPEG snapshot images through /api/snapshot.jpg failed when
running on OpenJDK, but rendered successfully with a Oracle JDK.
Details in mantis 772 ( http://mantis.tokeek.de/view.php?id=772 ).

Removing any alpha component (useless in snapshot images) from the
rendered resized image solves the issue.
pull/135/head
luccioman 7 years ago
parent c1c4174816
commit 1de86cf1bf

@ -21,6 +21,7 @@
import java.awt.Container;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
@ -312,7 +313,14 @@ public class snapshot {
final MediaTracker mediaTracker = new MediaTracker(new Container());
mediaTracker.addImage(scaled, 0);
try {mediaTracker.waitForID(0);} catch (final InterruptedException e) {}
return new EncodedImage(scaled, ext, true);
/*
* Ensure there is no alpha component on the ouput image, as it is pointless
* here and it is not well supported by the JPEGImageWriter from OpenJDK
*/
BufferedImage scaledBufferedImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
scaledBufferedImg.createGraphics().drawImage(scaled, 0, 0, width, height, null);
return new EncodedImage(scaledBufferedImg, ext, true);
} catch (IOException e) {
ConcurrentLog.logException(e);
return null;

@ -20,7 +20,6 @@
package net.yacy.peers.graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;
import java.io.ByteArrayOutputStream;
@ -90,30 +89,6 @@ public class EncodedImage {
}
/**
* set an encoded image from a buffered image. Image ByteBuffer will be empty when encoding format is not supported.
* @param sourceImage the image
* @param targetExt the target extension of the image when converted into a file
* @param isStatic shall be true if the image will never change, false if not
*/
public EncodedImage(final Image i, final String targetExt, final boolean isStatic) {
this.extension = targetExt;
this.isStatic = isStatic;
// generate an byte array from the generated image
int width = i.getWidth(null);
if (width < 0) {
width = 96; // bad hack
}
int height = i.getHeight(null);
if (height < 0) {
height = 96; // bad hack
}
final BufferedImage sourceImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
sourceImage.createGraphics().drawImage(i, 0, 0, width, height, null);
this.image = RasterPlotter.exportImage(sourceImage, targetExt);
}
/**
* set an encoded image from an animated GIF. The target extension will be "gif"
* @param sourceImage the image

Loading…
Cancel
Save