]> Creatis software - gdcm.git/commitdiff
ENH: /binary_write/ gdcm source. Now even on big endian we are writting little endian...
authormalaterre <malaterre>
Wed, 3 Nov 2004 20:52:12 +0000 (20:52 +0000)
committermalaterre <malaterre>
Wed, 3 Nov 2004 20:52:12 +0000 (20:52 +0000)
12 files changed:
ChangeLog
src/gdcmBinEntry.cxx
src/gdcmCommon.h
src/gdcmDefaultDicts.cxx.in
src/gdcmDicomDir.cxx
src/gdcmDocEntry.cxx
src/gdcmFile.cxx
src/gdcmSQItem.cxx
src/gdcmSeqEntry.cxx
src/gdcmUtil.cxx
src/gdcmUtil.h
src/gdcmValEntry.cxx

index 07c83360f82df77a0664d06460b665688fc070d2..58061aace582d61fa87baf32c94b6a0ec2363911 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2004-11-03 Mathieu Malaterre  <Mathieu.Malaterre@creatis.insa-lyon.fr>
+  * /binary_write/ gdcm source. Now even on big endian we are writting
+    little endian. This should -heopfully- fix some tests
+
 2004-11-03 Mathieu Malaterre  <Mathieu.Malaterre@creatis.insa-lyon.fr>
   * Now the dictionary is compiled into gdcm lib. This is a default 
     behavior, thus any dic file specified is picked before failback to 
index b560cc2cd0787d70b2c20f42c6172d6a94f0fd85..f6645e7b28f5edc9704b6abcb3d7fa964041cbd7 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmBinEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/22 03:05:40 $
-  Version:   $Revision: 1.34 $
+  Date:      $Date: 2004/11/03 20:52:12 $
+  Version:   $Revision: 1.35 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -111,6 +111,7 @@ void BinEntry::Write(std::ofstream* fp, FileType filetype)
    {
       // there is a 'non string' LUT, overlay, etc
       fp->write ( (char*)binArea, lgr ); // Elem value
+      //assert( strlen((char*)binArea) == lgr );
 
    }
    else
index e180d3cb3eb1f02b7387daadeef99ca8251905b0..5d1c9b102c9d0bc87ddee26f6cc8e954301983c3 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmCommon.h,v $
   Language:  C++
-  Date:      $Date: 2004/11/02 03:10:32 $
-  Version:   $Revision: 1.37 $
+  Date:      $Date: 2004/11/03 20:52:13 $
+  Version:   $Revision: 1.38 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -81,6 +81,7 @@ typedef  unsigned int   uint32_t;
 #endif
 
 #include <string>
+#include <cassert>
 
 namespace gdcm
 {
index 63db2001cc07e2fc3c301c9a6cc78774ed504edd..727be345d11c302182a8fa5ae868de5d45ca9925 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDefaultDicts.cxx.in,v $
   Language:  C++
-  Date:      $Date: 2004/11/03 19:35:49 $
-  Version:   $Revision: 1.2 $
+  Date:      $Date: 2004/11/03 20:52:13 $
+  Version:   $Revision: 1.3 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
index 5c264bf26b06875a1973b1948a5b7c49fa2941c8..b7f4cb00d04bfa18f3376856c1c2f893daaad918 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/25 04:47:43 $
-  Version:   $Revision: 1.76 $
+  Date:      $Date: 2004/11/03 20:52:13 $
+  Version:   $Revision: 1.77 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -340,6 +340,7 @@ void DicomDir::SetEndMethodArgDelete(Method* method)
  
 bool DicomDir::WriteDicomDir(std::string const& fileName) 
 {  
+   int i;
    uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff };
    uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
 
@@ -347,20 +348,23 @@ bool DicomDir::WriteDicomDir(std::string const& fileName)
                                          std::ios::out | std::ios::binary);
    if( !fp ) 
    {
-      printf("Failed to open(write) File [%s] \n", fileName.c_str());
+      dbg.Verbose(2, "Failed to open(write) File: ", fileName.c_str());
       return false;
    }
 
-   uint8_t filePreamble[128];
+   char filePreamble[128];
    memset(filePreamble, 0, 128);
-   fp->write((char*)filePreamble, 128);
-   fp->write("DICM",4);
+   fp->write(filePreamble, 128); //FIXME
+   binary_write( *fp, "DICM");
  
    DicomDirMeta *ptrMeta = GetDicomDirMeta();
    ptrMeta->Write(fp, ExplicitVR);
    
    // force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
-   fp->write((char*)&sq[0],8);
+   for(i=0;i<4;++i)
+   {
+      binary_write(*fp, sq[i]);
+   }
         
    for(ListDicomDirPatient::iterator cc  = Patients.begin();
                                      cc != Patients.end();
@@ -370,7 +374,10 @@ bool DicomDir::WriteDicomDir(std::string const& fileName)
    }
    
    // force writing Sequence Delimitation Item
-   fp->write((char*)&sqt[0],8);  // fffe e0dd ffff ffff 
+   for(i=0;i<4;++i)
+   {
+      binary_write(*fp, sqt[i]);  // fffe e0dd ffff ffff 
+   }
 
    fp->close();
    return true;
