]> Creatis software - gdcm.git/blobdiff - src/gdcmFile.cxx
BUG: In c++ you are never garantee your var is initialized to 0
[gdcm.git] / src / gdcmFile.cxx
index 064eb84a6d4b23a92dcb301db86e3caa80d929c0..94f5ca5b22b4895807937ffae513695655a7fc4c 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/02/07 12:54:00 $
-  Version:   $Revision: 1.216 $
+  Date:      $Date: 2005/02/10 20:53:23 $
+  Version:   $Revision: 1.223 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -367,7 +367,8 @@ int File::GetZSize()
   */
 float File::GetXSpacing()
 {
-   float xspacing, yspacing;
+   float xspacing = 1.0;
+   float yspacing = 1.0;
    const std::string &strSpacing = GetEntryValue(0x0028,0x0030);
 
    if( strSpacing == GDCM_UNFOUND )
@@ -1159,42 +1160,40 @@ void File::AnonymizeNoLoad()
 {
    std::fstream *fp = new std::fstream(Filename.c_str(), 
                               std::ios::in | std::ios::out | std::ios::binary);
    // TODO : FIXME
    // how to white out disk space if longer than 50 ?
-   char spaces[50] = "                                               ";
+   
    
    gdcm::DocEntry *d;
    uint32_t offset;
    uint32_t lgth;
-   uint32_t lgtToWrite;
+   uint32_t valLgth = 0;
+   std::string *spaces;
    for (ListElements::iterator it = AnonymizeList.begin();  
                                it != AnonymizeList.end();
                              ++it)
-   {  
+   { 
       d = GetDocEntry( (*it).Group, (*it).Elem);
 
+      if ( d == NULL)
+         continue;
+
       if ( dynamic_cast<BinEntry *>(d)
         || dynamic_cast<SeqEntry *>(d) )
          continue;
 
       offset = d->GetOffset();
       lgth =   d->GetLength();
-      fp->seekp( offset, std::ios::beg );
-
-      if ( (*it).Value == "" )
+      if (valLgth < lgth)
       {
-         lgtToWrite = lgth > 50 ? 50 : lgth;
-         fp->write( spaces, lgtToWrite );
-      }
-      else
-      {
-         // TODO : FIXME
-         // how to white out disk space if longer than 50 ?
-         (*it).Value = (*it).Value + spaces;
-         lgtToWrite = lgth > (*it).Value.length() ? (*it).Value.length() : lgth;
-         fp->write( (char *)(*it).Value.c_str(), lgtToWrite );
-
+         spaces = new std::string( lgth-valLgth, ' ');
+         (*it).Value = (*it).Value + *spaces;
+         delete spaces;
       }
+      fp->seekp( offset, std::ios::beg );
+      fp->write( (*it).Value.c_str(), lgth );
+     
    }
    fp->close();
    delete fp;
@@ -1206,7 +1205,7 @@ void File::AnonymizeNoLoad()
  */
 bool File::AnonymizeFile()
 {
-   // If Anonymisation list is empty, let's perform some basic anonymisation
+   // If Anonymisation list is empty, let's perform some basic anonymization
    if ( AnonymizeList.begin() == AnonymizeList.end() )
    {
       // If exist, replace by spaces
@@ -1238,6 +1237,9 @@ bool File::AnonymizeFile()
       {  
          d = GetDocEntry( (*it).Group, (*it).Elem);
 
+         if ( d == NULL)
+            continue;
+
          if ( dynamic_cast<BinEntry *>(d)
            || dynamic_cast<SeqEntry *>(d) )
             continue;
@@ -1385,40 +1387,8 @@ bool File::Write(std::string fileName, FileType filetype)
       }
    }
 
-
-#ifdef GDCM_WORDS_BIGENDIAN
-   // Super Super hack that will make gdcm a BOMB ! but should
-   // Fix temporarily the dashboard
-   BinEntry *b = GetBinEntry(GrPixel,NumPixel);
-   if ( GetPixelSize() ==  16 )
-   {
-      uint16_t *im16 = (uint16_t *)b->GetBinArea();
-      int lgth = b->GetLength();
-      for( int i = 0; i < lgth / 2; i++ )
-      {
-         im16[i]= (im16[i] >> 8) | (im16[i] << 8 );
-      }
-   }
-#endif //GDCM_WORDS_BIGENDIAN
-
-
    Document::WriteContent(fp, filetype);
 
-
-#ifdef GDCM_WORDS_BIGENDIAN
-   // Flip back the pixel ... I told you this is a hack
-   if ( GetPixelSize() ==  16 )
-   {
-      uint16_t *im16 = (uint16_t*)b->GetBinArea();
-      int lgth = b->GetLength();
-      for( int i = 0; i < lgth / 2; i++ )
-      {
-         im16[i]= (im16[i] >> 8) | (im16[i] << 8 );
-      }
-   }
-#endif //GDCM_WORDS_BIGENDIAN
-
-
    fp->close();
    delete fp;