X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmParser.cxx;h=60d2277ee1ebace8aa2821786b30df5b09b3a24c;hb=fe567cbab192d8c3efd93684b731e7b97b6c7e15;hp=cea36d4ec8f30adadf59d4497a59077c06882e85;hpb=cdc2a0e2a1e53f0efef4412a248566e076b1f4c9;p=gdcm.git diff --git a/src/gdcmParser.cxx b/src/gdcmParser.cxx index cea36d4e..60d2277e 100644 --- a/src/gdcmParser.cxx +++ b/src/gdcmParser.cxx @@ -1,8 +1,7 @@ // gdcmParser.cxx //----------------------------------------------------------------------------- -#include "gdcmParser.h" -#include "gdcmUtil.h" #include +#include // For nthos: #ifdef _MSC_VER @@ -19,64 +18,16 @@ #endif # include +#include "gdcmParser.h" +#include "gdcmGlobal.h" +#include "gdcmUtil.h" +#include "gdcmDebug.h" + #define UI1_2_840_10008_1_2 "1.2.840.10008.1.2" #define UI1_2_840_10008_1_2_1 "1.2.840.10008.1.2.1" #define UI1_2_840_10008_1_2_2 "1.2.840.10008.1.2.2" #define UI1_2_840_10008_1_2_1_99 "1.2.840.10008.1.2.1.99" - // Fourth semantics: - // - // ---> Warning : This fourth field is NOT part - // of the 'official' Dicom Dictionnary - // and should NOT be used. - // (Not defined for all the groups - // may be removed in a future release) - // - // CMD Command - // META Meta Information - // DIR Directory - // ID - // PAT Patient - // ACQ Acquisition - // REL Related - // IMG Image - // SDY Study - // VIS Visit - // WAV Waveform - // PRC - // DEV Device - // NMI Nuclear Medicine - // MED - // BFS Basic Film Session - // BFB Basic Film Box - // BIB Basic Image Box - // BAB - // IOB - // PJ - // PRINTER - // RT Radio Therapy - // DVH - // SSET - // RES Results - // CRV Curve - // OLY Overlays - // PXL Pixels - // DL Delimiters - // - - // Other usefull abreviations : - // Radiographic view associated with Patient Position (0018,5100). - // Defined Terms: - // - // AP = Anterior/Posterior - // PA = Posterior/Anterior - // LL = Left Lateral - // RL = Right Lateral - // RLD = Right Lateral Decubitus - // LLD = Left Lateral Decubitus - // RLO = Right Lateral Oblique - // LLO = Left Lateral Oblique - //----------------------------------------------------------------------------- // Refer to gdcmParser::CheckSwap() const unsigned int gdcmParser::HEADER_LENGTH_TO_READ = 256; @@ -92,27 +43,26 @@ const unsigned int gdcmParser::MAX_SIZE_PRINT_ELEMENT_VALUE = 64; // Constructor / Destructor /** - * \ingroup gdcmParser - * \brief constructor + * \brief constructor * @param inFilename * @param exception_on_error whether we throw an exception or not * @param enable_sequences = true to allow the header * to be parsed *inside* the SeQuences, * when they have an actual length - * @param ignore_shadow to allow skipping the shadow elements, - * to save memory space. - * \warning The TRUE value for this param has to be used - * with a FALSE value for the 'enable_sequence' param. - * ('public elements' may be embedded in 'shadow Sequences') + * @param ignore_shadow to allow skipping the shadow elements, + * to save memory space. + * \warning The TRUE value for this param has to be used + * with a FALSE value for the 'enable_sequence' param. + * ('public elements' may be embedded in 'shadow Sequences') */ gdcmParser::gdcmParser(const char *inFilename, bool exception_on_error, bool enable_sequences, - bool ignore_shadow) { + bool ignore_shadow) { enableSequences=enable_sequences; ignoreShadow =ignore_shadow; - SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE); + SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE); filename = inFilename; Initialise(); @@ -161,13 +111,13 @@ gdcmParser::~gdcmParser (void) { */ void gdcmParser::PrintEntry(std::ostream & os) { std::ostringstream s; - + for (ListTag::iterator i = listEntries.begin(); - i != listEntries.end(); - ++i) + i != listEntries.end(); + ++i) { - (*i)->SetPrintLevel(printLevel); - (*i)->Print(os); + (*i)->SetPrintLevel(printLevel); + (*i)->Print(os); } os<GetGroup(), - dictEntry->GetElement()); + dictEntry->GetElement()); return elem->GetVR(); } @@ -643,7 +592,7 @@ int gdcmParser::GetEntryLengthByNumber(guint16 group, guint16 element) { bool gdcmParser::SetEntryByName(std::string content,std::string tagName) { gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName); if( dictEntry == NULL) - return false; + return false; return(SetEntryByNumber(content,dictEntry->GetGroup(), dictEntry->GetElement())); @@ -694,11 +643,11 @@ bool gdcmParser::SetEntryByNumber(std::string content, else if( (vr == "UL") || (vr == "SL") ) lgr = 4; else - lgr = l; + lgr = l; a->SetLength(lgr); return true; -} +} /** * \ingroup gdcmParser @@ -714,15 +663,15 @@ bool gdcmParser::SetEntryByNumber(std::string content, */ bool gdcmParser::SetEntryLengthByNumber(guint32 l, guint16 group, - guint16 element) + guint16 element) { TagKey key = gdcmDictEntry::TranslateToKey(group, element); if ( ! tagHT.count(key)) return false; if (l%2) l++; // length must be even - ( ((tagHT.equal_range(key)).first)->second )->SetLength(l); - - return true ; + ( ((tagHT.equal_range(key)).first)->second )->SetLength(l); + + return true ; } /** @@ -735,7 +684,7 @@ bool gdcmParser::SetEntryLengthByNumber(guint32 l, */ size_t gdcmParser::GetEntryOffsetByNumber(guint16 Group, guint16 Elem) { - gdcmHeaderEntry* Entry = GetHeaderEntryByNumber(Group, Elem); + gdcmHeaderEntry* Entry = GetHeaderEntryByNumber(Group, Elem); if (!Entry) { dbg.Verbose(1, "gdcmParser::GetHeaderEntryByNumber", @@ -755,7 +704,7 @@ size_t gdcmParser::GetEntryOffsetByNumber(guint16 Group, guint16 Elem) */ void * gdcmParser::GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem) { - gdcmHeaderEntry* Entry = GetHeaderEntryByNumber(Group, Elem); + gdcmHeaderEntry* Entry = GetHeaderEntryByNumber(Group, Elem); if (!Entry) { dbg.Verbose(1, "gdcmParser::GetHeaderEntryByNumber", @@ -766,7 +715,6 @@ void * gdcmParser::GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem) } /** - * \ingroup gdcmParser * \brief Loads (from disk) the element content * when a string is not suitable * @param Group group of the Entry @@ -782,15 +730,15 @@ void *gdcmParser::LoadEntryVoidArea(guint16 Group, guint16 Elem) int l=Element->GetLength(); void * a = malloc(l); if(!a) - return NULL; + return NULL; SetEntryVoidAreaByNumber(a, Group, Elem); // TODO check the result size_t l2 = fread(a, 1, l ,fp); if(l != l2) { - free(a); - return NULL; + free(a); + return NULL; } return a; @@ -806,19 +754,19 @@ void *gdcmParser::LoadEntryVoidArea(guint16 Group, guint16 Elem) */ bool gdcmParser::SetEntryVoidAreaByNumber(void * area, guint16 group, - guint16 element) + guint16 element) { TagKey key = gdcmDictEntry::TranslateToKey(group, element); if ( ! tagHT.count(key)) return false; - ( ((tagHT.equal_range(key)).first)->second )->SetVoidArea(area); + ( ((tagHT.equal_range(key)).first)->second )->SetVoidArea(area); return true; } /** * \ingroup gdcmParser * \brief Update the entries with the shadow dictionary. - * Only non even entries are analyzed + * Only non even entries are analyzed */ void gdcmParser::UpdateShaEntries(void) { gdcmDictEntry *entry; @@ -922,7 +870,6 @@ void gdcmParser::LoadHeaderEntrySafe(gdcmHeaderEntry * entry) { } /** - * \ingroup gdcmParser * \brief Re-computes the length of a ACR-NEMA/Dicom group from a DcmHeader * \warning : to be re-written using the chained list instead of the H table. * \warning : DO NOT use (doesn't work any longer because of the multimap) @@ -958,7 +905,7 @@ void gdcmParser::UpdateGroupLength(bool SkipSequence, FileType type) { vr = elem->GetVR(); sprintf(trash, "%04x", gr); - key = trash; // generate 'group tag' + key = trash; // generate 'group tag' // if the caller decided not to take SEQUENCEs into account // e.g : he wants to write an ACR-NEMA File @@ -979,8 +926,8 @@ void gdcmParser::UpdateGroupLength(bool SkipSequence, FileType type) { if ( groupHt.count(key) == 0) // we just read the first elem of a given group { if (el == 0x0000) // the first elem is 0x0000 - { - groupHt[key] = 0; // initialize group length + { + groupHt[key] = 0; // initialize group length } else { @@ -1009,14 +956,14 @@ void gdcmParser::UpdateGroupLength(bool SkipSequence, FileType type) { // FIXME: g++ -Wall -Wstrict-prototypes reports on following line: // warning: unsigned int format, different type arg sscanf(g->first.c_str(),"%x",&gr_bid); - tk = g->first + "|0000"; // generate the element full tag + tk = g->first + "|0000"; // generate the element full tag if ( tagHT.count(tk) == 0) // if element 0x0000 not found - { + { gdcmDictEntry * tagZ = new gdcmDictEntry(gr_bid, 0x0000, "UL"); elemZ = new gdcmHeaderEntry(tagZ); elemZ->SetLength(4); - AddHeaderEntry(elemZ); // create it + AddHeaderEntry(elemZ); // create it } else { @@ -1029,146 +976,155 @@ void gdcmParser::UpdateGroupLength(bool SkipSequence, FileType type) { } /** - * \ingroup gdcmParser - * \brief writes on disc according to the requested format - * (ACR-NEMA, ExplicitVR, ImplicitVR) ONE - * gdcmHeaderEntry - * @param tag pointer on the gdcmHeaderEntry to be written - * @param type type of the File to be written + * \brief Writes in a file (according to the requested format) + * the group, the element, the value representation and the length + of a single gdcmHeaderEntry passed as argument. + * @param tag pointer on the gdcmHeaderEntry to be written + * @param _fp already open file pointer + * @param type type of the File to be written * (ACR-NEMA, ExplicitVR, ImplicitVR) - * @param _fp already open file pointer */ -void gdcmParser::WriteEntry(gdcmHeaderEntry *tag, FILE *_fp,FileType type) +void gdcmParser::WriteEntryTagVRLength(gdcmHeaderEntry *tag, + FILE *_fp, + FileType type) { - guint16 gr, el; - guint32 lgr; - std::string value; - const char * val; - std::string vr; - guint32 val_uint32; - guint16 val_uint16; - guint16 valZero =0; - void *voidArea; - std::vector tokens; + guint16 group = tag->GetGroup(); + std::string vr = tag->GetVR(); + guint16 el = tag->GetElement(); + guint32 lgr = tag->GetReadLength(); - void *ptr; - int ff=0xffffffff; - // TODO (?) tester les echecs en ecriture (apres chaque fwrite) - int compte =0; - itsTimeToWritePixels = false; - - // === Deal with the length - // -------------------- - if((tag->GetLength())%2==1) - { - tag->SetValue(tag->GetValue()+"\0"); - tag->SetLength(tag->GetReadLength()+1); - } - - gr = tag->GetGroup(); - el = tag->GetElement(); - lgr = tag->GetReadLength(); - val = tag->GetValue().c_str(); - vr = tag->GetVR(); - voidArea = tag->GetVoidArea(); + fwrite ( &group,(size_t)2 ,(size_t)1 ,_fp); //group + fwrite ( &el,(size_t)2 ,(size_t)1 ,_fp); //element - if ( type == ACR ) - { - if (gr < 0x0008) return; // ignore pure DICOM V3 groups - if (gr %2) return; // ignore shadow groups - if (vr == "SQ" ) return; // ignore Sequences - // TODO : find a trick to *skip* the SeQuences ! - // Not only ignore the SQ element - if (gr == 0xfffe ) return; // ignore delimiters - } + if ( type == ExplicitVR ) { + + // Special case of delimiters: + if (group == 0xfffe) { + // Delimiters have NO Value Representation and have NO length. + // Hence we skip writing the VR and length and we pad by writing + // 0xffffffff + + if (el == 0x0000) + // Fix in order to make some MR PHILIPS images e-film readable + // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm: + // we just ignore spurious fffe|0000 tag ! + return; - fwrite ( &gr,(size_t)2 ,(size_t)1 ,_fp); //group - fwrite ( &el,(size_t)2 ,(size_t)1 ,_fp); //element - - if ( (type == ExplicitVR) || (type == DICOMDIR) ) { - // EXPLICIT VR - guint16 z=0, shortLgr; - - if (gr == 0xfffe) { // NO Value Representation for 'delimiters' - // no length : write ffffffff - fwrite (&ff,(size_t)4 ,(size_t)1 ,_fp); - return; // NO value for 'delimiters' - } - - shortLgr=lgr; - if (vr == "unkn") { // Unknown was 'written' - // deal with Little Endian - fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp); + int ff=0xffffffff; + fwrite (&ff,(size_t)4 ,(size_t)1 ,_fp); + return; + } + + guint16 z=0; + guint16 shortLgr = lgr; + if (vr == "unkn") { // Unknown was 'written' + // deal with Little Endian + fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp); + fwrite ( &z, (size_t)2 ,(size_t)1 ,_fp); + } else { + fwrite (vr.c_str(),(size_t)2 ,(size_t)1 ,_fp); + if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) + { fwrite ( &z, (size_t)2 ,(size_t)1 ,_fp); + fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp); } else { - fwrite (vr.c_str(),(size_t)2 ,(size_t)1 ,_fp); - if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ){ - fwrite ( &z, (size_t)2 ,(size_t)1 ,_fp); - fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp); - } else { - fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp); - } + fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp); } - } - else // IMPLICIT VR - { - fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp); } + } + else // IMPLICIT VR + { + fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp); + } +} - // === Deal with the value - // ------------------- - if (vr == "SQ") return; // no "value" to write for the SEQuences - if (gr == 0xfffe)return; // no "value" to write for the delimiters +void gdcmParser::WriteEntryValue(gdcmHeaderEntry *tag, FILE *_fp,FileType type) +{ + guint16 group = tag->GetGroup(); + std::string vr = tag->GetVR(); + guint32 lgr = tag->GetReadLength(); + + if (vr == "SQ") + // SeQuences have no value: + return; + if (group == 0xfffe) + // Delimiters have no associated value: + return; + - if (voidArea != NULL) - { // there is a 'non string' LUT, overlay, etc - fwrite ( voidArea,(size_t)lgr ,(size_t)1 ,_fp); // Elem value - return; - } + void *voidArea; + voidArea = tag->GetVoidArea(); + if (voidArea != NULL) + { // there is a 'non string' LUT, overlay, etc + fwrite ( voidArea,(size_t)lgr ,(size_t)1 ,_fp); // Elem value + return; + } - if (vr == "US" || vr == "SS") + if (vr == "US" || vr == "SS") + { + std::vector tokens; + tokens.erase(tokens.begin(),tokens.end()); // clean any previous value + Tokenize (tag->GetValue(), tokens, "\\"); + for (unsigned int i=0; iGetValue(), tokens, "\\"); - for (unsigned int i=0; i tokens; + tokens.erase(tokens.begin(),tokens.end()); // clean any previous value + Tokenize (tag->GetValue(), tokens, "\\"); + for (unsigned int i=0; iGetValue(), tokens, "\\"); - for (unsigned int i=0; iGetValue().c_str(), (size_t)lgr ,(size_t)1, _fp); // Elem value +} + +void gdcmParser::WriteEntry(gdcmHeaderEntry *tag, FILE *_fp,FileType type) +{ + guint32 length = tag->GetLength(); + + // The value of a tag MUST (see the DICOM norm) be an odd number of + // bytes. When this is not the case, pad with an additional byte: + if(length%2==1) + { + tag->SetValue(tag->GetValue()+"\0"); + tag->SetLength(tag->GetReadLength()+1); + } + + WriteEntryTagVRLength(tag, _fp, type); + + // Pixels are never loaded in the element ! + // we stop writting when Pixel are processed + // FIX : we loose trailing elements (RAB, right now) + guint16 el = tag->GetElement(); + guint16 group = tag->GetGroup(); + int compte =0; + itsTimeToWritePixels = false; + if ((group == GrPixel) && (el == NumPixel) ) { + compte++; + if (compte == countGrPixel) {// we passed *all* the GrPixel,NumPixel + itsTimeToWritePixels = true; + return; + } + } + WriteEntryValue(tag, _fp, type); } /** - * \ingroup gdcmParser * \brief writes on disc according to the requested format * (ACR-NEMA, ExplicitVR, ImplicitVR) the image * using the Chained List @@ -1191,9 +1147,24 @@ void gdcmParser::WriteEntries(FILE *_fp,FileType type) tag2 != listEntries.end(); ++tag2) { - WriteEntry(*tag2,_fp,type); - if (itsTimeToWritePixels) - break; + if ( type == ACR ){ + if ((*tag2)->GetGroup() < 0x0008) + // Ignore pure DICOM V3 groups + continue; + if ((*tag2)->GetElement() %2) + // Ignore the "shadow" groups + continue; + if ((*tag2)->GetVR() == "SQ" ) + // For the time being sequences are simply ignored + // TODO : find a trick not to *skip* the SeQuences ! + continue; + if ((*tag2)->GetGroup() == 0xfffe ) + // Ignore the documented delimiter + continue; + } + WriteEntry(*tag2,_fp,type); + if (itsTimeToWritePixels) + break; } } @@ -1221,6 +1192,15 @@ void gdcmParser::WriteEntriesDeprecated(FILE *_fp,FileType type) { for (TagHeaderEntryHT::iterator tag2=tagHT.begin(); tag2 != tagHT.end(); ++tag2){ + if ( type == ACR ){ + if ((*tag2->second).GetGroup() < 0x0008) continue; // ignore pure DICOM V3 groups + if ((*tag2->second).GetElement() %2) continue; // ignore shadow groups + if ((*tag2->second).GetVR() == "SQ" ) continue; // ignore Sequences + // TODO : find a trick to *skip* the SeQuences ! + // Not only ignore the SQ element + // --> will be done with the next organization + if ((*tag2->second).GetGroup() == 0xfffe ) continue; // ignore delimiters + } WriteEntry(tag2->second,_fp,type); if (itsTimeToWritePixels) break; @@ -1304,7 +1284,7 @@ bool gdcmParser::ParseHeader(bool exception_on_error) throw(gdcmFormatError) { SkipHeaderEntry(newHeaderEntry); if ( (ignoreShadow==0) || (newHeaderEntry->GetGroup()%2) == 0) { AddHeaderEntry(newHeaderEntry); - } + } } return true; } @@ -1346,7 +1326,7 @@ void gdcmParser::LoadHeaderEntries(void) { // if recognition code tells us we deal with a LibIDO image // we switch lineNumber and columnNumber // - std::string RecCode; + std::string RecCode; RecCode = GetEntryByNumber(0x0008, 0x0010); // recognition code if (RecCode == "ACRNEMA_LIBIDO_1.1" || RecCode == "CANRME_AILIBOD1_1." ) @@ -1415,10 +1395,10 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry) { // When integer(s) are expected, read and convert the following // n *(two or four bytes) - // properly i.e. as integers as opposed to strings. + // properly i.e. as integers as opposed to strings. // Elements with Value Multiplicity > 1 // contain a set of integers (not a single one) - + // Any compacter code suggested (?) if ( IsHeaderEntryAnInteger(Entry) ) { guint32 NewInt; @@ -1434,7 +1414,7 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry) { NewInt = ReadInt16(); s << NewInt; } - } + } } else if (vr == "UL" || vr == "SL") { nbInt = length / 4; @@ -1453,7 +1433,7 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry) { #endif //GDCM_NO_ANSI_STRING_STREAM Entry->SetValue(s.str()); - return; + return; } // We need an additional byte for storing \0 that is not on disk @@ -1466,7 +1446,7 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry) { } if( (vr == "UI") ) // Because of correspondance with the VR dic - Entry->SetValue(NewValue.c_str()); // ??? JPR ??? + Entry->SetValue(NewValue.c_str()); else Entry->SetValue(NewValue); } @@ -1627,7 +1607,7 @@ void gdcmParser::FindHeaderEntryVR( gdcmHeaderEntry *Entry) // is in explicit VR and try to fix things if it happens not to be // the case. - int lgrLue=fread (&VR, (size_t)2,(size_t)1, fp); // lgrLue not used + (void)fread (&VR, (size_t)2,(size_t)1, fp); VR[2]=0; if(!CheckHeaderEntryVR(Entry,VR)) { @@ -1686,7 +1666,7 @@ bool gdcmParser::CheckHeaderEntryVR(gdcmHeaderEntry *Entry, VRKey vr) gdcmDictEntry* NewEntry = NewVirtualDictEntry( Entry->GetGroup(),Entry->GetElement(), "UL","FIXME","Group Length"); - Entry->SetDictEntry(NewEntry); + Entry->SetDictEntry(NewEntry); } return(false); } @@ -1846,7 +1826,7 @@ void gdcmParser::SkipHeaderEntry(gdcmHeaderEntry *entry) void gdcmParser::FixHeaderEntryFoundLength(gdcmHeaderEntry *Entry, guint32 FoundLength) { Entry->SetReadLength(FoundLength); // will be updated only if a bug is found - + if ( FoundLength == 0xffffffff) { FoundLength = 0; } @@ -1882,34 +1862,23 @@ void gdcmParser::FixHeaderEntryFoundLength(gdcmHeaderEntry *Entry, guint32 Found Entry->SetReadLength(4); // a bug is to be fixed } // end of fix - + // to try to 'go inside' SeQuences (with length), and not to skip them else if ( Entry->GetVR() == "SQ") { if (enableSequences) // only if the user does want to ! - FoundLength =0; // ReadLength is unchanged + FoundLength =0; // ReadLength is unchanged } // a SeQuence Element is beginning - // Let's forget it's length - // (we want to 'go inside') - - // Pb : *normaly* fffe|e000 is just a marker, its length *should be* zero - // in gdcm-MR-PHILIPS-16-Multi-Seq.dcm we find lengthes as big as 28800 - // if we set the length to zero IsHeaderEntryAnInteger() breaks... - // if we don't, we lost 28800 characters from the Header :-( - + // fffe|e000 is just a marker, its length *should be* zero else if(Entry->GetGroup() == 0xfffe) { - // cout << "ReadLength " <GetReadLength() << " UsableLength " << FoundLength << endl; - // Entry->Print(); - // sometimes, length seems to be wrong - FoundLength =0; // some more clever checking to be done ! - // I give up! - // only gdcm-MR-PHILIPS-16-Multi-Seq.dcm - // causes troubles :-( - } - + // *normally, fffe|0000 doesn't exist ! + if( Entry->GetElement() != 0x0000 ) // gdcm-MR-PHILIPS-16-Multi-Seq.dcm + // causes extra troubles :-( + FoundLength =0; + } Entry->SetUsableLength(FoundLength); } @@ -1935,22 +1904,21 @@ bool gdcmParser::IsHeaderEntryAnInteger(gdcmHeaderEntry *Entry) { else { std::ostringstream s; - int filePosition = ftell(fp); + int filePosition = ftell(fp); s << "Erroneous Group Length element length on : (" \ << std::hex << group << " , " << element - << ") -before- position x(" << filePosition << ")" - << "lgt : " << length; - // These 2 lines commented out : a *very dirty* patch - // to go on PrintHeader'ing gdcm-MR-PHILIPS-16-Multi-Seq.dcm. - // have a glance at offset x(8336) ... - // For *regular* headers, the test is useless.. - // lets's print a warning message and go on, - // instead of giving up with an error message - - //std::cout << s.str().c_str() << std::endl; - - // dbg.Error("gdcmParser::IsHeaderEntryAnInteger", - // s.str().c_str()); + << ") -before- position x(" << filePosition << ")" + << "lgt : " << length; + // These 2 lines commented out : a *very dirty* patch + // to go on PrintHeader'ing gdcm-MR-PHILIPS-16-Multi-Seq.dcm. + // have a glance at offset x(8336) ... + // For *regular* headers, the test is useless.. + // lets's print a warning message and go on, + // instead of giving up with an error message + + //std::cout << s.str().c_str() << std::endl; + // dbg.Error("gdcmParser::IsHeaderEntryAnInteger", + // s.str().c_str()); } } if ( (vr == "UL") || (vr == "US") || (vr == "SL") || (vr == "SS") ) @@ -1982,7 +1950,7 @@ bool gdcmParser::IsHeaderEntryAnInteger(gdcmHeaderEntry *Entry) { return 0; TotalLength += 4; // We even have to decount the group and element - if ( g != 0xfffe && g!=0xb00c ) /*for bogus header */ + if ( g != 0xfffe && g!=0xb00c ) //for bogus header { char msg[100]; // for sprintf. Sorry sprintf(msg,"wrong group (%04x) for an item sequence (%04x,%04x)\n",g, g,n); @@ -1990,7 +1958,7 @@ bool gdcmParser::IsHeaderEntryAnInteger(gdcmHeaderEntry *Entry) { errno = 1; return 0; } - if ( n == 0xe0dd || ( g==0xb00c && n==0x0eb6 ) ) /* for bogus header */ + if ( n == 0xe0dd || ( g==0xb00c && n==0x0eb6 ) ) // for bogus header FoundSequenceDelimiter = true; else if ( n != 0xe000 ) { @@ -2133,18 +2101,17 @@ bool gdcmParser::CheckSwap() { // FIXME : FIXME: // Sometimes (see : gdcmData/icone.dcm) group 0x0002 *is* Explicit VR, - // but elem 0002,0010 (Transfert Syntax) tells us the file is *Implicit* VR. - // -and it is !- + // but elem 0002,0010 (Transfert Syntax) tells us the file is + // *Implicit* VR. -and it is !- if( (memcmp(entCur, "UL", (size_t)2) == 0) || - (memcmp(entCur, "OB", (size_t)2) == 0) || - (memcmp(entCur, "UI", (size_t)2) == 0) || - (memcmp(entCur, "CS", (size_t)2) == 0) ) // CS, to remove later - // when Write DCM *adds* + (memcmp(entCur, "OB", (size_t)2) == 0) || + (memcmp(entCur, "UI", (size_t)2) == 0) || + (memcmp(entCur, "CS", (size_t)2) == 0) ) // CS, to remove later + // when Write DCM *adds* // FIXME // Use gdcmParser::dicom_vr to test all the possibilities - // instead of just checking for UL, OB and UI !? // group 0000 - + // instead of just checking for UL, OB and UI !? group 0000 { filetype = ExplicitVR; dbg.Verbose(1, "gdcmParser::CheckSwap:", @@ -2212,7 +2179,7 @@ bool gdcmParser::CheckSwap() { filetype = ACR; return true; default : - + // We are out of luck. It is not a DicomV3 nor a 'clean' ACR/NEMA file. // It is time for despaired wild guesses. // So, let's check if this file wouldn't happen to be 'dirty' ACR/NEMA, @@ -2242,20 +2209,20 @@ bool gdcmParser::CheckSwap() { case 0x0800 : sw = 4321; filetype = ACR; - return true; + return true; default : dbg.Verbose(0, "gdcmParser::CheckSwap:", "ACR/NEMA unfound swap info (Really hopeless !)"); filetype = Unknown; return false; } - - // Then the only info we have is the net2host one. - //if (! net2host ) + + // Then the only info we have is the net2host one. + //if (! net2host ) // sw = 0; //else // sw = 4321; - //return; + //return; } } @@ -2407,19 +2374,19 @@ gdcmHeaderEntry *gdcmParser::ReadNextHeaderEntry(void) { // header parsing has to be considered as finished. return (gdcmHeaderEntry *)0; -/* Pb : how to propagate the element length (used in SkipHeaderEntry) +// Pb : how to propagate the element length (used in SkipHeaderEntry) // direct call to SkipBytes ? - if (ignoreShadow == 1 && g%2 ==1) //JPR +// if (ignoreShadow == 1 && g%2 ==1) // if user wants to skip shadow groups // and current element *is* a shadow element // we don't create anything - return (gdcmHeaderEntry *)1; // to tell caller it's NOT finished -*/ +// return (gdcmHeaderEntry *)1; // to tell caller it's NOT finished + NewEntry = NewHeaderEntryByNumber(g, n); FindHeaderEntryVR(NewEntry); FindHeaderEntryLength(NewEntry); - + if (errno == 1) { // Call it quits return NULL;