Index: trunk/SophyaPI/PI/parradapter.cc
===================================================================
--- trunk/SophyaPI/PI/parradapter.cc	(revision 3457)
+++ trunk/SophyaPI/PI/parradapter.cc	(revision 3458)
@@ -378,25 +378,35 @@
 
 /* --Methode-- */
-int P2DArrayAdapter::ComputeLut_Range(double& min, double& max, double fracmin, double fracmax, int vit,int nmax)
+int P2DArrayAdapter::ComputeLut_Range(double& min, double& max, double fracmin, double fracmax,int nmax)
 // Compute min and max by throwing away the "fracmin" lowest values and the "fracmax" greatest values
 // Use 1 value over "vit". Maximum number values to be used is "nmax".
 // Si echec alors min,max restent inchanges.
 {
+  int lp=0;
  if(fracmin<0. || fracmin>=1.) fracmin=0.;
- if(fracmax<0. || fracmin>=1.) fracmax=0.;
- if (vit<1) vit = 1;
- if(nmax<10) nmax = 10000;
-
- if (sX*sY/vit < 1000) vit = sX*sY/1000;  // need enough values
- if (vit<1) vit = 1;
- if (sX*sY/vit > nmax) vit = sX*sY/nmax;  // but not too much !
- if (vit<1) vit = 1;
+ if(fracmax<0. || fracmax>=1.) fracmax=0.;
+ if(nmax<10) nmax = 5000;
+
+ int vit = sX*sY/nmax;  // Not too many values, we are using qsort !
+ if(vit<1) vit = 1;
+ // On recalcule nmax pour bien echantillonner le tableau:
+ // ex: sX*sY=9999, nmax=5000 -> vit=1
+ //     - si on ne recalcule pas nmax alors on echantillonne [0,5000[
+ //          et on ne considere pas les 4999 dernieres valeurs!
+ //     - si on recalcule nmax=sX*sY/vit=9999 on echantillonne tout le tableau
+ //          le prix a payer: l'allocation varie entre nmax et 2*nmax-1
+ nmax = sX*sY/vit;
 
  double *buff = new double[nmax];
 
- int n=0, nfill=0;
+ if(lp) {printf("ComputeLut_Range: sX*sY=%d fracmin=%g fracmax=%g nmax=%d min=%g max=%g\n"
+		,sX*sY,fracmin,fracmax,nmax,min,max); fflush(stdout);}
+
+ int npix=0, nfill=0;
  for(int j=0;j<sY;j++) for(int i=0;i<sX;i++)   {
-   if(nfill>=nmax) continue;
-   if((n++)%vit==0) buff[nfill++] = Value(i,j);
+   if(nfill>=nmax) {j+=sY; break;} // On arrete completement: sortie bouble interne + j>sY
+   if((npix++)%vit!=0) continue;
+   double val = Value(i,j);
+   if( min>=max || (val>=min && val<=max) ) buff[nfill++] = val;
  }
 
@@ -410,6 +420,6 @@
  if(buff[i1]<buff[i2]) {min=buff[i1]; max=buff[i2];}
 
- //printf("DEBUG (%d,%g,%g,%d,%d) nfill=%d [0]=%g [n]=%g min=[%d]=%g max=[%d]=%g\n"
- //      ,sX*sY,fracmin,fracmax,vit,nmax,nfill,buff[0],buff[nfill-1],i1,min,i2,max); fflush(stdout);
+ if(lp) {printf("   ...npix=%d nfill=%d [0]=%g [n]=%g min=[%d]=%g max=[%d]=%g\n"
+		,npix,nfill,buff[0],buff[nfill-1],i1,min,i2,max); fflush(stdout);}
 
  delete [] buff;
Index: trunk/SophyaPI/PI/parradapter.h
===================================================================
--- trunk/SophyaPI/PI/parradapter.h	(revision 3457)
+++ trunk/SophyaPI/PI/parradapter.h	(revision 3458)
@@ -86,5 +86,5 @@
 				      double nbsig=1., double fracmax=0.95);
 //    Calcul stable Range
-  virtual int     ComputeLut_Range(double& min,double& max,double fracmin=0.,double fracmax=0.,int vit=10,int nmax=10000);
+  virtual int     ComputeLut_Range(double& min,double& max,double fracmin=0.,double fracmax=0.,int nmax=10000);
 
 //    Calcul pixmap avec un LUT
Index: trunk/SophyaPI/PI/piimage.cc
===================================================================
--- trunk/SophyaPI/PI/piimage.cc	(revision 3457)
+++ trunk/SophyaPI/PI/piimage.cc	(revision 3458)
@@ -458,5 +458,5 @@
    break;
  case AutoLut_Range :
-   img->ComputeLut_Range(min, max, nsa/2., nsa/2., 1, 5000);
+   img->ComputeLut_Range(min, max,(1.-nsa)/2.,(1.-nsa)/2., 5000);
    break;
  case AutoLut_MinMax :
@@ -658,12 +658,12 @@
 	else pnsal = atof( suop.c_str() );
       }
-      AutoLutType palt = AutoLut_No;     
+      AutoLutType palt = AutoLut_No;
       if (opts.substr(8,6) == "minmax")  palt = AutoLut_MinMax;
       else if (opts.substr(8,7) == "meansig")  palt = AutoLut_MeanSigma;
       else if (opts.substr(8,7) == "hispeak")  palt = AutoLut_HistoPeak;
-      else if (opts.substr(8,9) == "hispeak")  palt = AutoLut_HistoPeak;
       else if (opts.substr(8,6) == "hispic")   palt = AutoLut_HistoPeak;
       else if (opts.substr(8,7) == "histail")  palt = AutoLut_HistoTail;
-      if ( palt != AutoLut_No )  SetLut(palt, min_al, max_al, ctlut, pnsal, false);
+      else if (opts.substr(8,6) == "hisrng")   palt = AutoLut_Range;
+      if ( palt != AutoLut_No )  SetLut(palt, min, max, ctlut, pnsal, false);
       continue;
     }
Index: trunk/SophyaPI/PI/piimgtools.cc
===================================================================
--- trunk/SophyaPI/PI/piimgtools.cc	(revision 3457)
+++ trunk/SophyaPI/PI/piimgtools.cc	(revision 3458)
@@ -122,6 +122,6 @@
 mOpt[1]->AppendItem("HistoPeak+1s", 1209);
 mOpt[1]->AppendItem("HistoPeak+2s", 1210);
-mOpt[1]->AppendItem("Range-10%", 1211);
-mOpt[1]->AppendItem("Range-30%", 1212);
+mOpt[1]->AppendItem("Range90%", 1211);
+mOpt[1]->AppendItem("Range70%", 1212);
 mOpt[1]->SetValue(1200);
 mOpt[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
@@ -361,5 +361,5 @@
 			 AutoLut_HistoPeak, AutoLut_HistoPeak,
                          AutoLut_Range, AutoLut_Range } ; 
-double nsas[13] = {0., 1., 2., 3., 0.70, 0.9, -1., 1., 2., 1., 2., 0.1, 0.3};
+double nsas[13] = {0., 1., 2., 3., 0.70, 0.9, 1., 1., 2., 1., 2., 0.9, 0.7};
  
 msg = UserMsg(msg);
