Index: trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm
===================================================================
--- trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 27236)
+++ trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 27237)
@@ -454,62 +454,68 @@
         # so we interpret the requested image in that way
 
-        my $stack_id = $image->{stack2};
         # XXX difftool currently returns max long long for null
-        # this line is ready if we switch the code to return zero for null
-        if ($stack_id and ($stack_id != 9223372036854775807)) {
-            $image->{stack_id} = $stack_id;
-        }
-
-        my ($warp_id, $exp_id, $exp_name, $chip_id, $cam_id);
-        if ($inverse and !$image->{bothways}) {
-            print STDERR "Inverse images requested for diffRun that is not bothways. Ignoring inverse.\n";
-            $inverse = 0;
-        }
-        if ($inverse) {
-            $warp_id =  $image->{warp2};
-            $exp_id = $image->{exp_id_2};
-            $exp_name = $image->{exp_name_2};
-            $chip_id = $image->{chip_id_2};
-            $cam_id = $image->{cam_id_2};
-        } else {
-            $warp_id =  $image->{warp1};
-            $exp_id = $image->{exp_id_1};
-            $exp_name = $image->{exp_name_1};
-            $chip_id = $image->{chip_id_1};
-            $cam_id = $image->{cam_id_1};
-        }
-        # XXX difftool currently returns max long long for null
-        # this line is ready if we switch the code to return zero for null
-        if ($warp_id and ($warp_id != 9223372036854775807)) {
-            $image->{warp_id} = $warp_id;
-            $image->{exp_id} = $exp_id;
-            $image->{exp_name} = $exp_name;
-            $image->{chip_id} = $chip_id;
-            $image->{cam_id} = $cam_id;
-        } else {
-            my $stack1 = $image->{stack1};
-            # XXX: change this to check $image->{diff_mode} once it's populated and
-            # included in the difftool output
-            if ($stack1 and ($stack1 != 9223372036854775807)) {
-
-                # we have a stack - stack diff (well it might be stack - warp....)
-                # but at any rate we only handle image type diff
-                if ($img_type ne "diff") {
-                    print STDERR "lookup_diff: cannot lookup IMG_TYPE $img_type bydiff from SSdiff\n";
-                    next;
-                }
-
-                # XXX: If difftool doesn't return a camera insert it here
-                if (!$image->{camera}) {
-                    $image->{camera} = "GPC1";
-                    # lie about the magicked status since stack stack diffs don't require destreaking
-                    # we can remove this once diff_mode gets included
-                    $image->{magicked} = 42;
-                }
-            } else {
-                print STDERR "unexpected result: both warp1 and stack1 are null\n";
+        # these checks are ready if we switch the code to return zero for null
+        my $stack1 = $image->{stack1};
+        if (($stack1 == 0) or ($stack1 == 9223372036854775807)) {
+            $stack1 = undef
+        }
+        my $stack2 = $image->{stack2};
+        if (($stack2 == 0) or ($stack2 == 9223372036854775807)) {
+            $stack2 = undef
+        }
+        my $stack_id;
+        if ($stack1 and $stack2) {
+            # we have a stack - stack diff (well it might be stack - warp....)
+            # but at any rate we only handle image type diff and stack
+            if (($img_type ne "diff") and ($img_type ne "stack")) {
+                print STDERR "lookup_diff: cannot lookup IMG_TYPE $img_type bydiff from a stack stack diff run\n";
                 next;
             }
-        }
+            # stack-stack diff
+            # XXX: define another flag for this
+            if (! $inverse) {
+                $stack_id = $stack1;
+            } else {
+                $stack_id = $stack2;
+            }
+            $image->{stack_id} = $stack_id;
+        } else {
+            my ($warp_id, $exp_id, $exp_name, $chip_id, $cam_id);
+            if ($inverse and !$image->{bothways}) {
+                print STDERR "Inverse images requested for diffRun that is not bothways. Ignoring inverse.\n";
+                $inverse = 0;
+            }
+            if ($inverse) {
+                $warp_id =  $image->{warp2};
+                $exp_id = $image->{exp_id_2};
+                $exp_name = $image->{exp_name_2};
+                $chip_id = $image->{chip_id_2};
+                $cam_id = $image->{cam_id_2};
+            } else {
+                $warp_id =  $image->{warp1};
+                $exp_id = $image->{exp_id_1};
+                $exp_name = $image->{exp_name_1};
+                $chip_id = $image->{chip_id_1};
+                $cam_id = $image->{cam_id_1};
+            }
+            # XXX difftool currently returns max long long for null
+            # this line is ready if we switch the code to return zero for null
+            if ($warp_id and ($warp_id != 9223372036854775807)) {
+                $image->{warp_id} = $warp_id;
+                $image->{exp_id} = $exp_id;
+                $image->{exp_name} = $exp_name;
+                $image->{chip_id} = $chip_id;
+                $image->{cam_id} = $cam_id;
+            }
+        }
+
+        # XXX: If difftool doesn't return a camera insert it here
+        if (!$image->{camera}) {
+            $image->{camera} = "GPC1";
+            # lie about the magicked status since stack stack diffs don't require destreaking
+            # we can remove this once diff_mode gets included
+            $image->{magicked} = 42;
+        }
+
         if ($img_type eq "diff") {
             # the $image is going to be returned directly in this case so we need to duplicate
