changeset 1420:e12398d83238 new_scaling

Merge with latest HEAD 18690b59687e361887579c009e3e35dc9260d614
author robcast
date Mon, 26 Oct 2015 15:24:43 +0100
parents 67134a81061b (current diff) 18690b59687e (diff)
children 8a713bc0e86f
files webapp/src/main/webapp/jquery/annotator-dl.js webapp/src/main/webapp/jquery/annotator-dl.min.js webapp/src/main/webapp/jquery/digilib-ann.html webapp/src/main/webapp/jquery/digilib-vector.html webapp/src/main/webapp/jquery/img/fullscreen/32/annotation-polygon.png webapp/src/main/webapp/jquery/img/fullscreen/32/annotation-polyline.png webapp/src/main/webapp/jquery/img/info.png webapp/src/main/webapp/jquery/img/move.png webapp/src/main/webapp/jquery/jquery.colorPicker.js webapp/src/main/webapp/jquery/jquery.digilib.annotator.js webapp/src/main/webapp/jquery/jquery.digilib.geometry.js webapp/src/main/webapp/jquery/jquery.digilib.vector.js
diffstat 8 files changed, 176 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/common/pom.xml	Tue Oct 20 19:31:10 2015 +0200
+++ b/common/pom.xml	Mon Oct 26 15:24:43 2015 +0100
@@ -1,55 +1,104 @@
 <?xml version="1.0"?>
-<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-  <modelVersion>4.0.0</modelVersion>
-  <parent>
-    <artifactId>digilib</artifactId>
-    <groupId>digilib</groupId>
-    <version>2.3-SNAPSHOT</version>
-  </parent>
-  <artifactId>digilib-common</artifactId>
-  <name>digilib-common</name>
-  <description>The Digital Image Library - common library</description>
-  <url>http://digilib.sourceforge.net</url>
-  <packaging>jar</packaging>
-  <build>
-  	<pluginManagement>
-  		<plugins>
-  			<plugin>
-  				<groupId>org.apache.maven.plugins</groupId>
-  				<artifactId>maven-compiler-plugin</artifactId>
-                <configuration>
-                    <source>1.7</source>
-                    <target>1.7</target> 
-                </configuration>
-  			</plugin>
-   		</plugins>
-  	</pluginManagement>
-  </build>
+<project
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<artifactId>digilib</artifactId>
+		<groupId>digilib</groupId>
+		<version>2.3-SNAPSHOT</version>
+	</parent>
+	
+	<artifactId>digilib-common</artifactId>
+	<name>digilib-common</name>
+	<description>The Digital Image Library - common library</description>
+	<url>http://digilib.sourceforge.net</url>
+	<packaging>jar</packaging>
+	
+	<build>
+		<pluginManagement>
+			<plugins>
+				<plugin>
+					<groupId>org.apache.maven.plugins</groupId>
+					<artifactId>maven-compiler-plugin</artifactId>
+					<configuration>
+						<source>1.7</source>
+						<target>1.7</target>
+					</configuration>
+				</plugin>
+			</plugins>
+		</pluginManagement>
+	</build>
 
-  <dependencies>
-    <dependency>
-        <groupId>com.github.jai-imageio</groupId>
-        <artifactId>jai-imageio-core</artifactId>
-        <version>1.3.0</version>
-    </dependency>
-    <!-- <dependency>
-        <groupId>com.github.jai-imageio</groupId>
-        <artifactId>jai-imageio-jpeg2000</artifactId>
-        <version>1.3.0</version>
-    </dependency> -->
-  	<dependency>
-  		<groupId>org.devlib.schmidt</groupId>
-  		<artifactId>imageinfo</artifactId>
-        <version>1.9</version>
-  		<type>jar</type>
-  		<scope>compile</scope>
-  	</dependency>
-  	<dependency>
-  		<groupId>log4j</groupId>
-  		<artifactId>log4j</artifactId>
-  		<type>jar</type>
-  		<scope>compile</scope>
-  	</dependency>
-  </dependencies>
+	<profiles>
+		<profile>
+			<id>imageio-jai</id>
+            <!--  use JAI-ImageIO plugin -->
+			<activation>
+				<activeByDefault>true</activeByDefault>
+				<property>
+					<name>imageio</name>
+					<value>jai</value>
+				</property>
+			</activation>
+			<dependencies>
+				<dependency>
+					<groupId>com.github.jai-imageio</groupId>
+					<artifactId>jai-imageio-core</artifactId>
+					<version>1.3.0</version>
+                    <type>jar</type>
+                    <scope>compile</scope>
+				</dependency>
+				<!-- 
+				<dependency> 
+			         <groupId>com.github.jai-imageio</groupId> 
+			         <artifactId>jai-imageio-jpeg2000</artifactId> 
+				     <version>1.3.0</version> 
+				 </dependency> 
+				 -->
+			</dependencies>
+		</profile>
+		<profile>
+			<id>imageio-12m</id>
+            <!-- use Twelvemonkeys ImageIO plugins -->
+			<activation>
+				<property>
+					<name>imageio</name>
+					<value>12m</value>
+				</property>
+			</activation>
+			<dependencies>
+				<dependency>
+					<groupId>com.twelvemonkeys.imageio</groupId>
+					<artifactId>imageio-jpeg</artifactId>
+					<version>3.1.2</version>
+                    <type>jar</type>
+                    <scope>compile</scope>
+				</dependency>
+				<dependency>
+					<groupId>com.twelvemonkeys.imageio</groupId>
+					<artifactId>imageio-tiff</artifactId>
+					<version>3.1.2</version>
+                    <type>jar</type>
+                    <scope>compile</scope>
+				</dependency>
+			</dependencies>
+		</profile>
+	</profiles>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.devlib.schmidt</groupId>
+			<artifactId>imageinfo</artifactId>
+			<version>1.9</version>
+			<type>jar</type>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>log4j</groupId>
+			<artifactId>log4j</artifactId>
+			<type>jar</type>
+			<scope>compile</scope>
+		</dependency>
+	</dependencies>
 </project>
