-/**
- * \brief Accesses the info from 0002,0010 : Transfer Syntax and TS
- * else 1.
- * @return The full Transfer Syntax Name (as opposed to Transfer Syntax UID)
- */
-std::string Document::GetTransferSyntaxName()
-{
- // use the TS (TS : Transfer Syntax)
- std::string transferSyntax = GetEntry(0x0002,0x0010);
-
- if ( transferSyntax == GDCM_NOTLOADED )
- {
- gdcmErrorMacro( "Transfer Syntax not loaded. " << std::endl
- << "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE" );
- return "Uncompressed ACR-NEMA";
- }
- if ( transferSyntax == GDCM_UNFOUND )
- {
- gdcmVerboseMacro( "Unfound Transfer Syntax (0002,0010)");
- return "Uncompressed ACR-NEMA";
- }
-
- // we do it only when we need it
- const TSKey &tsName = Global::GetTS()->GetValue( transferSyntax );
-
- // Global::GetTS() is a global static you shall never try to delete it!
- return tsName;
-}
-
-/**
- * \brief Group 0002 is always coded Little Endian
- * whatever Transfer Syntax is
- * @return no return
- */
-void Document::HandleOutOfGroup0002(uint16_t group)
-{
- // Endian reversion. Some files contain groups of tags with reversed endianess.
- if ( !Group0002Parsed && group != 0x0002)
- {
- Group0002Parsed = true;
- // we just came out of group 0002
- // if Transfer syntax is Big Endian we have to change CheckSwap
-
- std::string ts = GetTransferSyntaxName();
- if ( !Global::GetTS()->IsTransferSyntax(ts) )
- {
- gdcmVerboseMacro("True DICOM File, with NO Tansfer Syntax: " << ts );
- return;
- }
-
- // FIXME Strangely, this works with
- //'Implicit VR Transfer Syntax (GE Private)
- if ( Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRBigEndian )
- {
- gdcmVerboseMacro("Tansfer Syntax = Explicit VR - Big Endian");
- SwitchByteSwapCode();
- }
- }
-}
-
-/**
- * \brief Read the next tag but WITHOUT loading it's value
- * (read the 'Group Number', the 'Element Number',
- * gets the Dict Entry
- * gets the VR, gets the length, gets the offset value)
- * @return On succes the newly created DocEntry, NULL on failure.
- */
-DocEntry *Document::ReadNextDocEntry()
-{
- uint16_t group;
- uint16_t elem;
-
- try
- {
- group = ReadInt16();
- elem = ReadInt16();
- }
- catch ( FormatError e )
- {
- // We reached the EOF (or an error occured) therefore
- // header parsing has to be considered as finished.
- //std::cout << e;
- return 0;
- }
-
- // Sometimes file contains groups of tags with reversed endianess.
- HandleBrokenEndian(group, elem);
-
-// In 'true DICOM' files Group 0002 is allways little endian
- if ( HasDCMPreamble )
- HandleOutOfGroup0002(group);
-
- std::string vr = FindDocEntryVR();
- std::string realVR = vr;
-
- if( vr == GDCM_UNKNOWN)
- {
- DictEntry *dictEntry = GetDictEntry(group,elem);
- if( dictEntry )
- realVR = dictEntry->GetVR();
- }
-
- DocEntry *newEntry;
- if( Global::GetVR()->IsVROfSequence(realVR) )
- newEntry = NewSeqEntry(group, elem);
- else if( Global::GetVR()->IsVROfStringRepresentable(realVR) )
- newEntry = NewValEntry(group, elem,vr);
- else
- newEntry = NewBinEntry(group, elem,vr);
-
- if( vr == GDCM_UNKNOWN )