index dce3028c11a37db9e755f09601d39df20b7f836b..0777f253782b470407d8f10d41fad627c03d9926 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/22 03:05:41 $
-  Version:   $Revision: 1.28 $
+  Date:      $Date: 2004/11/03 20:52:13 $
+  Version:   $Revision: 1.29 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -137,9 +137,9 @@ void DocEntry::Write(std::ofstream* fp, FileType filetype)
    //
    // ----------- Writes the common part
    //
-   fp->write ((char*) &group,(size_t)2 );  //group
-   fp->write ( (char*)&el,   (size_t)2 );  //element
-      
+   binary_write( *fp, group);  //group
+   binary_write( *fp, el);  //element
+
    if ( filetype == ExplicitVR )
    {
       // Special case of delimiters:
@@ -155,8 +155,8 @@ void DocEntry::Write(std::ofstream* fp, FileType filetype)
 
          // TODO : verify if the Sequence Delimitor Item was forced during Parsing 
 
-         int ff = 0xffffffff;
-         fp->write ((char*)&ff,(size_t)4 );
+         uint32_t ff = 0xffffffff;
+         binary_write(*fp, ff);
          return;
       }
 
@@ -167,32 +167,32 @@ void DocEntry::Write(std::ofstream* fp, FileType filetype)
       {
          // Unknown was 'written'
          // deal with Little Endian            
-         fp->write ( (char*)&shortLgr,(size_t)2 );
-         fp->write ( (char*)&z,       (size_t)2 );
+         binary_write(*fp, shortLgr);
+         binary_write(*fp, z);
       }
       else
       {
-         fp->write (vr.c_str(),(size_t)2 ); 
-
+         binary_write(*fp, vr);
+         assert( vr.size() == 2 );
                   
          if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") )
          {
-            fp->write ( (char*)&z,  (size_t)2 );
+            binary_write(*fp, z);
             if (vr == "SQ")
             {
                // we set SQ length to ffffffff
                // and  we shall write a Sequence Delimitor Item 
                // at the end of the Sequence! 
-               fp->write ( (char*)&ffff,(size_t)4 );
+               binary_write(*fp, ffff);
             }
             else
             {
-               fp->write ( (char*)&lgr,(size_t)4 );
+               binary_write(*fp, lgr);
             }
          }
          else
          {
-            fp->write ( (char*)&shortLgr,(size_t)2 );
+            binary_write(*fp, shortLgr);
          }
       }
    } 
@@ -200,11 +200,11 @@ void DocEntry::Write(std::ofstream* fp, FileType filetype)
    { 
       if (vr == "SQ")
       {
-         fp->write ( (char*)&ffff,(size_t)4 );
+         binary_write(*fp, ffff);
       }
       else
       {
-         fp->write ( (char*)&lgr,(size_t)4 );
+         binary_write(*fp, lgr);
       }
    }
 }
index f044feb11eb06bf4ffbd20d45c59ca749f2cb6af..0b9fe2dbf1c1c816259700a2c3834eba619a9217 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/28 03:10:58 $
-  Version:   $Revision: 1.150 $
+  Date:      $Date: 2004/11/03 20:52:13 $
+  Version:   $Revision: 1.151 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -558,7 +558,7 @@ bool File::WriteRawData(std::string const & fileName)
   std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary );
    if (!fp1)
    {
-      printf("Fail to open (write) file [%s] \n", fileName.c_str());
+      dbg.Verbose(2, "Fail to open (write) file:", fileName.c_str());
       return false;
    }
    fp1.write((char*)Pixel_Data, ImageDataSize);
@@ -634,16 +634,16 @@ bool File::WriteBase (std::string const & fileName, FileType type)
                               std::ios::out | std::ios::binary);
    if (fp1 == NULL)
    {
-      printf("Failed to open (write) File [%s] \n", fileName.c_str());
+      dbg.Verbose(2, "Failed to open (write) File: " , fileName.c_str());
       return false;
    }
 
    if ( type == ImplicitVR || type == ExplicitVR )
    {
       // writing Dicom File Preamble
-      uint8_t filePreamble[128];
+      char filePreamble[128];
       memset(filePreamble, 0, 128);
-      fp1->write((char*)filePreamble, 128);
+      fp1->write(filePreamble, 128);
       fp1->write("DICM", 4);
    }
 