--- a/common/src/main/java/digilib/image/ImageJobDescription.java	Tue Oct 20 19:31:10 2015 +0200
+++ b/common/src/main/java/digilib/image/ImageJobDescription.java	Mon Oct 26 15:24:43 2015 +0100
@@ -404,7 +404,13 @@
             double scaleX = getDw() / areaWidth * ws;
             double scaleY = getDh() / areaHeight * ws;
             // use the smaller factor to get fit-in-box
-            scaleXY = (scaleX > scaleY) ? scaleY : scaleX;
+            if (scaleX == 0) {
+            	scaleXY = scaleY;
+            } else if (scaleY == 0) {
+            	scaleXY = scaleX;
+            } else {
+            	scaleXY = (scaleX > scaleY) ? scaleY : scaleX;
+            }
         } else if (isAbsoluteScale()) {
             /*
              * absolute scaling factor -- either original size, based on dpi, or absolute 
@@ -479,7 +485,7 @@
             paramDW = getAsInt("dw");
             paramDH = getAsInt("dh");
 
-            if (paramDW == 0) {
+            if (paramDW == 0 && input != null) {
                 /*
                  * calculate dw using aspect ratio of image area
                  */
@@ -488,7 +494,7 @@
                 // round up to make sure we don't squeeze dh
                 paramDW = (int) Math.ceil(paramDH * imgAspect);
                 setValue("dw", paramDW);
-            } else if (paramDH == 0) {
+            } else if (paramDH == 0 && input != null) {
                 /*
                  * calculate dh using aspect ratio of image area
                  */
@@ -516,7 +522,7 @@
             paramDW = getAsInt("dw");
             paramDH = getAsInt("dh");
 
-            if (paramDW == 0) {
+            if (paramDW == 0 && input != null) {
                 /*
                  * calculate dw using aspect ratio of image area
                  */
@@ -525,7 +531,7 @@
                 // round up to make sure we don't squeeze dh
                 paramDW = (int) Math.ceil(paramDH * imgAspect);
                 setValue("dw", paramDW);
-            } else if (paramDH == 0) {
+            } else if (paramDH == 0 && input != null) {
                 /*
                  * calculate dh using aspect ratio of image area
                  */
--- a/common/src/main/java/digilib/image/ImageLoaderDocuImage.java	Tue Oct 20 19:31:10 2015 +0200
+++ b/common/src/main/java/digilib/image/ImageLoaderDocuImage.java	Mon Oct 26 15:24:43 2015 +0100
@@ -72,7 +72,7 @@
 public class ImageLoaderDocuImage extends ImageInfoDocuImage {
 
     /** DocuImage version */
-    public static final String version = "ImageLoaderDocuImage 2.1.7";
+    public static final String version = "ImageLoaderDocuImage 2.1.8";
 
     /** image object */
     protected BufferedImage img;
@@ -104,8 +104,10 @@
     /* lookup table for false-color */
     protected static LookupTable mapBgrByteTable;
     protected static boolean needsMapBgr = false;
+    /* set destination type to sRGB if available */
+    protected static boolean setDestSrgb = true;
     /* set destination type to sRGB if available, even for non-RGB images */
-    protected static boolean alwaysSetDestSrgb = false;
+    protected static boolean setDestSrgbForNonRgb = false;
 
     static {
         /*
@@ -161,7 +163,7 @@
         // this hopefully works for all
         mapBgrByteTable = new ByteLookupTable(0, new byte[][] { mapR, mapG, mapB });
         logger.debug("ImageIO Hacks: needsRescaleRgba="+needsRescaleRgba+" needsInvertRgba="+needsInvertRgba+
-                " needsMapBgr="+needsMapBgr);
+                " needsMapBgr="+needsMapBgr+" setDestSrgb="+setDestSrgb+" setDestSrgbForNonRgb="+setDestSrgbForNonRgb);
     }
 
     /** the size of the current image */
@@ -364,36 +366,48 @@
         // ImageReader reader = null;
         try {
             reader = getReader(ii);
-            // set up reader parameters
+            /*
+             * set up reader parameters
+             */
             ImageReadParam readParam = reader.getDefaultReadParam();
             readParam.setSourceRegion(region);
             if (prescale > 1) {
                 readParam.setSourceSubsampling(prescale, prescale, 0, 0);
             }
-            // try to set target color space to sRGB
-            for (Iterator<ImageTypeSpecifier> i = reader.getImageTypes(0); i.hasNext();) {
-                ImageTypeSpecifier type = (ImageTypeSpecifier) i.next();
-                ColorModel cm = type.getColorModel();
-                ColorSpace cs = cm.getColorSpace();
-                logger.debug("loadSubimage: possible color model:"+cm+" color space:"+cs);
-                if (cs.getNumComponents() < 3 && ! ImageLoaderDocuImage.alwaysSetDestSrgb) {
-                    // if the first type is not RGB do nothing
-                    logger.debug("loadSubimage: image is not RGB " + type);
-                    break;
-                }
-                if (cs.isCS_sRGB()) {
-                    logger.debug("loadSubimage: substituted sRGB destination type " + type);
-                    readParam.setDestinationType(type);
-                    break;
-                }
-            }
-            // read image
+			if (ImageLoaderDocuImage.setDestSrgb) {
+				/*
+				 * try to set target color space to sRGB
+				 */
+				for (Iterator<ImageTypeSpecifier> i = reader.getImageTypes(0); i.hasNext();) {
+					ImageTypeSpecifier type = (ImageTypeSpecifier) i.next();
+					ColorModel cm = type.getColorModel();
+					ColorSpace cs = cm.getColorSpace();
+					logger.debug("loadSubimage: possible color model:" + cm + " color space:" + cs);
+					if (cs.getNumComponents() < 3 && !ImageLoaderDocuImage.setDestSrgbForNonRgb) {
+						// if the first type is not RGB do nothing
+						logger.debug("loadSubimage: image is not RGB " + type);
+						break;
+					}
+					if (cs.isCS_sRGB()) {
+						logger.debug("loadSubimage: substituted sRGB destination type " + type);
+						readParam.setDestinationType(type);
+						break;
+					}
+				}
+			}
+			
+            /*
+             * read image
+             */
             logger.debug("loadSubimage: loading..");
             img = reader.read(0, readParam);
             logger.debug("loadSubimage: loaded");
             // invalidate image size if it was set
             imageSize = null;
-            // downconvert highcolor images
+            
+            /*
+             * downconvert highcolor images
+             */
             if (img.getColorModel().getComponentSize(0) > 8) {
                 logger.debug("loadSubimage: converting to 8bit");
                 int type = BufferedImage.TYPE_INT_RGB;
--- a/doc/src/site/markdown/java-settings.md	Tue Oct 20 19:31:10 2015 +0200
+++ b/doc/src/site/markdown/java-settings.md	Mon Oct 26 15:24:43 2015 +0100
@@ -36,12 +36,17 @@
 [`/server/dlConfig.jsp`](http://localhost:8080/digilib/server/dlConfig.jsp)
 status page.
 
-Sometimes there are memory issues. Newer versions of Tomcat refuse to load
-the libraries and I found that in some cases digilib stopped reading TIFF files
+Sometimes there are problems with leaking memory. Newer versions of Tomcat refuse to load
+the libraries (see JREMemoryLeakPreventionListener) and I found that in some 
+cases digilib stopped reading TIFF files
 after a period of running. In these cases it helped to install the JAI files in 
 Tomcats `lib/` directory or globally in the local Java JDK
 installation (i.e. in the Java's 'jre/lib/ext/' directory on linux).
 
+If you really need to have the imageio-plugins JAR inside the web app, please consider 
+using Harald Kuhrs [IIOProviderContextListener](https://github.com/haraldk/TwelveMonkeys#deploying-the-plugins-in-a-web-app).
+ 
+
 # Codec availability and Performance
 
 (Ubbo Veentjer, Oct 2015)
@@ -61,21 +66,27 @@
 
     1564059 [http-apr-9092-exec-4] DEBUG digilib.image.DocuImage  - ImageIO: this reader: class com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader
 
+(Robert Casties, Oct 2015)
+
+You can now use the TwelveMonkeys codecs instead of the default JAI-ImageIO by just [building digilib](build-maven.html) with the Maven-Parameter `imageio=12m`:
+
+    mvn -Dimageio=12m package
+
 # Codec performance
 
 (Ubbo Veentjer, Oct 2015)
 
-In our tests comparing the performance of OpenJDK7, OpenJDK8, imageio-ext and TwelveMonkeys codecs we experienced the following numbers for decoding, encoding and scaling a 4968px*5968px to 50% size: 
+In our tests comparing the performance of OpenJDK7, OpenJDK8, imageio-ext and TwelveMonkeys codecs we experienced the following numbers for decoding, encoding and scaling a 4968px*5968px JPEG file with a color profile to 50% size: 
 
-24801 ms - OpenJDK7
-11507 ms - OpenJDK7 with com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader
-4216 ms - OpenJDK7 with imageio-ext using libjpeg-turbo
-3635 ms - OpenJDK8 
+    24801 ms - OpenJDK7
+    11507 ms - OpenJDK7 with com.twelvemonkeys.imageio.plugins.jpeg.JPEGImageReader
+    4216 ms - OpenJDK7 with imageio-ext using libjpeg-turbo
+    3635 ms - OpenJDK8 
 
-This numbers may depend on the actual implementation used, the processing power of the CPU and many other factors, to this are just meant to be a rough hint.
+This numbers may depend on the actual implementation used, the processing power of the CPU and many other factors, to this is just meant to be a rough hint.
 
 For using imageio-ext, the native library needs to be 
-available with the LD_LIBRARY_PATH environment variable (compare: https://github.com/geosolutions-it/imageio-ext/wiki/TurboJPEG-plugin), also the .jar archives need to be on the classpath.
+available with the `LD_LIBRARY_PATH` environment variable (compare: https://github.com/geosolutions-it/imageio-ext/wiki/TurboJPEG-plugin), also the .jar archives need to be on the classpath.
 
 For using the TwelveMonkey Codecs we added the following jars to the tomcat lib directory, which were retrieved by maven (dependency on imageio-jpeg-3.1.2):
 
@@ -87,7 +98,7 @@
 * imageio-metadata-3.1.2.jar
 
 
-# Codec availability
+# Available image formats
 
 (Ubbo Veentjer, Oct 2015)
 
--- a/pom.xml	Tue Oct 20 19:31:10 2015 +0200
+++ b/pom.xml	Mon Oct 26 15:24:43 2015 +0100
@@ -3,6 +3,10 @@
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
 
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
   <groupId>digilib</groupId>
   <artifactId>digilib</artifactId>
   <version>2.3-SNAPSHOT</version>
@@ -242,9 +246,6 @@
       </dependency>
     </dependencies>
   </dependencyManagement>
-  <properties>
-    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-  </properties>
 
   <dependencies>
   </dependencies>
--- a/servlet3/pom.xml	Tue Oct 20 19:31:10 2015 +0200
+++ b/servlet3/pom.xml	Mon Oct 26 15:24:43 2015 +0100
@@ -13,7 +13,6 @@
   			<plugin>
   				<groupId>org.apache.maven.plugins</groupId>
   				<artifactId>maven-compiler-plugin</artifactId>
-                <version>3.3</version>
                 <configuration>
                     <source>1.7</source>
                     <target>1.7</target> 
--- a/servlet3/src/main/java/digilib/servlet/Scaler.java	Tue Oct 20 19:31:10 2015 +0200
+++ b/servlet3/src/main/java/digilib/servlet/Scaler.java	Mon Oct 26 15:24:43 2015 +0100
@@ -228,7 +228,7 @@
 
         accountlog.debug("request: " + request.getQueryString());
         logger.debug("request: " + request.getQueryString());
-        logger.debug("headers: " + ServletOps.headersToString(request));
+        //logger.debug("headers: " + ServletOps.headersToString(request));
         // logger.debug("response:"+ response + " committed=" +
         // response.isCommitted());
         final long startTime = System.currentTimeMillis();
--- a/webapp/src/main/webapp/jquery/jquery.digilib.measure.js	Tue Oct 20 19:31:10 2015 +0200
+++ b/webapp/src/main/webapp/jquery/jquery.digilib.measure.js	Mon Oct 26 15:24:43 2015 +0100
@@ -1393,7 +1393,7 @@
                     shape.properties.maxvtx = 2;
                 },
                 'svg' : function (shape) {
-                    var $s = factory['Line'](shape);
+                    var $s = factory['Line'].svg(shape);
                     var place = $s.place;
                     var gridID = shape.id + '-grid';
                     var props = shape.properties;