From: jpr Date: Tue, 17 May 2005 17:10:49 +0000 (+0000) Subject: ENH : Now, FileHelper::CheckMandatoryElements() makes some consistency checking, X-Git-Tag: Version1.2.bp~718 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;ds=inline;h=2e1c3057561211515df8c8ccc03b3ed0df1a2fc1;p=gdcm.git ENH : Now, FileHelper::CheckMandatoryElements() makes some consistency checking, at LTTG (Least Time To Go) around Bits Allocated, Bits Stored, High Bit Position, to avoid unaware user to mess up the stuff. --- diff --git a/src/gdcmFileHelper.cxx b/src/gdcmFileHelper.cxx index 85527601..f403df7f 100644 --- a/src/gdcmFileHelper.cxx +++ b/src/gdcmFileHelper.cxx @@ -4,8 +4,8 @@ Module: $RCSfile: gdcmFileHelper.cxx,v $ Language: C++ - Date: $Date: 2005/05/03 09:51:06 $ - Version: $Revision: 1.37 $ + Date: $Date: 2005/05/17 17:10:49 $ + Version: $Revision: 1.38 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -695,6 +695,9 @@ bool FileHelper::CheckWriteIntegrity() int numberBitsAllocated = FileInternal->GetBitsAllocated(); if ( numberBitsAllocated == 0 || numberBitsAllocated == 12 ) { + gdcmWarningMacro( "numberBitsAllocated changed from " + << numberBitsAllocated << " to 16 " + << " for consistency purpose" ); numberBitsAllocated = 16; } @@ -1099,6 +1102,7 @@ BinEntry *FileHelper::CopyBinEntry(uint16_t group, uint16_t elem, void FileHelper::CheckMandatoryElements() { + // just to remember : 'official' 0002 group //0002 0000 UL 1 Meta Group Length @@ -1166,7 +1170,47 @@ void FileHelper::CheckMandatoryElements() Archive->Push(e_0028_0100); } - // --- Check UID-related Entries --- + // Check if user wasn't drunk ;-) + + ValEntry *e_0028_0100; + int nbBitsAllocated = FileInternal->GetBitsAllocated(); + if ( nbBitsAllocated == 0 || nbBitsAllocated > 32) + { + e_0028_0100 = CopyValEntry(0x0028,0x0100); + e_0028_0100->SetValue("16"); + Archive->Push(e_0028_0100); + gdcmWarningMacro("(0028,0100) changed from " + << nbBitsAllocated << " to 16 for consistency purpose"); + nbBitsAllocated = 16; + } + + int nbBitsStored = FileInternal->GetBitsStored(); + if ( nbBitsStored == 0 || nbBitsStored > nbBitsAllocated ) + { + ValEntry *e_0028_0101 = CopyValEntry(0x0028,0x0101); + e_0028_0101->SetValue( e_0028_0100->GetValue( ) ); + Archive->Push(e_0028_0101); + gdcmWarningMacro("(0028,0101) changed from " + << nbBitsStored << " to " << nbBitsAllocated + << " for consistency purpose" ); + nbBitsStored = nbBitsAllocated; + } + + int highBitPosition = FileInternal->GetHighBitPosition(); + if ( highBitPosition == 0 || + highBitPosition > nbBitsAllocated-1 || + highBitPosition < nbBitsStored-1 ) + { + ValEntry *e_0028_0102 = CopyValEntry(0x0028,0x0102); + std::ostringstream s; + s << nbBitsStored - 1; + e_0028_0102->SetValue( s.str() ); + Archive->Push(e_0028_0102); + gdcmWarningMacro("(0028,0102) changed from " + << highBitPosition << " to " << nbBitsAllocated-1 + << " for consistency purpose"); + } + // --- Check UID-related Entries --- // If 'SOP Class UID' exists ('true DICOM' image) // we create the 'Source Image Sequence' SeqEntry