Index: trunk/SophyaPI/PI/lut.cc
===================================================================
--- trunk/SophyaPI/PI/lut.cc	(revision 3523)
+++ trunk/SophyaPI/PI/lut.cc	(revision 3527)
@@ -23,4 +23,12 @@
 if (bornes == NULL)  return;
 type = typ;  nLevel = nlev;
+int qqq = 1;
+quantum = 1;
+for(quantum=2; quantum<=42; quantum++) {
+  qqq = quantum*quantum*quantum;
+  if (qqq > NCol())  break;
+}
+quantum--;
+
 table = NULL;  
 tablenbin = 0;
@@ -47,4 +55,12 @@
 bornes = new double[nlev+1];
 nLevel = nlev;
+int qqq = 1;
+quantum = 1;
+for(quantum=2; quantum<=42; quantum++) {
+  qqq = quantum*quantum*quantum;
+  if (qqq > NCol())  break;
+}
+quantum--;
+// printf("*DBG*LUT* quantum= %d \n", (int)quantum);
 SetLut(min, max, Type());
 }
@@ -59,4 +75,6 @@
 type = typ;
 if (max <= min)  max = min+1.;
+mMin = min;  mMax = max;
+mMinI = (int)(min+0.1);  mMaxI = (int)(max+0.1);
 if (nLevel > 0)
   {
@@ -125,20 +143,10 @@
 {
   long lv = x+0.3;
-  double r = (lv%256);
+  int r = (lv%256);
   lv /= 256;
-  double g = (lv%256);
+  int g = (lv%256);
   lv /= 256;
-  double b = (lv%256);
-  int qqq = 1;
-  int quantum = 1;
-  for(quantum=2; quantum<=42; quantum++) {
-  	qqq = quantum*quantum*quantum;
-  	if (qqq > NCol())  break;
-  }
-  quantum--;
-  int ir = AppFast(r)*quantum/(NCol());
-  int ig = AppFast(g)*quantum/(NCol());
-  int ib = AppFast(b)*quantum/(NCol());
-  return ((unsigned short)((ib*quantum+ig)*quantum+ir));
+  int b = (lv%256);
+  return (unsigned short)((Contraste(b)*quantum+Contraste(g))*quantum+Contraste(r));
 }
 
Index: trunk/SophyaPI/PI/lut.h
===================================================================
--- trunk/SophyaPI/PI/lut.h	(revision 3523)
+++ trunk/SophyaPI/PI/lut.h	(revision 3527)
@@ -49,8 +49,16 @@
     return(table[k]); 
     } 
-  	  
+  inline int  Contraste(int ii)   /* for ApplyRGB */
+    {
+    if (ii >= mMaxI) return quantum-1;
+    if (ii <= mMinI) return 0;
+    else return ((ii-mMinI)*(quantum-1)/mMaxI);
+    }	  
   int type;
   int nLevel;
+  int quantum;
   double * bornes;
+  double mMin, mMax;
+  int mMinI, mMaxI;
   int tablenbin;
   unsigned short * table;
