Changeset 3549 in Sophya for trunk


Ignore:
Timestamp:
Dec 13, 2008, 4:40:33 PM (17 years ago)
Author:
ansari
Message:

Petite amelioration classe PIPixRGBArray, et ajout methode PIWdg::ExportToRGB(PIPixRGBArray & rgba) avec implementation X11 - Reza 13/12/2008

Location:
trunk/SophyaPI/PI
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PI/pipixutils.cc

    r3545 r3549  
    8080PIPixRGBArray::PIPixRGBArray(int sx, int sy)
    8181{
    82   if (sx < 0) sx = 0;
    83   if (sy < 0) sy = 0;
    84   sx_ = sx;  sy_ = sy; 
    85   size_t sz = sx_*sy_;
    86   if (sz>0) rgbpix_ = new PIPixRGB[sz];
    87   else rgbpix_ = NULL; 
     82  sx_ = sy_  = 0;
     83  rgbpix_ = NULL;
     84  SetSize(sx, sy);
    8885}
    8986
     
    10097}
    10198
    102 int PIPixRGBArray::SaveToFile(const char * filename)
     99void PIPixRGBArray::SetSize(int sx, int sy)
     100{
     101  if ((sx == sx_)&&(sy == sy_)) return;
     102  if (sx < 0) sx = 0;
     103  if (sy < 0) sy = 0;
     104  if (rgbpix_)  delete[] rgbpix_;
     105  sx_ = sx;  sy_ = sy; 
     106  size_t sz = sx_*sy_;
     107  if (sz>0) rgbpix_ = new PIPixRGB[sz];
     108  else rgbpix_ = NULL; 
     109}
     110
     111int PIPixRGBArray::SaveToFile(const char * filename)   const
    103112{
    104113  FILE * fip = fopen(filename,"wb");
     
    121130{
    122131  if (rgbpix_) {
    123         delete[] rgbpix_;       
     132    delete[] rgbpix_;   
    124133    sx_ = sy_ = 0;
    125134    rgbpix_ = NULL;
     
    139148  size_t sz = sx_*sy_;
    140149  if (sz>0) {
    141         rgbpix_ = new PIPixRGB[sz];
    142         fread((void *)rgbpix_, sizeof(PIPixRGB), sx_*sy_, fip);
     150    rgbpix_ = new PIPixRGB[sz];
     151    fread((void *)rgbpix_, sizeof(PIPixRGB), sx_*sy_, fip);
    143152  }
    144153  else rgbpix_ = NULL; 
  • trunk/SophyaPI/PI/pipixutils.h

    r3545 r3549  
    1616  PIPixColIdx();
    1717  ~PIPixColIdx();
    18   inline int XSize() { return sx_; }
    19   inline int YSize() { return sy_; }
     18  inline int XSize() const { return sx_; }
     19  inline int YSize() const { return sy_; }
    2020
    2121  void AllocateByte(int sx, int sy);
     
    6262  ~PIPixRGBArray();
    6363 
    64   inline int XSize() { return sx_; }
    65   inline int YSize() { return sy_; }
     64  void SetSize(int sx, int sy);
     65
     66  inline int XSize() const { return sx_; }
     67  inline int YSize() const { return sy_; }
    6668
    6769  inline PIPixRGB operator()(int i, int j) const
     
    7072    { return rgbpix_[j*sx_+i]; }
    7173 
    72   int SaveToFile(const char * filename);
     74  int SaveToFile(const char * filename) const ;
    7375  int ReadFrFile(const char * filename);
    7476   
  • trunk/SophyaPI/PI/pitherm.cc

    r2615 r3549  
    139139void PIThermometer::Draw(PIGraphicGen* g, int /*x0*/, int /*y0*/, int /*dx*/, int /*dy*/)
    140140{
     141  if (!IsVisible())  return;
    141142  double delta = (max_-min_);
    142143  if (delta < 1.e-39) delta = 1.e-39;
  • trunk/SophyaPI/PI/piwdggen.cc

    r3473 r3549  
    5757//--
    5858//++
    59 // void  PSPrint(PSFile *psf, int ofx=0, int ofy=0)
    60 //      Méthode virtuelle qui doit être redéfinie pour chacune des classes filles.
    61 //      produit une représentation graphique de l'objet en Postscript.
    6259// SetSize(int sx, int sy)
    6360//      Modifie la taille de l'objet.
     
    181178// int  UserFlag()
    182179//      Renvoie la valeur "int" user de l'objet.
     180//--
     181
     182//++
     183// Titre        Export postscript et format RGB
     184//--
     185//++
     186// void  PSPrint(PSFile *psf, int ofx=0, int ofy=0)
     187//      Méthode virtuelle qui doit être redéfinie pour chacune des classes filles.
     188//      produit une représentation graphique de l'objet en Postscript.
     189// void  ExportToRGB(PIPixRGBArray & rgba)
     190//      Méthode virtuelle qui doit être redéfinie pour chaque architecture.
     191//      Remplit un tableau PIPixRGBArray le contenu pixels du widget en couleurs RGB.
    183192//--
    184193
     
    309318}
    310319
     320/* --Methode-- */
     321void PIWdgGen::ExportToRGB(PIPixRGBArray & rgba)
     322{
     323return;
     324}
     325
    311326//++
    312327// Titre        Gestion des Draw/Event Handler
  • trunk/SophyaPI/PI/piwdggen.h

    r3473 r3549  
    1010#include "pimsghandler.h"
    1111#include "picolist.h"
     12#include "pipixutils.h"
    1213
    1314#include <string>
     
    107108  virtual bool           IfSensitive()=0;
    108109
     110//  Pour exporter le contenu d'un widget (dessin vectoriel) en postscript
    109111  virtual void           PSPrint(PSFile *psf, int ofx=0, int ofy=0,
    110112                                 double scale_x=1., double scale_y=1.);
     113// Pour exporter le tableau des pixels du widget en classe  PIPixRGBArray
     114// L'implementation par defaut ne fait rien
     115  virtual void           ExportToRGB(PIPixRGBArray & rgba);
    111116
    112117//  Gestion de copier-coller
  • trunk/SophyaPI/PI/piwdgx.cc

    r3215 r3549  
    831831}
    832832
     833
     834// Pour exporter le tableau des pixels du widget en classe  PIPixRGBArray
     835inline void _col2_fcol_(unsigned long & col, unsigned long & fcol)
     836{
     837  if (col > 0x00FFFFFF)  fcol = 0x01000000;
     838  else if  (col > 0x0000FFFF)  fcol = 0x000010000;
     839  else if (col > 0x000000FF) fcol = 0x00000100;
     840  else fcol = 1; 
     841}   
     842/* --Methode-- */
     843void PIWdgX::ExportToRGB(PIPixRGBArray & rgba)
     844{
     845Display* mdsp = PIXDisplay();
     846int scr = XDefaultScreen(mdsp);
     847int depth = DefaultDepth(mdsp,scr);
     848Window xw = XtWindow(XtWdg());
     849unsigned long plane_mask = ~0;  // tous les bits a 1
     850XImage * ximg = XGetImage(mdsp, xw, 0, 0, XSize(), YSize(), plane_mask, ZPixmap);
     851//DBG  cout << " Resultat XGetImage -> " << hex << ximg << dec << endl;
     852if (ximg == NULL)  return;     
     853                           
     854unsigned long red,green,blue;
     855unsigned long fred,fgreen,fblue;
     856XColor col;
     857Colormap  cmap = XDefaultColormap (mdsp, scr);
     858red = 0x000000FF;
     859green = 0x0000FF00;
     860blue = 0x00FF0000;
     861unsigned short maxrgb = ~0;
     862col.red = maxrgb;  col.green = col.blue = 0;
     863if (XAllocColor(mdsp, cmap, &col)) red = col.pixel;
     864col.green = maxrgb;  col.red = col.blue = 0;
     865if (XAllocColor(mdsp, cmap, &col)) green = col.pixel;     
     866col.blue = maxrgb;  col.red = col.green = 0;
     867if (XAllocColor(mdsp, cmap, &col)) blue = col.pixel;     
     868_col2_fcol_(red, fred);
     869_col2_fcol_(green, fgreen);
     870_col2_fcol_(blue, fblue);
     871rgba.SetSize(XSize(), YSize());
     872unsigned long pixel;
     873PIPixRGB rgb;
     874for(int j=0; j<YSize(); j++)
     875  for(int i=0; i<XSize(); i++) {
     876    pixel = XGetPixel(ximg, i, j);
     877    rgb.red = (pixel&red)/fred;
     878    rgb.green = (pixel&green)/fgreen;
     879    rgb.blue = (pixel&blue)/fblue;
     880    rgba(i,j) = rgb;
     881  }
     882  XDestroyImage(ximg);
     883  return; 
     884}
    833885
    834886
  • trunk/SophyaPI/PI/piwdgx.h

    r3473 r3549  
    6363  virtual void           SetUnSensitive();
    6464  virtual bool           IfSensitive();
     65
     66// Pour exporter le tableau des pixels du widget en classe  PIPixRGBArray
     67  virtual void           ExportToRGB(PIPixRGBArray & rgba);
    6568
    6669//  Gestion de copier-coller
Note: See TracChangeset for help on using the changeset viewer.