Index: trunk/psModules/src/camera/pmChipMosaic.c
===================================================================
--- trunk/psModules/src/camera/pmChipMosaic.c	(revision 7364)
+++ trunk/psModules/src/camera/pmChipMosaic.c	(revision 7382)
@@ -1,8 +1,7 @@
 #include <stdio.h>
 #include <assert.h>
-#include "pslib.h"
+#include <pslib.h>
 #include "pmFPA.h"
 #include "pmHDU.h"
-#include "psRegionIsBad.h"
 
 
@@ -52,5 +51,5 @@
         pmCell *cell = cells->data[i];  // Cell of interest
         psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim section
-        if (!mdok || !trimsec || psRegionIsBad(*trimsec)) {
+        if (!mdok || !trimsec || psRegionIsNaN(*trimsec)) {
             psError(PS_ERR_IO, true, "CELL.TRIMSEC hasn't been set for cell %d.\n", i);
             return false;
@@ -86,5 +85,5 @@
         psRegion *biassec = NULL;       // Bias section from iteration
         while ((biassec = psListGetAndIncrement(biassecsIter))) {
-            if (psRegionIsBad(*biassec)) {
+            if (psRegionIsNaN(*biassec)) {
                 continue;
             }
Index: trunk/psModules/src/camera/pmFPACopy.c
===================================================================
--- trunk/psModules/src/camera/pmFPACopy.c	(revision 7364)
+++ trunk/psModules/src/camera/pmFPACopy.c	(revision 7382)
@@ -2,7 +2,5 @@
 #include <assert.h>
 
-#include "pslib.h"
-#include "psImageFlip.h"
-#include "psRegionIsBad.h"
+#include <pslib.h>
 
 #include "pmFPA.h"
@@ -17,34 +15,4 @@
 // File-static functions
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-// Copy pixels from a target image to a source image, with flips
-static psImage *copyPixels(psImage *source, // Source image (from source cell)
-                           bool xFlip,      // Flip in x?
-                           bool yFlip       // Flip in y?
-                          )
-{
-    assert(source);
-
-    psImage *copy = psMemIncrRefCounter(source);
-    bool copied = false;                // Have the pixels been copied?
-    if (xFlip) {
-        psImage *temp = psImageFlipX(copy); // Flipped version
-        psFree(copy);
-        copy = temp;
-        copied = true;
-    }
-    if (yFlip) {
-        psImage *temp = psImageFlipY(copy); // Flipped version
-        psFree(copy);
-        copy = temp;
-        copied = true;
-    }
-    if (!copied) {
-        psFree(copy);
-        copy = psImageCopy(NULL, source, source->type.type);
-    }
-
-    return copy;
-}
 
 // Bin a region down by specified factors in x and y
@@ -154,5 +122,5 @@
                     psFree(targetReadout->image);
                 }
-                targetReadout->image = copyPixels(sourceReadout->image, xFlip, yFlip);
+                targetReadout->image = psImageFlip(NULL, sourceReadout->image, xFlip, yFlip);
             }
 
@@ -162,5 +130,5 @@
                     psFree(targetReadout->mask);
                 }
-                targetReadout->mask = copyPixels(sourceReadout->mask, xFlip, yFlip);
+                targetReadout->mask = psImageFlip(NULL, sourceReadout->mask, xFlip, yFlip);
             }
 
@@ -170,5 +138,5 @@
                     psFree(targetReadout->weight);
                 }
-                targetReadout->weight = copyPixels(sourceReadout->weight, xFlip, yFlip);
+                targetReadout->weight = psImageFlip(NULL, sourceReadout->weight, xFlip, yFlip);
             }
 
