- * \brief Skips to the begining of the next Header Entry
- * \warning NOT end user intended method !
- * @param entry
- */
-void gdcmDocument::SkipToNextDocEntry(gdcmDocEntry *entry)
-{
- fseek(Fp, (long)(entry->GetOffset()), SEEK_SET);
- fseek(Fp, (long)(entry->GetReadLength()), SEEK_CUR);
-}
-
-/**
- * \brief When the length of an element value is obviously wrong (because
- * the parser went Jabberwocky) one can hope improving things by
- * applying some heuristics.
- */
-void gdcmDocument::FixDocEntryFoundLength(gdcmDocEntry *entry,
- uint32_t foundLength)
-{
- entry->SetReadLength( foundLength ); // will be updated only if a bug is found
- if ( foundLength == 0xffffffff)
- {
- foundLength = 0;
- }
-
- uint16_t gr = entry->GetGroup();
- uint16_t el = entry->GetElement();
-
- if ( foundLength % 2)
- {
- std::ostringstream s;
- s << "Warning : Tag with uneven length "
- << foundLength
- << " in x(" << std::hex << gr << "," << el <<")" << std::dec;
- dbg.Verbose(0, s.str().c_str());
- }
-
- //////// Fix for some naughty General Electric images.
- // Allthough not recent many such GE corrupted images are still present
- // on Creatis hard disks. Hence this fix shall remain when such images
- // are no longer in user (we are talking a few years, here)...
- // Note: XMedCom probably uses such a trick since it is able to read
- // those pesky GE images ...
- if ( foundLength == 13)
- {
- // Only happens for this length !
- if ( entry->GetGroup() != 0x0008
- || ( entry->GetElement() != 0x0070
- && entry->GetElement() != 0x0080 ) )
- {
- foundLength = 10;
- entry->SetReadLength(10); /// \todo a bug is to be fixed !?
- }
- }
-
- //////// Fix for some brain-dead 'Leonardo' Siemens images.
- // Occurence of such images is quite low (unless one leaves close to a
- // 'Leonardo' source. Hence, one might consider commenting out the
- // following fix on efficiency reasons.
- else if ( entry->GetGroup() == 0x0009
- && ( entry->GetElement() == 0x1113
- || entry->GetElement() == 0x1114 ) )
- {
- foundLength = 4;
- entry->SetReadLength(4); /// \todo a bug is to be fixed !?
- }
-
- else if ( entry->GetVR() == "SQ" )
- {
- foundLength = 0; // ReadLength is unchanged
- }
-
- //////// We encountered a 'delimiter' element i.e. a tag of the form
- // "fffe|xxxx" which is just a marker. Delimiters length should not be
- // taken into account.
- else if( entry->GetGroup() == 0xfffe )
- {
- // According to the norm, fffe|0000 shouldn't exist. BUT the Philips
- // image gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm happens to
- // causes extra troubles...
- if( entry->GetElement() != 0x0000 )
- {
- foundLength = 0;
- }
- }
-
- entry->SetUsableLength(foundLength);
-}
-
-/**
- * \brief Apply some heuristics to predict whether the considered
- * element value contains/represents an integer or not.
- * @param Entry The element value on which to apply the predicate.
- * @return The result of the heuristical predicate.
- */
-bool gdcmDocument::IsDocEntryAnInteger(gdcmDocEntry *entry)
-{
- uint16_t element = entry->GetElement();
- uint16_t group = entry->GetGroup();
- std::string vr = entry->GetVR();
- uint32_t length = entry->GetLength();
-
- // 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.
- if ( element == 0 ) // This is the group length of the group
- {
- if ( length == 4 )
- {
- return true;
- }
- else
- {
- // Allthough this should never happen, still some images have a
- // corrupted group length [e.g. have a glance at offset x(8336) of
- // gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm].
- // Since for dicom compliant and well behaved headers, the present
- // test is useless (and might even look a bit paranoid), when we
- // encounter such an ill-formed image, we simply display a warning
- // message and proceed on parsing (while crossing fingers).
- std::ostringstream s;
- int filePosition = ftell(Fp);
- s << "Erroneous Group Length element length on : (" \
- << std::hex << group << " , " << element
- << ") -before- position x(" << filePosition << ")"
- << "lgt : " << length;
- dbg.Verbose(0, "gdcmDocument::IsDocEntryAnInteger", s.str().c_str() );
- }
- }
-
- if ( vr == "UL" || vr == "US" || vr == "SL" || vr == "SS" )
- {
- return true;
- }
-
- return false;
-}
-
-/**
- * \brief Find the Length till the next sequence delimiter