X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Futil%2FImageMaker.java;h=fa473f3d02be27be9f32cf013ec59454be60c094;hb=c066504317ab00acef89d0c7d8be620682caa14d;hp=3306b0d1585e400b07c0757322b242df54a1a1e4;hpb=173c541c3bdef7cee4f72a76cc8e23e8902a8614;p=jalview.git diff --git a/src/jalview/util/ImageMaker.java b/src/jalview/util/ImageMaker.java index 3306b0d..fa473f3 100755 --- a/src/jalview/util/ImageMaker.java +++ b/src/jalview/util/ImageMaker.java @@ -189,9 +189,9 @@ public class ImageMaker BitmapImageSizing bis = ImageMaker.getScaleWidthHeight(width, height, userBis); - float usescale = bis.scale; - int usewidth = bis.width; - int useheight = bis.height; + float usescale = bis.scale(); + int usewidth = bis.width(); + int useheight = bis.height(); bi = new BufferedImage(usewidth, useheight, BufferedImage.TYPE_INT_RGB); graphics = bi.getGraphics(); @@ -247,14 +247,22 @@ public class ImageMaker } /** - * Takes suggested float scale, int width, int height and create a bounding - * box returned as a BitmapImageSizing object with consistent scale, width, - * height fields. + * Takes initial width and height, and suggested float scale, int width, int + * height and create a bounding box returned as a BitmapImageSizing object + * with consistent scale, width, height fields. * + * @param width + * The unscaled image width + * @param height + * The unscaled image height * @param scale + * The suggested scaling * @param bitmapwidth + * The suggested width * @param bitmapheight - * @return BitmapImageSizing + * The suggested height + * @return BitmapImageSizing A consistent scale,width and height for the final + * image */ public static BitmapImageSizing getScaleWidthHeight(int width, int height, float scale, int bitmapwidth, int bitmapheight) @@ -263,6 +271,13 @@ public class ImageMaker int usewidth = width; int useheight = height; + if ((width == 0 && bitmapwidth > 0) + || (height == 0 && bitmapheight > 0)) + { + // original image is zero sized! Avoid dividing by zero! + return BitmapImageSizing.nullBitmapImageSizing(); + } + // use the smallest positive scale (i.e. fit in the box) if (scale > 0.0f) { @@ -290,7 +305,7 @@ public class ImageMaker useheight = bitmapheight; } } - return new BitmapImageSizing(usescale, usewidth, useheight); + return new BitmapImageSizing(usescale, usewidth, useheight, false); } /** @@ -304,8 +319,8 @@ public class ImageMaker public static BitmapImageSizing getScaleWidthHeight(int width, int height, BitmapImageSizing bis) { - return ImageMaker.getScaleWidthHeight(width, height, bis.scale, - bis.width, bis.height); + return ImageMaker.getScaleWidthHeight(width, height, bis.scale(), + bis.width(), bis.height()); } /** @@ -321,6 +336,13 @@ public class ImageMaker public static BitmapImageSizing parseScaleWidthHeightStrings( String scaleS, String widthS, String heightS) { + if (scaleS == null && widthS == null && heightS == null) + { + // if all items are null (i.e. not provided) we use the dynamic + // preferences set BIS + return BitmapImageSizing.defaultBitmapImageSizing(); + } + float scale = 0.0f; int width = 0; int height = 0; @@ -359,6 +381,6 @@ public class ImageMaker } } - return new BitmapImageSizing(scale, width, height); + return new BitmapImageSizing(scale, width, height, false); } }