changeset 140:c878ea574c29

Servlet Version 1.12b2 - fixed small error in XML config parser - improved high quality scaling with minSubsample parameter
author robcast
date Fri, 15 Aug 2003 23:52:20 +0200
parents 11cfe4c89fdc
children 8b327d506968
files servlet/src/digilib/image/ImageLoaderDocuImage.java servlet/src/digilib/io/XMLListLoader.java servlet/src/digilib/servlet/DigilibConfiguration.java servlet/src/digilib/servlet/Scaler.java
diffstat 4 files changed, 64 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/image/ImageLoaderDocuImage.java	Thu Jul 31 20:56:51 2003 +0200
+++ b/servlet/src/digilib/image/ImageLoaderDocuImage.java	Fri Aug 15 23:52:20 2003 +0200
@@ -120,6 +120,12 @@
 		ImageInputStream istream = ImageIO.createImageInputStream(rf);
 		Iterator readers = ImageIO.getImageReaders(istream);
 		reader = (ImageReader) readers.next();
+		/* are there more readers?
+		System.out.println("this reader: " + reader.getClass());
+		while (readers.hasNext()) {
+			System.out.println("next reader: " + readers.next().getClass());
+		}
+		*/
 		reader.setInput(istream);
 		if (reader == null) {
 			util.dprintln(3, "ERROR(loadImage): unable to load file");
@@ -168,6 +174,35 @@
 				util.dprintln(2, "ERROR(writeImage): Unknown mime type " + mt);
 				throw new FileOpException("Unknown mime type: " + mt);
 			}
