Index: /tags/pipV0/AddOn/PIPhoto/README
===================================================================
--- /tags/pipV0/AddOn/PIPhoto/README	(revision 3555)
+++ /tags/pipV0/AddOn/PIPhoto/README	(revision 3555)
@@ -0,0 +1,51 @@
+##########################################################
+  Module d'interface SOPHYA/piapp avec ImageMagick pour 
+  manipulation d'images jpeg/gif...
+  (C) LAL-IN2P3/CNRS & Univ. Paris Sud (11)
+  (C) IRFU - CEA   
+                         R. Ansari - 2008
+##########################################################
+
+1/ Compilation/Installation 
+  - Installer ImageMagick (C++) - Voir http://www.imagemagick.org/Magick++/
+  - Verifier que sophya est installe et accessible (var.env $SOPHYABASE)
+       (Voir http://www.sophya.org )
+  - Modifier les chemins d'acces et liste des librairies ImageMagick dans 
+  le fichier makefile
+  - Compiler (make)     
+  
+2/ Ce module contient des executables et un module chargeable pour piapp
+  (Par defaut ds $SOPHYABASE/exe et $SOPHYABASE/slb) 
+  Les fichiers PI-RGB correspondent aux objets PIPixRGBArray (module PI)
+  - img2rgb : Conversion de fichier image (jpeg, gif...) en fichier PI-RGB 
+  - rgb2img : Conversion de fichier PI-RGB en fichier image (jpeg,gif ...)
+  - animrgbs : Conversion d'une sequence de fichier PI-RGB en GIF anime
+  - Module imgmagmod.so qui peut Ãªtre charge dans (s)piapp :
+      piapp>  loadmodule $SOPHYABASE/slb/imgmagmod.so imgmagmod
+    Les commandes suivantes sont ajoutees a (s)piapp (groupe ImageMagick)
+      readphoto , writephoto , pirgb_rdphoto , pirgb_wrphoto 
+      wdg2imgfile , win2imgfile
+    Les fichiers image lus sont representes dans piapp par des objets de 
+    la classe ImgMagObj. 
+    On peut utiliser la commande disp sur ces objets :
+      piapp> readphoto toto.jpg
+      piapp> disp toto 
+      piapp> disp toto 'zoomx2 rgb4096cm'
+      piapp> disp toto 'zoom/2 lut=rgb,10,250 rgb32768cm'
+      piapp> disp toto 'monochrome grey128'
+      piapp> disp toto 'monochrome colrj128'
+    On peut aussi faire des traces d'expressions (plot2d n/pl ...)
+    Les variables suivantes sont disponibles pour chaque pixel de l'image :
+      x,y,i,j,r,g,b,I
+      i=x , j=y , composantes RGB  r , g , b    intensite I 
+      
+3/ script tanim.pic 
+  Creation d'une sequence de fichiers PI-RGB (tanim0.rgb ... tanim36.rgb), 
+  permettant la creation d'une animation (mini-film)
+  - Executer le script ds (s)piapp 
+  - Creer un gif anime avec la commande animrgbs :
+  csh>  animrgbs tanim.gif tanim0.rgb tanim1.rgb tanim2.rgb ... tanim73.rgb
+  
+             
+    
+    
Index: /tags/pipV0/AddOn/PIPhoto/animrgbs.cc
===================================================================
--- /tags/pipV0/AddOn/PIPhoto/animrgbs.cc	(revision 3555)
+++ /tags/pipV0/AddOn/PIPhoto/animrgbs.cc	(revision 3555)
@@ -0,0 +1,61 @@
+#include "machdefs.h"
+#include "sopnamsp.h"
+
+#include <iostream>
+#include <sstream>
+#include <string>
+
+#include "array.h"
+#include "tarrinit.h"
+
+#include "imgmag_pi.h"
+
+ 
+using namespace std; 
+using namespace Magick; 
+
+// Conversion d'une serie de fichiers RGB en GIF anime
+
+int main(int argc,char **argv) 
+{ 
+  if (argc < 4) {
+    cout << "  Usage: animrgbs OutputFile InFile1 InFile2 InFile3 ...\n" 
+         << "    Output: .gif  - InputFiles: PI-RB (.rgb) " << endl;
+    return 0;
+  }
+/*
+  cout << " Initializing image magick ... " << endl;
+  InitializeMagick(argv[0]);
+*/
+  cout << " Initializing SOPHYA  ... " << endl;
+  SophyaInit();
+
+  try { 
+    list<Image> imageList; 
+    for(int k=2; k<argc; k++) {	
+      // Read a file into an PIPixRGBArray
+      cout << k-1 << "- Reading RGB file " << argv[k] << endl;
+      PIPixRGBArray rgba(argv[k]);
+      cout << "Converting to Magick::Image -  Width= " << rgba.XSize() 
+         << " Height= " << rgba.YSize() << endl;
+      ImgMagObj image(rgba);
+      image.adjoin(true);
+      image.animationDelay(10);  // en unite de 1/100 second -> 1/10 sec
+      image.animationIterations(5);
+      imageList.push_back(image);
+      /*
+      Image appended; 
+      appendImages( &appended, imageList.begin(), imageList.end() ); 
+      appended.write( "appended_image.miff" ); 
+      */
+    }
+    string outfile = argv[1];
+    cout << " ---- writing image sequence to file " << outfile << endl;
+    writeImages(imageList.begin(), imageList.end(), outfile, true); 
+  } 
+  catch( Exception &error_ ) { 
+    cout << "animrgbs: Caught Exception: " << error_.what() << endl; 
+    return 1; 
+  } 
+  return 0; 
+}
Index: /tags/pipV0/AddOn/PIPhoto/img2rgb.cc
===================================================================
--- /tags/pipV0/AddOn/PIPhoto/img2rgb.cc	(revision 3555)
+++ /tags/pipV0/AddOn/PIPhoto/img2rgb.cc	(revision 3555)
@@ -0,0 +1,55 @@
+#include "machdefs.h"
+#include "sopnamsp.h"
+
+#include <iostream>
+#include <sstream>
+#include <string>
+
+#include "array.h"
+#include "tarrinit.h"
+
+#include "imgmag_pi.h"
+
+ 
+using namespace std; 
+using namespace Magick; 
+
+int main(int argc,char **argv) 
+{ 
+  if (argc < 3) {
+    cout << "  Usage: img2rgb  InputImageFile OutputFile \n" 
+         << "    Input: jpeg/gif/...  OutFile: PI-RB (.rgb)  " << endl;
+    return 0;
+  }
+/*
+  cout << " Initializing image magick ... " << endl;
+  InitializeMagick(argv[0]);
+*/
+  cout << " Initializing SOPHYA  ... " << endl;
+  SophyaInit();
+
+  try { 
+    string infile = argv[1];
+    cout << " Reading input file " << infile << endl;
+    // Read a file into image object 
+    ImgMagObj image(infile);
+    cout << "Converting to PIPixRGBArray -  Width= " << image.columns()  
+         << "  Height " << image.rows() << endl;
+    PIPixRGBArray rgba(0,0);
+    image.FillPIRGBArray(rgba);
+    string outfile = argv[2];
+    cout << " ---- writing rgbimg to file " << outfile << endl;
+    rgba.SaveToFile(outfile.c_str());
+  } 
+  catch( Exception &error_ ) 
+    { 
+      cout << "Caught Exception: " << error_.what() << endl; 
+      return 1; 
+    } 
+  catch( std::exception &error_ ) 
+    { 
+      cout << "Caught exception: " << error_.what() << endl; 
+      return 1; 
+    } 
+  return 0; 
+}
Index: /tags/pipV0/AddOn/PIPhoto/imgmag_pi.cc
===================================================================
--- /tags/pipV0/AddOn/PIPhoto/imgmag_pi.cc	(revision 3555)
+++ /tags/pipV0/AddOn/PIPhoto/imgmag_pi.cc	(revision 3555)
@@ -0,0 +1,269 @@
+#include "imgmag_pi.h"
+// ------------------------------------------------------------------
+// ------------------ Classe ImgMagObj -----------------------
+
+/* --Methode--*/
+ImgMagObj::ImgMagObj(string filename)
+  :  Magick::Image()
+{
+  read(filename.c_str());	
+}
+
+/* --Methode--*/
+ImgMagObj::ImgMagObj(const unsigned int width, const unsigned int height)
+  : Magick::Image(Magick::Geometry(width, height), Magick::ColorRGB(0., 0., 0.) )
+{
+}  
+
+/* --Methode--*/
+ImgMagObj::ImgMagObj(PIPixRGBArray const & rgba)
+  : Magick::Image(Magick::Geometry(rgba.XSize(), rgba.YSize()), Magick::ColorRGB(0., 0., 0.) )
+{
+  for (unsigned int i=0; i<columns(); i++) 
+    for (unsigned int j=0; j<rows(); j++) {
+      PIPixRGB rgb = rgba(i,j);	
+      Magick::ColorRGB col((double)rgb.red/255., (double)rgb.green/255., 
+                           (double)rgb.blue/255.);  
+      pixelColor(i,j,col);
+    }
+}
+
+/* --Methode--*/
+void ImgMagObj::FillPIRGBArray(PIPixRGBArray& rgba)
+{
+  rgba.SetSize(XSize(), YSize());
+  for (unsigned int i=0; i<columns(); i++) 
+    for (unsigned int j=0; j<rows(); j++) {
+      Magick::ColorRGB col = pixelColor(i,j); 
+      PIPixRGB rgb;
+      rgba(i,j).red = (unsigned char)(col.red()*255.); 
+      rgba(i,j).green = (unsigned char)(col.green()*255.); 
+      rgba(i,j).blue = (unsigned char)(col.blue()*255.); 
+    }
+  return;  	
+}
+
+// ------------------------------------------------------------------
+// ------------------ Classe ImgMagP2DAdaptRGB -----------------------
+
+/* --Methode--*/
+ImgMagP2DAdaptRGB::ImgMagP2DAdaptRGB(Magick::Image * img, bool ad) 
+      : P2DArrayAdapter(img->columns(), img->rows() )
+{ 
+  aDel = ad;   mPix = img; 
+}
+
+/* --Methode--*/
+ImgMagP2DAdaptRGB::~ImgMagP2DAdaptRGB() 
+{ 
+  if ( (aDel) && (mPix) ) delete mPix; 
+}
+
+/* --Methode--*/
+double ImgMagP2DAdaptRGB::Value(int ix, int jy) 
+{  
+  if ( (ix < 0)  || (jy < 0) || (ix >= sX) || (jy >= sY) ) return(0.); 
+  Magick::ColorRGB col = mPix->pixelColor(ix,jy); 
+  return ( ((col.blue()*256.+col.green())*256.+col.red())*255. );
+}
+
+/* --Methode--*/
+double ImgMagP2DAdaptRGB::MeanVal(int ix1, int ix2, int jy1, int jy2)  
+{
+  int ec;
+  if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; }
+  if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; }    
+  unsigned long r = 0.;
+  unsigned long g = 0.;
+  unsigned long b = 0.;
+  Magick::ColorRGB rgb;
+  for(int j=jy1; j<=jy2; j++) {
+    for(int i=ix1; i<=ix2; i++)  {
+      rgb = mPix->pixelColor(i, j);
+      r += (unsigned long)(rgb.red()*255.);  
+      g += (unsigned long)(rgb.green()*255.);   
+      b += (unsigned long)(rgb.blue()*255.); 
+    }
+  }
+  unsigned long n = (jy2-jy1+1)*(ix2-ix1+1);   
+  r /= n; g /= n; b /= n;
+  return ((double)((b*256+g)*256+r)); 
+/*  La meme chose calculee en double ne marche pas !!!!
+  double r = 0.;
+  double g = 0.;
+  double b = 0.;
+  Magick::ColorRGB rgb;
+  for(int j=jy1; j<=jy2; j++) {
+    for(int i=ix1; i<=ix2; i++)  {
+      rgb = mPix->pixelColor(i, j);
+      r += rgb.red();  g += rgb.green();   b += rgb.blue(); 
+    }
+  }
+  double n = (jy2-jy1+1)*(ix2-ix1+1);   
+  r /= n; g /= n; b /= n;
+  return ( ((b*256.+g)*256.+r)*255. );
+*/
+}   
+
+
+// ------------------------------------------------------------------
+// ------------------ Classe ImgMagP2DAdaptGS -----------------------
+
+/* --Methode--*/
+ImgMagP2DAdaptGS::ImgMagP2DAdaptGS(Magick::Image * img, bool ad) 
+      : P2DArrayAdapter(img->columns(), img->rows() )
+{ 
+  aDel = ad;   mPix = img; 
+}
+
+/* --Methode--*/
+ImgMagP2DAdaptGS::~ImgMagP2DAdaptGS() 
+{ 
+  if ( (aDel) && (mPix) ) delete mPix; 
+}
+
+/* --Methode--*/
+double  ImgMagP2DAdaptGS::Value(int ix, int jy) 
+{  
+  if ( (ix < 0)  || (jy < 0) || (ix >= sX) || (jy >= sY) ) return(0.); 
+  Magick::ColorGray grey = mPix->pixelColor(ix,jy); 
+  return ( grey.shade() );
+}
+
+/* --Methode--*/
+double  ImgMagP2DAdaptGS::MeanVal(int ix1, int ix2, int jy1, int jy2)  
+{
+  int ec;
+  if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; }
+  if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; }    
+  double gr = 0;
+  for(int j=jy1; j<=jy2; j++) 
+    for(int i=ix1; i<=ix2; i++)  {
+      Magick::ColorGray grey = mPix->pixelColor(i, j);
+      gr += grey.shade();
+    }
+  double n = (jy2-jy1+1)*(ix2-ix1+1);   
+  return ( gr/n );  
+}   
+
+// ------------------------------------------------------------------
+//  Adapteur d'objet ImgMagObj pour gestion  par NamedObjMgr de piapp
+
+/* --Methode-- */
+NOMAdapter_ImgMag::NOMAdapter_ImgMag(ImgMagObj* o)
+  : NObjMgrAdapter(o)
+{
+mImg = o;
+}
+
+/* --Methode-- */
+NOMAdapter_ImgMag::~NOMAdapter_ImgMag()
+{
+}
+
+/* --Methode-- */
+NObjMgrAdapter* NOMAdapter_ImgMag::Clone(AnyDataObj* o)
+{
+ImgMagObj* img = dynamic_cast<ImgMagObj *>(o);
+if (img) return ( new NOMAdapter_ImgMag(img) );
+return ( new NObjMgrAdapter(o) );
+}
+string NOMAdapter_ImgMag::GetDataObjType()
+{
+  return ("ImgMagObj ");
+}
+
+/* --Methode-- */
+void NOMAdapter_ImgMag::Print(ostream& os, int lev)
+{
+  if (mImg == NULL) return;	
+  os << " ImgMagObj - File=" << mImg->fileName() << "  Width=" << mImg->columns()
+     << " x Height=" << mImg->rows() << endl; 
+//  if (lev > 1) 
+}
+
+/* --Methode-- */
+P2DArrayAdapter* NOMAdapter_ImgMag::Get2DArray(string& dopt)
+{
+  if (mImg == NULL) return NULL;
+  if (dopt.find("monochrome") < dopt.length()) {
+    dopt = "lut=lin,0.,1.  grey128 " + dopt;
+    return new ImgMagP2DAdaptGS(mImg);		
+  }
+  else {
+    dopt = "lut=rgb  rgb32768cm " + dopt;
+    return new ImgMagP2DAdaptRGB(mImg);		
+  }
+}
+
+/* --Methode-- */
+NTupleInterface* NOMAdapter_ImgMag::GetNTupleInterface(bool& adel)
+{
+  if (mImg == NULL) return NULL;	
+  adel = true;
+  return( new NTupInt_ImgMag(mImg) );
+}
+
+
+// ---- Class Interface NTuple pour ImgMagObj
+
+/* --Methode-- */
+NTupInt_ImgMag::NTupInt_ImgMag(ImgMagObj* img)
+{
+  mImg = img;
+}
+
+/* --Methode-- */
+NTupInt_ImgMag::~NTupInt_ImgMag()
+{
+}
+
+/* --Methode-- */
+sa_size_t NTupInt_ImgMag::NbLines() const
+{
+  if (mImg)  return( mImg->XSize()*mImg->YSize() );
+  else return 0;
+}
+
+/* --Methode-- */
+sa_size_t NTupInt_ImgMag::NbColumns() const 
+{
+  return(6);
+}
+
+/* --Methode-- */
+r_8* NTupInt_ImgMag::GetLineD(sa_size_t n) const 
+{
+  int i;
+  if ((n < 0) || (n >= (int)(mImg->XSize()*mImg->YSize())  )) 
+    for(i=0; i<6; i++)  mRet[i] = 0.;
+else { 
+  int i = n%mImg->XSize(); 
+  int j = n/mImg->XSize();
+  Magick::ColorRGB rgb = mImg->pixelColor(i, j);
+  Magick::ColorGray grey = mImg->pixelColor(i, j);
+  mRet[0] = i;  mRet[1] = j; 
+  mRet[2] = rgb.red();  
+  mRet[3] = rgb.green();  
+  mRet[4] = rgb.blue();  
+  mRet[5] = grey.shade();
+  }
+return(mRet);
+}
+
+/* --Methode-- */
+string NTupInt_ImgMag::VarList_C(const char* nx) const 
+{
+string nomx;
+if (nx) nomx = nx;
+else nomx = "_xh_";
+string vardec = "double x,y,i,j,r,g,b,I; \n";
+vardec += "x = " + nomx + "[0]; i = " + nomx + "[0]; \n";
+vardec += "y = " + nomx + "[1]; j = " + nomx + "[1]; \n";
+vardec += "r = " + nomx + "[2];  g = " + nomx + "[3]; \n";
+vardec += "b = " + nomx + "[4];  I = " + nomx + "[5]; \n";
+return(vardec);
+}
+
+
+
Index: /tags/pipV0/AddOn/PIPhoto/imgmag_pi.h
===================================================================
--- /tags/pipV0/AddOn/PIPhoto/imgmag_pi.h	(revision 3555)
+++ /tags/pipV0/AddOn/PIPhoto/imgmag_pi.h	(revision 3555)
@@ -0,0 +1,113 @@
+// Classes adaptateurs d'objets ImageMagick++ pour piapp 
+//   R. Ansari -  Decembre 2008
+//   (C)  Univ.Paris Sud LAL-IN2P3/CNRS    CEA-IRFU (DAPNIA)  
+
+#ifndef IMAGMAGPI_H_SEEN
+#define IMAGMAGPI_H_SEEN
+
+#include "machdefs.h"
+#include "sopnamsp.h"
+
+#include <string>
+#include <iostream>
+
+#include "anydataobj.h"
+#include "pipixutils.h"
+#include "parradapter.h"
+#include "nomgadapter.h"
+
+#include <Magick++.h> 
+
+// ---------------------------------------------------------------------------------
+//  Classe heritant de AnyDataObj et de ImageMagick::Image pour utilisation ds piapp
+// ---------------------------------------------------------------------------------
+
+class ImgMagObj : public SOPHYA::AnyDataObj, public Magick::Image {
+public:
+// Read Image from file (jpeg, gif ...)
+  ImgMagObj(string filename);
+// Create a black image with the specified size
+  ImgMagObj(const unsigned int width=10, const unsigned int height=10);
+// Create an image from  a PIPixRGBArray  object 
+  ImgMagObj(PIPixRGBArray const & rgba);
+ 
+  virtual ~ImgMagObj() { } 
+  
+  inline unsigned int XSize() { return columns(); }
+  inline unsigned int YSize() { return rows(); }
+  
+  inline PIPixRGB pixelPIRGB(const unsigned int ix, const unsigned int jy)
+    { PIPixRGB rcol;     
+      Magick::ColorRGB col = pixelColor(ix,jy); 
+      rcol.red =  (unsigned char)(col.red()*255.);
+      rcol.green =  (unsigned char)((float)col.green()*255.);
+      rcol.blue =  (unsigned char)((float)col.blue()*255.);
+      rcol.alpha = 0;
+      return rcol;
+    }
+   
+   void FillPIRGBArray(PIPixRGBArray& rgba);
+    
+// protected :  
+};
+
+// ------------------------------------------------------------------
+//  Adapteur tableau 2D mode RGB pour affichage par PIImage 
+class ImgMagP2DAdaptRGB : public P2DArrayAdapter {
+public :
+  ImgMagP2DAdaptRGB(Magick::Image * img, bool ad=false);
+  virtual ~ImgMagP2DAdaptRGB();
+  virtual double  Value(int ix, int iy); 
+  virtual double  MeanVal(int ix1, int ix2, int jy1, int jy2);
+protected :
+  bool aDel;
+  Magick::Image* mPix;
+};
+
+// ------------------------------------------------------------------
+//  Adapteur tableau 2D mode GreyScale pour affichage par PIImage 
+class ImgMagP2DAdaptGS : public P2DArrayAdapter {
+public :
+  ImgMagP2DAdaptGS(Magick::Image * img, bool ad=false);
+  virtual ~ImgMagP2DAdaptGS();
+  virtual double  Value(int ix, int iy); 
+  virtual double  MeanVal(int ix1, int ix2, int jy1, int jy2);
+protected :
+  bool aDel;
+  Magick::Image* mPix;
+};
+
+// ------------------------------------------------------------------
+//  Adapteur d'objet ImgMagObj pour gestion  par NamedObjMgr de piapp
+class NOMAdapter_ImgMag : public NObjMgrAdapter {
+public:
+                                NOMAdapter_ImgMag(ImgMagObj* img = NULL);
+  virtual                       ~NOMAdapter_ImgMag();
+
+  virtual NObjMgrAdapter*       Clone(AnyDataObj* o);
+  virtual string                GetDataObjType();
+  virtual P2DArrayAdapter*      Get2DArray(string& dopt);
+  virtual NTupleInterface*      GetNTupleInterface(bool& adel);
+  virtual void                  Print(ostream& os, int lev=0);
+
+protected:
+  ImgMagObj* mImg;
+
+};
+
+// ---- Class Interface NTuple pour ImgMagObj
+class NTupInt_ImgMag : public NTupleInterface {
+public:
+                        NTupInt_ImgMag(ImgMagObj* img);
+  virtual               ~NTupInt_ImgMag();
+  virtual sa_size_t     NbLines() const ;
+  virtual sa_size_t     NbColumns() const ;
+  virtual r_8 *         GetLineD(sa_size_t n) const ;
+  virtual string        VarList_C(const char* nomx=NULL) const ;
+protected:
+  ImgMagObj* mImg;
+  mutable r_8 mRet[8];
+};
+
+// 
+#endif
Index: /tags/pipV0/AddOn/PIPhoto/imgmagmod.cc
===================================================================
--- /tags/pipV0/AddOn/PIPhoto/imgmagmod.cc	(revision 3555)
+++ /tags/pipV0/AddOn/PIPhoto/imgmagmod.cc	(revision 3555)
@@ -0,0 +1,304 @@
+#include "sopnamsp.h"
+#include "machdefs.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <math.h>
+
+#include <typeinfo>
+
+#include <vector>
+#include <string>
+
+#include "piacmd.h"
+#include "nobjmgr.h"
+#include "pistdimgapp.h"
+#include "servnobjm.h"
+#include "picmap.h"
+#include "srandgen.h"
+
+#include "imgmag_pi.h"
+//--- Pour WidgetToImgMag()
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xatom.h>
+
+//-----------------------------------------------------------------------
+//  Module chargeable de gestion d'images (jpeg,gif...) dans piapp 
+//  Ce module utilise la librairie ImageMagick
+
+//  Declaration de la fonction d'activation et de desactivation du module
+extern "C" {
+void imgmagmod_init();
+void imgmagmod_end();
+}
+
+//  Fonction pour creer et remplir un ImgMagObj en copiant le contenu d'un widget
+ImgMagObj* WidgetToImgMag(PIWdg* wdg);
+
+//  Une classe commande-executor, permettant d'enregistrer de 
+//  nouvelles commandes a piapp
+class imgmagmodExecutor : public CmdExecutor {
+public:
+                imgmagmodExecutor();
+  virtual       ~imgmagmodExecutor();
+  // Execute s'occupe de l'execution effective des commandes
+  virtual int   Execute(string& keyw, vector<string>& args, string& toks);
+};
+
+/* --Methode-- */
+imgmagmodExecutor::imgmagmodExecutor()
+{
+
+PIACmd * mpiac;
+NamedObjMgr omg;
+mpiac = omg.GetImgApp()->CmdInterpreter();
+
+// On enregistre deux nouvelles commandes 
+string hgrp = "ImageMagick";
+// commande readphoto
+string kw = "readphoto";
+string usage = "readphoto: Read an image file (jpeg/gif ...) \n" ;
+usage += "An object of type ImgMagObj (wrapper for Magick::Image) is \n";
+usage += "created and managed by the NamedObjMgr\n";
+usage += "   Usage: readphoto ImageFileName \n";
+usage += "   See also writephoto \n";
+mpiac->RegisterCommand(kw, usage, this, hgrp);
+// commande pirgb_rdphoto
+kw = "pirgb_rdphoto";
+usage = "pirgb_rdphoto: Read an PI_RGB file (.rgb) into a ImgMagObj object\n" ;
+usage += "   Usage: pirgb_rdphoto PI_RGB_FileName \n";
+usage += "   See also readphoto \n";
+mpiac->RegisterCommand(kw, usage, this, hgrp);
+// commande writephoto
+kw = "writephoto";
+usage = "writephoto: Save an ImgMagObj object to an image file (jpeg/gif ...) \n" ;
+usage += "   Usage: writephoto ObjName OutFileName \n";
+usage += "   - ObjName : ImgMagObj object name \n";
+usage += "   - OutFileName : .jpg .gif .tiff output filename \n";
+usage += "   See also readphoto pirgb_wrphoto";
+mpiac->RegisterCommand(kw, usage, this, hgrp);
+// commande pirgb_wrphoto
+kw = "pirgb_wrphoto";
+usage = "pirgb_wrphoto: Save an ImgMagObj object to a PI_RGB file (.rgb) \n" ;
+usage += "   Usage: pirgb_wrphoto ObjName OutFileName \n";
+usage += "   See also writephoto ";
+mpiac->RegisterCommand(kw, usage, this, hgrp);
+// commande wdg2imgfile win2imgfile 
+kw = "wdg2imgfile";
+usage = "wdg2imgfile: Save current widget to image file \n" ;
+usage += "   Usage: wdg2imgfile  OutFileName \n";
+mpiac->RegisterCommand(kw, usage, this, hgrp);
+kw = "win2imgfile";
+usage = "win2imgfile: Save current window to image file \n" ;
+usage += "   Usage: win2imgfile  OutFileName \n";
+mpiac->RegisterCommand(kw, usage, this, hgrp);
+
+}
+
+/* --Methode-- */
+imgmagmodExecutor::~imgmagmodExecutor()
+{
+}
+
+/* --Methode-- */
+int imgmagmodExecutor::Execute(string& kw, vector<string>& tokens, string&)
+{
+
+NamedObjMgr omg;
+if ((kw=="readphoto") || (kw=="pirgb_rdphoto")) {
+  if (tokens.size() < 1) {
+    cout << "Usage: readphoto/pirgb_rdphoto FileName" << endl;
+    return(0);
+    }
+  cout << " readphoto: reading file: " << tokens[0] << endl;  
+  Services2NObjMgr* serv = omg.GetServiceObj();
+  string objname = serv->FileName2Name(tokens[0]);
+  ImgMagObj* img = NULL; 
+  if (kw=="readphoto")  img = new ImgMagObj(tokens[0]);
+  else {
+    PIPixRGBArray rgbimg(tokens[0].c_str());
+    img = new ImgMagObj(rgbimg);
+  }
+  if (img != NULL) omg.AddObj(img, objname);
+}
+else if ((kw=="writephoto") || (kw=="pirgb_wrphoto")) {
+  if (tokens.size() < 2) {
+    cout << "Usage: writephoto/pirgb_wrphoto ObjName OutFileName" << endl;
+    return(0);
+  }	
+  AnyDataObj* obj=omg.GetObj(tokens[0]);
+  if (obj == NULL) {
+    cout << " No object with name " << tokens[0] << endl;
+    return 1;
+  }
+  ImgMagObj* img = dynamic_cast<ImgMagObj*>(obj);
+  if (img == NULL)  {
+    cout << " Object with name " << tokens[0] << "  Not an ImgMagObj object" << endl;
+    return 2;
+  }
+  if (kw=="writephoto")  {
+    cout << " writephoto: saving" << tokens[0] << " to file " << tokens[1] << endl;
+    img->write(tokens[1]);
+    return 0; 
+  }
+  else if (kw=="pirgb_wrphoto") {
+    cout << " pirgb_wrphoto: saving" << tokens[0] << " to PI_RGB file " << tokens[1] << endl;
+    PIPixRGBArray rgba(0,0);
+    img->FillPIRGBArray(rgba);
+    rgba.SaveToFile(tokens[1].c_str());
+    return 0; 
+  }
+}
+else if ((kw=="wdg2imgfile")||(kw=="win2imgfile")) {
+  if (tokens.size() < 1) {
+    cout << "Usage: wdg2imgfile/win2imgfile FileName" << endl;
+    return(0);
+  }
+  PIWdg* wdg = NULL; 
+  if (kw=="wdg2imgfile") wdg = (PIWdg *)omg.GetImgApp()->CurrentBaseWdg();
+  else wdg = (PIWdg *)omg.GetImgApp()->CurrentWindow();
+  if (wdg == NULL) {
+  	cout << " wdg2imgfile/win2imgfile: No current window/widget " << endl;
+  	return 1;
+  }
+  ImgMagObj* img = WidgetToImgMag(wdg);
+  if (img) {
+    cout << " wdg2imgfile : saving current widget to file " << tokens[0] << endl;
+    img->write(tokens[0]);
+  }
+  return 0;
+}
+
+return(0);
+}
+
+static imgmagmodExecutor * imgmagex = NULL;
+static PIColorMap * cmap32768 = NULL;
+/* Nouvelle-Fonction */
+void imgmagmod_init()
+{
+// Fonction d'initialisation du module
+cout << " imgmagmod_init() : Initializing ImageMagick interface piapp-module ..." << endl;
+// Appele par le gestionnaire de modules de piapp (PIACmd::LoadModule())
+if (imgmagex) delete imgmagex;
+imgmagex = new imgmagmodExecutor;
+NamedObjMgr omg;
+// On alloue la grosse table de couleur avec 32768 couleurs RGB ...
+if (cmap32768 == NULL)  {
+  omg.GetImgApp()->LockMutex(); 	
+  cmap32768 = new PIColorMap(CMAP_RGB32768);
+//  cmap32768 = new PIColorMap(CMAP_RGB4096);
+  omg.GetImgApp()->UnlockMutex(true);
+}
+Services2NObjMgr* serv = omg.GetServiceObj();
+serv->RegisterClass(new ImgMagObj, new NOMAdapter_ImgMag );
+cout << " imgmagmod_init() : Initialization OK " << endl;
+}
+
+/* Nouvelle-Fonction */
+void imgmagmod_end()
+{
+// Desactivation du module
+if (imgmagex) delete imgmagex;
+imgmagex = NULL;
+NamedObjMgr omg;
+omg.GetImgApp()->CkEvt_LockMutex();
+if (cmap32768) delete cmap32768;
+omg.GetImgApp()->UnlockMutex(true);
+cmap32768 = NULL;
+}
+
+inline void _col2fcol_(unsigned long & col, unsigned long & fcol)
+{
+  if (col > 0x00FFFFFF)  fcol = 0x01000000;
+  else if  (col > 0x0000FFFF)  fcol = 0x000010000;
+  else if (col > 0x000000FF) fcol = 0x00000100;
+  else fcol = 1;     
+//DBG  cout << " _col2fcol_ col= " << col << " fcol=" << fcol << " ->" << col/fcol << endl;
+//DBG  cout << " HEX _col2fcol_ col= " << hex << col << " fcol=" << fcol << " ->" << col/fcol << dec << endl;
+}
+
+/* Nouvelle-Fonction */
+ImgMagObj* WidgetToImgMag(PIWdg* wdg)
+{
+  if (wdg == NULL) {
+  	cout << " WidgetToImgMag() wdg=NULL " << endl;
+  	return NULL; 
+  }	
+//DBG  cout << "------ WidgetToImgMag() ------" << endl;
+
+  NamedObjMgr omg;
+  omg.GetImgApp()->CkEvt_LockMutex();
+  Display* mdsp = PIXDisplay();
+  int scr = XDefaultScreen(mdsp);
+  int depth = DefaultDepth(mdsp,scr);
+  Window xw = XtWindow(wdg->XtWdg());
+  unsigned long plane_mask = ~0;  // tous les bits a 1
+  XImage * ximg = XGetImage(mdsp, xw, 0, 0, wdg->XSize(), wdg->YSize(),
+                            plane_mask, ZPixmap);
+//DBG  cout << " Resultat XGetImage -> " << hex << ximg << dec << endl;
+  if (ximg == NULL)  return NULL;
+                            
+  unsigned long red,green,blue;
+  unsigned long fred,fgreen,fblue;
+
+  XColor col;
+  Colormap  cmap = XDefaultColormap (mdsp, scr);
+  red = 0x000000FF; 
+  green = 0x0000FF00;
+  blue = 0x00FF0000;
+  unsigned short maxrgb = ~0;
+  col.red = maxrgb;  col.green = col.blue = 0;
+  if (XAllocColor(mdsp, cmap, &col))  {
+//DBG  	cout << " --DBG red-color , R,G,B=" << hex << col.red << "," << col.green << ","
+//         << col.blue << " -> pixel=" << col.pixel << dec << endl;
+    red = col.pixel; 
+  }
+  col.green = maxrgb;  col.red = col.blue = 0;
+  if (XAllocColor(mdsp, cmap, &col))  {
+//DBG  	cout << " --DBG green-color , R,G,B=" << hex << col.red << "," << col.green << ","
+//         << col.blue << " -> pixel=" << col.pixel << dec << endl;
+    green = col.pixel;      
+  }
+  col.blue = maxrgb;  col.red = col.green = 0;
+  if (XAllocColor(mdsp, cmap, &col))  {
+//DBG  	cout << " --DBG blue-color , R,G,B=" << hex << col.red << "," << col.green << ","
+//         << col.blue << " -> pixel=" << col.pixel << dec << endl;
+    blue = col.pixel;      
+  }
+  _col2fcol_(red, fred);
+  _col2fcol_(green, fgreen);
+  _col2fcol_(blue, fblue);
+
+  ImgMagObj* img = new ImgMagObj(wdg->XSize(), wdg->YSize());
+  Magick::ColorRGB rgb;
+
+  int errcnt[3] = {0,0,0};
+  int errcnt2[3] = {0,0,0};
+  unsigned long pixel;
+  for(int j=0; j<wdg->YSize(); j++)
+    for(int i=0; i<wdg->XSize(); i++) {
+      pixel = XGetPixel(ximg, i, j);
+      double xcc[3];
+      xcc[0] = (double)((pixel&red)/fred)/255.;
+      xcc[1] = (double)((pixel&green)/fgreen)/255.;
+      xcc[2] = (double)((pixel&blue)/fblue)/255.;
+      // Il faut proteger contre <0 et >1 sinon exception ImageMagck !
+      for(int kk=0; kk<3;kk++) {
+      	if (xcc[kk]<=0.)  { xcc[kk] = 0.;  errcnt[kk]++; }
+      	if (xcc[kk]>=1.)  { xcc[kk] = 1.;  errcnt2[kk]++; }
+      }
+     Magick::ColorRGB mcol(xcc[0], xcc[1], xcc[2]);
+//       Magick::ColorRGB mcol(0.5+0.2*frandpm1(), 0.5+0.35*frandpm1(), 0.6+0.2*frandpm1());
+     img->pixelColor(i,j,mcol);
+    }  
+/*        
+   for(int kk=0; kk<3;kk++)
+     cout << " ErrCnt k=" << kk << " : " << errcnt[kk] << "," << errcnt2[kk] << endl;   
+*/
+  XDestroyImage(ximg);
+  omg.GetImgApp()->UnlockMutex(true);
+  return img;	
+}
+
Index: /tags/pipV0/AddOn/PIPhoto/makefile
===================================================================
--- /tags/pipV0/AddOn/PIPhoto/makefile	(revision 3555)
+++ /tags/pipV0/AddOn/PIPhoto/makefile	(revision 3555)
@@ -0,0 +1,63 @@
+# -------------------------------------------------------
+# Makefile pour module piapp imgmagmod , interface 
+# avec ImageMagick pour manipulation d'images jpeg/gif...
+#  Part of SOPHYA/PI/piapp software 
+# (C) LAL-IN2P3/CNRS & Univ. Paris Sud (11)
+# (C) IRFU - CEA   
+# -------------------------------------------------------
+ 
+include $(SOPHYABASE)/include/sophyamake.inc
+
+### Liste des librairies pour ImageMagick 
+IMGMAGLIBS = -L/sw/lib -L/usr/X11/lib \
+             -lfreetype -lz -Wl,-framework,CoreServices,-framework,ApplicationServices \
+             -L/sw/lib -lMagick++ -lWand -lMagick -llcms -ltiff -lfreetype \
+             -ljpeg -lpng -lXext -lXt -lSM -lICE -lX11 -lbz2 -lxml2 -lz \
+             -lpthread -lm -lpthread 
+IMGMAGINCP = -I/sw/include                     
+###########
+
+MOBJ = $(SOPHYAOBJP)
+MEXE = $(SOPHYAEXEP)
+MSLB = $(SOPHYASLBP)
+
+all : $(MEXE)/rgb2img  $(MEXE)/img2rgb  $(MEXE)/animrgbs $(MSLB)/imgmagmod.so
+
+
+clean :
+	rm $(MEXE)/rgb2img  $(MEXE)/img2rgb  $(MEXE)/animrgbs $(MSLB)/imgmagmod.so
+	rm $(MOBJ)/rgb2img.o  $(MOBJ)/img2rgb.o  $(MOBJ)/animrgbs.o $(MOBJ)/imgmagmod.o $(MOBJ)imgmag_pi.o
+
+ 
+$(MEXE)/img2rgb : $(MOBJ)/img2rgb.o $(MOBJ)/imgmag_pi.o 
+	$(CXXLINK) -o $(MEXE)/img2rgb  $(MOBJ)/img2rgb.o $(MOBJ)/imgmag_pi.o \
+	   $(SOPHYAALLSLBLIST) $(IMGMAGLIBS)          
+
+$(MOBJ)/img2rgb.o : img2rgb.cc imgmag_pi.h
+	 $(CXXCOMPILE) -I/sw/include -o $(MOBJ)/img2rgb.o img2rgb.cc
+
+$(MEXE)/rgb2img : $(MOBJ)/rgb2img.o $(MOBJ)/imgmag_pi.o 
+	$(CXXLINK) -o $(MEXE)/rgb2img  $(MOBJ)/rgb2img.o $(MOBJ)/imgmag_pi.o \
+	   $(SOPHYAALLSLBLIST) $(IMGMAGLIBS)          
+
+$(MEXE)/animrgbs : $(MOBJ)/animrgbs.o $(MOBJ)/imgmag_pi.o 
+	$(CXXLINK) -o $(MEXE)/animrgbs  $(MOBJ)/animrgbs.o $(MOBJ)/imgmag_pi.o \
+	   $(SOPHYAALLSLBLIST) $(IMGMAGLIBS)          
+
+$(MOBJ)/animrgbs.o : animrgbs.cc imgmag_pi.h
+	 $(CXXCOMPILE) -I/sw/include -o $(MOBJ)/animrgbs.o animrgbs.cc
+
+$(MOBJ)/rgb2img.o : rgb2img.cc imgmag_pi.h
+	 $(CXXCOMPILE) -I/sw/include -o $(MOBJ)/rgb2img.o rgb2img.cc
+	 
+$(MOBJ)/imgmag_pi.o : imgmag_pi.cc imgmag_pi.h
+	 $(CXXCOMPILE) -I/sw/include -o $(MOBJ)/imgmag_pi.o imgmag_pi.cc
+	 
+$(MSLB)/imgmagmod.so : $(MOBJ)/imgmagmod.o $(MOBJ)/imgmag_pi.o	 
+	$(CXXDLL) -o $(MSLB)/imgmagmod.so  $(MOBJ)/imgmagmod.o $(MOBJ)/imgmag_pi.o \
+	   $(SOPHYAALLSLBLIST) $(IMGMAGLIBS)          
+
+$(MOBJ)/imgmagmod.o : imgmagmod.cc imgmag_pi.h
+	 $(CXXCOMPILE) -I/sw/include -o $(MOBJ)/imgmagmod.o imgmagmod.cc
+	 
+
Index: /tags/pipV0/AddOn/PIPhoto/rgb2img.cc
===================================================================
--- /tags/pipV0/AddOn/PIPhoto/rgb2img.cc	(revision 3555)
+++ /tags/pipV0/AddOn/PIPhoto/rgb2img.cc	(revision 3555)
@@ -0,0 +1,54 @@
+#include "machdefs.h"
+#include "sopnamsp.h"
+
+#include <iostream>
+#include <sstream>
+#include <string>
+
+#include "array.h"
+#include "tarrinit.h"
+
+#include "imgmag_pi.h"
+
+ 
+using namespace std; 
+using namespace Magick; 
+
+int main(int argc,char **argv) 
+{ 
+  if (argc < 3) {
+    cout << "  Usage: rgb2img  InputImageFile OutputFile \n" 
+         << "     Input: PI-RB (.rgb)  Output: jpeg/gif/... " << endl;
+    return 0;
+  }
+/*
+  cout << " Initializing image magick ... " << endl;
+  InitializeMagick(argv[0]);
+*/
+  cout << " Initializing SOPHYA  ... " << endl;
+  SophyaInit();
+
+  try { 
+    string infile = argv[1];
+    cout << " Reading input file " << infile << endl;
+    // Read a file into an PIPixRGBArray
+    PIPixRGBArray rgba(argv[1]);
+    cout << "Converting to Magick::Image -  Width= " << rgba.XSize() 
+         << " Height= " << rgba.YSize() << endl;
+    ImgMagObj image(rgba);
+    string outfile = argv[2];
+    cout << " ---- writing Magick::Image to file " << outfile << endl;
+    image.write(outfile);
+  } 
+  catch( Exception &error_ ) 
+    { 
+      cout << "Caught Exception: " << error_.what() << endl; 
+      return 1; 
+    } 
+  catch( std::exception &error_ ) 
+    { 
+      cout << "Caught exception: " << error_.what() << endl; 
+      return 1; 
+    } 
+  return 0; 
+}
Index: /tags/pipV0/AddOn/PIPhoto/tanim.pic
===================================================================
--- /tags/pipV0/AddOn/PIPhoto/tanim.pic	(revision 3555)
+++ /tags/pipV0/AddOn/PIPhoto/tanim.pic	(revision 3555)
@@ -0,0 +1,36 @@
+#######################################################
+####  Script exemple de creation d'une animation simple
+####  a l'aide (s)piapp et ImageMagick 
+####  SOPHYA/PI - (C) LAL / IRFU    2008
+#######################################################
+newwin 1 1 250 250 
+setaxesatt 'font=courier,roman,12 fixedfontsize white'
+
+xc1 = 0.
+yc1 = 0.
+a1 = 1.15
+b1 = 0.75
+xc2 = 0.
+yc2 = -0.2
+a2 = 0.6
+b2 = 1.
+
+## repertoire ou se trouveront les images RGB des frames 
+RGBDIR = '../TAnim/'
+
+for i 0:73
+  drpanel  -1.1 1.1 -1.1 1.1 'centeredaxes nolabels wbgcol=black'
+  addoval $xc1 $yc1 $a1 $b1 'red line=solid,2'
+  addoval $xc2 $yc2 $a2 $b2 'navyblue line=solid,2'
+  t = $i*(Pi*2./72.)
+  x = cos($t)*$a1+$xc1
+  y = sin($t)*$b1+$yc1
+  addmarker $x $y 'marker=fcircle,19 gold'
+  t = $i*(Pi*2./72.)*1.75
+  x = cos($t)*$a2+$xc2
+  y = sin($t)*$b2+$yc2
+  addmarker $x $y 'marker=fcircle,19 skyblue'
+  addtext -1 1 "PIAppTestAnim I=  $i" 'font=helvetica,bold,20 white'
+#  sleep 1
+  win2rgb $(RGBDIR)/tanim$i.rgb 
+end  
