From: Svjatoslav Agejenko Date: Sun, 7 Dec 2014 20:29:04 +0000 (+0200) Subject: bugfix: correctly handle very thin images X-Git-Tag: meviz-1.0~42 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=9539c23d02f606244863b15a6edd88b3008946b3;p=meviz.git bugfix: correctly handle very thin images --- diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/Picture.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/Picture.java index 9af52df..2b9b802 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/Picture.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/Picture.java @@ -32,6 +32,13 @@ import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension; public class Picture extends AbstractFile { + private static void ensureNonzeroImageArea(final java.awt.Dimension result) { + if (result.width < 1) + result.width = 1; + if (result.height < 1) + result.height = 1; + } + /** * Actual returned target thumbnail size will be adjusted from desired one * by attempting to generate as large as possible thumbnail, while not @@ -53,6 +60,8 @@ public class Picture extends AbstractFile { desiredTargetDimension.width, (int) (desiredTargetDimension.width / inputImageWidthToHeightRatio)); + ensureNonzeroImageArea(result); + return result; } else { @@ -60,6 +69,8 @@ public class Picture extends AbstractFile { (int) (desiredTargetDimension.height * inputImageWidthToHeightRatio), desiredTargetDimension.height); + ensureNonzeroImageArea(result); + return result; } } @@ -122,16 +133,15 @@ public class Picture extends AbstractFile { public static Image scaleImage(final Image srcImage, final int width, final int height) { - ImageFilter filter; - filter = new java.awt.image.AreaAveragingScaleFilter(width, height); + final ImageFilter filter = new java.awt.image.AreaAveragingScaleFilter( + width, height); final ImageProducer prod = new FilteredImageSource( srcImage.getSource(), filter); final Image newImage = Toolkit.getDefaultToolkit().createImage(prod); - final ImageIcon imageIcon = new ImageIcon(newImage); - return imageIcon.getImage(); + return new ImageIcon(newImage).getImage(); } private static final long serialVersionUID = -4156533490858298387L;;