NIHVIVO-1208 When creating a thumbnail from a PNG image, suppress the alpha channel so the colors of the thumbnail won't be screwed up.
This commit is contained in:
parent
54349c7427
commit
49e4badda7
1 changed files with 25 additions and 3 deletions
|
@ -33,6 +33,7 @@ import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.sun.media.jai.codec.JPEGEncodeParam;
|
import com.sun.media.jai.codec.JPEGEncodeParam;
|
||||||
import com.sun.media.jai.codec.MemoryCacheSeekableStream;
|
import com.sun.media.jai.codec.MemoryCacheSeekableStream;
|
||||||
|
import com.sun.media.jai.codec.PNGDecodeParam;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
@ -284,7 +285,7 @@ public class ImageUploadHelper {
|
||||||
mainStream = fileStorage.getInputStream(mainBytestreamUri,
|
mainStream = fileStorage.getInputStream(mainBytestreamUri,
|
||||||
mainFilename);
|
mainFilename);
|
||||||
|
|
||||||
thumbStream = scaleImageForThumbnail(mainStream, crop);
|
thumbStream = scaleImageForThumbnail(mainStream, crop, newImage);
|
||||||
|
|
||||||
String mimeType = RECOGNIZED_FILE_TYPES.get(".jpg");
|
String mimeType = RECOGNIZED_FILE_TYPES.get(".jpg");
|
||||||
String filename = createThumbnailFilename(mainFilename);
|
String filename = createThumbnailFilename(mainFilename);
|
||||||
|
@ -392,12 +393,17 @@ public class ImageUploadHelper {
|
||||||
* width, height).
|
* width, height).
|
||||||
*/
|
*/
|
||||||
private InputStream scaleImageForThumbnail(InputStream source,
|
private InputStream scaleImageForThumbnail(InputStream source,
|
||||||
CropRectangle crop) throws IOException {
|
CropRectangle crop, FileInfo newImage) throws IOException {
|
||||||
try {
|
try {
|
||||||
// Read the main image.
|
// Read the main image.
|
||||||
MemoryCacheSeekableStream stream = new MemoryCacheSeekableStream(
|
MemoryCacheSeekableStream stream = new MemoryCacheSeekableStream(
|
||||||
source);
|
source);
|
||||||
RenderedOp mainImage = JAI.create("stream", stream);
|
|
||||||
|
ParameterBlock streamParams = new ParameterBlock();
|
||||||
|
streamParams.add(stream);
|
||||||
|
addDecodeParametersAsNeeded(newImage, streamParams);
|
||||||
|
RenderedOp mainImage = JAI.create("stream", streamParams);
|
||||||
|
|
||||||
int imageWidth = mainImage.getWidth();
|
int imageWidth = mainImage.getWidth();
|
||||||
int imageHeight = mainImage.getHeight();
|
int imageHeight = mainImage.getHeight();
|
||||||
|
|
||||||
|
@ -445,6 +451,22 @@ public class ImageUploadHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The JAI 1.1.3 package has a known bug writing JPEG images from sources
|
||||||
|
* that have transparency (alpha channel) enabled.
|
||||||
|
*
|
||||||
|
* For PNG images, we can add a parameter that will disable the alpha
|
||||||
|
* channel.
|
||||||
|
*/
|
||||||
|
private void addDecodeParametersAsNeeded(FileInfo newImage,
|
||||||
|
ParameterBlock streamParams) {
|
||||||
|
if ("image/png".equals(newImage.getMimeType())) {
|
||||||
|
PNGDecodeParam pdp = new PNGDecodeParam();
|
||||||
|
pdp.setSuppressAlpha(true);
|
||||||
|
streamParams.add(pdp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The bounds of the cropping rectangle should be limited to the bounds of
|
* The bounds of the cropping rectangle should be limited to the bounds of
|
||||||
* the image.
|
* the image.
|
||||||
|
|
Loading…
Add table
Reference in a new issue