Changeset 3545 in Sophya for trunk/SophyaPI


Ignore:
Timestamp:
Nov 17, 2008, 11:45:06 AM (17 years ago)
Author:
ansari
Message:

1/ Ajout table de couleur RGB32768 , et corrections/optimisation ds picmap.cc
2/ Ajout type LUT Exp (inverse de log) et correction/optimisation ds lut.cc
3/ Codage de lecture/ecriture sur fichier de PIPixRGBArray (pipixutils.cc)
4/ Correction et adaptation ds piimage.cc , picmapview.cc ...

Reza 17 Novembre 2008

Location:
trunk/SophyaPI/PI
Files:
11 edited

Legend:

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

    r3527 r3545  
    1212#include "lut.h"
    1313
    14 
     14//++
     15// Class        LUT
     16// Lib          PI
     17// include      lut.h
     18//
     19//      Classe Look-Up table : transformation de valeurs (intensite/RGB) en index de couleur
     20//--
     21//++
     22// Links        Voir aussi
     23// PIColorMap
     24// PIPixmap
     25// PIImage
     26//--
    1527/* --Methode-- */
    1628
     
    8092  {
    8193  int i;
    82   double dx;
    83   double dlx;
     94  double dx, dlx, fmx;
    8495  switch (typ)
    8596    {
     
    91102      break;
    92103    case kLutType_Log :
    93       dlx = log(max-min) / (double)nLevel;
     104      fmx = (max-min)/(exp(1.)-1.);
     105      dlx = 1./(double)nLevel;
    94106      for(i=0; i<nLevel; i++)
    95         bornes[i] = min+(double)exp((double)i*dlx);
     107        bornes[i] = min+((double)exp((double)i*dlx)-1.)*fmx;
     108      break;
     109    case kLutType_Exp :
     110      dlx = (exp(1.)-1.)/(double)nLevel;
     111      for(i=0; i<nLevel; i++)
     112        bornes[i] = min+(double)log(1.+(double)i*dlx)*(max-min);
    96113      break;
    97114    case kLutType_Sqrt :
     
    114131else  bornes[0] = 0.5*(min+max);
    115132// ComputeTable((ntable > nLevel) ? ntable : tablenbin);
    116 ComputeTable(0);
     133if (type != kLutType_RGB) ComputeTable(0);
    117134return;
    118135}
     
    131148
    132149/* --Methode-- */
    133 unsigned short LUT::Apply(double x)
     150unsigned short LUT::ApplyI(double x)
    134151{
    135152int i;
     
    154171void LUT::ComputeTable(int nt)
    155172{
    156 if (nt <= 0) nt = 16*(nLevel+2);
     173if (nt <= 0) {
     174  int fm = 16;
     175  if ((nLevel+2)>4096) fm = 1;
     176  else if ((nLevel+2)>2048) fm = 2;
     177  else if ((nLevel+2)>1024) fm = 4;
     178  else if ((nLevel+2)>512) fm = 8;
     179  nt = fm*(nLevel+2);
     180}
    157181else if (nt < (nLevel+2))  nt = (nLevel+2);
    158182tablenbin = nt;
     
    161185tablebinwidth = (Max()-Min())/(nt-2);
    162186double x = Min()+0.5*tablebinwidth;
    163 for(int i=0; i<nt-2; i++)  { table[i] = Apply(x); x += tablebinwidth; }
     187for(int i=0; i<nt-2; i++)  { table[i] = ApplyI(x); x += tablebinwidth; }
    164188}
  • trunk/SophyaPI/PI/lut.h

    r3527 r3545  
    1313
    1414// Type de lut possibles
    15 enum {kLutType_Lin=1, kLutType_Log=2, kLutType_Sqrt=3, kLutType_Square=4, kLutType_RGB=11 };
     15enum {kLutType_Lin=1, kLutType_Log=2, kLutType_Exp=3, kLutType_Sqrt=4, kLutType_Square=5, kLutType_RGB=11 };
    1616
    1717class LUT
     
    2424  void SetLut(double min, double max, int typ=kLutType_Lin);
    2525  void Print();
    26   unsigned short Apply(double x);
    27   unsigned short ApplyRGB(double x);
     26
     27  inline unsigned short Apply(double x)
     28    {
     29    if (type == kLutType_RGB) return ApplyRGB(x);
     30    else return ApplyI(x);     
     31    }
    2832
    2933  inline unsigned short ApplyFast(double x)
     
    4246protected:
    4347  void ComputeTable(int nt);
     48  unsigned short ApplyI(double x);
     49  unsigned short ApplyRGB(double x);
    4450  inline unsigned short AppFast(double x)
    4551    {
  • trunk/SophyaPI/PI/picmap.cc

    r3527 r3545  
    66#include "picmap.h"
    77#include <iostream>
     8
    89
    910//++
     
    2425//--
    2526
    26 #define  MXMAPIDS   33
     27#define  MXMAPIDS   34
    2728static   int    MapNCols[MXMAPIDS] = {
    2829  256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
    2930  256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
    3031  256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
    31   216, 512, 4096  };
     32  216, 512, 4096, 32768  };
    3233
    3334// Tables de couleurs :
     
    4142// 1 Standard PI , 512 couleurs RGB (8x8x8)
    4243// 1 Standard PI , 4096 couleurs RGB (16x16x16)
     44// 1 Standard PI , 32768 couleurs RGB (32x32x32)
    4345
    4446static   const char*  MapNoms[MXMAPIDS]  = {
     
    5153                      "MIDAS_Stairs9","MIDAS_StairCase","MIDAS_Color",
    5254                      "MIDAS_ManyCol","MIDAS_Idl14","MIDAS_Idl15",
    53                       "MultiCol16","MultiCol64","RGB216CM","RGB512CM","RGB4096CM"};
     55                      "MultiCol16","MultiCol64",
     56                      "RGB216CM","RGB512CM","RGB4096CM","RGB32768CM"};
    5457
    5558static   CMapId MapIds[MXMAPIDS] = {
     
    6265                      CMAP_MIDAS_Stairs9, CMAP_MIDAS_StairCase, CMAP_MIDAS_Color,
    6366                      CMAP_MIDAS_ManyCol, CMAP_MIDAS_Idl14, CMAP_MIDAS_Idl15,
    64                       CMAP_COL16, CMAP_COL64, CMAP_RGB216, CMAP_RGB512, CMAP_RGB4096, } ;
     67                      CMAP_COL16, CMAP_COL64,
     68                      CMAP_RGB216, CMAP_RGB512, CMAP_RGB4096, CMAP_RGB32768} ;
    6569
    6670static   int mColTNums[8192];   // Max 8192 tables differentes pour le moment 
     
    7579                                  NULL, NULL, NULL, NULL, NULL,
    7680                                  NULL, NULL, NULL, NULL, NULL,
    77                                   NULL, NULL, NULL, };
     81                                  NULL, NULL, NULL, NULL };
    7882
    7983int  PIColorMap::NumberStandardColorMaps()
     
    130134//|     CMAP_RGB512     :  512 couleurs, 8x8x8 couleurs en composantes RGB
    131135//|     CMAP_RGB4096    :  4096 couleurs, 16x16x16 couleurs en composantes RGB
     136//|     CMAP_RGB4096    :  32768 couleurs, 32x32x32 couleurs en composantes RGB
    132137
    133138//      Toutes les tables de couleurs standard possèdent 256 cellules de couleurs,
    134 //      contenant 16 ou 32 ou 128 (ou 216) couleurs distinctes, sauf CMAP_RGB512 et CMAP_RGB4096.
     139//      contenant 16 ou 32 ou 128 (ou 216) couleurs distinctes,
     140//      sauf CMAP_RGB512 , CMAP_RGB4096 et CMAP_RGB32768.
    135141//
    136142// PIColorMap(string const& nom, int nCol)
     
    153159
    154160   if (NMaxTableAuto == 0) { //  Il faut allouer les tables de depart
    155      if ( TotNbColors() > 4096 ) NMaxTableAuto = MXMAPIDS-1;
     161     if ( TotNbColors() >= 4096 ) NMaxTableAuto = MXMAPIDS-2;
     162     if ( TotNbColors() >= 65536 ) NMaxTableAuto = MXMAPIDS-1;
    156163     else NMaxTableAuto = 3;
    157164     //     for(k=0; k<NMaxTableAuto; k++)  {
     
    167174   for(kdx=0; kdx<MXMAPIDS; kdx++)  if (id == MapIds[kdx])  break;
    168175   if (kdx == MXMAPIDS)  { id = MapIds[0];  kdx = 0; }
    169    for(k=0; k<NMaxTableAuto; k++) {
     176   for(k=0; k<=NMaxTableAuto; k++) {
    170177     if ((MapIds[k] == id) && (mMaps[k] == NULL))  { //  Table pas encore alloue
    171178       mnom = MapNoms[k];
     
    185192       if ( mMaps[k] ) { 
    186193         mColTNums[mMaps[k]->mCTId] = 1;  // Je force a liberer les couleurs
    187          delete mMaps[k] ;
     194         delete mMaps[k] ;   mMaps[k] = NULL;
     195         mnom = MapNoms[k];
     196         cout << " PIColorMap::PIColorMap(CMapId id) Freeing colors for ColorMap "
     197              << mnom << " ... " << endl;
    188198       }
    189199       mnom = MapNoms[kdx];
     200       cout << " PIColorMap::PIColorMap(CMapId id) Allocating ColorMap "
     201             << mnom << " ... " << endl;
    190202       mMaps[k] = new PIColorMap(MapIds[kdx],  MapNCols[kdx], mnom);
    191203     }
     
    592604    case CMAP_RGB512 :
    593605    case CMAP_RGB4096 :
     606    case CMAP_RGB32768 :
    594607      {
    595608      int nlev = 8;
    596       if ( mType == CMAP_RGB4096)  nlev = 16;
     609      if (mType == CMAP_RGB4096)  nlev = 16;
     610      else if (mType == CMAP_RGB32768)  nlev = 32;
    597611      int drgb = 65535/(nlev-1);
    598612      i = 0;
  • trunk/SophyaPI/PI/picmap.h

    r3519 r3545  
    5252 CMAP_RGB216      = 993,        // 216 couleurs avec toutes les nuances RGB
    5353 CMAP_RGB512      = 994,        // 512 couleurs avec toutes les nuances RGB
    54  CMAP_RGB4096     = 995         // 4096 couleurs avec toutes les nuances RGB
     54 CMAP_RGB4096     = 995,        // 4096 couleurs avec toutes les nuances RGB
     55 CMAP_RGB32768    = 996         // 32768 couleurs avec toutes les nuances RGB
    5556 };
    5657
  • trunk/SophyaPI/PI/picmapview.cc

    r2652 r3545  
    7979  if ( cmap && (cmp->Type() == cmap->Type()) && (cmp->Type() != CMAP_OTHER)
    8080       && (cmp->IsColorIndexReversed() == cmap->IsColorIndexReversed())
    81        && (fabs(vmin-min) < 1.e-69)  && (fabs(vmax-max) > -1.e-69) )  return;
     81       && (fabs(vmin-min) < 1.e-69)  && (fabs(vmax-max) > -1.e-69) )  {
     82    if (refr)  Refresh();     
     83    return;
     84  }
    8285  if (cmap) delete cmap;
    8386  cmap = new PIColorMap(*cmp);
     
    9396       (cmap->IsColorIndexReversed() == revidx) &&
    9497       ((vmin-min) < 1.e-69) &&  ((vmin-min) > -1.e-69) &&
    95        ((vmax-max) < 1.e-69) &&  ((vmax-max) > -1.e-69) )  return;
     98       ((vmax-max) < 1.e-69) &&  ((vmax-max) > -1.e-69) )  {
     99    if (refr)  Refresh();     
     100    return;
     101  }
    96102  if (cmap) delete cmap;
    97103  cmap = new PIColorMap(cmapid);
     
    117123
    118124  int k;
     125  // On limite le nombre de carres de couleurs traces, si trop de couleur ...
     126  int dk = cmap->NCol()/128;
     127  if (dk<1) dk=1;
    119128  if (sx > sy) {    // horizontal
    120129    int xc, dx;
    121130    xc = 0;
    122     for(k=0; k<cmap->NCol(); k++) {
    123       dx = (sx-xc)/(cmap->NCol()-k);
     131    for(k=0; k<cmap->NCol(); k+=dk) {
     132      dx = dk*(sx-xc)/(cmap->NCol()-k);
    124133      g->SelForeground((*cmap), k);
    125134      g->DrawFBox(xc, 0, dx+1, sy);
     
    130139    int yc, dy;
    131140    yc = sy;
    132     for(k=0; k<cmap->NCol(); k++) {
    133       dy = yc/(cmap->NCol()-k);
     141    for(k=0; k<cmap->NCol(); k+=dk) {
     142      dy = dk*yc/(cmap->NCol()-k);
    134143      yc -= dy;
    135144      g->SelForeground((*cmap), k);
  • trunk/SophyaPI/PI/picmapx.cc

    r2615 r3545  
    187187  mColRGB = new PIColor[mNCol];
    188188  mNewCol = new bool[mNCol];
     189  /*   Remplace par memcpy pour performances, Reza, Nov 2008
    189190  for (int i=0; i<mNCol; i++) 
    190191    { mColors[i] = ((PIColorMapX *)x)->mColors[i];
     
    192193// C'est la table de couleur originale qui est responsable de liberer les couleurs - Reza 8/2/98
    193194    mNewCol[i] = false; } 
    194 }
     195  -> memcpy (Nov08) */
     196  memcpy(mColors, ((PIColorMapX *)x)->mColors, sizeof(PIXColor)*mNCol);
     197  memcpy(mColRGB, ((PIColorMapX *)x)->mColRGB, sizeof(PIColor)*mNCol);
     198// C'est la table de couleur originale qui est responsable de liberer les couleurs - Reza 8/2/98
     199  for (int i=0; i<mNCol; i++)   mNewCol[i] = false;
     200}
  • trunk/SophyaPI/PI/piimage.cc

    r3527 r3545  
    628628      if (opts.substr(4,3) == "lin")  typlut=kLutType_Lin;
    629629      else if (opts.substr(4,3) == "log")  typlut=kLutType_Log;
     630      else if (opts.substr(4,3) == "exp")  typlut=kLutType_Exp;
    630631      else if (opts.substr(4,4) == "sqrt")  typlut=kLutType_Sqrt;
    631632      else if (opts.substr(4,6) == "square")  typlut=kLutType_Square;
     
    724725{
    725726if (!cmp)  return;
     727int ncolold = 0;
     728if (cmap) ncolold = cmap->NCol();
     729bool fgapp = false;
     730if (refr && cmp->NCol() != ncolold) {
     731  fgapp = true;  refr = false;
     732}
    726733int cmapid = cmp->Type();
    727734if ( (cmapid == CMAP_GREY32) || (cmapid == CMAP_GREYINV32) ||
     
    732739if (refr) { xcurs =  ycurs = -1; }
    733740if (zow)  zow->SetColMap(cmp, refr);
    734 if (gvw)  gvw->SetColMap(cmp, refr);
     741if (gvw)  {
     742    if (cmap->NCol() != ncolold) {
     743    ComputeGloVPixmap();
     744    SetGloVPixmap();
     745  }
     746  else  gvw->SetColMap(cmp, refr);
     747}
    735748if (cmvw) cmvw->SetColMap(cmap, Lut()->Min(), Lut()->Max(), refr);
     749if (fgapp)  Apply();
    736750return;
    737751}
     
    740754void PIImage::SetColMapId(CMapId cmapid, bool revidx, bool refr)
    741755{
     756int ncolold = 0;
     757if (cmap) ncolold = cmap->NCol();
    742758if ( (cmapid == CMAP_GREY32) || (cmapid == CMAP_GREYINV32) ||
    743759     (cmapid == CMAP_GREY128) || (cmapid == CMAP_GREYINV128))  mdrw->GetGraphicAtt().SetColAtt(PI_Red);
    744760else mdrw->GetGraphicAtt().SetColAtt(PI_Turquoise);
    745761PIPixmap::SetColMapId(cmapid, revidx, false);
     762if (refr) { xcurs =  ycurs = -1; }
     763bool fgapp = false;
     764if (refr && cmap->NCol() != ncolold) {
     765  fgapp = true;  refr = false;
     766}
    746767if (lut) lut->SetNCol(GetColMap()->NCol());
    747768if (refr) Refresh();
    748769if (zow)  zow->SetColMapId(cmapid, revidx, refr);
    749 if (gvw)  gvw->SetColMapId(cmapid, revidx, refr);
     770if (gvw)  {
     771    if (cmap->NCol() != ncolold) {
     772    ComputeGloVPixmap();
     773    SetGloVPixmap();
     774  }
     775  else  gvw->SetColMapId(cmapid, revidx, refr);
     776}
    750777if (cmvw) cmvw->SetColMapId(cmapid, revidx, Lut()->Min(), Lut()->Max(), refr);
     778if (fgapp)  Apply();
    751779return;
    752780}
  • trunk/SophyaPI/PI/piimgtools.cc

    r3527 r3545  
    9999mOpt[0] = new PIOptMenu(this, "imglut-opt-1", 1.5*bsx, bsy, cpx, cpy);
    100100mOpt[0]->AppendItem("Linear", 1100);
    101 mOpt[0]->AppendItem("Log.", 1101);
    102 mOpt[0]->AppendItem("Sqrt", 1102);
    103 mOpt[0]->AppendItem("Square", 1103);
    104 mOpt[0]->AppendItem("RGB", 1104);
     101mOpt[0]->AppendItem("Log", 1101);
     102mOpt[0]->AppendItem("Exp", 1102);
     103mOpt[0]->AppendItem("Sqrt", 1103);
     104mOpt[0]->AppendItem("Square", 1104);
     105mOpt[0]->AppendItem("RGB", 1105);
    105106mOpt[0]->SetValue(1100);
    106107mOpt[0]->SetBinding(PIBK_elastic,PIBK_elastic, PIBK_elastic,PIBK_elastic);
     
    175176mCasc[1] = new PIMenu(mOptzc[0]->Menu(), "PIUniCol32");
    176177mCasc[2] = new PIMenu(mOptzc[0]->Menu(), "MIDAS-CMap");
    177 
    178 int nsct1,nsct2,nsct3,nsct4;
     178mCasc[3] = new PIMenu(mOptzc[0]->Menu(), "RGB-CMap");
     179
     180int nsct1,nsct2,nsct3,nsct4,nsct5;
    179181//  D'abord les tables standard de PI  32 couleurs
    180182nsct1 = 5;   // Les 5 premieres tables
     
    191193mOptzc[0]->AppendPDMenu(mCasc[1]);
    192194//  Apres les tables importees de MIDAS
    193 nsct4 = PIColorMap::NumberStandardColorMaps()-5; // Les reste jusqu'a l'avant derniere
     195nsct4 = PIColorMap::NumberStandardColorMaps()-6; // Les reste jusqu'a l'avant derniere
    194196for(kcc=nsct3; kcc<nsct4; kcc++)
    195197  mCasc[2]->AppendItem(PIColorMap::GetStandardColorMapName(kcc).c_str(), 201+kcc);
    196198mOptzc[0]->AppendPDMenu(mCasc[2]);
    197 // Les tables qui restent ( RGB218, Col16 , ... )
    198 for(kcc=nsct4; kcc<PIColorMap::NumberStandardColorMaps(); kcc++)
     199nsct5 = PIColorMap::NumberStandardColorMaps()-4; // Les reste jusqu'aux tables RGB
     200for(kcc=nsct4; kcc<nsct5; kcc++)
    199201  mOptzc[0]->AppendItem(PIColorMap::GetStandardColorMapName(kcc).c_str(), 201+kcc);
    200 // On ajoute un CheckItem pour inverser les index de table de couleur
     202// Les tables de couleur RGB  ( RGB216, RGB512 , ... )
     203for(kcc=nsct5; kcc<PIColorMap::NumberStandardColorMaps(); kcc++)
     204  mCasc[3]->AppendItem(PIColorMap::GetStandardColorMapName(kcc).c_str(), 201+kcc);
     205mOptzc[0]->AppendPDMenu(mCasc[3]);
     206  // On ajoute un CheckItem pour inverser les index de table de couleur
    201207mOptzc[0]->Menu()->AppendSeparator();
    202208mOptzc[0]->Menu()->AppendCheckItem("Reverse CMap", 299);
     
    311317for(i=0; i<3; i++)  delete mBut[i];
    312318delete mButR;
    313 for(i=0; i<2; i++)  delete mCasc[i];
     319for(i=0; i<4; i++)  delete mCasc[i];
    314320for(i=0; i<5; i++)  delete mButsz[i];
    315321for(i=0; i<3; i++)  delete mButcax[i];
     
    372378  if     ( (mpii->Lut())->Type() == kLutType_Lin )    mOpt[0]->SetValue(1100);
    373379  else if( (mpii->Lut())->Type() == kLutType_Log )    mOpt[0]->SetValue(1101);
    374   else if( (mpii->Lut())->Type() == kLutType_Sqrt )   mOpt[0]->SetValue(1102);
    375   else if( (mpii->Lut())->Type() == kLutType_Square ) mOpt[0]->SetValue(1103);
    376   else if( (mpii->Lut())->Type() == kLutType_RGB )    mOpt[0]->SetValue(1104);
     380  else if( (mpii->Lut())->Type() == kLutType_Exp )    mOpt[0]->SetValue(1102);
     381  else if( (mpii->Lut())->Type() == kLutType_Sqrt )   mOpt[0]->SetValue(1103);
     382  else if( (mpii->Lut())->Type() == kLutType_Square ) mOpt[0]->SetValue(1104);
     383  else if( (mpii->Lut())->Type() == kLutType_RGB )    mOpt[0]->SetValue(1105);
    377384  else                                                mOpt[0]->SetValue(1100);
    378385}
     
    390397double min, max, del;
    391398int lauto, typ;
    392 int typlut[5] = {kLutType_Lin, kLutType_Log, kLutType_Sqrt, kLutType_Square, kLutType_RGB } ;
     399int typlut[6] = {kLutType_Lin, kLutType_Log,  kLutType_Exp, kLutType_Sqrt, kLutType_Square, kLutType_RGB } ;
    393400AutoLutType alts[13] = { AutoLut_No,
    394401                         AutoLut_MeanSigma, AutoLut_MeanSigma, AutoLut_MeanSigma,
     
    448455    if ((lauto < 0) || (lauto > 12))  lauto = 12;
    449456    typ = mOpt[0]->GetValue() - 1100;
    450     if ( (typ < 0) || (typ > 4) )  typ = 0;
     457    if ( (typ < 0) || (typ > 5) )  typ = 0;
    451458    (PIImage::CurrentPIImage())->SetLut(alts[lauto], min, max, typlut[typ], nsas[lauto]);
    452459    if (msg == 2500) {
  • trunk/SophyaPI/PI/pipixmapx.cc

    r3519 r3545  
    88#include "pipixmapx.h"
    99#include <iostream>
     10
    1011using namespace std;
    1112
  • trunk/SophyaPI/PI/pipixutils.cc

    r3519 r3545  
    9292  sx_ = sy_ = 0;
    9393  rgbpix_ = NULL;
    94   // lecture fichier a faire   
     94  ReadFrFile(filename);         
    9595}
    9696
     
    100100}
    101101
    102 void PIPixRGBArray::SaveToFile(const char * filename)
     102int PIPixRGBArray::SaveToFile(const char * filename)
    103103{
    104   // ECRIRE fichier A FAIRE
    105   return;       
     104  FILE * fip = fopen(filename,"wb");
     105  if (fip == NULL) {
     106    cout << " PIPixRGBArray::SaveToFile()/Error opening file " << filename << endl;
     107    return 1;
     108  }
     109  char buff[48];
     110  for(int k=0; k<48; k++) buff[k] = '\0';
     111  sprintf(buff, "PI-RGB File Sx,Sy= %d %d", sx_, sy_);
     112  fwrite((void *)buff, 1, 48, fip);
     113  fwrite((void *)rgbpix_, sizeof(PIPixRGB), sx_*sy_, fip);
     114  fclose(fip);
     115  //  cout << " PIPixRGBArray::SaveToFile()*DBG* sizeof(PIPixRGB)=" << sizeof(PIPixRGB)
     116  //     << " sx*sy=" << sx_*sy_ << endl;
     117  return 0;     
    106118}
    107119
     120int PIPixRGBArray::ReadFrFile(const char * filename)
     121{
     122  if (rgbpix_) {
     123        delete[] rgbpix_;       
     124    sx_ = sy_ = 0;
     125    rgbpix_ = NULL;
     126  }
     127  FILE * fip = fopen(filename,"rb");
     128  if (fip == NULL) {
     129    cout << " PIPixRGBArray::ReadFrFile()/Error opening file " << filename << endl;
     130    return 1;
     131  }
     132  char buff[48];
     133  fread((void *)buff, 1, 48, fip);
     134  if (strncmp(buff, "PI-RGB File Sx,Sy=",18) != 0) {
     135    cout << " PIPixRGBArray::ReadFrFile()/Error wrong header - file=" << filename << endl;
     136    return 2;
     137  }
     138  sscanf(buff+18,"%d %d", &sx_, &sy_);
     139  size_t sz = sx_*sy_;
     140  if (sz>0) {
     141        rgbpix_ = new PIPixRGB[sz];
     142        fread((void *)rgbpix_, sizeof(PIPixRGB), sx_*sy_, fip);
     143  }
     144  else rgbpix_ = NULL; 
     145 
     146  fclose(fip);
     147  // cout << " PIPixRGBArray::ReadFrFile()*DBG* sizeof(PIPixRGB)=" << sizeof(PIPixRGB)
     148  //     << " Sx=" << sx_ << " Sy=" << sy_ << endl;
     149  return 0;       
     150}
    108151
  • trunk/SophyaPI/PI/pipixutils.h

    r3519 r3545  
    7070    { return rgbpix_[j*sx_+i]; }
    7171 
    72   void SaveToFile(const char * filename);
     72  int SaveToFile(const char * filename);
     73  int ReadFrFile(const char * filename);
    7374   
    7475protected:
Note: See TracChangeset for help on using the changeset viewer.