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
#include <mem.h> // for memset
#endif
-namespace gdcm
+namespace GDCM_NAME_SPACE
{
//-----------------------------------------------------------------------------
// 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)
// -----------------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()
{
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]; // = {' ',' ',' ',' '};
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
// 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 )
// 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;
case 0x0006 :
case 0x0007 :
case 0x0008 :
+ case 0x0028 :
SwapCode = 1234;
Filetype = ACR;
return true;
case 0x0600 :
case 0x0700 :
case 0x0800 :
+ case 0x2800 :
SwapCode = 4321;
Filetype = ACR;
return true;
//
// --> 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 = ["
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)