| 1 | // Classes adaptateurs d'objets ImageMagick++ pour piapp 
 | 
|---|
| 2 | //   R. Ansari -  Decembre 2008
 | 
|---|
| 3 | //   (C)  Univ.Paris Sud LAL-IN2P3/CNRS    CEA-IRFU (DAPNIA)  
 | 
|---|
| 4 | 
 | 
|---|
| 5 | #ifndef IMAGMAGPI_H_SEEN
 | 
|---|
| 6 | #define IMAGMAGPI_H_SEEN
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #include "machdefs.h"
 | 
|---|
| 9 | #include "sopnamsp.h"
 | 
|---|
| 10 | 
 | 
|---|
| 11 | #include <string>
 | 
|---|
| 12 | #include <iostream>
 | 
|---|
| 13 | 
 | 
|---|
| 14 | #include "anydataobj.h"
 | 
|---|
| 15 | #include "pipixutils.h"
 | 
|---|
| 16 | #include "parradapter.h"
 | 
|---|
| 17 | #include "nomgadapter.h"
 | 
|---|
| 18 | 
 | 
|---|
| 19 | #include <Magick++.h> 
 | 
|---|
| 20 | 
 | 
|---|
| 21 | // ---------------------------------------------------------------------------------
 | 
|---|
| 22 | //  Classe heritant de AnyDataObj et de ImageMagick::Image pour utilisation ds piapp
 | 
|---|
| 23 | // ---------------------------------------------------------------------------------
 | 
|---|
| 24 | 
 | 
|---|
| 25 | class ImgMagObj : public SOPHYA::AnyDataObj, public Magick::Image {
 | 
|---|
| 26 | public:
 | 
|---|
| 27 | // Read Image from file (jpeg, gif ...)
 | 
|---|
| 28 |   ImgMagObj(string filename);
 | 
|---|
| 29 | // Create a black image with the specified size
 | 
|---|
| 30 |   ImgMagObj(const unsigned int width=10, const unsigned int height=10);
 | 
|---|
| 31 | // Create an image from  a PIPixRGBArray  object 
 | 
|---|
| 32 |   ImgMagObj(PIPixRGBArray const & rgba);
 | 
|---|
| 33 |  
 | 
|---|
| 34 |   virtual ~ImgMagObj() { } 
 | 
|---|
| 35 |   
 | 
|---|
| 36 |   inline unsigned int XSize() { return columns(); }
 | 
|---|
| 37 |   inline unsigned int YSize() { return rows(); }
 | 
|---|
| 38 |   
 | 
|---|
| 39 |   inline PIPixRGB pixelPIRGB(const unsigned int ix, const unsigned int jy)
 | 
|---|
| 40 |     { PIPixRGB rcol;     
 | 
|---|
| 41 |       Magick::ColorRGB col = pixelColor(ix,jy); 
 | 
|---|
| 42 |       rcol.red =  (unsigned char)(col.red()*255.);
 | 
|---|
| 43 |       rcol.green =  (unsigned char)((float)col.green()*255.);
 | 
|---|
| 44 |       rcol.blue =  (unsigned char)((float)col.blue()*255.);
 | 
|---|
| 45 |       rcol.alpha = 0;
 | 
|---|
| 46 |       return rcol;
 | 
|---|
| 47 |     }
 | 
|---|
| 48 |    
 | 
|---|
| 49 |    void FillPIRGBArray(PIPixRGBArray& rgba);
 | 
|---|
| 50 |     
 | 
|---|
| 51 | // protected :  
 | 
|---|
| 52 | };
 | 
|---|
| 53 | 
 | 
|---|
| 54 | // ------------------------------------------------------------------
 | 
|---|
| 55 | //  Adapteur tableau 2D mode RGB pour affichage par PIImage 
 | 
