changeset 1522:3709c60f4c2e

scaler mode 'lpic' (more precise params for large images > 10000px)
author hertzhaft
date Sun, 28 Aug 2016 01:28:49 +0200
parents d830c76eebc5
children debdc9fdf48f
files webapp/src/main/webapp/jquery/jquery-test-measure.html webapp/src/main/webapp/jquery/jquery.digilib.js webapp/src/main/webapp/jquery/jquery.digilib.regions.js
diffstat 3 files changed, 42 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/webapp/src/main/webapp/jquery/jquery-test-measure.html	Fri Jun 17 19:11:44 2016 +0200
+++ b/webapp/src/main/webapp/jquery/jquery-test-measure.html	Sun Aug 28 01:28:49 2016 +0200
@@ -36,13 +36,10 @@
             $(document).ready(function(){
                 var opts = {
                     interactionMode : 'fullscreen',
-                    showRegionNumbers : true
+                    showRegionNumbers : true,
                     };
                 var $div = $('div#digilib');
                 $div.digilib(opts);
-                DIGILIB = function (action) {
-                    return $div.digilib(action);
-                    };
             });
         </script>
     </head>
--- a/webapp/src/main/webapp/jquery/jquery.digilib.js	Fri Jun 17 19:11:44 2016 +0200
+++ b/webapp/src/main/webapp/jquery/jquery.digilib.js	Sun Aug 28 01:28:49 2016 +0200
@@ -101,7 +101,9 @@
         // parameters used by background image
         'previewImgParamNames' : ['fn','pn','dw','dh','mo','rot'],
         // reserved space in full page display (default value accounts for body margins)
-        'scalerInsets' : { 'x' : 26, 'y': 20 }
+        'scalerInsets' : { 'x' : 26, 'y': 20 },
+        // number of decimal places, for cropping parameters wx,wy,wh,ww
+        'decimals' : 4
         };
 
     // list of plugins
@@ -221,7 +223,7 @@
                             pos = url.indexOf('/digilib.html');
                             if (pos > 0) {
                                 elemSettings.digilibBaseUrl = url.substring(0, pos);
-                            }                    
+                            }
                         }
                     } else {
                         // may be we got the scaler URL from the img
@@ -844,22 +846,31 @@
         retrieveOptions(data);
     };
 
-    /** put area into parameters
+    /** put area dimensions into parameters
      * 
      */
-    var packArea = function (settings, area) {
-        if (!area) return;
-        // zoom area
-        settings.wx = cropFloat(area.x);
-        settings.wy = cropFloat(area.y);
-        settings.ww = cropFloat(area.width);
-        settings.wh = cropFloat(area.height);
+    var packArea = function (data, area) {
+      // pack the dimensions of the zoom into parameters
+      if (!area) return;
+      // use higher precision if the image is large and mode="lpic" (large picture)
+      var decimals = defaults.decimals;
+      var imgInfo = data.imgInfo;
+      if (data.scalerFlags.lpic != null
+        && imgInfo != null
+        && Math.max(imgInfo.width, imgInfo.height) > 10000) {
+          decimals = 5;
+          }
+      var settings = data.settings;
+      settings.wx = cropFloat(area.x, decimals);
+      settings.wy = cropFloat(area.y, decimals);
+      settings.ww = cropFloat(area.width, decimals);
+      settings.wh = cropFloat(area.height, decimals);
     };
 
     /** pack scaler flags into parameters
      * 
      */
-    var packScalerFlags = function (settings, flags) {
+    var packScalerFlags = function (data, flags) {
         if (!flags) return;
         var mo = '';
         for (var f in flags) {
@@ -868,16 +879,15 @@
             }
             mo += f;
         }
-        settings.mo = mo;
+        data.settings.mo = mo;
     };
 
     /** put objects back into parameters
      * 
      */
     var packParams = function (data) {
-        var settings = data.settings;
-        packArea(settings, data.zoomArea);
-        packScalerFlags(settings, data.scalerFlags);
+        packArea(data, data.zoomArea);
+        packScalerFlags(data, data.scalerFlags);
         // store user interface options in cookie
         storeOptions(data);
         // trigger pack handlers
@@ -971,7 +981,10 @@
                         console.debug("cached img.load");
                         $img.trigger('load');
                     }
-                    if (data.scalerFlags.clip != null || data.scalerFlags.osize != null) {
+                    if (data.scalerFlags.clip != null
+                      || data.scalerFlags.osize != null
+                      || data.scalerFlags.lpic != null
+                    ) {
                         // we need image info, do we have it?
                         if (data.imgInfo == null) {
                             loadImageInfo(data);
@@ -1006,7 +1019,11 @@
                 console.debug("cached img.load");
                 $img.trigger('load');
             }
-            if (data.scalerFlags.clip != null || data.scalerFlags.osize != null) {
+            // parameter "mo"
+            if (data.scalerFlags.clip != null
+              || data.scalerFlags.osize != null
+              || data.scalerFlags.lpic != null)
+            {
                 // we need image info, do we have it?
                 if (data.imgInfo == null) {
                     loadImageInfo(data);
@@ -1755,14 +1772,16 @@
     /** return number with reduced precision.
      * ("crop senseless precision")
      */
-    var cropFloat = function (x) {
-        return parseInt(10000 * x, 10) / 10000;
+    var cropFloat = function (x, dec) {
+        // return parseInt(10000 * x, 10) / 10000;
+        var decimals = dec || defaults.decimals;
+        return +(Math.round(x + "e+" + decimals)  + "e-" + decimals);
     };
 
     /** return string from number with reduced precision.
      */
-    var cropFloatStr = function (x) {
-        return cropFloat(x).toString();
+    var cropFloatStr = function (x, dec) {
+        return cropFloat(x, dec).toString();
     };
 
     /**
--- a/webapp/src/main/webapp/jquery/jquery.digilib.regions.js	Fri Jun 17 19:11:44 2016 +0200
+++ b/webapp/src/main/webapp/jquery/jquery.digilib.regions.js	Sun Aug 28 01:28:49 2016 +0200
@@ -232,7 +232,7 @@
             var show = !data.settings.isRegionVisible;
             data.settings.isRegionVisible = show;
             fn.highlightButtons(data, 'regions', show);
-            renderRegions(data, 1);
+            renderRegions(data, 0);
             return show;
         },