changeset 103:0e49645f98c8

Servlet V1.9b2 Fixes error in rotation for ImageLoader DocuImage.
author robcast
date Mon, 12 May 2003 22:33:44 +0200
parents 5fdf109d31c2
children 4b3a9bedf33e
files servlet/src/digilib/image/ImageLoaderDocuImage.java servlet/src/digilib/servlet/Scaler.java
diffstat 2 files changed, 17 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/image/ImageLoaderDocuImage.java	Mon May 05 22:30:50 2003 +0200
+++ b/servlet/src/digilib/image/ImageLoaderDocuImage.java	Mon May 12 22:33:44 2003 +0200
@@ -286,32 +286,37 @@
 		// create offset to make shure the rotated image has no negative coordinates
 		double w = img.getWidth();
 		double h = img.getHeight();
-		double xoff = (w / 2) * Math.sin(rangle);
-		double yoff = (h / 2) * Math.sin(rangle);
-		double off = Math.max(xoff, yoff)+10;
-		// move image
-		AffineTransform trafo = AffineTransform.getTranslateInstance(off, off);
-		// new center of rotation 
-		double x = (w / 2) + off;
-		double y = (h / 2) + off;
+		AffineTransform trafo = new AffineTransform();
+		// center of rotation 
+		double x = (w / 2);
+		double y = (h / 2);
 		trafo.rotate(rangle, x, y);
+		// try rotation to see how far we're out of bounds
+		AffineTransformOp rotOp = new AffineTransformOp(trafo, interpol);
+		Rectangle2D rotbounds = rotOp.getBounds2D(img);
+		double xoff = rotbounds.getX();
+		double yoff = rotbounds.getY();
+		// move image back in line
+		trafo.preConcatenate(AffineTransform.getTranslateInstance(-xoff, -yoff));
 		// transform image
-		AffineTransformOp rotOp = new AffineTransformOp(trafo, interpol);
+		rotOp = new AffineTransformOp(trafo, interpol);
 		BufferedImage rotImg = rotOp.filter(img, null);
 		// calculate new bounding box
-		Rectangle2D bounds = rotOp.getBounds2D(img);
+		//Rectangle2D bounds = rotOp.getBounds2D(img);
 
 		if (rotImg == null) {
 			util.dprintln(2, "ERROR: error in rotate");
 			throw new ImageOpException("Unable to rotate");
 		}
+		img = rotImg;
 		// crop new image (with self-made rounding)
-		img =
+		/* img =
 			rotImg.getSubimage(
 				(int) (bounds.getX()+0.5),
 				(int) (bounds.getY()+0.5),
 				(int) (bounds.getWidth()+0.5),
 				(int) (bounds.getHeight()+0.5));
+		*/
 	}
 
 	public void mirror(double angle) throws ImageOpException {
--- a/servlet/src/digilib/servlet/Scaler.java	Mon May 05 22:30:50 2003 +0200
+++ b/servlet/src/digilib/servlet/Scaler.java	Mon May 12 22:33:44 2003 +0200
@@ -56,7 +56,7 @@
 public class Scaler extends HttpServlet {
 
 	// digilib servlet version (for all components)
-	public static final String dlVersion = "1.9b1";
+	public static final String dlVersion = "1.9b2";
 
 	// Utils instance with debuglevel
 	Utils util;