|---|
| 56 | class ImgMagP2DAdaptRGB : public P2DArrayAdapter {
 | 
|---|
| 57 | public :
 | 
|---|
| 58 |   ImgMagP2DAdaptRGB(Magick::Image * img, bool ad=false);
 | 
|---|
| 59 |   virtual ~ImgMagP2DAdaptRGB();
 | 
|---|
| 60 |   virtual double  Value(int ix, int iy); 
 | 
|---|
| 61 |   virtual double  MeanVal(int ix1, int ix2, int jy1, int jy2);
 | 
|---|
| 62 | protected :
 | 
|---|
| 63 |   bool aDel;
 | 
|---|
| 64 |   Magick::Image* mPix;
 | 
|---|
| 65 | };
 | 
|---|
| 66 | 
 | 
|---|
| 67 | // ------------------------------------------------------------------
 | 
|---|
| 68 | //  Adapteur tableau 2D mode GreyScale pour affichage par PIImage 
 | 
|---|
| 69 | class ImgMagP2DAdaptGS : public P2DArrayAdapter {
 | 
|---|
| 70 | public :
 | 
|---|
| 71 |   ImgMagP2DAdaptGS(Magick::Image * img, bool ad=false);
 | 
|---|
| 72 |   virtual ~ImgMagP2DAdaptGS();
 | 
|---|
| 73 |   virtual double  Value(int ix, int iy); 
 | 
|---|
| 74 |   virtual double  MeanVal(int ix1, int ix2, int jy1, int jy2);
 | 
|---|
| 75 | protected :
 | 
|---|
| 76 |   bool aDel;
 | 
|---|
| 77 |   Magick::Image* mPix;
 | 
|---|
| 78 | };
 | 
|---|
| 79 | 
 | 
|---|
| 80 | // ------------------------------------------------------------------
 | 
|---|
| 81 | //  Adapteur d'objet ImgMagObj pour gestion  par NamedObjMgr de piapp
 | 
|---|
| 82 | class NOMAdapter_ImgMag : public NObjMgrAdapter {
 | 
|---|
| 83 | public:
 | 
|---|
| 84 |                                 NOMAdapter_ImgMag(ImgMagObj* img = NULL);
 | 
|---|
| 85 |   virtual                       ~NOMAdapter_ImgMag();
 | 
|---|
| 86 | 
 | 
|---|
| 87 |   virtual NObjMgrAdapter*       Clone(AnyDataObj* o);
 | 
|---|
| 88 |   virtual string                GetDataObjType();
 | 
|---|
| 89 |   virtual P2DArrayAdapter*      Get2DArray(string& dopt);
 | 
|---|
| 90 |   virtual NTupleInterface*      GetNTupleInterface(bool& adel);
 | 
|---|
| 91 |   virtual void                  Print(ostream& os, int lev=0);
 | 
|---|
| 92 | 
 | 
|---|
| 93 | protected:
 | 
|---|
| 94 |   ImgMagObj* mImg;
 | 
|---|
| 95 | 
 | 
|---|
| 96 | };
 | 
|---|
| 97 | 
 | 
|---|
| 98 | // ---- Class Interface NTuple pour ImgMagObj
 | 
|---|
| 99 | class NTupInt_ImgMag : public NTupleInterface {
 | 
|---|
| 100 | public:
 | 
|---|
| 101 |                         NTupInt_ImgMag(ImgMagObj* img);
 | 
|---|
| 102 |   virtual               ~NTupInt_ImgMag();
 | 
|---|
| 103 |   virtual sa_size_t     NbLines() const ;
 | 
|---|
| 104 |   virtual sa_size_t     NbColumns() const ;
 | 
|---|
| 105 |   virtual r_8 *         GetLineD(sa_size_t n) const ;
 | 
|---|
| 106 |   virtual string        VarList_C(const char* nomx=NULL) const ;
 | 
|---|
| 107 | protected:
 | 
|---|
| 108 |   ImgMagObj* mImg;
 | 
|---|
| 109 |   mutable r_8 mRet[8];
 | 
|---|
| 110 | };
 | 
|---|
| 111 | 
 | 
|---|
| 112 | // 
 | 
|---|
| 113 | #endif
 | 
|---|