X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmDocument.cxx;h=8937fa3ea97638ab36e1d647d066bc983c8867fd;hb=827d0d72b115d9e54aac8f0b054856dffff862ca;hp=c2ea01aa8c0aee230569c22843b0a20d68ad3b49;hpb=a462ce9f1af0894cd930ab04f2e65cd80dfa7084;p=gdcm.git diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index c2ea01aa..8937fa3e 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2005/01/08 15:03:59 $ - Version: $Revision: 1.168 $ + Date: $Date: 2005/01/11 00:21:48 $ + Version: $Revision: 1.172 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -47,7 +47,7 @@ namespace gdcm static const char *TransferSyntaxStrings[] = { // Implicit VR Little Endian "1.2.840.10008.1.2", - // Implicit VR Big Endian DLX G.E? + // Implicit VR Big Endian DLX (G.E Private) "1.2.840.113619.5.2", // Explicit VR Little Endian "1.2.840.10008.1.2.1", @@ -449,6 +449,9 @@ std::ifstream *Document::OpenFile() zero == 0x0005 || zero == 0x0500 || zero == 0x0006 || zero == 0x0600 || zero == 0x0007 || zero == 0x0700 || zero == 0x0008 || zero == 0x0800 ) { + std::string msg + = Util::Format("ACR/DICOM with no preamble: (%04x)\n", zero); + gdcmVerboseMacro( msg.c_str() ); return Fp; } @@ -967,7 +970,7 @@ void Document::LoadEntryBinArea(BinEntry *element) /// \todo check the result Fp->read((char*)a, l); - if( Fp->fail() || Fp->eof()) //Fp->gcount() == 1 + if( Fp->fail() || Fp->eof()) { delete[] a; return; @@ -1109,8 +1112,7 @@ uint32_t Document::SwapLong(uint32_t a) a=( ((a<< 8) & 0xff00ff00) | ((a>>8) & 0x00ff00ff) ); break; default : - //std::cout << "swapCode= " << SwapCode << std::endl; - gdcmErrorMacro( "Unset swap code"); + gdcmErrorMacro( "Unset swap code:" << SwapCode ); a = 0; } return a; @@ -1462,8 +1464,8 @@ void Document::LoadDocEntry(DocEntry *entry) else { // fusible - std::cout<< "MaxSizeLoadEntry exceeded, neither a BinEntry " - << "nor a ValEntry ?! Should never print that !" << std::endl; + gdcmErrorMacro( "MaxSizeLoadEntry exceeded, neither a BinEntry " + << "nor a ValEntry ?! Should never print that !" ); } // to be sure we are at the end of the value ... @@ -1539,8 +1541,8 @@ void Document::LoadDocEntry(DocEntry *entry) if( length % 2 ) { newValue = Util::DicomString(str, length+1); - gdcmVerboseMacro("Warning: bad length: " << length ); - gdcmVerboseMacro("For string :" << newValue.c_str()); + gdcmVerboseMacro("Warning: bad length: " << length << + ",For string :" << newValue.c_str()); // Since we change the length of string update it length //entry->SetReadLength(length+1); } @@ -1552,9 +1554,9 @@ void Document::LoadDocEntry(DocEntry *entry) if ( ValEntry *valEntry = dynamic_cast(entry) ) { - if ( Fp->fail() || Fp->eof())//Fp->gcount() == 1 + if ( Fp->fail() || Fp->eof()) { - gdcmVerboseMacro( "Unread element value"); + gdcmVerboseMacro("Unread element value"); valEntry->SetValue(GDCM_UNREAD); return; } @@ -1675,8 +1677,7 @@ void Document::FindDocEntryLength( DocEntry *entry ) // and the dictionary entry depending on them. uint16_t correctGroup = SwapShort( entry->GetGroup() ); uint16_t correctElem = SwapShort( entry->GetElement() ); - DictEntry *newTag = GetDictEntry( correctGroup, - correctElem ); + DictEntry *newTag = GetDictEntry( correctGroup, correctElem ); if ( !newTag ) { // This correct tag is not in the dictionary. Create a new one. @@ -1717,7 +1718,7 @@ void Document::FindDocEntryLength( DocEntry *entry ) std::string Document::FindDocEntryVR() { if ( Filetype != ExplicitVR ) - return(GDCM_UNKNOWN); + return GDCM_UNKNOWN; long positionOnEntry = Fp->tellg(); // Warning: we believe this is explicit VR (Value Representation) because @@ -1735,9 +1736,9 @@ std::string Document::FindDocEntryVR() if( !CheckDocEntryVR(vr) ) { Fp->seekg(positionOnEntry, std::ios::beg); - return(GDCM_UNKNOWN); + return GDCM_UNKNOWN; } - return(vr); + return vr; } /** @@ -1903,14 +1904,12 @@ void Document::SkipDocEntry(DocEntry *entry) /** * \brief Skips to the begining of the next Header Entry * \warning NOT end user intended method ! - * @param offset start of skipping - * @param readLgth length to skip - + * @param currentDocEntry entry to skip */ -void Document::SkipToNextDocEntry(DocEntry *newDocEntry) +void Document::SkipToNextDocEntry(DocEntry *currentDocEntry) { - Fp->seekg((long)(newDocEntry->GetOffset()), std::ios::beg); - Fp->seekg( (long)(newDocEntry->GetReadLength()),std::ios::cur); + Fp->seekg((long)(currentDocEntry->GetOffset()), std::ios::beg); + Fp->seekg( (long)(currentDocEntry->GetReadLength()),std::ios::cur); } /** @@ -1918,7 +1917,7 @@ void Document::SkipToNextDocEntry(DocEntry *newDocEntry) * the parser went Jabberwocky) one can hope improving things by * applying some heuristics. * @param entry entry to check - * @param foundLength fist assumption about length + * @param foundLength first assumption about length */ void Document::FixDocEntryFoundLength(DocEntry *entry, uint32_t foundLength) @@ -1994,7 +1993,7 @@ void Document::FixDocEntryFoundLength(DocEntry *entry, */ bool Document::IsDocEntryAnInteger(DocEntry *entry) { - uint16_t element = entry->GetElement(); + uint16_t elem = entry->GetElement(); uint16_t group = entry->GetGroup(); const std::string &vr = entry->GetVR(); uint32_t length = entry->GetLength(); @@ -2002,7 +2001,7 @@ bool Document::IsDocEntryAnInteger(DocEntry *entry) // 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 ( elem == 0 ) // This is the group length of the group { if ( length == 4 ) { @@ -2019,7 +2018,7 @@ bool Document::IsDocEntryAnInteger(DocEntry *entry) // message and proceed on parsing (while crossing fingers). long filePosition = Fp->tellg(); gdcmVerboseMacro( "Erroneous Group Length element length on : (" - << std::hex << group << " , " << element + << std::hex << group << " , " << elem << ") -before- position x(" << filePosition << ")" << "lgt : " << length ); } @@ -2057,8 +2056,8 @@ uint32_t Document::FindDocEntryLengthOBOrOW() } catch ( FormatError ) { - throw FormatError("Document::FindDocEntryLengthOBOrOW()", - " group or element not present."); + throw FormatError("Unexpected end of file encountered during ", + "Document::FindDocEntryLengthOBOrOW()"); } // We have to decount the group and element we just read @@ -2066,7 +2065,11 @@ uint32_t Document::FindDocEntryLengthOBOrOW() if ( group != 0xfffe || ( ( elem != 0xe0dd ) && ( elem != 0xe000 ) ) ) { - gdcmVerboseMacro( "Neither an Item tag nor a Sequence delimiter tag."); + long filePosition = Fp->tellg(); + gdcmVerboseMacro( "Neither an Item tag nor a Sequence delimiter tag on :" + << std::hex << group << " , " << elem + << ") -before- position x(" << filePosition << ")" ); + Fp->seekg(positionOnEntry, std::ios::beg); throw FormatUnexpected( "Neither an Item tag nor a Sequence delimiter tag."); } @@ -2437,7 +2440,7 @@ void Document::HandleBrokenEndian(uint16_t group, uint16_t elem) group = 0xfffe; elem = 0xe000; } - else if ((group == 0xfffe) && (elem == 0xe00d) && reversedEndian) + else if (group == 0xfffe && elem == 0xe00d && reversedEndian) { // end of reversed endian group reversedEndian--; @@ -2579,7 +2582,7 @@ bool Document::ReadTag(uint16_t testGroup, uint16_t testElement) << std::hex << testGroup << "," << testElement << ")" << std::endl << " but instead we encountered tag (" << std::hex << itemTagGroup << "," << itemTagElement << ")" - << std::endl + << std::dec << " at address: " << (unsigned int)currentPosition ); Fp->seekg(positionOnEntry, std::ios::beg);