Index: /branches/eam_branches/ipp-20111110/Ohana/src/kapa2/include/structures.h
===================================================================
--- /branches/eam_branches/ipp-20111110/Ohana/src/kapa2/include/structures.h	(revision 32659)
+++ /branches/eam_branches/ipp-20111110/Ohana/src/kapa2/include/structures.h	(revision 32660)
@@ -26,6 +26,8 @@
   XFontStruct   *font;
   Cursor         cursor;
-  int            x,  y;
-  unsigned int   dx, dy;
+  int            x,  y;	      // corner coord in X world coords
+  unsigned int   dx, dy;      // size of window in X coords
+  int            xwin, ywin;  // corner coord of display subregion (eg, png, ps plot)
+  int            dxwin, dywin; // corner coord of display subregion (eg, png, ps plot)
   CCNode        *cube;
   XColor        *cmap;
Index: /branches/eam_branches/ipp-20111110/Ohana/src/kapa2/src/Sections.c
===================================================================
--- /branches/eam_branches/ipp-20111110/Ohana/src/kapa2/src/Sections.c	(revision 32659)
+++ /branches/eam_branches/ipp-20111110/Ohana/src/kapa2/src/Sections.c	(revision 32660)
@@ -237,2 +237,34 @@
   return (TRUE);
 }
+
+int SectionMinBoundary (Graphic *graphic) {
+
+    int Xs = graphic->dx;
+    int Ys = graphic->dy;
+    int Xe = 0;
+    int Ye = 0;
+
+    // the boundary for a single section should probably be adjusted depending on the 
+    // image status (should not include the imtool portion)
+    for (i = 0; i < Nsections; i++) {
+	Xs = PS_MIN (Xs, sections[i][0].x);
+	Ys = PS_MIN (Ys, sections[i][0].y);
+	Xe = PS_MAX (Xe, sections[i][0].x + sections[i][0].dx);
+	Ye = PS_MAX (Ye, sections[i][0].y + sections[i][0].dy);
+    }
+
+    if ((Xs >= Xe) || (Ys >- Ye)) {
+	// default values for the region window
+	graphic->xwin  = 0;
+	graphic->ywin  = 0;
+	graphic->dxwin = graphic->dx;
+	graphic->dywin = graphic->dy; 
+    }	
+    
+    // set min/max boundary (min window containing max range of sections)
+    graphic->xwin = Xs;
+    graphic->ywin = Ys;
+    graphic->dxwin = Xe - Xs;
+    graphic->dywin = Ye - Ys;
+    return TRUE;
+}
Index: /branches/eam_branches/ipp-20111110/Ohana/src/kapa2/src/SetUpGraphic.c
===================================================================
--- /branches/eam_branches/ipp-20111110/Ohana/src/kapa2/src/SetUpGraphic.c	(revision 32659)
+++ /branches/eam_branches/ipp-20111110/Ohana/src/kapa2/src/SetUpGraphic.c	(revision 32660)
@@ -16,4 +16,10 @@
   graphic->dx = 512;
   graphic->dy = 512; 
+
+  // default values for the region window
+  graphic->xwin  = 0;
+  graphic->ywin  = 0;
+  graphic->dxwin = graphic->dx;
+  graphic->dywin = graphic->dy; 
 
   if (!USE_XWINDOW) {
Index: /branches/eam_branches/ipp-20111110/Ohana/src/kapa2/src/bDrawImage.c
===================================================================
--- /branches/eam_branches/ipp-20111110/Ohana/src/kapa2/src/bDrawImage.c	(revision 32659)
+++ /branches/eam_branches/ipp-20111110/Ohana/src/kapa2/src/bDrawImage.c	(revision 32660)
@@ -47,6 +47,7 @@
   }
 
-  Xs = image[0].picture.x;
-  Ys = image[0].picture.y;
+  // Xs,Ys are in full-frame coords.  can we trim here?
+  Xs = image[0].picture.x - graphic[0].xwin;
+  Ys = image[0].picture.y - graphic[0].ywin;
   dx = image[0].picture.dx;
   dy = image[0].picture.dy;
@@ -54,4 +55,5 @@
   DY = image[0].image[0].matrix.Naxis[1];
 
+  // the created buffer is supposed to contain the output windows
   if (buffer[0].Nx < Xs + dx) {
     fprintf (stderr, "invalid condition\n");
Index: /branches/eam_branches/ipp-20111110/Ohana/src/kapa2/src/bDrawIt.c
===================================================================
--- /branches/eam_branches/ipp-20111110/Ohana/src/kapa2/src/bDrawIt.c	(revision 32659)
+++ /branches/eam_branches/ipp-20111110/Ohana/src/kapa2/src/bDrawIt.c	(revision 32660)
@@ -13,5 +13,9 @@
   black = KapaColorByName ("black");
 
-  buffer = bDrawBufferCreate (graphic->dx, graphic->dy, Nbyte, palette, Npalette);
+  SectionMinBoundary (graphic);
+
+  // if we want to trim, we'll need to carry about the start in graphic coords and
+  // the dx,dy size.  
+  buffer = bDrawBufferCreate (graphic->dxwin, graphic->dywin, Nbyte, palette, Npalette);
   bDrawSetStyle (buffer, black, 0, 0);
   
