reduce to nearest pow 2
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 2 Jul 2012 07:33:31 +0000 (07:33 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 2 Jul 2012 07:33:31 +0000 (07:33 +0000)
plack/lib/Plack/App/BookReader.pm

index 5d64955..224d511 100644 (file)
@@ -113,8 +113,9 @@ br.getPageURI = function(index, reduce, rotate) {
     // reduce and rotate are ignored in this simple implementation, but we
     // could e.g. look at reduce and load images from a different directory
     // or pass the information to an image server
-       var url = pages[index][0] + '?reduce='+Math.round(reduce);
-       console.debug('getPageURI', index, reduce, rotate, url);
+       var r = 1 << ( Math.ceil(reduce).toString(2).length - 1 ); // reduce to nearest higher pow 2
+       var url = pages[index][0] + '?reduce='+r;
+       console.debug('getPageURI', index, reduce, r, rotate, url);
     return url;
 }