Index: trunk/SophyaPI/PI/parradapter.cc
===================================================================
--- trunk/SophyaPI/PI/parradapter.cc	(revision 3454)
+++ trunk/SophyaPI/PI/parradapter.cc	(revision 3455)
@@ -8,4 +8,5 @@
 // #include "ctimer.h"   Pour mesure TCPU 
 #include "sopnamsp.h"
+#include "nbtri.h"
 #include "parradapter.h"
 
@@ -376,4 +377,43 @@
 }
 
+/* --Methode-- */
+int P2DArrayAdapter::ComputeLut_Range(double& min, double& max, double fracmin, double fracmax, int vit,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.
+{
+ 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;
+
+ double *buff = new double[nmax];
+
+ int n=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<1) {delete [] buff; return nfill;}
+
+ qsort(buff,(size_t) nfill,sizeof(double),qSort_Dble);
+
+ int i1 = int(nfill*fracmin);       if(i1<0) i1=0;
+ int i2 = int(nfill*(1.-fracmax));  if(i2>=nfill) i2=nfill-1;
+ if(i2<=i1) {i1=0; i2=nfill-1;}
+ 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);
+
+ delete [] buff;
+ return(nfill);
+}
 
 /* --Methode-- */
Index: trunk/SophyaPI/PI/parradapter.h
===================================================================
--- trunk/SophyaPI/PI/parradapter.h	(revision 3454)
+++ trunk/SophyaPI/PI/parradapter.h	(revision 3455)
@@ -85,4 +85,6 @@
   virtual void    ComputeLut_PicHisto(double& min, double& max, bool htail, 
 				      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);
 
 //    Calcul pixmap avec un LUT
Index: trunk/SophyaPI/PI/piimage.cc
===================================================================
--- trunk/SophyaPI/PI/piimage.cc	(revision 3454)
+++ trunk/SophyaPI/PI/piimage.cc	(revision 3455)
@@ -457,4 +457,7 @@
    if (min >= max)  img->CheckDyn(min, max, moy, sig, nbnul, nbsat);
    break;
+ case AutoLut_Range :
+   img->ComputeLut_Range(min, max, nsa/2., nsa/2., 1, 5000);
+   break;
  case AutoLut_MinMax :
    min = 1.; max = -1.;  
@@ -462,6 +465,6 @@
    if (max <= min) max = min+0.1*fabs(min);
    if ((nsa <= 0.)||(nsa > 1.))  nsa = 1.;
-   dmx = (nsa-1.)*(max-min);
-   min = min+dmx;  max = max-dmx;
+   dmx = (1.-nsa)*(max-min);
+   min = min+dmx/2.;  max = max-dmx/2.;
    break; 
  case AutoLut_MeanSigma :
Index: trunk/SophyaPI/PI/piimage.h
===================================================================
--- trunk/SophyaPI/PI/piimage.h	(revision 3454)
+++ trunk/SophyaPI/PI/piimage.h	(revision 3455)
@@ -21,5 +21,5 @@
 
 enum AutoLutType { AutoLut_No=0, AutoLut_MinMax=1, AutoLut_MeanSigma=2, 
-		   AutoLut_HistoPeak=3, AutoLut_HistoTail=4}; 
+		   AutoLut_HistoPeak=3, AutoLut_HistoTail=4, AutoLut_Range=5}; 
 
 class PIImage : public PIPixmap
Index: trunk/SophyaPI/PI/piimgtools.cc
===================================================================
--- trunk/SophyaPI/PI/piimgtools.cc	(revision 3454)
+++ trunk/SophyaPI/PI/piimgtools.cc	(revision 3455)
@@ -122,4 +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]->SetValue(1200);
 mOpt[1]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
@@ -353,10 +355,11 @@
 int lauto, typ;
 int typlut[4] = {kLutType_Lin, kLutType_Log, kLutType_Sqrt, kLutType_Square} ; 
-AutoLutType alts[11] = { AutoLut_No, 
+AutoLutType alts[13] = { AutoLut_No, 
 			 AutoLut_MeanSigma, AutoLut_MeanSigma, AutoLut_MeanSigma,
 			 AutoLut_MinMax, AutoLut_MinMax, AutoLut_MinMax, 
 			 AutoLut_HistoTail, AutoLut_HistoTail, 
-			 AutoLut_HistoPeak, AutoLut_HistoPeak } ; 
-double nsas[11] = {0., 1., 2., 3., 0.70, 0.9, 1., 2., 1., 2.};
+			 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};
  
 msg = UserMsg(msg);
@@ -398,5 +401,5 @@
     }
     else lauto = mOpt[1]->GetValue() - 1200;
-    if ((lauto < 0) || (lauto > 10))  lauto = 10;
+    if ((lauto < 0) || (lauto > 12))  lauto = 12;
     typ = mOpt[0]->GetValue() - 1100;
     if ( (typ < 0) || (typ > 3) )  typ = 0;
