Index: trunk/psLib/src/imageops/psImageConvolve.c
===================================================================
--- trunk/psLib/src/imageops/psImageConvolve.c	(revision 30078)
+++ trunk/psLib/src/imageops/psImageConvolve.c	(revision 30595)
@@ -67,5 +67,8 @@
 }
 
-psKernel *psKernelAlloc(int xMin, int xMax, int yMin, int yMax)
+psKernel *p_psKernelAlloc(const char *file,
+			  unsigned int lineno,
+			  const char *func,
+			  int xMin, int xMax, int yMin, int yMax)
 {
     // Check the inputs to make sure max > min; if not, switch.
@@ -91,5 +94,5 @@
     int numCols = xMax - xMin + 1;      // Number of columns for kernel image
 
-    psKernel *kernel = psAlloc(sizeof(psKernel)); // The kernel, to be returned
+    psKernel *kernel = p_psAlloc(file, lineno, func, sizeof(psKernel)); // The kernel, to be returned
     psMemSetDeallocator(kernel,(psFreeFunc)kernelFree);
 
@@ -272,7 +275,9 @@
     float threshold = sumKernel * (1.0 - frac); // Threshold for truncation
 
+    int truncateRadius = maxSize;	// Truncation radius
+    bool truncate = false;
+
     // Find truncation size
-    int truncate = 0;                     // Truncation radius
-    for (int radius = 1; truncate == 0 && radius < maxSize; radius++) {
+    for (int radius = 1; !truncate && (radius < maxSize); radius++) {
         int uMin = PS_MAX(-radius, xMin);
         int uMax = PS_MIN(radius, xMax);
@@ -290,11 +295,13 @@
             }
         }
+	// This is the truncation radius
         if (sum > threshold) {
-            // This is the truncation radius
-            truncate = radius;
-        }
-    }
-    if (truncate == maxSize) {
-        // No truncation possible
+	    truncate = true;
+            truncateRadius = radius;
+        }
+    }
+
+    // Do nothing if no truncation is possible
+    if (!truncate) {
         return true;
     }
@@ -302,9 +309,9 @@
     // Truncate the kernel
     {
-        int uMin = PS_MAX(-truncate, xMin);
-        int uMax = PS_MIN(truncate, xMax);
-        int vMin = PS_MAX(-truncate, yMin);
-        int vMax = PS_MIN(truncate, yMax);
-        int r2 = PS_SQR(truncate);
+        int uMin = PS_MAX(-truncateRadius, xMin);
+        int uMax = PS_MIN(truncateRadius, xMax);
+        int vMin = PS_MAX(-truncateRadius, yMin);
+        int vMax = PS_MIN(truncateRadius, yMax);
+        int r2 = PS_SQR(truncateRadius);
         for (int v = vMin; v <= vMax; v++) {
             int v2 = PS_SQR(v);
@@ -317,8 +324,8 @@
         }
     }
-    kernel->xMin = PS_MAX(-truncate, kernel->xMin);
-    kernel->xMax = PS_MIN(truncate, kernel->xMax);
-    kernel->yMin = PS_MAX(-truncate, kernel->yMin);
-    kernel->yMax = PS_MIN(truncate, kernel->yMax);
+    kernel->xMin = PS_MAX(-truncateRadius, kernel->xMin);
+    kernel->xMax = PS_MIN(truncateRadius, kernel->xMax);
+    kernel->yMin = PS_MAX(-truncateRadius, kernel->yMin);
+    kernel->yMax = PS_MIN(truncateRadius, kernel->yMax);
 
     return true;
Index: trunk/psLib/src/imageops/psImageConvolve.h
===================================================================
--- trunk/psLib/src/imageops/psImageConvolve.h	(revision 30078)
+++ trunk/psLib/src/imageops/psImageConvolve.h	(revision 30595)
@@ -84,4 +84,5 @@
 /// @return psKernel*          A new kernel object
 ///
+#ifdef DOXYGEN
 psKernel *psKernelAlloc(
     int xMin,                          ///< Most negative x index
@@ -89,5 +90,18 @@
     int yMin,                          ///< Most negative y index
     int yMax                           ///< Most positive y index
+);
+#else // ifdef DOXYGEN
+psKernel *p_psKernelAlloc(
+    const char *file,                   ///< File of caller
+    unsigned int lineno,                ///< Line number of caller
+    const char *func,                   ///< Function name of caller
+    int xMin,                          ///< Most negative x index
+    int xMax,                          ///< Most positive x index
+    int yMin,                          ///< Most negative y index
+    int yMax                           ///< Most positive y index
 ) PS_ATTR_MALLOC;
+#define psKernelAlloc(xMin, xMax, yMin, yMax)				\
+    p_psKernelAlloc(__FILE__, __LINE__, __func__, (xMin), (xMax), (yMin), (yMax))
+#endif // ifdef DOXYGEN
 
 /// Allocate a convolution kernel from a provided image
Index: trunk/psLib/src/imageops/psImageCovariance.c
===================================================================
--- trunk/psLib/src/imageops/psImageCovariance.c	(revision 30078)
+++ trunk/psLib/src/imageops/psImageCovariance.c	(revision 30595)
@@ -30,4 +30,15 @@
     return covar;
 }
+
+/** 
+
+ * changes from 28666
+ ** add scale to imageCovarianceCalculate (& multiply at return)
+ ** add scale to imageCovarianceCalculateThread
+
+ ** accumulate scale (sum kernel^2) in psImageCovarianceCalculate and pass to imageCovarianceCalculate
+ ** accumulate scale (sum kernel^2) in psImageCovarianceCalculateFactor and pass to imageCovarianceCalculate
+
+ **/
 
 /// Calculation of covariance matrix element when convolving
