]> Creatis software - gdcm.git/blobdiff - src/gdcmParser.cxx
* Bug fix on field having a VR = 'UI'. Assume that is a string field
[gdcm.git] / src / gdcmParser.cxx
index 054604313d3c2c81bdb39af6b02a91b72f8e1534..ad61419132e4bc03917241f98abd6e0d7defe346 100644 (file)
 #endif
 #  include <iomanip>
 
+#define UI1_2_840_10008_1_2      "1.2.840.10008.1.2"
+#define UI1_2_840_10008_1_2_1    "1.2.840.10008.1.2.1"
+#define UI1_2_840_10008_1_2_2    "1.2.840.10008.1.2.2"
+#define UI1_2_840_10008_1_2_1_99 "1.2.840.10008.1.2.1.99"
+
 //-----------------------------------------------------------------------------
 // Refer to gdcmParser::CheckSwap()
 const unsigned int gdcmParser::HEADER_LENGTH_TO_READ = 256;
@@ -182,21 +187,13 @@ bool gdcmParser::SetShaDict(DictKey dictName)
  */
 bool gdcmParser::IsReadable(void) 
 {
-   std::string res = GetEntryByNumber(0x0028, 0x0005);
-   if ( res != GDCM_UNFOUND && atoi(res.c_str()) > 4 ) 
-   {
-      return false; // Image Dimensions
-   }
+   if(filetype==Unknown)
+      return(false);
 
-   if ( !GetHeaderEntryByNumber(0x0028, 0x0100) )
-      return false; // "Bits Allocated"
-   if ( !GetHeaderEntryByNumber(0x0028, 0x0101) )
-      return false; // "Bits Stored"
-   if ( !GetHeaderEntryByNumber(0x0028, 0x0102) )
-      return false; // "High Bit"
-   if ( !GetHeaderEntryByNumber(0x0028, 0x0103) )
-      return false; // "Pixel Representation"
-   return true;
+   if(listEntries.size()<=0)
+      return(false);
+
+   return(true);
 }
 
 /**
@@ -214,7 +211,7 @@ bool gdcmParser::IsImplicitVRLittleEndianTransferSyntax(void)
    LoadHeaderEntrySafe(Element);
 
    std::string Transfer = Element->GetValue();
-   if ( Transfer == "1.2.840.10008.1.2" )
+   if ( Transfer == UI1_2_840_10008_1_2 )
       return true;
    return false;
 }
@@ -234,7 +231,7 @@ bool gdcmParser::IsExplicitVRLittleEndianTransferSyntax(void)
    LoadHeaderEntrySafe(Element);
 
    std::string Transfer = Element->GetValue();
-   if ( Transfer == "1.2.840.10008.1.2.1" )
+   if ( Transfer == UI1_2_840_10008_1_2_1 )
       return true;
    return false;
 }
@@ -254,7 +251,7 @@ bool gdcmParser::IsDeflatedExplicitVRLittleEndianTransferSyntax(void)
    LoadHeaderEntrySafe(Element);
 
    std::string Transfer = Element->GetValue();
-   if ( Transfer == "1.2.840.10008.1.2.1.99" )
+   if ( Transfer == UI1_2_840_10008_1_2_1_99 )
       return true;
    return false;
 }
@@ -274,7 +271,7 @@ bool gdcmParser::IsExplicitVRBigEndianTransferSyntax(void)
    LoadHeaderEntrySafe(Element);
 
    std::string Transfer = Element->GetValue();
-   if ( Transfer == "1.2.840.10008.1.2.2" )  //1.2.2 ??? A verifier !
+   if ( Transfer == UI1_2_840_10008_1_2_2 )  //1.2.2 ??? A verifier !
       return true;
    return false;
 }
@@ -375,7 +372,7 @@ bool gdcmParser::Write(FILE *fp, FileType type)
 
    if (type == ImplicitVR) 
    {
-      std::string implicitVRTransfertSyntax = "1.2.840.10008.1.2";
+      std::string implicitVRTransfertSyntax = UI1_2_840_10008_1_2;
       ReplaceOrCreateByNumber(implicitVRTransfertSyntax,0x0002, 0x0010);
       
       //FIXME Refer to standards on page 21, chapter 6.2 "Value representation":
@@ -387,7 +384,7 @@ bool gdcmParser::Write(FILE *fp, FileType type)
 
    if (type == ExplicitVR) 
    {
-      std::string explicitVRTransfertSyntax = "1.2.840.10008.1.2.1";
+      std::string explicitVRTransfertSyntax = UI1_2_840_10008_1_2_1;
       ReplaceOrCreateByNumber(explicitVRTransfertSyntax,0x0002, 0x0010);
       
       //FIXME Refer to standards on page 21, chapter 6.2 "Value representation":
@@ -782,6 +779,7 @@ void gdcmParser::UpdateShaEntries(void)
       else
          vr=(*it)->GetVR();
 
+      (*it)->SetValue(GetHeaderEntryUnvalue(*it));
       if(entry)
       {
          // Set the new entry and the new value
@@ -793,7 +791,6 @@ void gdcmParser::UpdateShaEntries(void)
       else
       {
          // Remove precedent value transformation
-         (*it)->SetValue(GetHeaderEntryUnvalue(*it));
          (*it)->SetDictEntry(NewVirtualDictEntry((*it)->GetGroup(),(*it)->GetElement(),vr));
       }
    }
@@ -1312,24 +1309,19 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry)
    }
    
    // We need an additional byte for storing \0 that is not on disk
-   char* NewValue = (char*)malloc(length+1);
-   if( !NewValue) 
-   {
-      dbg.Verbose(1, "LoadElementValue: Failed to allocate NewValue");
-      return;
-   }
-   NewValue[length]= 0;
-   
-   item_read = fread(NewValue, (size_t)length, (size_t)1, fp);
+   std::string NewValue(length,0);
+   item_read = fread(&(NewValue[0]), (size_t)length, (size_t)1, fp);
    if ( item_read != 1 ) 
    {
-      free(NewValue);
       dbg.Verbose(1, "gdcmParser::LoadElementValue","unread element value");
       Entry->SetValue("gdcm::UnRead");
       return;
    }
-   Entry->SetValue(NewValue);
-   free(NewValue);
+
+   if( (vr == "UI") ) // Because of correspondance with the VR dic
+      Entry->SetValue(NewValue.c_str());
+   else
+      Entry->SetValue(NewValue);
 }
 
 /**
@@ -1612,7 +1604,8 @@ std::string gdcmParser::GetHeaderEntryValue(gdcmHeaderEntry *Entry)
          {
             if(i!=0)
                s << '\\';
-            NewInt32=(val[4*i+0]&0xFF)+((val[4*i+1]&0xFF)<<8)+((val[4*i+2]&0xFF)<<16)+((val[4*i+3]&0xFF)<<24);
+            NewInt32= (val[4*i+0]&0xFF)+((val[4*i+1]&0xFF)<<8)+
+                     ((val[4*i+2]&0xFF)<<16)+((val[4*i+3]&0xFF)<<24);
             NewInt32=SwapLong(NewInt32);
             s << NewInt32;
          }
@@ -1643,7 +1636,6 @@ std::string gdcmParser::GetHeaderEntryUnvalue(gdcmHeaderEntry *Entry)
       std::string vr=Entry->GetVR();
       std::ostringstream s;
       std::vector<std::string> tokens;
-      unsigned char *ptr;
 
       if (vr == "US" || vr == "SS") 
       {