@@ -181,5 +149,5 @@
             psImage *bias = NULL;           // Bias image from iteration
             while ((bias = psListGetAndIncrement(biasIter))) {
-                psImage *biasCopy = copyPixels(bias, xFlip, yFlip);
+                psImage *biasCopy = psImageFlip(NULL, bias, xFlip, yFlip);
                 psListAdd(targetReadout->bias, PS_LIST_TAIL, biasCopy);
                 psFree(biasCopy);           // Drop reference
@@ -209,5 +177,5 @@
     if (xBin != 1 || yBin != 1) {
         psRegion *trimsec = psMetadataLookupPtr(&mdok, target->concepts, "CELL.TRIMSEC"); // The trim section
-        if (mdok && trimsec && !psRegionIsBad(*trimsec)) {
+        if (mdok && trimsec && !psRegionIsNaN(*trimsec)) {
             binRegion(trimsec, xBin, yBin);
         }
@@ -217,5 +185,5 @@
             psRegion *biassec = NULL;   // Bias section, from iteration
             while ((biassec = psListGetAndIncrement(biassecsIter))) {
-                if (!psRegionIsBad(*biassec)) {
+                if (!psRegionIsNaN(*biassec)) {
                     binRegion(biassec, xBin, yBin);
                 }
Index: trunk/psModules/src/camera/pmFPARead.c
===================================================================
--- trunk/psModules/src/camera/pmFPARead.c	(revision 7364)
+++ trunk/psModules/src/camera/pmFPARead.c	(revision 7382)
@@ -8,5 +8,4 @@
 #include "pmHDUUtils.h"
 #include "pmConcepts.h"
-#include "psRegionIsBad.h"
 #include "pmFPAHeader.h"
 
@@ -33,5 +32,5 @@
 
     // The image corresponding to the trim region
-    if (psRegionIsBad(*trimsec)) {
+    if (psRegionIsNaN(*trimsec)) {
         psString regionString = psRegionToString(*trimsec);
         psError(PS_ERR_UNKNOWN, true, "Invalid trim section: %s\n", regionString);
@@ -59,5 +58,5 @@
     psRegion *biassec = NULL;       // A BIASSEC region from the list
     while ((biassec = psListGetAndIncrement(iter))) {
-        if (psRegionIsBad(*biassec)) {
+        if (psRegionIsNaN(*biassec)) {
             psString regionString = psRegionToString(*biassec);
             psError(PS_ERR_IO, true, "Invalid bias section: %s\n", regionString);
@@ -190,5 +189,5 @@
     bool mdok = true;                   // Status of MD lookup
     psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim sections
-    if (!mdok || !trimsec || psRegionIsBad(*trimsec)) {
+    if (!mdok || !trimsec || psRegionIsNaN(*trimsec)) {
         psError(PS_ERR_IO, true, "CELL.TRIMSEC is not set.\n");
         return false;
Index: trunk/psModules/src/camera/pmFPA_JPEG.c
===================================================================
--- trunk/psModules/src/camera/pmFPA_JPEG.c	(revision 7364)
+++ trunk/psModules/src/camera/pmFPA_JPEG.c	(revision 7382)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-06-03 01:02:08 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-06-07 03:27:52 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -17,7 +17,4 @@
 
 #include <pslib.h>
-# include "psImageJpeg.h"
-# include "psImageUnbin.h"
-# include "psAdditionals.h"
 
 #include "pmHDU.h"
@@ -141,8 +138,6 @@
 
         // XXX we need to decide where the scale will come from in the long term
-        unsigned long seed = 0;
-        psImageClippedStatsInit (10000, seed);
-
-        psStats *stats = psImageClippedStats (readout->image, NULL, 0, 0.25, 0.75);
+        psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 0);
+        psStats *stats = psImageBackground(readout->image, NULL, 0, 0.25, 0.75, 10000, rng);
         float delta = stats->robustUQ - stats->robustLQ;
         float min = stats->robustMedian - 3*delta;
@@ -162,11 +157,11 @@
         psImageJpeg (map, readout->image, name, min, max);
 
-        psFree (name);
-        psFree (mode);
-        psFree (word);
-        psFree (mapname);
-        psFree (map);
-        psFree (stats);
-        psImageClippedStatsCleanup ();
+        psFree(name);
+        psFree(mode);
+        psFree(word);
+        psFree(mapname);
+        psFree(map);
+        psFree(stats);
+        psFree(rng);
 
         return true;
Index: trunk/psModules/src/camera/pmFPAfile.c
===================================================================
--- trunk/psModules/src/camera/pmFPAfile.c	(revision 7364)
+++ trunk/psModules/src/camera/pmFPAfile.c	(revision 7382)
@@ -1,5 +1,5 @@
 #include <stdio.h>
-#include "pslib.h"
-#include "psAdditionals.h"
+#include <pslib.h>
+
 #include "pmConfig.h"
 #include "pmHDU.h"
Index: trunk/psModules/src/camera/pmHDU.c
===================================================================
--- trunk/psModules/src/camera/pmHDU.c	(revision 7364)
+++ trunk/psModules/src/camera/pmHDU.c	(revision 7382)
@@ -4,5 +4,4 @@
 #include "pslib.h"
 #include "pmFPA.h"
-#include "psAdditionals.h"
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
Index: trunk/psModules/src/camera/pmHDUGenerate.c
===================================================================
--- trunk/psModules/src/camera/pmHDUGenerate.c	(revision 7364)
+++ trunk/psModules/src/camera/pmHDUGenerate.c	(revision 7382)
@@ -6,5 +6,4 @@
 #include "pmHDU.h"
 #include "pmHDUUtils.h"
-#include "psRegionIsBad.h"
 
 #include "pmHDUGenerate.h"
@@ -66,5 +65,5 @@
     while ((cell = psListGetAndIncrement(cellsIter))) {
         psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim section
-        if (mdok && trimsec && !psRegionIsBad(*trimsec)) {
+        if (mdok && trimsec && !psRegionIsNaN(*trimsec)) {
             *xSize = PS_MAX(trimsec->x1, *xSize);
             *ySize = PS_MAX(trimsec->y1, *ySize);
@@ -78,5 +77,5 @@
             psRegion *biassec = NULL;   // The bias section
             while ((biassec = psListGetAndIncrement(biassecsIter))) {
-                if (!psRegionIsBad(*trimsec)) {
+                if (!psRegionIsNaN(*trimsec)) {
                     *xSize = PS_MAX(biassec->x1, *xSize);
                     *ySize = PS_MAX(biassec->y1, *ySize);
