Index: trunk/SophyaLib/NTools/cimage.cc
===================================================================
--- trunk/SophyaLib/NTools/cimage.cc	(revision 270)
+++ trunk/SophyaLib/NTools/cimage.cc	(revision 490)
@@ -5,5 +5,5 @@
 // LAL (Orsay) / IN2P3-CNRS  DAPNIA/SPP (Saclay) / CEA
 
-// $Id: cimage.cc,v 1.4 1999-04-27 15:03:01 ansari Exp $        
+// $Id: cimage.cc,v 1.5 1999-10-21 15:25:42 ansari Exp $        
 
 
@@ -1069,5 +1069,5 @@
   if(deb>0) cout<<"MoySigmaIter mean="<<mean<<" sigma="<<sigma
                 <<" npix="<<rc<<" entre "<<xmin<<","<<xmax<<endl;
-  if( rc <= 0 ) return rc;
+  if( rc <= 0 || sigma<=0. ) return rc;
   if( it>=1 && fabs((double)(sigma-sigmaold))/sigma < perdiff ) break;
   xmin = mean - scut*sigma; if(testl && xmin<lowbad ) xmin = lowbad;
@@ -1213,5 +1213,5 @@
 {
 int i,j;
-int x,y;
+// int x,y;  $CHECK$ Reza 21/06/99 changement de methode de calcul des bornes
 const T1* pt_pim;
 T2* pt_copie;
@@ -1221,5 +1221,5 @@
 int step_pim_x;
 int pim_siz_x, pim_siz_y;
-int copie_siz_x, copie_siz_y;
+// int copie_siz_x, copie_siz_y;  $CHECK$ Reza 21/06/99 changement de methode de calcul des bornes
 int switch_copie;
 
@@ -1227,18 +1227,21 @@
 pim_siz_y=pim.YSize();
 if((org_pim_x < 0) || (org_pim_x > pim_siz_x))
-  { cout<< "CopieImage_erreure : org_pim_x: " <<org_pim_x<<" < 0 ou > a "<<pim_siz_x<<"\n\n";
+  { cout<< "CopieImage_erreure : org_pim_x: " <<org_pim_x<<" < 0 ou > a "<<pim_siz_x<<endl;
     THROW(rangeCheckErr);}
 if((org_pim_y < 0) || (org_pim_y > pim_siz_y))
-  { cout<< "CopieImage_erreure : org_pim_y: " <<org_pim_y<<" < 0 ou > a "<<pim_siz_y<<"\n\n";
+  { cout<< "CopieImage_erreure : org_pim_y: " <<org_pim_y<<" < 0 ou > a "<<pim_siz_y<<endl;
     THROW(rangeCheckErr);}
 
-copie_siz_x=copie.XSize();
-copie_siz_y=copie.YSize();
-if((org_copie_x < 0) || (org_copie_x > copie_siz_x))
-  { cout<< "CopieImage_erreure : org_copie_x: " <<org_copie_x<<" < 0 ou > a "<<copie_siz_x<<"\n\n";
+if( (org_copie_x < 0) || (org_copie_x > copie.XSize()) )
+  { cout<< "CopieImage_erreure : org_copie_x: " <<org_copie_x<<" < 0 ou > a "<< copie.XSize() << endl;
     THROW(rangeCheckErr);}
-if((org_copie_y < 0) || (org_copie_y > copie_siz_y))
-  { cout<< "CopieImage_erreure : org_copie_y: " <<org_copie_y<<" < 0 ou > a "<<copie_siz_y<<"\n\n";
+if( (org_copie_y < 0) || (org_copie_y > copie.YSize()) )
+  { cout<< "CopieImage_erreure : org_copie_y: " <<org_copie_y<<" < 0 ou > a "<< copie.YSize() << endl;
     THROW(rangeCheckErr);}
+
+/* $CHECK$ Reza 21/06/99  Changement de methode de calcul ------
+$CHECK$ Reza 21/06/99 , je change la taille a copier en fonction de l'origine de copie 
+copie_siz_x=copie.XSize()-org_copie_x;
+copie_siz_y=copie.YSize()-org_copie_y;
 
 x=pim_lpav_x;
@@ -1268,5 +1271,5 @@
     }
   else
-    {
+    { 
      step_copie_x=copie_siz_x-l_copie_x;
     }
@@ -1285,6 +1288,17 @@
    }
 
-pt_pim  = pim.ImagePtr()+org_pim_y*pim_siz_x+org_pim_x;
-pt_copie=copie.ImagePtr()+org_copie_y*copie_siz_x+org_copie_x;
+*/
+
+l_copie_x = copie.XSize()-org_copie_x;
+l_copie_y = copie.YSize()-org_copie_y;
+if ( pim_lpav_x > (pim.XSize()-org_pim_x) )  pim_lpav_x = pim.XSize()-org_pim_x;
+if ( pim_lpav_y > (pim.YSize()-org_pim_y) )  pim_lpav_y = pim.YSize()-org_pim_y;
+if ( (pim_lpav_x > 0) && (l_copie_x > pim_lpav_x) )  l_copie_x = pim_lpav_x;
+if ( (pim_lpav_y > 0) && (l_copie_y > pim_lpav_y) )  l_copie_y = pim_lpav_y;
+step_pim_x = pim.XSize()-l_copie_x;
+step_copie_x = copie.XSize()-l_copie_x;
+
+pt_pim  = pim.ImagePtr() + org_pim_y*pim.XSize() + org_pim_x;
+pt_copie=copie.ImagePtr() + org_copie_y*copie.XSize() + org_copie_x;
 
 switch((int)ConvType(*pt_pim,*pt_copie)) {
@@ -1361,26 +1375,48 @@
 if (!pim.ImagePtr())   THROW(nullPtrErr);
 if (!copie.ImagePtr()) THROW(nullPtrErr);
-copie.SetOrg(org_pim_x,org_pim_y);
-
-/* $CHECK$ Reza 28/04/95 : Je protege pour le moment contre les pave en
+copie.SetOrg( pim.XOrg()+org_pim_x-org_copie_x, pim.YOrg()+org_pim_y-org_copie_y);
+// copie.SetOrg(org_pim_x,org_pim_y);
+
+/* Reza 28/04/95 : Je protege pour le moment contre les pave en
 dehors de l'image, mais je veux pouvoir copier des paves decale par
-rapport aux bornes de l'image source  Re- $CHECK$ CMV+Reza 30/09/96 */
+rapport aux bornes de l'image source  Re- CMV+Reza 30/09/96 */
+/* $CHECK$ Reza 21/06/99 - Ca devrait etre OK  */
 if ( (org_pim_x < 0) || (org_pim_y < 0) ||
      (org_pim_x >= pim.XSize() ) || (org_pim_y >= pim.YSize() ) ||
      ((org_pim_x+copie.XSize()) > pim.XSize()) ||
-     ((org_pim_y+copie.YSize()) > pim.YSize()) ) copie.Zero();
-if ( (org_pim_x < 0) || (org_pim_y < 0) ||
-     (org_pim_x >= pim.XSize() ) || (org_pim_y >= pim.YSize() )) return;
+     ((org_pim_y+copie.YSize()) > pim.YSize()) ) copie.Zero(); 
+
+if ( (org_pim_x >= pim.XSize()) || (org_pim_y >= pim.YSize()) ) {
+  copie.SetOrg( pim.XOrg()+org_pim_x-org_copie_x, pim.YOrg()+org_pim_y-org_copie_y);
+  return;
+}   
+// if ( (org_pim_x < 0) || (org_pim_y < 0) ||
+//      (org_pim_x >= pim.XSize() ) || (org_pim_y >= pim.YSize() )) return;
+
+int oox = org_pim_x;
+int ooy = org_pim_y;
+int ocx = org_copie_x;
+int ocy = org_copie_y;
+if (oox < 0)  { ocx -= oox;  oox = 0; }
+if (ooy < 0)  { ocy -= ooy;  ooy = 0; }
 /*  Fin de $CHECK$  */
+
+// void CopieImageF(Image<T2>& copie, Image<T1> const& pim,
+//         int org_pim_x, int org_pim_y,            /* origine pave a copier */
+//         int pim_lpav_x, int pim_lpav_y,          /* largeur pave a copier */
+//         int org_copie_x, int org_copie_y,        /* origine copie         */
+//         double cutmin, double cutmax)            /* coupure pour max range*/
 
 if((pim_lpav_x <= 0) || (pim_lpav_x > pim.XSize())) pim_lpav_x=pim.XSize();
 if((pim_lpav_y <= 0) || (pim_lpav_y > pim.YSize())) pim_lpav_y=pim.YSize();
-TRY {
-  CopieImageF(copie, pim,org_pim_x,org_pim_y,
+try {
+  CopieImageF(copie, pim, oox, ooy, 
               pim_lpav_x, pim_lpav_y,
-              org_copie_x,org_copie_y,cutmin,cutmax);
+              ocx, ocy, cutmin,cutmax);
   }  catch(RangeCheckError) {
-      // if (merr != rangeCheckErr) THROW(merr);   Re- $CHECK$ CMV+Reza 30/09/96
+// $PLANCKCHECK$   if (merr != rangeCheckErr) THROW(merr);  // Re- $CHECK$ CMV+Reza 30/09/96
   } ENDTRY
+
+copie.SetOrg( pim.XOrg()+org_pim_x-org_copie_x, pim.YOrg()+org_pim_y-org_copie_y);
 }
 
