]> Creatis software - gdcm.git/blobdiff - src/gdcmHeader.cxx
add '\0' after ostringstream to avoid oddities on Solrais
[gdcm.git] / src / gdcmHeader.cxx
index 9cdc5beb8606f7a56c9e7a1e413d26064378a8ca..e9ae38fc4c71c315e2f68879429bb3a6fc330da7 100644 (file)
@@ -1,4 +1,4 @@
-// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.112 2003/11/10 09:21:40 jpr Exp $
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.117 2003/11/13 18:08:34 jpr Exp $
 
 #include "gdcmHeader.h"
 
@@ -38,7 +38,14 @@ void gdcmHeader::Initialise(void) {
  * @param   InFilename
  * @param   exception_on_error
  */
-gdcmHeader::gdcmHeader(const char *InFilename, bool exception_on_error) {
+gdcmHeader::gdcmHeader(const char *InFilename, 
+                       bool exception_on_error,
+                      bool  enable_sequences ) {
+   if (enable_sequences)
+      enableSequences = 1;
+   else
+      enableSequences = 0;
+   
    SetMaxSizeLoadElementValue(_MaxSizeLoadElementValue_);
    filename = InFilename;
    Initialise();
@@ -627,17 +634,23 @@ bool gdcmHeader::IsDicomV3(void) {
  *          applying this heuristic.
  */
 void gdcmHeader::FixFoundLength(gdcmElValue * ElVal, guint32 FoundLength) {
-   if ( FoundLength == 0xffffffff)
+
+   ElVal->SetReadLength(FoundLength); // will be updated only if a bug is found
+                    
+   if ( FoundLength == 0xffffffff) {  
       FoundLength = 0;
+   }
       
       // Sorry for the patch!  
       // XMedCom did the trick to read some nasty GE images ...
    else if (FoundLength == 13) {
       // The following 'if' will be removed when there is no more
       // images on Creatis HDs with a 13 length for Manufacturer...
-      if ( (ElVal->GetGroup() != 0x0008) || (ElVal->GetElement() != 0x0070)) {
+      if ( (ElVal->GetGroup() != 0x0008) &&  
+           ( (ElVal->GetElement() != 0x0070) || (ElVal->GetElement() != 0x0080) ) ) {
       // end of remove area
          FoundLength =10;
+        ElVal->SetReadLength(10); // a bug is to be fixed
       }
    } 
      // to fix some garbage 'Leonardo' Siemens images
@@ -645,12 +658,14 @@ void gdcmHeader::FixFoundLength(gdcmElValue * ElVal, guint32 FoundLength) {
    else if ( (ElVal->GetGroup() == 0x0009) 
        &&
        ( (ElVal->GetElement() == 0x1113) || (ElVal->GetElement() == 0x1114) ) ){
-        FoundLength =4; 
+        FoundLength =4;
+       ElVal->SetReadLength(4); // a bug is to be fixed 
    } 
      // end of fix
         
-    // to try to 'go inside' SeQuences (with length), and not to ship them        
+    // to try to 'go inside' SeQuences (with length), and not to skip them        
     else if ( ElVal->GetVR() == "SQ") { 
+       if (enableSequences)    // only if the user does want to !
          FoundLength =0;        
     } 
     
@@ -661,7 +676,7 @@ void gdcmHeader::FixFoundLength(gdcmElValue * ElVal, guint32 FoundLength) {
          FoundLength =0;            
     }
                  
-   ElVal->SetLength(FoundLength);
+   ElVal->SetUsableLength(FoundLength);
 }
 
 /**
@@ -744,7 +759,6 @@ void gdcmHeader::FixFoundLength(gdcmElValue * ElVal, guint32 FoundLength) {
             return;
          }
          FixFoundLength(ElVal, length32); 
-
          return;
       }
 
@@ -768,7 +782,7 @@ void gdcmHeader::FixFoundLength(gdcmElValue * ElVal, guint32 FoundLength) {
       //   appear when we find the first group with big endian encoding. This
       //   is easy to detect since the length of a "Group Length" tag (the
       //   ones with zero as element number) has to be of 4 (0x0004). When we
-      //   encouter 1024 (0x0400) chances are the encoding changed and we
+      //   encounter 1024 (0x0400) chances are the encoding changed and we
       //   found a group with big endian encoding.
       // We shall use this second strategy. In order to make sure that we
       // can interpret the presence of an apparently big endian encoded
@@ -821,6 +835,7 @@ void gdcmHeader::FixFoundLength(gdcmElValue * ElVal, guint32 FoundLength) {
    // not coexist in a Data Set and Data Sets nested within it".]
    // Length is on 4 bytes.
    FixFoundLength(ElVal, ReadInt32());
+   return;
 }
 
 /**
@@ -996,7 +1011,8 @@ void gdcmHeader::LoadElementValue(gdcmElValue * ElVal) {
                s << NewInt;
             }
          }
-      }                                        
+      }        
+      s << '\0'; // to avoid oddities on Solaris
       ElVal->SetValue(s.str());
       return;  
    }
@@ -1244,6 +1260,7 @@ gdcmElValue * gdcmHeader::ReadNextElement(void) {
    NewElVal = NewElValueByNumber(g, n);
    FindVR(NewElVal);
    FindLength(NewElVal);
+       
    if (errno == 1) {
       // Call it quits
       return (gdcmElValue *)0;
@@ -1768,14 +1785,14 @@ void gdcmHeader::LoadElements(void) {
    rewind(fp);
    
    // We don't use any longer the HashTable, since a lot a stuff is missing
-   // we SeQuences were encountered 
+   // when SeQuences were encountered 
    //  
    //TagElValueHT ht = PubElValSet.GetTagHt();
    //for (TagElValueHT::iterator tag = ht.begin(); tag != ht.end(); ++tag) {
    //     LoadElementValue(tag->second);
    //}
    
-     for (std::list<gdcmElValue*>::iterator i = GetListElem().begin();  
+     for (ListTag::iterator i = GetListElem().begin();  
           i != GetListElem().end();
           ++i){
         LoadElementValue(*i);   
@@ -2220,7 +2237,7 @@ int gdcmHeader::GetLUTNbits(void) {
   * @return Lookup Table RGBA
   */ 
   
-void * gdcmHeader::GetLUTRGBA(void) {
+unsigned char * gdcmHeader::GetLUTRGBA(void) {
 // Not so easy : see 
 // http://www.barre.nom.fr/medical/dicom2/limitations.html#Color%20Lookup%20Tables
 // and  OT-PAL-8-face.dcm
@@ -2230,9 +2247,7 @@ void * gdcmHeader::GetLUTRGBA(void) {
    if (gdcmHeader::GetPubElValByNumber(0x0028,0x0004) != "PALETTE COLOR ") {
        return NULL;
    }  
-   
-   void * LutR,*LutG,*LutB;
-   int l;
+
    int lengthR, debR, nbitsR;
    int lengthG, debG, nbitsG;
    int lengthB, debB, nbitsB;