Program: gdcm
Module: $RCSfile: gdcmDocument.cxx,v $
Language: C++
- Date: $Date: 2005/10/24 16:00:47 $
- Version: $Revision: 1.304 $
+ Date: $Date: 2005/10/26 17:06:33 $
+ Version: $Revision: 1.312 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
* \brief Accessor to the Transfer Syntax (when present) of the
* current document (it internally handles reading the
* value from disk when only parsing occured).
- * @return The encountered Transfer Syntax of the current document.
+ * @return The encountered Transfer Syntax of the current document, if DICOM.
+ * GDCM_UNKNOWN for ACR-NEMA files (or broken headers ...)
*/
std::string Document::GetTransferSyntax()
{
return a;
}
+/**
+ * \brief Swaps back the bytes of 8-byte long 'double' accordingly to
+ * processor order.
+ * @return The properly swaped 64 bits double.
+ */
+double Document::SwapDouble(double a)
+{
+ switch (SwapCode)
+ {
+ // There were no 'double' at ACR-NEMA time.
+ // We just have to deal with 'straight Little Endian' and
+ // 'straight Big Endian'
+ case 1234 :
+ break;
+ case 4321 :
+ {
+ char *beg = (char *)&a;
+ char *end = beg + 7;
+ char t;
+ for (unsigned int i = 0; i<7; i++)
+ {
+ t = *beg;
+ *beg = *end;
+ *end = t;
+ beg++,
+ end--;
+ }
+ }
+ break;
+ default :
+ gdcmErrorMacro( "Unset swap code:" << SwapCode );
+ a = 0.;
+ }
+ return a;
+}
+
+
//
// -----------------File I/O ---------------
/**
// Skip if user wants to write an ACR-NEMA file
if ( filetype == ImplicitVR || filetype == ExplicitVR ||
- filetype == JPEG )
+ filetype == JPEG )
{
// writing Dicom File Preamble
char filePreamble[128];
}
case 8:
{
- gdcmWarningMacro("Can't swap 64 bits data");
-/* uint64_t *data64 = (uint64_t *)data;
+ double *data64 = (double *)data;
for(i=0;i<l/vrLgth;i++)
- data64[i] = SwapLongLong(data64[i]);*/
+ data64[i] = SwapDouble(data64[i]);
break;
}
}
// It's too late to do the Job
// (we should check the value, but we know it after LoadDocEntry ...)
- // Uncoment this printf line to be able to 'follow' the DocEntries
+ // Uncoment this cerr line to be able to 'follow' the DocEntries
// when something *very* strange happens
- //printf( "%04x|%04x %s\n",newDocEntry->GetGroup(),
- // newDocEntry->GetElement(),
- // newDocEntry->GetVR().c_str() );
+ if( Debug::GetDebugFlag() )
+ std::cerr<<newDocEntry->GetKey()<<" "<<newDocEntry->GetVR()<<std::endl;
if ( !newDocEntry )
{
}
else
{
+ newDataEntry->Delete();
// Load only if we can add (not a duplicate key)
LoadDocEntry( newDataEntry );
}
<< newSeqEntry->GetOffset() << " )" );
used = false;
}
+ else
+ {
+ newDocEntry->Delete();
+ }
if ( !delim_mode && ((long)(Fp->tellg())-offset) >= l_max)
{
if ( !used )
newDocEntry->Delete();
- break;
+ break;
}
} // end SeqEntry : VR = "SQ"
if ( newDocEntry->IsSequenceDelimitor() )
{
seqEntry->SetDelimitationItem( newDocEntry );
+ newDocEntry->Delete();
break;
}
}
break;
}
// create the current SQItem
- SQItem *itemSQ = new SQItem( seqEntry->GetDepthLevel() );
+ SQItem *itemSQ = SQItem::New( seqEntry->GetDepthLevel() );
unsigned int l = newDocEntry->GetReadLength();
if ( l == 0xffffffff )
// Let's try :------------
// remove fff0,e000, created out of the SQItem
- newDocEntry->Delete();
Fp->seekg(offsetStartCurrentSQItem, std::ios::beg);
// fill up the current SQItem, starting at the beginning of fff0,e000
// end try -----------------
seqEntry->AddSQItem( itemSQ, SQItemNumber );
+ itemSQ->Delete();
+ newDocEntry->Delete();
SQItemNumber++;
if ( !delim_mode && ((long)(Fp->tellg())-offset ) >= l_max )
{
VRKey vr;
Fp->read(&(vr[0]),(size_t)2);
- gdcmDebugMacro( "--> VR: " << vr )
+ //gdcmDebugMacro( "--> VR: " << vr )
if ( !CheckDocEntryVR(vr) )
{
- gdcmWarningMacro( "Unknown VR '" << vr << "'" )
+ gdcmWarningMacro( "Unknown VR '" << vr << "' at offset :"
+ << positionOnEntry );
Fp->seekg(positionOnEntry, std::ios::beg);
return GDCM_VRUNKNOWN;
}
}
}
}
- gdcmDebugMacro( "Found VR: " << vr << " / Real VR: " << realVR );
+ // gdcmDebugMacro( "Found VR: " << vr << " / Real VR: " << realVR );
DocEntry *newEntry;
if ( Global::GetVR()->IsVROfSequence(realVR) )