From eae9a01c2edd9f615a78dc64a8e7731d09e815a1 Mon Sep 17 00:00:00 2001 From: malaterre Date: Fri, 12 Nov 2004 21:33:46 +0000 Subject: [PATCH] BUG: Apply patch proposed by Peter Cech (ITK user), to handle some Philips NTSCAN where some private tag were being flip to Big endian for no reason (the rest of the file is in little endian). --- src/gdcmDocument.cxx | 34 ++++++++++++++++++++++++++++++++-- src/gdcmDocument.h | 5 +++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index df8bd9fc..e406a1c4 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -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); diff --git a/src/gdcmDocument.h b/src/gdcmDocument.h index 628f8bca..0324a946 100644 --- a/src/gdcmDocument.h +++ b/src/gdcmDocument.h @@ -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 -- 2.48.1