Index: trunk/SophyaPI/PI/parradapter.cc
===================================================================
--- trunk/SophyaPI/PI/parradapter.cc	(revision 3523)
+++ trunk/SophyaPI/PI/parradapter.cc	(revision 3527)
@@ -562,8 +562,7 @@
   if (zm == 1)  {  // Pas de zoom  
     for(j=ofy; j<ofy+npy; j++)
-      for(i=ofx; i<ofx+npx; i++) 
-        { *pp = (unsigned char) lut->ApplyFast( 
-                this->Value(j*sgnX+offX, i*sgnY+offY));  
-           pp++; }
+      for(i=ofx; i<ofx+npx; i++) {
+        *pp = lut->ApplyFast(this->Value(j*sgnX+offX, i*sgnY+offY));  pp++; 
+      }
     }
   else if (zm < -1) {       // Compression 
@@ -578,5 +577,5 @@
     for(j=ofy; j<ofy+npy; j++)
       for(i=ofx; i<ofx+npx; i++)  {
-        ucp = (unsigned char) lut->ApplyFast(this->Value(j*sgnX+offX, i*sgnY+offY));
+        ucp = lut->ApplyFast(this->Value(j*sgnX+offX, i*sgnY+offY));
         for(l=0; l<zm; l++)  {
           pp = pixc.ShortPointer()+((j-ofy)*zm+l)*nppx+((i-ofx)*zm);
@@ -589,8 +588,7 @@
   if (zm == 1)  {  // Pas de zoom  
     for(j=ofy; j<ofy+npy; j++)
-      for(i=ofx; i<ofx+npx; i++) 
-        { *pp = (unsigned char) lut->ApplyFast( 
-                this->Value(i*sgnX+offX, j*sgnY+offY));  
-           pp++; }
+      for(i=ofx; i<ofx+npx; i++) {
+        *pp = lut->ApplyFast(this->Value(i*sgnX+offX, j*sgnY+offY));  pp++; 
+      }
     }
   else if (zm < -1) {       // Compression 
@@ -605,5 +603,5 @@
     for(j=ofy; j<ofy+npy; j++)
       for(i=ofx; i<ofx+npx; i++)  {
-        ucp = (unsigned char) lut->ApplyFast(this->Value(i*sgnX+offX, j*sgnY+offY));
+        ucp = lut->ApplyFast(this->Value(i*sgnX+offX, j*sgnY+offY));
         for(l=0; l<zm; l++)  {
           pp = pixc.ShortPointer()+((j-ofy)*zm+l)*nppx+((i-ofx)*zm);
Index: trunk/SophyaPI/PI/picmap.cc
===================================================================
--- trunk/SophyaPI/PI/picmap.cc	(revision 3523)
+++ trunk/SophyaPI/PI/picmap.cc	(revision 3527)
@@ -597,9 +597,9 @@
       int drgb = 65535/(nlev-1);
       i = 0;
-      for(int kb=0; kb<8; kb++) {
+      for(int kb=0; kb<nlev; kb++) {
         mycol.blue = (unsigned short)(kb*drgb);
-        for(int jg=0; jg<8; jg++) { 
+        for(int jg=0; jg<nlev; jg++) { 
           mycol.green = (unsigned short)(jg*drgb);
-          for(int ir=0; ir<8; ir++) {
+          for(int ir=0; ir<nlev; ir++) {
             mycol.red = (unsigned short)(ir*drgb);
             AllocColor(mycol, i);   i++;
Index: trunk/SophyaPI/PI/piimage.cc
===================================================================
--- trunk/SophyaPI/PI/piimage.cc	(revision 3523)
+++ trunk/SophyaPI/PI/piimage.cc	(revision 3527)
@@ -625,7 +625,4 @@
       double min = Lut()->Min();
       double max = Lut()->Max();
-      size_t q = opts.find(',');
-      if (q < opts.length()-1)
-	sscanf(opts.substr(q+1).c_str(),"%lg,%lg",&min, &max);
       int typlut=kLutType_Lin;      ;
       if (opts.substr(4,3) == "lin")  typlut=kLutType_Lin;
@@ -633,5 +630,12 @@
       else if (opts.substr(4,4) == "sqrt")  typlut=kLutType_Sqrt;
       else if (opts.substr(4,6) == "square")  typlut=kLutType_Square;
-      else if (opts.substr(4,6) == "rgb")  typlut=kLutType_RGB;
+      else if (opts.substr(4,3) == "rgb")  { 
+        typlut=kLutType_RGB;
+        min = 0;  max = 255;
+      } 
+      size_t q = opts.find(',');
+      if (q < opts.length()-1)
+	sscanf(opts.substr(q+1).c_str(),"%lg,%lg",&min, &max);
+
       SetLut(AutoLut_No, min, max, typlut, 0, false);
       continue;
Index: trunk/SophyaPI/PI/piimgtools.cc
===================================================================
--- trunk/SophyaPI/PI/piimgtools.cc	(revision 3523)
+++ trunk/SophyaPI/PI/piimgtools.cc	(revision 3527)
@@ -448,5 +448,5 @@
     if ((lauto < 0) || (lauto > 12))  lauto = 12;
     typ = mOpt[0]->GetValue() - 1100;
-    if ( (typ < 0) || (typ > 3) )  typ = 0;
+    if ( (typ < 0) || (typ > 4) )  typ = 0;
     (PIImage::CurrentPIImage())->SetLut(alts[lauto], min, max, typlut[typ], nsas[lauto]);
     if (msg == 2500) { 
