Index: trunk/psLib/src/imageops/psImageConvolve.c
===================================================================
--- trunk/psLib/src/imageops/psImageConvolve.c	(revision 27910)
+++ trunk/psLib/src/imageops/psImageConvolve.c	(revision 27911)
@@ -871,14 +871,13 @@
             psFree(job);
         }
+        if (!psThreadPoolWait(true)) {
+            psError(PS_ERR_UNKNOWN, false, "Error waiting for threads.");
+            psFree(gaussNorm);
+            psFree(out);
+            return NULL;
+        }
     } else if (!imageSmoothMaskPixels(out, image, mask, maskVal, x, y,
                                       gaussNorm, minGauss, size, 0, num)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to smooth pixels.");
-        psFree(gaussNorm);
-        psFree(out);
-        return NULL;
-    }
-
-    if (threaded && !psThreadPoolWait(true)) {
-        psError(PS_ERR_UNKNOWN, false, "Error waiting for threads.");
         psFree(gaussNorm);
         psFree(out);
@@ -1192,35 +1191,48 @@
           psImage *calcMask = psImageAlloc(numRows, numCols, PS_TYPE_IMAGE_MASK); /* Mask for calculation image; BW */
 
-          /** Smooth in X direction **/
-          for (int rowStart = 0; rowStart < numRows; rowStart+=scanRows) {
-              int rowStop = PS_MIN (rowStart + scanRows, numRows);
-
-              // allocate a job, construct the arguments for this job
-              psThreadJob *job = psThreadJobAlloc("PSLIB_IMAGE_SMOOTHMASK_SCANROWS");
-              psArrayAdd(job->args, 1, calculation);
-              psArrayAdd(job->args, 1, calcMask);
-              psArrayAdd(job->args, 1, (psImage *) image); // cast away const
-              psArrayAdd(job->args, 1, (psImage *) mask); // cast away const
-              PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
-              psArrayAdd(job->args, 1, gaussNorm);
-              PS_ARRAY_ADD_SCALAR(job->args, minGauss, PS_TYPE_F32);
-              PS_ARRAY_ADD_SCALAR(job->args, size,     PS_TYPE_S32);
-              PS_ARRAY_ADD_SCALAR(job->args, rowStart, PS_TYPE_S32);
-              PS_ARRAY_ADD_SCALAR(job->args, rowStop,  PS_TYPE_S32);
-              // -> psImageSmoothMask_ScanRows_F32 (calculation, calcMask, image, mask, maskVal, gauss, minGauss, size, rowStart, rowStop);
-
-              // if threading is not active, we simply run the job and return
-              if (!psThreadJobAddPending(job)) {
+          if (threaded) {
+              /** Smooth in X direction **/
+              for (int rowStart = 0; rowStart < numRows; rowStart+=scanRows) {
+                  int rowStop = PS_MIN (rowStart + scanRows, numRows);
+
+                  // allocate a job, construct the arguments for this job
+                  psThreadJob *job = psThreadJobAlloc("PSLIB_IMAGE_SMOOTHMASK_SCANROWS");
+                  psArrayAdd(job->args, 1, calculation);
+                  psArrayAdd(job->args, 1, calcMask);
+                  psArrayAdd(job->args, 1, (psImage *) image); // cast away const
+                  psArrayAdd(job->args, 1, (psImage *) mask); // cast away const
+                  PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
+                  psArrayAdd(job->args, 1, gaussNorm);
+                  PS_ARRAY_ADD_SCALAR(job->args, minGauss, PS_TYPE_F32);
+                  PS_ARRAY_ADD_SCALAR(job->args, size,     PS_TYPE_S32);
+                  PS_ARRAY_ADD_SCALAR(job->args, rowStart, PS_TYPE_S32);
+                  PS_ARRAY_ADD_SCALAR(job->args, rowStop,  PS_TYPE_S32);
+                  // -> psImageSmoothMask_ScanRows_F32 (calculation, calcMask, image, mask, maskVal, gauss, minGauss, size, rowStart, rowStop);
+
+                  // if threading is not active, we simply run the job and return
+                  if (!psThreadJobAddPending(job)) {
+                      psError(PS_ERR_UNKNOWN, false, "Unable to smooth image");
+                      psFree(job);
+                      psFree(calculation);
+                      psFree(calcMask);
+                      psFree(gaussNorm);
+                      return false;
+                  }
+                  psFree(job);
+              }
+              // wait here for the threaded jobs to finish (NOP if threading is not active)
+              if (!psThreadPoolWait(true)) {
                   psError(PS_ERR_UNKNOWN, false, "Unable to smooth image");
-                  psFree(job);
+                  psFree(calculation);
+                  psFree(calcMask);
+                  psFree(gaussNorm);
                   return false;
               }
-              psFree(job);
-
-          }
-
-          // wait here for the threaded jobs to finish (NOP if threading is not active)
-          if (!psThreadPoolWait(true)) {
+          } else if (!psImageSmoothMask_ScanRows_F32(calculation, calcMask, image, mask, maskVal,
+                                                     gaussNorm, minGauss, size, 0, numRows)) {
               psError(PS_ERR_UNKNOWN, false, "Unable to smooth image");
+              psFree(calculation);
+              psFree(calcMask);
+              psFree(gaussNorm);
               return false;
           }
@@ -1229,34 +1241,50 @@
 
           /** Smooth in Y direction  **/
-          for (int colStart = 0; colStart < numCols; colStart+=scanCols) {
-              int colStop = PS_MIN (colStart + scanCols, numCols);
-
-              // allocate a job, construct the arguments for this job
-              psThreadJob *job = psThreadJobAlloc("PSLIB_IMAGE_SMOOTHMASK_SCANCOLS");
-              psArrayAdd(job->args, 1, output);
-              psArrayAdd(job->args, 1, calculation);
-              psArrayAdd(job->args, 1, calcMask);
-              PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
-              psArrayAdd(job->args, 1, gaussNorm);
-              PS_ARRAY_ADD_SCALAR(job->args, minGauss, PS_TYPE_F32);
-              PS_ARRAY_ADD_SCALAR(job->args, size,     PS_TYPE_S32);
-              PS_ARRAY_ADD_SCALAR(job->args, colStart, PS_TYPE_S32);
-              PS_ARRAY_ADD_SCALAR(job->args, colStop,  PS_TYPE_S32);
-              // -> psImageSmoothMask_ScanCols_F32 (output, calculation, calcMask, maskVal, gauss, minGauss, size, colStart, colStop);
-
-              // if threading is not active, we simply run the job and return
-              if (!psThreadJobAddPending(job)) {
+          if (threaded) {
+              for (int colStart = 0; colStart < numCols; colStart+=scanCols) {
+                  int colStop = PS_MIN (colStart + scanCols, numCols);
+
+                  // allocate a job, construct the arguments for this job
+                  psThreadJob *job = psThreadJobAlloc("PSLIB_IMAGE_SMOOTHMASK_SCANCOLS");
+                  psArrayAdd(job->args, 1, output);
+                  psArrayAdd(job->args, 1, calculation);
+                  psArrayAdd(job->args, 1, calcMask);
+                  PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
+                  psArrayAdd(job->args, 1, gaussNorm);
+                  PS_ARRAY_ADD_SCALAR(job->args, minGauss, PS_TYPE_F32);
+                  PS_ARRAY_ADD_SCALAR(job->args, size,     PS_TYPE_S32);
+                  PS_ARRAY_ADD_SCALAR(job->args, colStart, PS_TYPE_S32);
+                  PS_ARRAY_ADD_SCALAR(job->args, colStop,  PS_TYPE_S32);
+                  // -> psImageSmoothMask_ScanCols_F32 (output, calculation, calcMask, maskVal, gauss, minGauss, size, colStart, colStop);
+
+                  // if threading is not active, we simply run the job and return
+                  if (!psThreadJobAddPending(job)) {
+                      psError(PS_ERR_UNKNOWN, false, "Unable to smooth image");
+                      psFree(job);
+                      psFree(calculation);
+                      psFree(calcMask);
+                      psFree(gaussNorm);
+                      return false;
+                  }
+                  psFree(job);
+              }
+
+              // wait here for the threaded jobs to finish (NOP if threading is not active)
+              if (!psThreadPoolWait(true)) {
                   psError(PS_ERR_UNKNOWN, false, "Unable to smooth image");
-                  psFree(job);
+                  psFree(calculation);
+                  psFree(calcMask);
+                  psFree(gaussNorm);
                   return false;
               }
-              psFree(job);
-          }
-
-          // wait here for the threaded jobs to finish (NOP if threading is not active)
-          if (!psThreadPoolWait(true)) {
+          } else if (!psImageSmoothMask_ScanCols_F32(output, calculation, calcMask, maskVal,
+                                                     gaussNorm, minGauss, size, 0, numCols)) {
               psError(PS_ERR_UNKNOWN, false, "Unable to smooth image");
+              psFree(calculation);
+              psFree(calcMask);
+              psFree(gaussNorm);
               return false;
           }
+
           psFree(calculation);
           psFree(calcMask);
@@ -1559,13 +1587,12 @@
             psFree(job);
         }
+        if (!psThreadPoolWait(true)) {
+            psError(PS_ERR_UNKNOWN, false, "Error waiting for threads.");
+            psFree(conv);
+            psFree(out);
+            return NULL;
+        }
     } else if (!imageConvolveMaskColumns(conv, mask, 0, numRows, maskVal, xMin, xMax)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to convolve mask columns.");
-        psFree(conv);
-        psFree(out);
-        return NULL;
-    }
-
-    if (threaded && !psThreadPoolWait(true)) {
-        psError(PS_ERR_UNKNOWN, false, "Error waiting for threads.");
         psFree(conv);
         psFree(out);
@@ -1597,13 +1624,12 @@
             psFree(job);
         }
+        if (!psThreadPoolWait(true)) {
+            psError(PS_ERR_UNKNOWN, false, "Error waiting for threads.");
+            psFree(conv);
+            psFree(out);
+            return NULL;
+        }
     } else if (!imageConvolveMaskRows(out, conv, 0, numCols, setVal, yMin, yMax)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to convolve mask columns.");
-        psFree(conv);
-        psFree(out);
-        return NULL;
-    }
-
-    if (threaded && !psThreadPoolWait(true)) {
-        psError(PS_ERR_UNKNOWN, false, "Error waiting for threads.");
         psFree(conv);
         psFree(out);
