Index: /branches/eam_branches/20090715/Ohana/src/kapa2/src/JPEGit24.c
===================================================================
--- /branches/eam_branches/20090715/Ohana/src/kapa2/src/JPEGit24.c	(revision 25290)
+++ /branches/eam_branches/20090715/Ohana/src/kapa2/src/JPEGit24.c	(revision 25291)
@@ -22,4 +22,5 @@
   int ii, i, j;
   int i_start, i_end, j_start, j_end;
+  int I_start, J_start;
   int dropback;  /* this is a bit of a kludge... */
   int dx, dy, DX, DY, inDX, inDY;
@@ -95,17 +96,17 @@
   DY = image[0].image[0].matrix.Naxis[1];
 
-  // x, y are the closest lit screen pixel to 0,0
-  Picture_Lower (&i_start, &j_start, &image[0].image[0].matrix, &image[0].picture);
-
-  // x, y are the closest lit screen pixel to dx, dy
-  Picture_Upper (&i_end, &j_end, &image[0].image[0].matrix, &image[0].picture);
-
-  if (i_end < i_start) MY_SWAP_INT (i_start, i_end);
-  if (j_end < j_start) MY_SWAP_INT (j_start, j_end);
-
-  // Ix,Iy are the first displayed image pixel
-  Picture_to_Image (&Ix, &Iy, i_start, j_start, &image[0].picture);
-  Ix = MIN (MAX (0, Ix), DX - 1);
-  Iy = MIN (MAX (0, Iy), DY - 1);
+  // i_start, j_start are the closest lit screen pixel to 0,0
+  // I_start, J_start are the image pixel corresponding to i_start, j_start
+  Picture_Lower (&i_start, &j_start, &I_start, &J_start, &image[0].image[0].matrix, &image[0].picture);
+
+  // i_end, j_end are the closest lit screen pixel to dx, dy
+  // I_end, J_end are the image pixel corresponding to i_end, j_end
+  Picture_Upper (&i_end, &j_end, i_start, j_start, &image[0].image[0].matrix, &image[0].picture);
+
+  assert (i_start <= i_end);
+  assert (j_start <= j_end);
+
+  Ix = image[0].picture.flipx ? I_start - 1 : I_start;
+  Iy = image[0].picture.flipy ? J_start - 1 : J_start;
 
   inDX = image[0].picture.flipx ? -1 : +1;
