Program: gdcm
Module: $RCSfile: gdcmDocument.cxx,v $
Language: C++
- Date: $Date: 2004/11/10 18:27:23 $
- Version: $Revision: 1.121 $
+ Date: $Date: 2004/11/15 16:12:30 $
+ Version: $Revision: 1.123 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
* @param group group number of the Entry
* @param elem element number of the Entry
*/
-void* Document::LoadEntryBinArea(uint16_t group, uint16_t elem)
+void Document::LoadEntryBinArea(uint16_t group, uint16_t elem)
{
+ // Search the corresponding DocEntry
DocEntry *docElement = GetDocEntryByNumber(group, elem);
if ( !docElement )
- {
- return NULL;
- }
+ return;
+
size_t o =(size_t)docElement->GetOffset();
Fp->seekg( o, std::ios_base::beg);
size_t l = docElement->GetLength();
if(!a)
{
dbg.Verbose(0, "Document::LoadEntryBinArea cannot allocate a");
- return NULL;
+ return;
}
+
+ // Read the value
Fp->read((char*)a, l);
if( Fp->fail() || Fp->eof() )//Fp->gcount() == 1
{
delete[] a;
- return NULL;
+ return;
}
- /// \todo Drop any already existing void area! JPR
+
+ // Set the value to the DocEntry
if( !SetEntryBinAreaByNumber( a, group, elem ) )
{
+ delete[] a;
dbg.Verbose(0, "Document::LoadEntryBinArea setting failed.");
}
- return a;
}
/**
* \brief Loads (from disk) the element content
* when a string is not suitable
* @param element Entry whose binArea is going to be loaded
*/
-void* Document::LoadEntryBinArea(BinEntry* element)
+void Document::LoadEntryBinArea(BinEntry* element)
{
size_t o =(size_t)element->GetOffset();
Fp->seekg(o, std::ios_base::beg);
if( !a )
{
dbg.Verbose(0, "Document::LoadEntryBinArea cannot allocate a");
- return NULL;
+ return;
}
- element->SetBinArea((uint8_t*)a);
+
/// \todo check the result
Fp->read((char*)a, l);
if( Fp->fail() || Fp->eof()) //Fp->gcount() == 1
{
delete[] a;
- return NULL;
+ return;
}
- return a;
+ element->SetBinArea((uint8_t*)a);
}
/**
{
return false;
}
+
if ( BinEntry* binEntry = dynamic_cast<BinEntry*>(currentEntry) )
{
binEntry->SetBinArea( area );
return true;
}
- return true;
+
+ return false;
}
/**
+/**
+ * \brief Handle broken private tag from Philips NTSCAN
+ * where the endianess is being switch to BigEndian for no
+ * apparent reason
+ * @return no return
+ */
+void Document::HandleBrokenEndian(uint16_t group, uint16_t elem)
+{
+ // Endian reversion. Some files contain groups of tags with reversed endianess.
+ static int reversedEndian = 0;
+ // try to fix endian switching in the middle of headers
+ if ((group == 0xfeff) && (elem == 0x00e0))
+ {
+ // start endian swap mark for group found
+ reversedEndian++;
+ SwitchSwapToBigEndian();
+ // fix the tag
+ group = 0xfffe;
+ elem = 0xe000;
+ }
+ else if ((group == 0xfffe) && (elem == 0xe00d) && reversedEndian)
+ {
+ // end of reversed endian group
+ reversedEndian--;
+ SwitchSwapToBigEndian();
+ }
+
+}
+
/**
* \brief Read the next tag but WITHOUT loading it's value
* (read the 'Group Number', the 'Element Number',
return 0;
}
+ HandleBrokenEndian(group, elem);
DocEntry *newEntry = NewDocEntryByNumber(group, elem);
FindDocEntryVR(newEntry);