Index: trunk/psModules/src/camera/pmFPA_JPEG.c
===================================================================
--- trunk/psModules/src/camera/pmFPA_JPEG.c	(revision 10715)
+++ trunk/psModules/src/camera/pmFPA_JPEG.c	(revision 10883)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-12-14 06:27:52 $
+ *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-01-03 03:18:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -123,4 +123,5 @@
 bool pmReadoutWriteJPEG (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, pmConfig *config)
 {
+    bool status;
     PS_ASSERT_PTR_NON_NULL(readout, false);
     PS_ASSERT_PTR_NON_NULL(view, false);
@@ -134,7 +135,20 @@
     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
+    psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PPIMAGE");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, true, "missing recipe PPIMAGE in config data");
+        return false;
+    }
+
+    psMetadata *options = psMetadataLookupMetadata(&status, recipe, file->name);
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, true, "missing %s options in PPIMAGE recipe", file->name);
+        return false;
+    }
+
     float min, max;                 // Minimum and maximum for stretch
     float mean, delta;
+
+    // measure the image statistics for scaling
     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
     psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN);
@@ -159,25 +173,30 @@
     psFree(stats);
 
-    psString mode = pmFPAfileNameFromRule (file->extrule, file, view);
-    psString word = pmFPAfileNameFromRule (file->extxtra, file, view);
-    psArray *range = psStringSplitArray (word, ":", false);
-
-    if (!strcasecmp (mode, "RANGE") && range) {
-        float fmin = atof(range->data[0]);
-        float fmax = atof(range->data[1]);
+    char *colormapName = psMemIncrRefCounter (psMetadataLookupStr (NULL, options, "COLORMAP"));
+    if (!colormapName)
+        colormapName = psStringCopy ("-greyscale");
+    char *mode = psMemIncrRefCounter (psMetadataLookupStr (NULL, options, "SCALE.MODE"));
+    if (!mode)
+        mode = psStringCopy ("RANGE");
+    float fmin = psMetadataLookupF32 (&status, options, "SCALE.MIN");
+    if (!status)
+        fmin = -3.0;
+    float fmax = psMetadataLookupF32 (&status, options, "SCALE.MAX");
+    if (!status)
+        fmax = +6.0;
+
+    if (!strcasecmp (mode, "RANGE")) {
         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]);
+    }
+    if (!strcasecmp (mode, "FRACTION")) {
         min = fmin*mean;
         max = fmax*mean;
-    } else {
-        min = mean - 3*delta;
-        max = mean + 6*delta;
-    }
-    psFree(mode);
-    psFree(word);
-    psFree(range);
+    }
+    if (!strcasecmp (mode, "VALUE")) {
+        min = fmin;
+        max = fmax;
+    }
+
 
     if (!isfinite(min) || !isfinite(max)) {
@@ -189,7 +208,6 @@
     psString name = pmFPAfileNameFromRule (file->filerule, file, view);
     psString newName = pmConfigConvertFilename (name, config);
-    psString mapname = pmFPAfileNameFromRule (file->filextra, file, view);
-    psImageJpegColormap *map = psImageJpegColormapSet (NULL, mapname);
-    psFree(mapname);
+
+    psImageJpegColormap *map = psImageJpegColormapSet (NULL, colormapName);
     if (!map) {
         map = psImageJpegColormapSet (NULL, "-greyscale");
@@ -197,8 +215,11 @@
 
     psImageJpeg (map, readout->image, newName, min, max);
+
+    psFree(name);
     psFree(newName);
-    psFree(name);
+
     psFree(map);
-
-    return true;
-}
+    psFree(colormapName);
+    psFree(mode);
+    return true;
+}
