Index: trunk/pstamp/src/ppstampParseCamera.c
===================================================================
--- trunk/pstamp/src/ppstampParseCamera.c	(revision 29379)
+++ trunk/pstamp/src/ppstampParseCamera.c	(revision 33378)
@@ -8,5 +8,5 @@
 
 // Set up the ppstamp output Image file
-bool setupOutput(pmConfig *config, pmFPAfile *input, psString stage, bool doMask, bool doWeight)
+bool setupOutput(pmConfig *config, pmFPAfile *input, psString stage, bool doMask, bool doWeight, pmFPAfile **pOutput)
 {
     pmFPAfile *output;
@@ -22,4 +22,5 @@
         return false;
     }
+    *pOutput = output;
 
     output->save = true;
@@ -33,4 +34,5 @@
         outWeight->save = true;
     }
+
 
     return true;
@@ -76,5 +78,4 @@
         
 
-
     // XXX: create a filerule for PPSTAMP.ASTROM
     pmFPAfile *astrom = pmFPAfileDefineFromArgs(&status, config, "PSWARP.ASTROM", "ASTROM");
@@ -95,10 +96,11 @@
 
     // Set up the output target
-    if (!setupOutput(config, input, options->stage, doMask, doWeight)) {
+    pmFPAfile *output;
+    if (!setupOutput(config, input, options->stage, doMask, doWeight, &output)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to setup output.");
         return false;
     }
 
-    pmFPAfile *chipImage = pmFPAfileDefineChipMosaic(config, input->fpa, "PPSTAMP.CHIP");
+    pmFPAfile *chipImage = pmFPAfileDefineChipMosaic(config, output->fpa, "PPSTAMP.CHIP");
     if (!chipImage) {
         psError(PS_ERR_IO, false, _("Unable to generate new file from PPSTAMP.CHIP"));
@@ -108,4 +110,26 @@
         psError(PS_ERR_IO, true, "PPSTAMP.CHIP is not of type IMAGE");
         return NULL;
+    }
+
+    if (options->writeJPEG) {
+        char *filerule;
+        // If stage is chip flip the X axis otherwise don't flip.
+        // XXX: is this the right thing to do?
+        // Shouldn't the JPEG match the stamp even for chip stage?
+        if (!options->stage || strcmp(options->stage, "chip")) {
+            filerule = "PPSTAMP.OUTPUT.JPEG";
+        } else {
+            filerule = "PPSTAMP.OUTPUT.JPEG.FLIP";
+        }
+        pmFPAfile *jpg = pmFPAfileDefineOutput(config, output->fpa, filerule);
+        if (!jpg) {
+            psError(PS_ERR_IO, false, "Unable to generate new file from %s", filerule);
+            return NULL;
+        }
+        if (jpg->type != PM_FPA_FILE_JPEG) {
+            psError(PS_ERR_IO, true, "%s is not of type JPEG", filerule);
+            return NULL;
+        }
+        jpg->save = true;
     }
 
