From fe3b2ed8c460fdf307cccbd8e4f885b8bbb35351 Mon Sep 17 00:00:00 2001 From: jpr Date: Fri, 15 Jun 2007 13:16:55 +0000 Subject: [PATCH] Within some Dicom images, all the elements of shadow groups are tagged with a VR = "UN", and we get trouble when using a private Dicom dictionary. -> Fix the trouble. Thx to Mathieu Malaterre for proving image. --- src/gdcmDocument.cxx | 31 +++++++++++++++++++++++++------ src/gdcmDocument.h | 7 +++++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 0641e208..717fd44a 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2007/06/11 18:18:37 $ - Version: $Revision: 1.359 $ + Date: $Date: 2007/06/15 13:16:55 $ + Version: $Revision: 1.360 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -70,6 +70,7 @@ Document::Document() LoadMode = LD_ALL; // default : load everything, later SetFileName(""); + changeFromUN=false; } /** @@ -1502,12 +1503,12 @@ void Document::FindDocEntryLength( DocEntry *entry ) { const VRKey &vr = entry->GetVR(); uint16_t length16; - if ( Filetype == ExplicitVR && !entry->IsImplicitVR() ) { if ( vr == "OB" || vr == "OW" || vr == "SQ" || vr == "UT" - || vr == "UN" ) + || vr == "UN" || changeFromUN == true) { + changeFromUN = false; // The following reserved two bytes (see PS 3.5-2003, section // "7.1.2 Data element structure with explicit vr", p 27) must be // skipped before proceeding on reading the length on 4 bytes. @@ -1549,11 +1550,9 @@ void Document::FindDocEntryLength( DocEntry *entry ) FixDocEntryFoundLength(entry, length32); return; } - // Length is encoded on 2 bytes. //length16 = ReadInt16(); length16 = GetInt16(); - // 0xffff means that we deal with 'No Length' Sequence // or 'No Length' SQItem if ( length16 == 0xffff) @@ -2207,6 +2206,7 @@ DocEntry *Document::ReadNextDocEntry() return 0; } + changeFromUN = false; CurrentGroup = GetInt16(); CurrentElem = GetInt16(); @@ -2256,6 +2256,25 @@ DocEntry *Document::ReadNextDocEntry() } } } + + // if UN found, let's check the dictionary, and trust it! + // (maybe a private dictionary exists?) + else if (vr == "UN") + { + DictEntry *dictEntry = GetDictEntry(CurrentGroup,CurrentElem); + if ( dictEntry ) + { + realVR = dictEntry->GetVR(); + dictEntry->Unregister(); // GetDictEntry registered it + + // for VR = "UN", length is always stored on 4 bytes. + changeFromUN=true; + /// \todo : fixme If inside a supposed to be UN DataElement (but SQ according to a private dictionnary) + /// there is some more supposed to UN DataElements, it will probabely fail. + /// --> find a -non time consuming- trick to store changeFromUN info at DataElement level, + /// not at the Document level. + } + } DocEntry *newEntry; //if ( Global::GetVR()->IsVROfSequence(realVR) ) diff --git a/src/gdcmDocument.h b/src/gdcmDocument.h index ae6ce9ac..e3d0d74a 100644 --- a/src/gdcmDocument.h +++ b/src/gdcmDocument.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.h,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:10 $ - Version: $Revision: 1.143 $ + Date: $Date: 2007/06/15 13:16:56 $ + Version: $Revision: 1.144 $ 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,9 @@ private: char *PtrBegBuffer; /// \brief to avoid time consuming ftellg size_t CurrentOffsetPosition; + /// \brief to indicate if last supposed to be UN DataElement is not + /// (according to a private Dicom dictionary) + bool changeFromUN; }; } // end namespace gdcm -- 2.45.1