X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmDocument.cxx;h=2fd8fdfeee442e1da526a2b3b78fde8086967e67;hb=8afcac16f1406492a512a14845b6234bc9fee5ed;hp=92ee5d3c76bc438716d4692399421c788b36380f;hpb=bba6b52311989034cfaca84d1ab1e492d94c1873;p=gdcm.git diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 92ee5d3c..2fd8fdfe 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2004/11/30 16:24:31 $ - Version: $Revision: 1.143 $ + Date: $Date: 2004/12/02 15:14:17 $ + Version: $Revision: 1.145 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -101,19 +101,19 @@ Document::Document( std::string const & filename ) : ElementSet(-1) dbg.Verbose(0, "Document::Document: starting parsing of file: ", Filename.c_str()); - Fp->seekg( 0, std::ios_base::beg); + Fp->seekg( 0, std::ios::beg); - Fp->seekg(0, std::ios_base::end); + Fp->seekg(0, std::ios::end); long lgt = Fp->tellg(); - Fp->seekg( 0, std::ios_base::beg); + Fp->seekg( 0, std::ios::beg); CheckSwap(); long beg = Fp->tellg(); lgt -= beg; ParseDES( this, beg, lgt, false); // le Load sera fait a la volee - Fp->seekg( 0, std::ios_base::beg); + Fp->seekg( 0, std::ios::beg); // Load 'non string' values @@ -411,7 +411,11 @@ FileType Document::GetFileType() */ std::ifstream* Document::OpenFile() { - if (Filename.length() == 0) return 0; + if (Filename.length() == 0) + { + return 0; + } + if(Fp) { dbg.Verbose( 0, @@ -420,12 +424,13 @@ std::ifstream* Document::OpenFile() } Fp = new std::ifstream(Filename.c_str(), std::ios::in | std::ios::binary); - - if(!Fp) + if( ! *Fp ) { dbg.Verbose( 0, "Document::OpenFile cannot open file: ", Filename.c_str()); + delete Fp; + Fp = 0; return 0; } @@ -443,7 +448,7 @@ std::ifstream* Document::OpenFile() } //DICOM - Fp->seekg(126L, std::ios_base::cur); + Fp->seekg(126L, std::ios::cur); char dicm[4]; Fp->read(dicm, (size_t)4); if( memcmp(dicm, "DICM", 4) == 0 ) @@ -649,6 +654,7 @@ BinEntry* Document::ReplaceOrCreateByNumber( dbg.Verbose(0, "Document::ReplaceOrCreateByNumber: AddEntry" " failed allthough this is a creation."); } + delete currentEntry; } else { @@ -1073,7 +1079,7 @@ void Document::LoadEntryBinArea(BinEntry* element) OpenFile(); size_t o =(size_t)element->GetOffset(); - Fp->seekg(o, std::ios_base::beg); + Fp->seekg(o, std::ios::beg); size_t l = element->GetLength(); uint8_t* a = new uint8_t[l]; @@ -1243,7 +1249,7 @@ void Document::LoadDocEntrySafe(DocEntry * entry) { long PositionOnEntry = Fp->tellg(); LoadDocEntry(entry); - Fp->seekg(PositionOnEntry, std::ios_base::beg); + Fp->seekg(PositionOnEntry, std::ios::beg); } } @@ -1423,16 +1429,16 @@ void Document::ParseDES(DocEntrySet *set, long offset, if ( ts == RLELossless ) { long PositionOnEntry = Fp->tellg(); - Fp->seekg( newDocEntry->GetOffset(), std::ios_base::beg ); + Fp->seekg( newDocEntry->GetOffset(), std::ios::beg ); ComputeRLEInfo(); - Fp->seekg( PositionOnEntry, std::ios_base::beg ); + Fp->seekg( PositionOnEntry, std::ios::beg ); } else if ( IsJPEG() ) { long PositionOnEntry = Fp->tellg(); - Fp->seekg( newDocEntry->GetOffset(), std::ios_base::beg ); + Fp->seekg( newDocEntry->GetOffset(), std::ios::beg ); ComputeJPEGFragmentInfo(); - Fp->seekg( PositionOnEntry, std::ios_base::beg ); + Fp->seekg( PositionOnEntry, std::ios::beg ); } } @@ -1571,7 +1577,7 @@ void Document::LoadDocEntry(DocEntry* entry) std::string vr = entry->GetVR(); uint32_t length = entry->GetLength(); - Fp->seekg((long)entry->GetOffset(), std::ios_base::beg); + Fp->seekg((long)entry->GetOffset(), std::ios::beg); // A SeQuence "contains" a set of Elements. // (fffe e000) tells us an Element is beginning @@ -1625,7 +1631,7 @@ void Document::LoadDocEntry(DocEntry* entry) // to be sure we are at the end of the value ... Fp->seekg((long)entry->GetOffset()+(long)entry->GetLength(), - std::ios_base::beg); + std::ios::beg); return; } @@ -1753,7 +1759,7 @@ void Document::FindDocEntryLength( DocEntry *entry ) // The following reserved two bytes (see PS 3.5-2003, section // "7.1.2 Data element structure with explicit vr", p 27) must be // skipped before proceeding on reading the length on 4 bytes. - Fp->seekg( 2L, std::ios_base::cur); + Fp->seekg( 2L, std::ios::cur); uint32_t length32 = ReadInt32(); if ( (vr == "OB" || vr == "OW") && length32 == 0xffffffff ) @@ -1773,9 +1779,9 @@ void Document::FindDocEntryLength( DocEntry *entry ) // until the end of the file. Hence we artificially fix the // the length and proceed. long currentPosition = Fp->tellg(); - Fp->seekg(0L,std::ios_base::end); + Fp->seekg(0L,std::ios::end); long lengthUntilEOF = (long)(Fp->tellg())-currentPosition; - Fp->seekg(currentPosition, std::ios_base::beg); + Fp->seekg(currentPosition, std::ios::beg); entry->SetLength(lengthUntilEOF); return; } @@ -1887,13 +1893,14 @@ void Document::FindDocEntryVR( DocEntry *entry ) // within an explicit VR file. Hence we make sure the present tag // is in explicit VR and try to fix things if it happens not to be // the case. - + vr[0] = 0x00; + vr[1] = 0x00; Fp->read (vr, (size_t)2); vr[2] = 0; if( !CheckDocEntryVR(entry, vr) ) { - Fp->seekg(positionOnEntry, std::ios_base::beg); + Fp->seekg(positionOnEntry, std::ios::beg); // When this element is known in the dictionary we shall use, e.g. for // the semantics (see the usage of IsAnInteger), the VR proposed by the // dictionary entry. Still we have to flag the element as implicit since @@ -2138,8 +2145,8 @@ void Document::SkipDocEntry(DocEntry *entry) */ void Document::SkipToNextDocEntry(DocEntry *entry) { - Fp->seekg((long)(entry->GetOffset()), std::ios_base::beg); - Fp->seekg( (long)(entry->GetReadLength()), std::ios_base::cur); + Fp->seekg((long)(entry->GetOffset()), std::ios::beg); + Fp->seekg( (long)(entry->GetReadLength()), std::ios::cur); } /** @@ -2307,7 +2314,7 @@ uint32_t Document::FindDocEntryLengthOB() { dbg.Verbose(1, "Document::FindDocEntryLengthOB: neither an Item " "tag nor a Sequence delimiter tag."); - Fp->seekg(positionOnEntry, std::ios_base::beg); + Fp->seekg(positionOnEntry, std::ios::beg); throw FormatUnexpected("Document::FindDocEntryLengthOB()", "Neither an Item tag nor a Sequence " "delimiter tag."); @@ -2328,7 +2335,7 @@ uint32_t Document::FindDocEntryLengthOB() break; } } - Fp->seekg( positionOnEntry, std::ios_base::beg); + Fp->seekg( positionOnEntry, std::ios::beg); return totalLength; } @@ -2384,7 +2391,7 @@ uint32_t Document::ReadInt32() void Document::SkipBytes(uint32_t nBytes) { //FIXME don't dump the returned value - Fp->seekg((long)nBytes, std::ios_base::cur); + Fp->seekg((long)nBytes, std::ios::cur); } /** @@ -2397,6 +2404,7 @@ void Document::Initialise() RefShaDict = NULL; RLEInfo = new RLEFramesInfo; JPEGInfo = new JPEGFragmentsInfo; + Filetype = Unknown; } /** @@ -2498,8 +2506,8 @@ bool Document::CheckSwap() // Position the file position indicator at first tag (i.e. // after the file preamble and the "DICM" string). - Fp->seekg(0, std::ios_base::beg); - Fp->seekg ( 132L, std::ios_base::beg); + Fp->seekg(0, std::ios::beg); + Fp->seekg ( 132L, std::ios::beg); return true; } // End of DicomV3 @@ -2507,7 +2515,7 @@ bool Document::CheckSwap() // preamble. We can reset the file position indicator to where the data // is (i.e. the beginning of the file). dbg.Verbose(1, "Document::CheckSwap:", "not a DICOM Version3 file"); - Fp->seekg(0, std::ios_base::beg); + Fp->seekg(0, std::ios::beg); // Our next best chance would be to be considering a 'clean' ACR/NEMA file. // By clean we mean that the length of the first tag is written down. @@ -2802,7 +2810,7 @@ bool Document::ReadTag(uint16_t testGroup, uint16_t testElement) s << " at address: " << (unsigned)currentPosition << std::endl; dbg.Verbose(0, "Document::ReadItemTagLength: wrong Item Tag found:"); dbg.Verbose(0, s.str().c_str()); - Fp->seekg(positionOnEntry, std::ios_base::beg); + Fp->seekg(positionOnEntry, std::ios::beg); return false; }