index 329a5a6dd95c0adc1638ef27ae0ea87ed4f873fe..332996971c115d5c79775eaa0b373cc7a3e02d11 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSQItem.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/28 03:10:58 $
-  Version:   $Revision: 1.33 $
+  Date:      $Date: 2004/11/03 20:52:13 $
+  Version:   $Revision: 1.34 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -98,12 +98,16 @@ SQItem::~SQItem()
  */
 void SQItem::Write(std::ofstream* fp, FileType filetype)
 {
+   int i;
    uint16_t item[4] = { 0xfffe, 0xe000, 0xffff, 0xffff };
    uint16_t itemt[4]= { 0xfffe, 0xe00d, 0xffff, 0xffff };
 
     //we force the writting of an 'Item' Start Element
     // because we want to write the Item as a 'no Length' item
-   fp->write((char*)&item[0],8);  // fffe e000 ffff ffff 
+   for(i=0;i<4;++i)
+   {
+      binary_write( *fp, item[i]);  // fffe e000 ffff ffff 
+   }
      
    for (ListDocEntry::iterator i = DocEntries.begin();  
                               i != DocEntries.end();
@@ -129,8 +133,11 @@ void SQItem::Write(std::ofstream* fp, FileType filetype)
       
     //we force the writting of an 'Item Delimitation' item
     // because we wrote the Item as a 'no Length' item
-   fp->write((char*)&itemt[0],8);  // fffe e000 ffff ffff 
-
+   for(i=0;i<4;++i)
+   {
+      binary_write( *fp, itemt[i]);  // fffe e000 ffff ffff 
+   }
 }
 
 //-----------------------------------------------------------------------------
index 88e79a62d7d0b24fe71914870daee30b8b33bdc4..b5d452c773c86bdd6801e15fd8a91c90bcd9cc83 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSeqEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/25 03:03:45 $
-  Version:   $Revision: 1.33 $
+  Date:      $Date: 2004/11/03 20:52:13 $
+  Version:   $Revision: 1.34 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -138,9 +138,9 @@ void SeqEntry::Write(std::ofstream* fp, FileType filetype)
    
    // we force the writting of a Sequence Delimitation item
    // because we wrote the Sequence as a 'no Length' sequence
-   fp->write ( (char*)&seq_term_gr,(size_t)2 );
-   fp->write ( (char*)&seq_term_el,(size_t)2 );
-   fp->write ( (char*)&seq_term_lg,(size_t)4 );
+   binary_write(*fp, seq_term_gr);
+   binary_write(*fp, seq_term_el);
+   binary_write(*fp, seq_term_lg);
 }
 
 //-----------------------------------------------------------------------------
index 889ece2064d22206fc35856c25f818fdfc714f56..f8dbe313c41eecaebda4f29267566010d037037e 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmUtil.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/28 23:10:25 $
-  Version:   $Revision: 1.58 $
+  Date:      $Date: 2004/11/03 20:52:13 $
+  Version:   $Revision: 1.59 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -225,6 +225,11 @@ std::ostream& binary_write(std::ostream& os, const char* val)
     return os.write(val, strlen(val));
 }
 
+std::ostream& binary_write(std::ostream& os, std::string const & val)
+{
+    return os.write(val.c_str(), val.size());
+}
+
 
 } // end namespace gdcm
 
index 6668b8035d38ec7d36fde1790a1791e5ecb4c696..0d3334fec9f1646a5e19f26b7fcf2e1647507045 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmUtil.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/27 22:58:06 $
-  Version:   $Revision: 1.38 $
+  Date:      $Date: 2004/11/03 20:52:13 $
+  Version:   $Revision: 1.39 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -48,7 +48,14 @@ public:
    static std::string NormalizePath(std::string const & name);
    static std::string GetPath(std::string const &fullName);
    static std::string GetName(std::string const &fullName);
+
 };
+   template <class T>
+   std::ostream& binary_write(std::ostream& os, const T& val);
+   std::ostream& binary_write(std::ostream& os, const uint16_t& val);
+   std::ostream& binary_write(std::ostream& os, const uint32_t& val);
+   std::ostream& binary_write(std::ostream& os, const char* val);
+   std::ostream& binary_write(std::ostream& os, std::string const & val);
 } // end namespace gdcm
 //-----------------------------------------------------------------------------
 #endif
index 9f337bdea15fef6f9fd84aaef8bdbbfaeb3872ce..6293e5dc73b0740748ddeac3574a5a71fe95a1eb 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmValEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/22 03:05:42 $
-  Version:   $Revision: 1.31 $
+  Date:      $Date: 2004/11/03 20:52:13 $
+  Version:   $Revision: 1.32 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -200,8 +200,7 @@ void ValEntry::Write(std::ofstream* fp, FileType filetype)
       for (unsigned int i=0; i<tokens.size();i++)
       {
          uint16_t val_uint16 = atoi(tokens[i].c_str());
-         void* ptr = &val_uint16;
-         fp->write ( (char*)ptr,(size_t)2);
+         binary_write( *fp, val_uint16);
       }
       tokens.clear();
       return;
@@ -218,14 +217,15 @@ void ValEntry::Write(std::ofstream* fp, FileType filetype)
       for (unsigned int i=0; i<tokens.size();i++)
       {
          uint32_t val_uint32 = atoi(tokens[i].c_str());
-         void* ptr = &val_uint32;
-         fp->write ( (char*)ptr,(size_t)4 );
+         binary_write( *fp, val_uint32);
       }
       tokens.clear();
       return;
    } 
           
    fp->write (GetValue().c_str(), (size_t)lgr ); // Elem value
+//   assert( lgr == GetValue().size() ); // FIXME ?????
+//   dbg.Assert(2, lgr == strlen(GetValue().c_str()), "Should be equal" );
 } 
 
 //-----------------------------------------------------------------------------