X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=src%2FgdcmDocument.cxx;h=c2754559da0d9946c7ea82506abc8bcb0f8401ff;hb=060a8c9a37ac1d6b5500f73de1690c11961cb87a;hp=c9e7bddc598844cb4249e082b8e982e7d28352af;hpb=f07febbce9f70fd0faee0f3ce3df674c1e7f8a13;p=gdcm.git diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index c9e7bddc..c2754559 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2006/07/10 09:41:46 $ - Version: $Revision: 1.353 $ + Date: $Date: 2007/05/23 14:18:09 $ + Version: $Revision: 1.358 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -37,7 +37,7 @@ #include // for memset #endif -namespace gdcm +namespace GDCM_NAME_SPACE { //----------------------------------------------------------------------------- @@ -244,7 +244,7 @@ bool Document::DoTheLoadingDocumentJob( ) // Force Loading some more elements if user asked to. - gdcm::DocEntry *d; + GDCM_NAME_SPACE::DocEntry *d; for (ListElements::iterator it = UserForceLoadList.begin(); it != UserForceLoadList.end(); ++it) @@ -581,8 +581,9 @@ double Document::SwapDouble(double a) // -----------------File I/O --------------- /** * \brief Tries to open the file \ref Document::Filename and - * checks the preamble when existing. - * @return The FILE pointer on success. + * checks the preamble when existing, + * or if the file starts with an ACR-NEMA look-like element. + * @return The FILE pointer on success, 0 on failure. */ std::ifstream *Document::OpenFile() { @@ -625,22 +626,6 @@ std::ifstream *Document::OpenFile() return 0; } - //-- Broken ACR or DICOM with no Preamble; may start with a Shadow Group -- - // FIXME : We cannot be sure the preable is only zeroes.. - // (see ACUSON-24-YBR_FULL-RLE.dcm ) - if ( - zero == 0x0001 || zero == 0x0100 || zero == 0x0002 || zero == 0x0200 || - zero == 0x0003 || zero == 0x0300 || zero == 0x0004 || zero == 0x0400 || - zero == 0x0005 || zero == 0x0500 || zero == 0x0006 || zero == 0x0600 || - zero == 0x0007 || zero == 0x0700 || zero == 0x0008 || zero == 0x0800 ) - { - std::string msg = Util::Format( - "ACR/DICOM starting by 0x(%04x) at the beginning of the file\n", zero); - // FIXME : is it a Warning message, or a Debug message? - gdcmWarningMacro( msg.c_str() ); - return Fp; - } - //-- DICOM -- Fp->seekg(126L, std::ios::cur); // Once per Document char dicm[4]; // = {' ',' ',' ',' '}; @@ -650,12 +635,32 @@ std::ifstream *Document::OpenFile() CloseFile(); return 0; } + if ( memcmp(dicm, "DICM", 4) == 0 ) { HasDCMPreamble = true; return Fp; } + //-- Broken ACR or DICOM (?) with no Preamble; may start with a Shadow Group -- + // FIXME : We cannot be sure the preable is only zeroes.. + // (see ACUSON-24-YBR_FULL-RLE.dcm ) + if ( + zero == 0x0001 || zero == 0x0100 || zero == 0x0002 || zero == 0x0200 || + zero == 0x0003 || zero == 0x0300 || zero == 0x0004 || zero == 0x0400 || + zero == 0x0005 || zero == 0x0500 || zero == 0x0006 || zero == 0x0600 || + zero == 0x0007 || zero == 0x0700 || zero == 0x0008 || zero == 0x0800 || + zero == 0x0028 || 0x2800 // worse : some ACR-NEMA like files + // start 00028 group ?!? + ) + { + std::string msg = Util::Format( + "ACR/DICOM starting by 0x(%04x) at the beginning of the file\n", zero); + // FIXME : is it a Warning message, or a Debug message? + gdcmWarningMacro( msg.c_str() ); + return Fp; + } + // -- Neither ACR/No Preamble Dicom nor DICOMV3 file CloseFile(); // Don't user Warning nor Error, not to pollute the output @@ -1848,7 +1853,7 @@ bool Document::IsDocEntryAnInteger(DocEntry *entry) // When we have some semantics on the element we just read, and if we // a priori know we are dealing with an integer, then we shall be - // able to swap it's element value properly. + // able to swap its element value properly. if ( elem == 0 ) // This is the group length of the group { if ( length == 4 ) @@ -1924,7 +1929,7 @@ bool Document::CheckSwap() // i.e. a total of 136 bytes. entCur = deb + 136; - // group 0x0002 *is always* Explicit VR Sometimes , + // group 0x0002 *is always* Explicit VR Sometimes, // even if elem 0002,0010 (Transfer Syntax) tells us the file is // *Implicit* VR (see former 'gdcmData/icone.dcm') @@ -1947,6 +1952,8 @@ bool Document::CheckSwap() << "Looks like a bugged Header!"); } + // Here, we assume that the file IS kosher Dicom ! + // (The meta elements - group 0x0002 - ARE little endian !) if ( net2host ) { SwapCode = 4321; @@ -2067,6 +2074,7 @@ bool Document::CheckSwap() case 0x0006 : case 0x0007 : case 0x0008 : + case 0x0028 : SwapCode = 1234; Filetype = ACR; return true; @@ -2078,6 +2086,7 @@ bool Document::CheckSwap() case 0x0600 : case 0x0700 : case 0x0800 : + case 0x2800 : SwapCode = 4321; Filetype = ACR; return true; @@ -2348,9 +2357,13 @@ void Document::HandleOutOfGroup0002(uint16_t &group, uint16_t &elem) // // --> Probabely normal, since we considered we never have // to trust manufacturers. - // (we find very often 'Implicit VR' tag, + // (we often find 'Implicit VR' tag, // even when Transfer Syntax tells us it's Explicit ... + // NEVER trust the meta elements! + // (see what ezDICOM does ...) + + /* if ( s == TS::ExplicitVRBigEndian ) { gdcmDebugMacro("Transfer Syntax Name = [" @@ -2359,7 +2372,20 @@ void Document::HandleOutOfGroup0002(uint16_t &group, uint16_t &elem) group = SwapShort(group); elem = SwapShort(elem); } - + */ + //-- Broken ACR may start with a Shadow Group -- + // worse : some ACR-NEMA like files start 00028 group ?!? + if ( !( (group >= 0x0001 && group <= 0x0008) || group == 0x0028 ) ) + { + // We trust what we see. + SwitchByteSwapCode(); + group = SwapShort(group); + elem = SwapShort(elem); + // not what we where told (by meta elements) ! + gdcmDebugMacro("Transfer Syntax Name = [" + << GetTransferSyntaxName() << "]" ); + } + /// \todo find a trick to warn user and stop processing if ( s == TS::DeflatedExplicitVRLittleEndian)