X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=src%2FgdcmFile.cxx;h=752af409b3bd206e7140676396687d591bce955f;hb=293b091c68447d30c8bda413cff1d6d76d9326a4;hp=b3eb62e680299e2f8d0ba6a44de98e652057a7ed;hpb=f4618aed21f60eeca799cf5807b3dca987831591;p=gdcm.git diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index b3eb62e6..752af409 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -1,10 +1,10 @@ -/*========================================================================= + /*========================================================================= Program: gdcm Module: $RCSfile: gdcmFile.cxx,v $ Language: C++ - Date: $Date: 2004/09/10 18:54:38 $ - Version: $Revision: 1.124 $ + Date: $Date: 2004/09/23 10:17:26 $ + Version: $Revision: 1.128 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -43,7 +43,7 @@ gdcmFile::gdcmFile(gdcmHeader *header) { Header = header; SelfHeader = false; - SetInitialValues(); + SaveInitialValues(); } /** @@ -65,15 +65,34 @@ gdcmFile::gdcmFile(std::string const & filename ) { Header = new gdcmHeader( filename ); SelfHeader = true; - SetInitialValues(); + SaveInitialValues(); } /** * \ingroup gdcmFile - * \brief Sets some initial for the Constructor + * \brief canonical destructor + * \note If the gdcmHeader was created by the gdcmFile constructor, + * it is destroyed by the gdcmFile */ -void gdcmFile::SetInitialValues() -{ +gdcmFile::~gdcmFile() +{ + if( SelfHeader ) + { + delete Header; + } + Header = 0; + + DeleteInitialValues(); +} + +/** + * \ingroup gdcmFile + * \brief Sets some initial values for the Constructor + * \warning not end user intended + */ +void gdcmFile::SaveInitialValues() +{ + PixelRead = -1; // no ImageData read yet. LastAllocatedPixelDataLength = 0; Pixel_Data = 0; @@ -82,6 +101,7 @@ void gdcmFile::SetInitialValues() InitialPhotInt = ""; InitialPlanConfig = ""; InitialBitsAllocated = ""; + InitialHighBit = ""; InitialRedLUTDescr = 0; InitialGreenLUTDescr = 0; @@ -100,57 +120,87 @@ void gdcmFile::SetInitialValues() InitialSpp = Header->GetEntryByNumber(0x0028,0x0002); InitialPhotInt = Header->GetEntryByNumber(0x0028,0x0004); InitialPlanConfig = Header->GetEntryByNumber(0x0028,0x0006); + InitialBitsAllocated = Header->GetEntryByNumber(0x0028,0x0100); - - // the following entries *may* be removed - // by gdcmFile::GetImageDataIntoVectorRaw - // we save them. + InitialHighBit = Header->GetEntryByNumber(0x0028,0x0102); - // we SHALL save them ! - // (some troubles, now) - /* + // the following entries *may* be removed from the H table + // (NOT deleted ...) by gdcmFile::GetImageDataIntoVectorRaw + // we keep a pointer on them. InitialRedLUTDescr = Header->GetDocEntryByNumber(0x0028,0x1101); InitialGreenLUTDescr = Header->GetDocEntryByNumber(0x0028,0x1102); InitialBlueLUTDescr = Header->GetDocEntryByNumber(0x0028,0x1103); + InitialRedLUTData = Header->GetDocEntryByNumber(0x0028,0x1201); InitialGreenLUTData = Header->GetDocEntryByNumber(0x0028,0x1202); InitialBlueLUTData = Header->GetDocEntryByNumber(0x0028,0x1203); - - if (InitialRedLUTData == NULL) - std::cout << "echec InitialRedLUTData " << std::endl; - else - { - printf("%p\n",InitialRedLUTData); - InitialRedLUTData->Print(); std::cout <IsReadable() ) + { + // the following values *may* have been modified + // by gdcmFile::GetImageDataIntoVectorRaw + // we restore their initial value. + if ( InitialSpp != "") + Header->SetEntryByNumber(InitialSpp,0x0028,0x0002); + if ( InitialPhotInt != "") + Header->SetEntryByNumber(InitialPhotInt,0x0028,0x0004); + if ( InitialPlanConfig != "") + + Header->SetEntryByNumber(InitialPlanConfig,0x0028,0x0006); + if ( InitialBitsAllocated != "") + Header->SetEntryByNumber(InitialBitsAllocated,0x0028,0x0100); + if ( InitialHighBit != "") + Header->SetEntryByNumber(InitialHighBit,0x0028,0x0102); + + // the following entries *may* be have been removed from the H table + // (NOT deleted ...) by gdcmFile::GetImageDataIntoVectorRaw + // we restore them. + + if (InitialRedLUTDescr) + Header->AddEntry(InitialRedLUTDescr); + if (InitialGreenLUTDescr) + Header->AddEntry(InitialGreenLUTDescr); + if (InitialBlueLUTDescr) + Header->AddEntry(InitialBlueLUTDescr); + + if (InitialRedLUTData) + Header->AddEntry(InitialBlueLUTDescr); + if (InitialGreenLUTData) + Header->AddEntry(InitialGreenLUTData); + if (InitialBlueLUTData) + Header->AddEntry(InitialBlueLUTData); } - Header = 0; +} + +/** + * \ingroup gdcmFile + * \brief delete initial values (il they were saved) + * of InitialLutDescriptors and InitialLutData + */ +void gdcmFile::DeleteInitialValues() +{ + +// InitialLutDescriptors and InitialLutData +// will have to be deleted if the don't belong any longer +// to the Header H table when the header is deleted... if ( InitialRedLUTDescr ) delete InitialRedLUTDescr; - + if ( InitialGreenLUTDescr ) delete InitialGreenLUTDescr; if ( InitialBlueLUTDescr ) delete InitialBlueLUTDescr; - -/* LATER ... if ( InitialRedLUTData ) delete InitialRedLUTData; @@ -160,9 +210,64 @@ gdcmFile::~gdcmFile() if ( InitialBlueLUTData != NULL) delete InitialBlueLUTData; -*/ } +/** + * \ingroup gdcmFile + * \brief drop palette related initial values -if any- + * (InitialLutDescriptors and InitialLutData) + * out of header, to make it consistent with the Pixel_Data + * as it's loaded in memory + */ + +//FIXME : Should be nice, if we could let it here. +// will be moved to PixelData class +// Now, the job is done in gdcmHeader.cxx + + /* +void gdcmFile::DropInitialValues() +{ + gdcmHeader* h=GetHeader(); + if ( GetEntryByNumber(0x0028,0x0002).c_str()[0] == '3' ) + { + // if SamplesPerPixel = 3, sure we don't need any LUT ! + // Drop 0028|1101, 0028|1102, 0028|1103 + // Drop 0028|1201, 0028|1202, 0028|1203 + + gdcmDocEntry* e = h->GetDocEntryByNumber(0x0028,0x01101); + if (e) + { + h->RemoveEntryNoDestroy(e); + } + e = h->GetDocEntryByNumber(0x0028,0x1102); + if (e) + { + h->RemoveEntryNoDestroy(e); + } + e = h->GetDocEntryByNumber(0x0028,0x1103); + if (e) + { + h->RemoveEntryNoDestroy(e); + } + e = h->GetDocEntryByNumber(0x0028,0x01201); + if (e) + { + h->RemoveEntryNoDestroy(e); + } + e = h->GetDocEntryByNumber(0x0028,0x1202); + if (e) + { + h->RemoveEntryNoDestroy(e); + } + e = h->GetDocEntryByNumber(0x0028,0x1203); + if (e) + { + h->RemoveEntryNoDestroy(e); + } + } +} +*/ + //----------------------------------------------------------------------------- // Print @@ -247,7 +352,7 @@ void gdcmFile::SetPixelDataSizeFromHeader() * @return Pointer to newly allocated pixel data. * NULL if alloc fails */ -void *gdcmFile::GetImageData() +uint8_t* gdcmFile::GetImageData() { // FIXME (Mathieu) // I need to deallocate Pixel_Data before doing any allocation: @@ -270,7 +375,7 @@ void *gdcmFile::GetImageData() GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); // Will be 7fe0, 0010 in standard case - GetHeader()->SetEntryVoidAreaByNumber( Pixel_Data, + GetHeader()->SetEntryBinAreaByNumber( Pixel_Data, GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); } PixelRead = 0; // no PixelRaw @@ -372,7 +477,7 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t maxSize) * @return Pointer to newly allocated pixel data. * \ NULL if alloc fails */ -void * gdcmFile::GetImageDataRaw () +uint8_t* gdcmFile::GetImageDataRaw () { size_t imgDataSize; if ( Header->HasLUT() ) @@ -402,7 +507,7 @@ void * gdcmFile::GetImageDataRaw () GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); // will be 7fe0, 0010 in standard cases - GetHeader()->SetEntryVoidAreaByNumber(Pixel_Data, + GetHeader()->SetEntryBinAreaByNumber(Pixel_Data, GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); } PixelRead = 1; // PixelRaw @@ -442,21 +547,9 @@ size_t gdcmFile::GetImageDataIntoVectorRaw (void *destination, size_t maxSize) // in order to be able to restore the header in a disk-consistent state // (if user asks twice to get the pixels from disk) - if ( PixelRead == -1 ) // File was never "read" before + if ( PixelRead != -1 ) // File was "read" before { - InitialSpp = Header->GetEntryByNumber(0x0028,0x0002); - InitialPhotInt = Header->GetEntryByNumber(0x0028,0x0004); - InitialPlanConfig = Header->GetEntryByNumber(0x0028,0x0006); - InitialBitsAllocated = Header->GetEntryByNumber(0x0028,0x0100); - } - else // File was already "read", the following *may* have been modified - // we restore them to be in a disk-consistent state - { - // FIXME : What happened with the LUTs ? - Header->SetEntryByNumber(InitialSpp,0x0028,0x0002); - Header->SetEntryByNumber(InitialPhotInt,0x0028,0x0004); - Header->SetEntryByNumber(InitialPlanConfig,0x0028,0x0006); - Header->SetEntryByNumber(InitialBitsAllocated,0x0028,0x0100); + RestoreInitialValues(); } PixelRead = 1 ; // PixelRaw @@ -696,20 +789,23 @@ size_t gdcmFile::GetImageDataIntoVectorRaw (void *destination, size_t maxSize) } // now, it's an RGB image // Lets's write it in the Header + + // Droping Palette Color out of the Header + // has been moved to the Write process. - // CreateOrReplaceIfExist ? + // TODO : move 'values' modification to the write process + // : save also (in order to be able to restore) + // : 'high bit' -when not equal to 'bits stored' + 1 + // : 'bits allocated', when it's equal to 12 ?! std::string spp = "3"; // Samples Per Pixel std::string photInt = "RGB "; // Photometric Interpretation std::string planConfig = "0"; // Planar Configuration - - Header->SetEntryByNumber(spp,0x0028,0x0002); Header->SetEntryByNumber(photInt,0x0028,0x0004); Header->SetEntryByNumber(planConfig,0x0028,0x0006); - /// \todo Drop Palette Color out of the Header? return ImageDataSize; } @@ -725,7 +821,7 @@ size_t gdcmFile::GetImageDataIntoVectorRaw (void *destination, size_t maxSize) * * @return boolean */ -bool gdcmFile::SetImageData(void *inData, size_t expectedSize) +bool gdcmFile::SetImageData(uint8_t* inData, size_t expectedSize) { Header->SetImageDataSize( expectedSize ); // FIXME : if already allocated, memory leak !