X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmFile.cxx;h=d3520ac40cf635f4b1fb682916f0d473eb874f47;hb=a9f954f2b63d67c79b206acec6493c3395030147;hp=71d26f6116b1d785f189daa13635fed0f3be710e;hpb=25c9af365d9221bd45f3fbe27275ff0f66a265b1;p=gdcm.git diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 71d26f61..d3520ac4 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.cxx,v $ Language: C++ - Date: $Date: 2005/02/07 09:51:03 $ - Version: $Revision: 1.214 $ + Date: $Date: 2005/02/10 14:23:18 $ + Version: $Revision: 1.222 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -367,7 +367,8 @@ int File::GetZSize() */ float File::GetXSpacing() { - float xspacing, yspacing; + float xspacing = 1.0; + float yspacing = 1.0; const std::string &strSpacing = GetEntryValue(0x0028,0x0030); if( strSpacing == GDCM_UNFOUND ) @@ -1101,7 +1102,7 @@ int File::GetNumberOfScalarComponentsRaw() */ size_t File::GetPixelOffset() { - DocEntry* pxlElement = GetDocEntry(GrPixel,NumPixel); + DocEntry *pxlElement = GetDocEntry(GrPixel, NumPixel); if ( pxlElement ) { return pxlElement->GetOffset(); @@ -1123,7 +1124,7 @@ size_t File::GetPixelOffset() */ size_t File::GetPixelAreaLength() { - DocEntry* pxlElement = GetDocEntry(GrPixel,NumPixel); + DocEntry *pxlElement = GetDocEntry(GrPixel, NumPixel); if ( pxlElement ) { return pxlElement->GetLength(); @@ -1136,13 +1137,12 @@ size_t File::GetPixelAreaLength() } } - /** * \brief Adds the characteristics of a new element we want to anonymize * */ void File::AddAnonymizeElement (uint16_t group, uint16_t elem, - std::string const &value) + std::string const &value) { Element el; @@ -1160,45 +1160,43 @@ void File::AnonymizeNoLoad() { std::fstream *fp = new std::fstream(Filename.c_str(), std::ios::in | std::ios::out | std::ios::binary); + // TODO : FIXME // how to white out disk space if longer than 50 ? - char spaces[50] = " "; + gdcm::DocEntry *d; uint32_t offset; uint32_t lgth; - uint32_t lgtToWrite; + uint32_t valLgth; + std::string *spaces; for (ListElements::iterator it = AnonymizeList.begin(); it != AnonymizeList.end(); ++it) - { + { d = GetDocEntry( (*it).Group, (*it).Elem); + if ( d == NULL) + continue; + if ( dynamic_cast(d) || dynamic_cast(d) ) continue; offset = d->GetOffset(); lgth = d->GetLength(); - fp->seekp( offset, std::ios::beg ); - - if ( (*it).Value == "" ) + if (valLgth < lgth) { - lgtToWrite = lgth > 50 ? 50 : lgth; - fp->write( spaces, lgtToWrite ); + spaces = new std::string( lgth-valLgth, ' '); + (*it).Value = (*it).Value + *spaces; + delete spaces; } - else - { - // TODO : FIXME - // how to white out disk space if longer than 50 ? - (*it).Value = (*it).Value + spaces; - lgtToWrite = lgth > (*it).Value.length() ? (*it).Value.length() : lgth; - fp->write( (char *)(*it).Value.c_str(), lgtToWrite ); - - } - fp->close(); - delete fp; + fp->seekp( offset, std::ios::beg ); + fp->write( (*it).Value.c_str(), lgth ); + } + fp->close(); + delete fp; } /** @@ -1207,7 +1205,7 @@ void File::AnonymizeNoLoad() */ bool File::AnonymizeFile() { - // If Anonymisation list is empty, let's perform some basic anonymisation + // If Anonymisation list is empty, let's perform some basic anonymization if ( AnonymizeList.begin() == AnonymizeList.end() ) { // If exist, replace by spaces @@ -1239,6 +1237,9 @@ bool File::AnonymizeFile() { d = GetDocEntry( (*it).Group, (*it).Elem); + if ( d == NULL) + continue; + if ( dynamic_cast(d) || dynamic_cast(d) ) continue; @@ -1386,40 +1387,8 @@ bool File::Write(std::string fileName, FileType filetype) } } - -#ifdef GDCM_WORDS_BIGENDIAN - // Super Super hack that will make gdcm a BOMB ! but should - // Fix temporarily the dashboard - BinEntry *b = GetBinEntry(GrPixel,NumPixel); - if ( GetPixelSize() == 16 ) - { - uint16_t *im16 = (uint16_t *)b->GetBinArea(); - int lgth = b->GetLength(); - for( int i = 0; i < lgth / 2; i++ ) - { - im16[i]= (im16[i] >> 8) | (im16[i] << 8 ); - } - } -#endif //GDCM_WORDS_BIGENDIAN - - Document::WriteContent(fp, filetype); - -#ifdef GDCM_WORDS_BIGENDIAN - // Flip back the pixel ... I told you this is a hack - if ( GetPixelSize() == 16 ) - { - uint16_t *im16 = (uint16_t*)b->GetBinArea(); - int lgth = b->GetLength(); - for( int i = 0; i < lgth / 2; i++ ) - { - im16[i]= (im16[i] >> 8) | (im16[i] << 8 ); - } - } -#endif //GDCM_WORDS_BIGENDIAN - - fp->close(); delete fp; @@ -1450,7 +1419,7 @@ void File::InitializeDefaultFile() // Media Storage SOP Class UID (CT Image Storage) InsertValEntry("1.2.840.10008.5.1.4.1.1.2", 0x0002, 0x0002); // Media Storage SOP Instance UID - InsertValEntry(uidClass.c_str(), 0x0002, 0x0003); + InsertValEntry(uidMedia.c_str(), 0x0002, 0x0003); // Transfer Syntax UID (Explicit VR Little Endian) InsertValEntry("1.2.840.10008.1.2.1 ", 0x0002, 0x0010); // META Implementation Class UID @@ -1669,7 +1638,7 @@ bool File::ReadTag(uint16_t testGroup, uint16_t testElement) long positionOnEntry = Fp->tellg(); long currentPosition = Fp->tellg(); // On debugging purposes - //// Read the Item Tag group and element, and make + // Read the Item Tag group and element, and make // sure they are what we expected: uint16_t itemTagGroup; uint16_t itemTagElement;