changeset 1410:9fc1a281575f new_scaling

fix for black-last-pixel locally in scale().
author robcast
date Tue, 20 Oct 2015 17:10:28 +0200
parents 5f3265ea088c
children 67134a81061b
files common/src/main/java/digilib/image/ImageLoaderDocuImage.java
diffstat 1 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/common/src/main/java/digilib/image/ImageLoaderDocuImage.java	Tue Oct 20 15:11:19 2015 +0200
+++ b/common/src/main/java/digilib/image/ImageLoaderDocuImage.java	Tue Oct 20 17:10:28 2015 +0200
@@ -449,12 +449,33 @@
     public void scale(double scaleX, double scaleY) throws ImageOpException {
         logger.debug("scale: " + scaleX);
         logger.debug("scaled from " + img.getWidth() + "x" + img.getHeight() + " img=" + img);
-        /* for downscaling in high quality the image is blurred first */
+        /* 
+         * for downscaling in high quality the image is blurred first 
+         */
         if ((scaleX <= 0.5) && (quality > 1)) {
             int bl = (int) Math.floor(1 / scaleX);
             blur(bl);
         }
-        /* then scaled */
+        /* 
+         * then scaled 
+         */
+        int oldWidth = img.getWidth();
+        int oldHeight = img.getHeight();
+        double targetWidth = oldWidth * scaleX;
+        double targetHeight = oldHeight * scaleY;
+        double deltaX = targetWidth - Math.floor(targetWidth);
+        double deltaY = targetHeight - Math.floor(targetHeight);
+        logger.debug("dw="+targetWidth+" dh="+targetHeight);
+        logger.debug("dx="+deltaX+" dy="+deltaY);
+        if (deltaX > epsilon) {
+            scaleX += (1 - deltaX) / oldWidth;
+        }
+        if (deltaY > epsilon) {
+            scaleY += (1 - deltaY) / oldHeight;
+        }
+        double targetWidth2 = oldWidth * scaleX;
+        double targetHeight2 = oldHeight * scaleY;
+        logger.debug("dw="+targetWidth2+" dh="+targetHeight2);
         AffineTransformOp scaleOp = new AffineTransformOp(AffineTransform.getScaleInstance(scaleX, scaleY), renderHint);
         img = scaleOp.filter(img, null);
         logger.debug("scaled to " + img.getWidth() + "x" + img.getHeight() + " img=" + img);