Skip to content

Commit

Permalink
Fixed JPEG snapshot resizing when running on OpenJDK.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
luccioman committed Oct 19, 2017
1 parent c1c4174 commit 1de86cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
10 changes: 9 additions & 1 deletion htroot/api/snapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -312,7 +313,14 @@ public static Object respond(final RequestHeader header, serverObjects post, fin
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;
Expand Down
25 changes: 0 additions & 25 deletions source/net/yacy/peers/graphics/EncodedImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,30 +89,6 @@ public EncodedImage(final BufferedImage bi, final String targetExt, final boolea

}

/**
* 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
Expand Down

0 comments on commit 1de86cf

Please sign in to comment.