changeset 562:baaa5bab5e16 digilibPDF

trying to reduce use of ImageOps
author robcast
date Fri, 17 Dec 2010 16:24:03 +0100
parents a5168978555f
children 686086d6e6d6
files servlet/src/digilib/image/DocuImage.java servlet/src/digilib/image/DocuImageImpl.java servlet/src/digilib/image/ImageJobDescription.java servlet/src/digilib/image/ImageOps.java servlet/src/digilib/servlet/DigilibConfiguration.java
diffstat 5 files changed, 24 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/image/DocuImage.java	Fri Dec 17 11:53:31 2010 +0100
+++ b/servlet/src/digilib/image/DocuImage.java	Fri Dec 17 16:24:03 2010 +0100
@@ -214,7 +214,7 @@
     /**
      * Check image size and type and store in ImageFile f
      */
-    public boolean identify(ImageFile imgf) throws IOException;
+    public ImageFile identify(ImageFile imgf) throws IOException;
 
     /**
      * Returns a list of supported image formats
--- a/servlet/src/digilib/image/DocuImageImpl.java	Fri Dec 17 11:53:31 2010 +0100
+++ b/servlet/src/digilib/image/DocuImageImpl.java	Fri Dec 17 16:24:03 2010 +0100
@@ -39,7 +39,7 @@
 /** Simple abstract implementation of the <code>DocuImage</code> interface.
  *
  * This implementation provides basic functionality for the utility methods like
- * <code>SetUtils</code>, and <code>getKnownFileTypes</code>. Image methods like
+ * <code>getKnownFileTypes</code>. Image methods like
  * <code>loadImage</code>, <code>writeImage</code>, <code>getWidth</code>,
  * <code>getHeight</code>, <code>crop</code> and <code>scale</code> must be
  * implemented by derived classes.
@@ -75,11 +75,7 @@
 	}
 
     /** Check image size and type and store in ImageFile f */
-    public static boolean identifyImg(ImageFile imgf) throws IOException {
-    }
-
-    /** Check image size and type and store in ImageFile f */
-    public boolean identify(ImageFile imgf) throws IOException {
+    public ImageFile identify(ImageFile imgf) throws IOException {
         // fileset to store the information
         File f = imgf.getFile();
         if (f == null) {
@@ -100,9 +96,9 @@
             //logger.debug("  format:"+iif.getFormatName());
             raf.close();
             logger.debug("image size: " + imgf.getSize());
-            return true;
+            return imgf;
         }
-        return false;
+        return null;
     }
         
     /** Crop and scale the current image.
@@ -122,7 +118,7 @@
 	public void cropAndScale(
 		int x_off, int y_off, int width, int height, double scale, int qual) 
 		throws ImageOpException {
-
+		// default implementation: first crop, then scale
 		setQuality(qual);
 		crop(x_off, y_off, width, height);
 		scale(scale, scale);
@@ -171,7 +167,6 @@
     public void crop(int xoff, int yoff, int width, int height)
             throws ImageOpException {
         // TODO Auto-generated method stub
-        
     }
 
     public Image getAwtImage() {
--- a/servlet/src/digilib/image/ImageJobDescription.java	Fri Dec 17 11:53:31 2010 +0100
+++ b/servlet/src/digilib/image/ImageJobDescription.java	Fri Dec 17 16:24:03 2010 +0100
@@ -2,7 +2,9 @@
 
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
+import java.io.File;
 import java.io.IOException;
+import java.lang.reflect.Method;
 
 import org.apache.log4j.Logger;
 
@@ -133,7 +135,7 @@
 		if (mimeType == null) {
 			fileToLoad = getFileToLoad();
 			if(! fileToLoad.isChecked()){
-				ImageOps.checkFile(fileToLoad);
+				dlConfig.docuImageIdentify(fileToLoad);
 			}
 			mimeType = fileToLoad.getMimetype();
 		}
@@ -250,12 +252,11 @@
 		if (getAbsoluteScale()) {
 			ImageFile hiresFile = fileset.getBiggest();
 			if (!hiresFile.isChecked()) {
-				ImageOps.checkFile(hiresFile);
+				dlConfig.docuImageIdentify(hiresFile);
 			}
 			hiresSize = hiresFile.getSize();
 		}
 		return hiresSize;
-		
 	}
 	
 	/** Returns image scaling factor.
--- a/servlet/src/digilib/image/ImageOps.java	Fri Dec 17 11:53:31 2010 +0100
+++ b/servlet/src/digilib/image/ImageOps.java	Fri Dec 17 16:24:03 2010 +0100
@@ -37,7 +37,7 @@
     
     private static DocuImage docuImg;
     
-    public static boolean checkFile(ImageFile imgf) throws IOException {
+    public static ImageFile checkFile(ImageFile imgf) throws IOException {
         return docuImg.identify(imgf);
     }
     
--- a/servlet/src/digilib/servlet/DigilibConfiguration.java	Fri Dec 17 11:53:31 2010 +0100
+++ b/servlet/src/digilib/servlet/DigilibConfiguration.java	Fri Dec 17 16:24:03 2010 +0100
@@ -22,6 +22,7 @@
 package digilib.servlet;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.Map;
 import java.util.Map.Entry;
 
@@ -34,6 +35,7 @@
 import digilib.image.DocuImage;
 import digilib.image.DocuImageImpl;
 import digilib.io.FileOps;
+import digilib.io.ImageFile;
 import digilib.io.XMLListLoader;
 import digilib.util.Parameter;
 import digilib.util.ParameterMap;
@@ -55,6 +57,9 @@
 	/** DocuImage class instance */
 	private Class<DocuImageImpl> docuImageClass = null;
 
+	/** DocuImage instance */
+	private DocuImage docuImage = null;
+
 	/** Log4J logger */
 	private Logger logger = Logger.getLogger("digilib.config");
 
@@ -270,12 +275,20 @@
 		return di;
 	}
 
+	public ImageFile docuImageIdentify(ImageFile imgf) throws IOException {
+		if (docuImage == null) {
+			docuImage = (DocuImageImpl) getDocuImageInstance();
+		}
+		return docuImage.identify(imgf);
+	}
+	
 	/**
 	 * @return Returns the docuImageClass.
 	 */
 	public Class<DocuImageImpl> getDocuImageClass() {
 		return docuImageClass;
 	}
+
 	/**
 	 * @param docuImageClass The docuImageClass to set.
 	 */