Program: gdcm
Module: $RCSfile: gdcmDocument.cxx,v $
Language: C++
- Date: $Date: 2006/10/19 10:30:45 $
- Version: $Revision: 1.354 $
+ Date: $Date: 2006/10/25 14:08:10 $
+ Version: $Revision: 1.355 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
// -----------------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()
{
CloseFile();
return 0;
}
+
if ( memcmp(dicm, "DICM", 4) == 0 )
{
HasDCMPreamble = true;
// 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')
<< "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;
// (we find very often '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 = ["
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)