changeset 854:1e2e9599d84c stream

(slightly) fixed enhance and colop in linux.
author robcast
date Mon, 07 Mar 2011 11:59:11 +0100
parents 4a3bb0888c93
children 456408791331
files servlet/src/digilib/image/ImageLoaderDocuImage.java servlet/src/digilib/servlet/Scaler.java
diffstat 2 files changed, 31 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/image/ImageLoaderDocuImage.java	Mon Mar 07 10:35:57 2011 +0100
+++ b/servlet/src/digilib/image/ImageLoaderDocuImage.java	Mon Mar 07 11:59:11 2011 +0100
@@ -74,10 +74,13 @@
             new Kernel(3, 3, new float[] {1f/9f, 1f/9f, 1f/9f, 1f/9f, 1f/9f, 1f/9f, 1f/9f, 1f/9f, 1f/9f})
 	};
 
-	/** lookup table for inverting images (byte) */
+	/* lookup tables for inverting images (byte) */
 	protected static LookupTable invertSingleByteTable;
     protected static LookupTable invertRgbaByteTable;
-	
+    protected static boolean needsInvertRgba = false;
+	/* RescaleOps for contrast/brightness operation */
+    protected static boolean needsRescaleRgba = false;
+    
 	static {
 		byte[] invertByte = new byte[256];
 		byte[] orderedByte = new byte[256];
@@ -97,6 +100,8 @@
 			// GRAB(WTF?) works in Linux JDK1.6 with transparency
 			invertRgbaByteTable = new ByteLookupTable(0, new byte[][] {
 					invertByte, invertByte, orderedByte, invertByte});
+			needsInvertRgba = true;
+			needsRescaleRgba = true;
 		} else {
 			invertRgbaByteTable = invertSingleByteTable;
 		}
@@ -430,24 +435,30 @@
 
 	public void enhance(float mult, float add) throws ImageOpException {
 		RescaleOp op = null;
-		logger.debug("enhance: cm="+img.getColorModel());
-		op = new RescaleOp(mult, add, renderHint);
-		/*
-		 * Only one constant should work regardless of the number of bands
-		 * according to the JDK spec. Doesn't work on JDK 1.4 for OSX and Linux
-		 * (at least). RescaleOp scaleOp = new RescaleOp( (float)mult,
-		 * (float)add, null); scaleOp.filter(img, img);
-		 */
+		logger.debug("enhance: cm=" + img.getColorModel());
+		if (needsRescaleRgba) {
+			/*
+			 * Only one constant should work regardless of the number of bands
+			 * according to the JDK spec. Doesn't work on JDK 1.4 for OSX and
+			 * Linux (at least). RescaleOp scaleOp = new RescaleOp( (float)mult,
+			 * (float)add, null); scaleOp.filter(img, img);
+			 */
 
-		/* The number of constants must match the number of bands in the image.
-		int ncol = img.getColorModel().getNumComponents();
-		float[] dm = new float[ncol];
-		float[] da = new float[ncol];
-		for (int i = 0; i < ncol; i++) {
-			dm[i] = (float) mult;
-			da[i] = (float) add;
+			/*
+			 * The number of constants must match the number of bands in the
+			 * image.
+			 */
+			int ncol = img.getColorModel().getNumComponents();
+			float[] dm = new float[ncol];
+			float[] da = new float[ncol];
+			for (int i = 0; i < ncol; i++) {
+				dm[i] = (float) mult;
+				da[i] = (float) add;
+			}
+			op = new RescaleOp(dm, da, null);
+		} else {
+			op = new RescaleOp(mult, add, renderHint);
 		}
-		RescaleOp scaleOp = new RescaleOp(dm, da, null); */
 		op.filter(img, img);
 	}
 
@@ -528,7 +539,7 @@
 			// TODO: is this enough for all image types?
 			LookupTable invtbl = null;
 			ColorModel cm = img.getColorModel();
-			if (cm.hasAlpha()) {
+			if (needsInvertRgba && cm.hasAlpha()) {
 				// JDK 1.6 in Linux (at least) is broken :-(
 				invtbl = invertRgbaByteTable;
 			} else {
--- a/servlet/src/digilib/servlet/Scaler.java	Mon Mar 07 10:35:57 2011 +0100
+++ b/servlet/src/digilib/servlet/Scaler.java	Mon Mar 07 11:59:11 2011 +0100
@@ -31,7 +31,7 @@
     private static final long serialVersionUID = 5289386646192471549L;
 
     /** digilib servlet version (for all components) */
-    public static final String version = "1.9.1a18";
+    public static final String version = "1.9.1a19";
 
     /** servlet error codes */
     public static enum Error {UNKNOWN, AUTH, FILE, IMAGE};