+
+			/* JPEG doesn't do transparency so we have to convert any RGBA image
+			 * to RGB :-(
+			 */
+			if ((type == "jpeg") && (img.getColorModel().hasAlpha())) {
+				util.dprintln(2, "BARF: JPEG with transparency!!");
+				int w = img.getWidth();
+				int h = img.getHeight();
+				// BufferedImage.TYPE_INT_RGB seems to be fastest (JDK1.4.1, OSX)
+				BufferedImage img2;
+				img2 = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
+				img2.createGraphics().drawImage(img, null, 0, 0);
+				img = img2;
+			}
+
+			/* try ImageWriter.write
+			Iterator writers = ImageIO.getImageWritersByFormatName(type);
+			ImageWriter writer = (ImageWriter) writers.next();
+			System.out.println("this writer: " + writer.getClass());
+			while (writers.hasNext()) {
+				System.out.println("next writer: " + writers.next().getClass());
+			}
+			//ImageWriteParam param = writer.getDefaultWriteParam();
+			IIOImage iimg = new IIOImage(img, null, null); 
+			ImageOutputStream iostream = new MemoryCacheImageOutputStream(ostream);
+			writer.setOutput(iostream);
+			writer.write(iimg);
+			*/
+
 			// render output
 			if (ImageIO.write(img, type, ostream)) {
 				// writing was OK
@@ -187,7 +222,8 @@
 			new AffineTransformOp(
 				AffineTransform.getScaleInstance(scale, scale),
 				interpol);
-		BufferedImage scaledImg = scaleOp.filter(img, null);
+		BufferedImage scaledImg = scaleOp.createCompatibleDestImage(img, null);
+		scaleOp.filter(img, scaledImg);
 
 		if (scaledImg == null) {
 			util.dprintln(2, "ERROR(cropAndScale): error in scale");
@@ -276,8 +312,7 @@
 		return fb;
 	}
 
-	public void rotate(double angle)
-		throws ImageOpException {
+	public void rotate(double angle) throws ImageOpException {
 		// setup rotation
 		double rangle = Math.toRadians(angle);
 		// create offset to make shure the rotated image has no negative coordinates
@@ -294,7 +329,8 @@
 		double xoff = rotbounds.getX();
 		double yoff = rotbounds.getY();
 		// move image back in line
-		trafo.preConcatenate(AffineTransform.getTranslateInstance(-xoff, -yoff));
+		trafo.preConcatenate(
+			AffineTransform.getTranslateInstance(-xoff, -yoff));
 		// transform image
 		rotOp = new AffineTransformOp(trafo, interpol);
 		BufferedImage rotImg = rotOp.filter(img, null);
--- a/servlet/src/digilib/io/XMLListLoader.java	Thu Jul 31 20:56:51 2003 +0200
+++ b/servlet/src/digilib/io/XMLListLoader.java	Fri Aug 15 23:52:20 2003 +0200
@@ -32,8 +32,7 @@
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLFilterImpl;
+import org.xml.sax.helpers.DefaultHandler;
 
 public class XMLListLoader {
 
@@ -60,7 +59,7 @@
 	/**
 	 *  inner class XMLListParser to be called by the parser
 	 */
-	private class XMLListParser extends XMLFilterImpl {
+	private class XMLListParser extends DefaultHandler {
 
 		private HashMap listData;
 		private LinkedList tagSpace;
--- a/servlet/src/digilib/servlet/DigilibConfiguration.java	Thu Jul 31 20:56:51 2003 +0200
+++ b/servlet/src/digilib/servlet/DigilibConfiguration.java	Fri Aug 15 23:52:20 2003 +0200
@@ -91,8 +91,8 @@
 	private String authURLPath = "authenticated/";
 	private String AuthURLPathParam = "auth-url-path";
 	// degree of subsampling on image load
-	private float subsampleDistance = 0;
-	private String subsampleDistanceParam = "subsample-distance";
+	private float minSubsample = 2;
+	private String minSubsampleParam = "subsample-minimum";
 	// DocuDirCache instance
 	private DocuDirCache dirCache = null;
 
@@ -163,9 +163,9 @@
 			authConfPath = tryToGetInitParam(authConfParam, authConfPath);
 			authOp = new XMLAuthOps(util, authConfPath);
 		}
-		// subsampleDistance
-		subsampleDistance =
-			tryToGetInitParam(subsampleDistanceParam, subsampleDistance);
+		// minSubsample
+		minSubsample =
+			tryToGetInitParam(minSubsampleParam, minSubsample);
 	}
 
 	/**
@@ -480,16 +480,16 @@
 	/**
 	 * @return float
 	 */
-	public float getSubsampleDistance() {
-		return subsampleDistance;
+	public float getMinSubsample() {
+		return minSubsample;
 	}
 
 	/**
-	 * Sets the subsampleDistance.
-	 * @param subsampleDistance The subsampleDistance to set
+	 * Sets the minSubsample.
+	 * @param minSubsample The minSubsample to set
 	 */
-	public void setSubsampleDistance(float subsampleDistance) {
-		this.subsampleDistance = subsampleDistance;
+	public void setMinSubsample(float f) {
+		this.minSubsample = f;
 	}
 
 	/**
--- a/servlet/src/digilib/servlet/Scaler.java	Thu Jul 31 20:56:51 2003 +0200
+++ b/servlet/src/digilib/servlet/Scaler.java	Fri Aug 15 23:52:20 2003 +0200
@@ -58,7 +58,7 @@
 public class Scaler extends HttpServlet {
 
 	// digilib servlet version (for all components)
-	public static final String dlVersion = "1.11b1";
+	public static final String dlVersion = "1.12b2";
 
 	// Utils instance with debuglevel
 	Utils util;
@@ -90,6 +90,7 @@
 
 		// Debuggin!
 		//TCTool tctool = new TCTool();
+		System.out.println("***** Digital Image Library Servlet (version "+dlVersion+") *****");
 
 		// get our ServletContext
 		ServletContext context = config.getServletContext();
@@ -617,7 +618,15 @@
 				double subsamp = 1d;
 				if (scaleXY < 1) {
 					subf = 1 / scaleXY;
-					subsamp = Math.floor(subf);
+					// for higher quality reduce subsample factor by minSubsample
+					if (scaleQual > 0) {
+						subsamp =
+							Math.max(
+								Math.floor(subf / dlConfig.getMinSubsample()),
+								1d);
+					} else {
+						subsamp = Math.floor(subf);
+					}
 					scaleXY = subsamp / subf;
 					System.out.println(
 						"Using subsampling: " + subsamp + " rest " + scaleXY);