From a0fbf995c51ba9e31cca7f14ba1deffdf188f3b9 Mon Sep 17 00:00:00 2001 From: regrain Date: Wed, 10 Nov 2004 16:13:17 +0000 Subject: [PATCH] * src/gdcmDocument.cxx : Set the file pointer TP to 0 in the constructors. Verify the file pointer value before open the file, and if it's not null, a verbose message is generated. Close correctly the file when the file isn't considered dicom-like. The correctly close is a call to CloseFile. When closing the file pointer, test if its not null to close the file. * src/gdcmPixelConvert.cxx : bug fix for the SIEMENS_GBS_III-16-ACR_NEMA_1.acr file. For an uncompressed image, the copied datas correspond in the least case to the image size (calculated) or the image size specified in the header. A verbose is generated if these two size mismatch -- BeNours --- ChangeLog | 16 ++++++++++++++-- src/gdcmDocument.cxx | 27 ++++++++++++++++++++------- src/gdcmPixelConvert.cxx | 27 ++++++++++++++++++++------- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 659f0433..3f929ffd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ +2004-11-10 Benoit Regrain + * src/gdcmDocument.cxx : Set the file pointer TP to 0 in the constructors. + Verify the file pointer value before open the file, and if it's not null, + a verbose message is generated. + Close correctly the file when the file isn't considered dicom-like. The + correctly close is a call to CloseFile. + When closing the file pointer, test if its not null to close the file. + * src/gdcmPixelConvert.cxx : bug fix for the SIEMENS_GBS_III-16-ACR_NEMA_1.acr + file. For an uncompressed image, the copied datas correspond in the least + case to the image size (calculated) or the image size specified in the + header. A verbose is generated if these two size mismatch + 2004-11-09 Benoit Regrain - * src/TestAllReadCompareDicom.cxx : test the existence of the directory + * Test/TestAllReadCompareDicom.cxx : test the existence of the directory using an 'ifstream' other than a 'FILE *'. The previous solution ('FILE *') break under windows (with msvc6 compilation). @@ -41,7 +53,7 @@ little endian. This should -heopfully- fix some tests 2004-11-03 Mathieu Malaterre - * Now the dictionary is compiled into gdcm lib. This is a default + * Now the dictionary is compiled into gdcm lib. This is a default behavior, thus any dic file specified is picked before failback to the one comiled into lib diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 289bf43a..f2c4fb95 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/09 21:55:55 $ - Version: $Revision: 1.119 $ + Date: $Date: 2004/11/10 16:13:18 $ + Version: $Revision: 1.120 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -90,6 +90,7 @@ Document::Document( std::string const & filename ) : ElementSet(-1) Filename = filename; Initialise(); + Fp = 0; if ( !OpenFile() ) { return; @@ -181,6 +182,8 @@ Document::Document( std::string const & filename ) : ElementSet(-1) */ Document::Document() : ElementSet(-1) { + Fp = 0; + SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE); Initialise(); PrintLevel = 1; // 'Medium' print level by default @@ -413,6 +416,13 @@ FileType Document::GetFileType() */ std::ifstream* Document::OpenFile() { + if(Fp) + { + dbg.Verbose( 0, + "Document::OpenFile is already opened when opening: ", + Filename.c_str()); + } + Fp = new std::ifstream(Filename.c_str(), std::ios::in | std::ios::binary); if(!Fp) @@ -441,7 +451,7 @@ std::ifstream* Document::OpenFile() return Fp; } - Fp->close(); + CloseFile(); dbg.Verbose( 0, "Document::OpenFile not DICOM/ACR (missing preamble)", Filename.c_str()); @@ -455,11 +465,14 @@ std::ifstream* Document::OpenFile() */ bool Document::CloseFile() { - Fp->close(); - delete Fp; - Fp = 0; + if( Fp ) + { + Fp->close(); + delete Fp; + Fp = 0; + } - return true; //FIXME how do we detect a non-close ifstream ? + return true; //FIXME how do we detect a non-close ifstream ? } /** diff --git a/src/gdcmPixelConvert.cxx b/src/gdcmPixelConvert.cxx index a4277a76..c23cbe8f 100644 --- a/src/gdcmPixelConvert.cxx +++ b/src/gdcmPixelConvert.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmPixelConvert.cxx,v $ Language: C++ - Date: $Date: 2004/11/09 21:55:56 $ - Version: $Revision: 1.26 $ + Date: $Date: 2004/11/10 16:13:18 $ + Version: $Revision: 1.27 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -588,16 +588,16 @@ bool PixelConvert::ReadAndDecompressPixelData( std::ifstream* fp ) //// First stage: get our hands on the Pixel Data. if ( !fp ) { - dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: " - "unavailable file pointer." ); + dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: " + "unavailable file pointer." ); return false; } fp->seekg( PixelOffset, std::ios_base::beg ); if( fp->fail() || fp->eof()) //Fp->gcount() == 1 { - dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: " - "unable to find PixelOffset in file." ); + dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: " + "unable to find PixelOffset in file." ); return false; } @@ -609,7 +609,20 @@ bool PixelConvert::ReadAndDecompressPixelData( std::ifstream* fp ) } else if ( IsDecompressed ) { - fp->read( (char*)Decompressed, PixelDataLength); + if( PixelDataLength != DecompressedSize) + { + dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: " + "Mismatch between PixelConvert and DecompressedSize." ); + } + if( PixelDataLength > DecompressedSize) + { + fp->read( (char*)Decompressed, DecompressedSize); + } + else + { + fp->read( (char*)Decompressed, PixelDataLength); + } + if ( fp->fail() || fp->eof())//Fp->gcount() == 1 { dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: " -- 2.48.1