]> Creatis software - gdcm.git/commitdiff
BUG: Apply patch proposed by Peter Cech (ITK user), to handle some Philips NTSCAN...
authormalaterre <malaterre>
Fri, 12 Nov 2004 21:33:46 +0000 (21:33 +0000)
committermalaterre <malaterre>
Fri, 12 Nov 2004 21:33:46 +0000 (21:33 +0000)
src/gdcmDocument.cxx
src/gdcmDocument.h

index df8bd9fcb4721a03cbfe7b0c9a538938deee062b..e406a1c480f5076ed2274d0f3e868cd3a455e89c 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/11/10 18:27:23 $
-  Version:   $Revision: 1.121 $
+  Date:      $Date: 2004/11/12 21:33:46 $
+  Version:   $Revision: 1.122 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -2637,6 +2637,35 @@ void Document::SetMaxSizePrintEntry(long newSize)
 
 
 
+/**
+ * \brief   Handle broken private tag from Philips NTSCAN
+ *          where the endianess is being switch to BigEndian for no
+ *          apparent reason
+ * @return  no return
+ */
+void Document::HandleBrokenEndian(uint16_t group, uint16_t elem)
+{
+   // Endian reversion. Some files contain groups of tags with reversed endianess.
+   static int reversedEndian = 0;
+   // try to fix endian switching in the middle of headers
+   if ((group == 0xfeff) && (elem == 0x00e0))
+   {
+     // start endian swap mark for group found
+     reversedEndian++;
+     SwitchSwapToBigEndian();
+     // fix the tag
+     group = 0xfffe;
+     elem = 0xe000;
+   } 
+   else if ((group == 0xfffe) && (elem == 0xe00d) && reversedEndian) 
+   {
+     // end of reversed endian group
+     reversedEndian--;
+     SwitchSwapToBigEndian();
+   }
+
+}
+
 /**
  * \brief   Read the next tag but WITHOUT loading it's value
  *          (read the 'Group Number', the 'Element Number',
@@ -2662,6 +2691,7 @@ DocEntry* Document::ReadNextDocEntry()
       return 0;
    }
 
+   HandleBrokenEndian(group, elem);
    DocEntry *newEntry = NewDocEntryByNumber(group, elem);
    FindDocEntryVR(newEntry);
 
index 628f8bca77c40f22255d23aeeb26d9fc7a7004e4..0324a946a87a7fe3807e9c1c8c110218cdb7fe12 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/28 03:10:57 $
-  Version:   $Revision: 1.56 $
+  Date:      $Date: 2004/11/12 21:33:46 $
+  Version:   $Revision: 1.57 $
  
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -261,6 +261,7 @@ private:
    void BuildFlatHashTableRecurse( TagDocEntryHT& builtHT,
                                    DocEntrySet* set );
 
+   void HandleBrokenEndian(uint16_t group, uint16_t elem);
 public:
 // Accessors:
    /// Accessor to \ref PrintLevel