Index: trunk/psModules/src/camera/pmFPA_JPEG.c
===================================================================
--- trunk/psModules/src/camera/pmFPA_JPEG.c	(revision 10421)
+++ trunk/psModules/src/camera/pmFPA_JPEG.c	(revision 10715)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-12-03 18:48:10 $
+ *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-12-14 06:27:52 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -117,5 +117,8 @@
 }
 
-// read in all readout-level Objects files for this cell
+// write JPEG image for readout
+// note that this function will try as hard a possible to write out a jpeg.  it will not fail
+// just because the values are in a poor range.  it is more convenient to know you are getting
+// a jpeg which is weird than to fail to get the file at all.
 bool pmReadoutWriteJPEG (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, pmConfig *config)
 {
@@ -129,23 +132,30 @@
     }
 
+    psTrace("psModules.camera", 3, "writing jpeg for readout %zd\n", (size_t) readout);
+
     // XXX we need to decide where the scale will come from in the long term
+    float min, max;                 // Minimum and maximum for stretch
+    float mean, delta;
     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN);
     stats->nSubsample = 10000;
     if (!psImageBackground(stats, readout->image, NULL, 0, rng)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to write JPEG of readout.\n");
-        psFree(rng);
-        psFree(stats);
-        return false;
+        psStats *statsAlt = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
+        stats->nSubsample = 10000;
+        if (!psImageBackground(stats, readout->image, NULL, 0, rng)) {
+            psLogMsg("jpeg", PS_LOG_WARN, "Unable to measure statistics for image, writing blank jpeg\n");
+            mean = 0;
+            delta = 1;
+        } else {
+            mean = statsAlt->sampleMean;
+            delta = 2*statsAlt->sampleStdev;
+        }
+        psFree(statsAlt);
+    } else {
+        mean = stats->robustMedian;
+        delta = stats->robustUQ - stats->robustLQ;
     }
     psFree(rng);
-
-    if (!isfinite(stats->robustMedian) || !isfinite(stats->robustUQ) || !isfinite(stats->robustLQ)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to measure statistics for image.\n");
-        psFree(stats);
-        return false;
-    }
-    float delta = stats->robustUQ - stats->robustLQ; // Inter-quartile range
-    float min, max;                 // Minimum and maximum for stretch
+    psFree(stats);
 
     psString mode = pmFPAfileNameFromRule (file->extrule, file, view);
@@ -156,23 +166,23 @@
         float fmin = atof(range->data[0]);
         float fmax = atof(range->data[1]);
-        min = stats->robustMedian + fmin*delta;
-        max = stats->robustMedian + fmax*delta;
+        min = mean + fmin*delta;
+        max = mean + fmax*delta;
     } else if (!strcasecmp (mode, "FRACTION")) {
         float fmin = atof(range->data[0]);
         float fmax = atof(range->data[1]);
-        min = fmin*stats->robustMedian;
-        max = fmax*stats->robustMedian;
+        min = fmin*mean;
+        max = fmax*mean;
     } else {
-        min = stats->robustMedian - 3*delta;
-        max = stats->robustMedian + 6*delta;
+        min = mean - 3*delta;
+        max = mean + 6*delta;
     }
     psFree(mode);
     psFree(word);
     psFree(range);
-    psFree(stats);
 
     if (!isfinite(min) || !isfinite(max)) {
-        psError(PS_ERR_UNKNOWN, true, "The stretch parameters are not both finite.\n");
-        return false;
+        psLogMsg("jpeg", PS_LOG_WARN, "The stretch parameters are not both finite, writing blank jpeg\n");
+        min = 0;
+        max = 1;
     }
 
