]> Creatis software - gdcm.git/blobdiff - src/gdcmHeader.cxx
Odd length strings are padded with '\0' (not with spaces, to remain compliant
[gdcm.git] / src / gdcmHeader.cxx
index c035d69fc55ec87996c7d2d72df411c7edd11825..de05007f99c906094f1a46418de49a34091d34ce 100644 (file)
@@ -1,4 +1,4 @@
-// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.93 2003/10/03 07:46:06 jpr Exp $
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.96 2003/10/09 13:22:54 jpr Exp $
 
 #include "gdcmHeader.h"
 
@@ -491,6 +491,8 @@ bool gdcmHeader::IsJPEGLossless(void) {
    const char * Transfert = Element->GetValue().c_str();
    if ( memcmp(Transfert+strlen(Transfert)-2 ,"70",2)==0) return true;
    if ( memcmp(Transfert+strlen(Transfert)-2 ,"55",2)==0) return true;
+   if (Element->GetValue() == "1.2.840.10008.1.2.4.57") return true;
+
    return false;
 }
 
@@ -610,6 +612,15 @@ bool gdcmHeader::IsDicomV3(void) {
 void gdcmHeader::FixFoundLength(gdcmElValue * ElVal, guint32 FoundLength) {
    if ( FoundLength == 0xffffffff)
       FoundLength = 0;
+      // Sorry for the patch!  
+      // XMedCom did the trick to read some nasty GE images ...
+    if (FoundLength == 13)
+      // The following 'if' will be removed when there is no more
+      // images on Creatis HD with a 13 length for Manufacturer...
+      if ( (ElVal->GetGroup() != 0x0008) || (ElVal->GetElem() )
+      // end of remove area
+         FoundLength =10;
+
    ElVal->SetLength(FoundLength);
 }
 
@@ -692,6 +703,7 @@ void gdcmHeader::FixFoundLength(gdcmElValue * ElVal, guint32 FoundLength) {
          fseek(fp, 2L, SEEK_CUR);
 
          guint32 length32 = ReadInt32();
+
          if ( (vr == "OB") && (length32 == 0xffffffff) ) {
             ElVal->SetLength(FindLengthOB());
             return;
@@ -756,9 +768,12 @@ void gdcmHeader::FixFoundLength(gdcmElValue * ElVal, guint32 FoundLength) {
       // Heuristic: well some files are really ill-formed.
       if ( length16 == 0xffff) {
          length16 = 0;
-         dbg.Verbose(0, "gdcmHeader::FindLength",
-                     "Erroneous element length fixed.");
+         //dbg.Verbose(0, "gdcmHeader::FindLength",
+         //            "Erroneous element length fixed.");
+         // Actually, length= 0xffff means that we deal with
+         // Unknown Sequence Length 
       }
+
       FixFoundLength(ElVal, (guint32)length16);
       return;
    }
@@ -1090,9 +1105,12 @@ int gdcmHeader::ReplaceOrCreateByNumber(std::string Value,
        // on l'ajoute au ElValSet
        // on affecte une valeur a cette ElValue a l'interieur du ElValSet
        // --> devrait pouvoir etre fait + simplement ???
-       
-   gdcmElValue* nvElValue=NewElValueByNumber(Group, Elem);
-   PubElValSet.Add(nvElValue); 
+   if (CheckIfExistByNumber(Group, Elem) == 0) {
+      gdcmElValue* a =NewElValueByNumber(Group, Elem);
+      if (a == NULL) 
+         return 0;
+      PubElValSet.Add(a);
+   }   
    PubElValSet.SetElValueByNumber(Value, Group, Elem);
    return(1);
 }   
@@ -1741,6 +1759,33 @@ void gdcmHeader::PrintPubDict(std::ostream & os) {
   * @return
   */ 
 int gdcmHeader::Write(FILE * fp, FileType type) {
+
+
+   // TODO : move the following lines (and a lot of others)
+   // to a future function CheckAndCorrectHeader
+
+   if (type == ImplicitVR) {
+      std::string implicitVRTransfertSyntax = "1.2.840.10008.1.2";
+      ReplaceOrCreateByNumber(implicitVRTransfertSyntax,0x0002, 0x0010);
+      
+      //FIXME Refer to standards on page 21, chapter 6.2 "Value representation":
+      //      values with a VR of UI shall be padded with a single trailing null
+      //      Dans le cas suivant on doit pader manuellement avec un 0
+      
+      PubElValSet.SetElValueLengthByNumber(18, 0x0002, 0x0010);
+   } 
+
+   if (type == ExplicitVR) {
+      std::string explicitVRTransfertSyntax = "1.2.840.10008.1.2.1";
+      ReplaceOrCreateByNumber(explicitVRTransfertSyntax,0x0002, 0x0010);
+      
+      //FIXME Refer to standards on page 21, chapter 6.2 "Value representation":
+      //      values with a VR of UI shall be padded with a single trailing null
+      //      Dans le cas suivant on doit pader manuellement avec un 0
+      
+      PubElValSet.SetElValueLengthByNumber(20, 0x0002, 0x0010);
+   }
+
    return PubElValSet.Write(fp, type);
 }