]> Creatis software - gdcm.git/commitdiff
Odd length strings are padded with '\0' (not with spaces, to remain compliant
authorjpr <jpr>
Thu, 9 Oct 2003 13:22:54 +0000 (13:22 +0000)
committerjpr <jpr>
Thu, 9 Oct 2003 13:22:54 +0000 (13:22 +0000)
with already defined strings, like Transfert Syntax UID and others)

src/gdcmElValSet.cxx
src/gdcmElValue.h
src/gdcmHeader.cxx

index a2781df6249b882a6e15610bb07a321f66b37cf5..91045a055093f03dfd8fddcedd534fef3ca0dfb2 100644 (file)
@@ -167,7 +167,13 @@ int gdcmElValSet::SetElValueByNumber(std::string content,
    TagKey key = gdcmDictEntry::TranslateToKey(group, element);
    if ( ! tagHt.count(key))
       return 0;
-   tagHt[key]->SetValue(content);      
+   int l = content.length();
+   if(l%2) {  // Odd length are padded with a space (020H).
+      l++;
+      content = content + '\0';
+   }
+   tagHt[key]->SetValue(content);
+
    std::string vr = tagHt[key]->GetVR();
    guint32 lgr;
 
@@ -176,8 +182,11 @@ int gdcmElValSet::SetElValueByNumber(std::string content,
    else if( (vr == "UL") || (vr == "SL") )
       lgr = 4;
    else
-      lgr = content.length();     
+      lgr = l;    
    tagHt[key]->SetLength(lgr); 
+
+       
+
    return 1;
 }
 
@@ -191,7 +200,16 @@ int gdcmElValSet::SetElValueByNumber(std::string content,
 int gdcmElValSet::SetElValueByName(std::string content, std::string TagName) {
    if ( ! NameHt.count(TagName))
       return 0;
+   int l = content.length();
+   if(l%2) {  // Odd length are padded with a space (020H).
+      l++;
+      // Well. I know that '/0' is NOT a space
+      // but it doesn't work with a space. 
+      // Use hexedit and see 0002|0010 value (Transfer Syntax UID)
+      content = content + '\0';
+   }
    NameHt[TagName]->SetValue(content);
+
    std::string vr = NameHt[TagName]->GetVR();
    guint32 lgr;
 
@@ -256,6 +274,7 @@ int gdcmElValSet::SetElValueLengthByNumber(guint32 length,
    TagKey key = gdcmDictEntry::TranslateToKey(group, element);
    if ( ! tagHt.count(key))
       return 0;
+   if (length%2) length++; // length must be even
    tagHt[key]->SetLength(length);       
    return 1 ;          
 }
@@ -269,6 +288,7 @@ int gdcmElValSet::SetElValueLengthByNumber(guint32 length,
 int gdcmElValSet::SetElValueLengthByName(guint32 length, std::string TagName) {
    if ( ! NameHt.count(TagName))
       return 0;
+   if (length%2) length++; // length must be even
    NameHt.find(TagName)->second->SetLength(length);     
    return 1 ;          
 }
@@ -384,7 +404,7 @@ void gdcmElValSet::WriteElements(FileType type, FILE * _fp) {
    void *ptr;
 
    // Tout ceci ne marche QUE parce qu'on est sur un proc Little Endian 
-   // restent à tester les echecs en écriture (apres chaque fwrite)
+   // restent a tester les echecs en ecriture (apres chaque fwrite)
 
    for (TagElValueHT::iterator tag2=tagHt.begin();
         tag2 != tagHt.end();
@@ -463,28 +483,13 @@ void gdcmElValSet::WriteElements(FileType type, FILE * _fp) {
  */
 int gdcmElValSet::Write(FILE * _fp, FileType type) {
 
-   if (type == ImplicitVR) {
-      std::string implicitVRTransfertSyntax = "1.2.840.10008.1.2";
-      SetElValueByNumber(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
-      
-      SetElValueLengthByNumber(18, 0x0002, 0x0010);
-   }  
        // Question :
-       // Comment pourrait-on savoir si le DcmHeader vient d'un fichier DicomV3 ou non ,
+       // Comment pourrait-on savoir si le DcmHeader vient d'un fichier DicomV3 ou non
        // (FileType est un champ de gdcmHeader ...)
        // WARNING : Si on veut ecrire du DICOM V3 a partir d'un DcmHeader ACR-NEMA
-       // no way
-       
-   if (type == ExplicitVR) {
-      std::string explicitVRTransfertSyntax = "1.2.840.10008.1.2.1";
-      SetElValueByNumber(explicitVRTransfertSyntax, 0x0002, 0x0010);
-      // See above comment 
-      SetElValueLengthByNumber(20, 0x0002, 0x0010);
-   }
+       // no way 
+        // a moins de se livrer a un tres complique ajout des champs manquants.
+        // faire un CheckAndCorrectHeader (?)
 
    if ( (type == ImplicitVR) || (type == ExplicitVR) )
       UpdateGroupLength(false,type);
index b4f9f150be18d6bb6ddf5b6f7bd6e072bc848620..0d91c3d78df545554238ba533865d8010abbbdb9 100644 (file)
@@ -1,4 +1,4 @@
-// $Header: /cvs/public/gdcm/src/Attic/gdcmElValue.h,v 1.7 2003/07/23 08:43:03 jpr Exp $
+// $Header: /cvs/public/gdcm/src/Attic/gdcmElValue.h,v 1.8 2003/10/09 13:22:54 jpr Exp $
 
 #ifndef GDCMELVALUE_H
 #define GDCMELVALUE_H
@@ -26,8 +26,8 @@ private:
 public:
    std::string  value;
    void * voidArea;  // unsecure memory area to hold 'non string' values 
-                      // (ie : Lookup Tables, overlays)
-   size_t Offset;     // Offset from the begining of file for direct user access
+                     // (ie : Lookup Tables, overlays)
+   size_t Offset;    // Offset from the begining of file for direct user access
        
    gdcmElValue(gdcmDictEntry*);
    void SetDictEntry(gdcmDictEntry *NewEntry) { entry = NewEntry; };
index a3e31d31131425a27f34d2315656f5e5539d2142..de05007f99c906094f1a46418de49a34091d34ce 100644 (file)
@@ -1,4 +1,4 @@
-// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.95 2003/10/06 13:37:25 jpr Exp $
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.96 2003/10/09 13:22:54 jpr Exp $
 
 #include "gdcmHeader.h"
 
@@ -614,8 +614,12 @@ void gdcmHeader::FixFoundLength(gdcmElValue * ElVal, guint32 FoundLength) {
       FoundLength = 0;
       // Sorry for the patch!  
       // XMedCom did the trick to read some nasty GE images ...
-    if (FoundLength == 13) 
-      FoundLength =10;
+    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);
 }
@@ -1101,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);
 }   
@@ -1752,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);
 }