From: jpr Date: Fri, 10 Sep 2004 18:54:38 +0000 (+0000) Subject: Cosmetic modif X-Git-Tag: Version0.6.bp~213 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=f4618aed21f60eeca799cf5807b3dca987831591;p=gdcm.git Cosmetic modif (Still don't solve Mathieu's pb on TestCopyDicom :-( --- diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index e1dd5332..9b5b2ac4 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/09/10 14:32:04 $ - Version: $Revision: 1.73 $ + Date: $Date: 2004/09/10 18:54:38 $ + Version: $Revision: 1.74 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -1034,7 +1034,7 @@ void *gdcmDocument::LoadEntryVoidArea(uint16_t group, uint16_t elem) delete[] a; return NULL; } - /// \todo Drop any already existing void area! JPR + /// \TODO Drop any already existing void area! JPR SetEntryVoidAreaByNumber(a, group, elem); return a; @@ -1539,10 +1539,9 @@ void gdcmDocument::LoadDocEntry(gdcmDocEntry* entry) // When we find a BinEntry not very much can be done : if (gdcmBinEntry* binEntryPtr = dynamic_cast< gdcmBinEntry* >(entry) ) { - - LoadEntryVoidArea(binEntryPtr); s << "gdcm::Loaded (BinEntry)"; binEntryPtr->SetValue(s.str()); + LoadEntryVoidArea(binEntryPtr); // last one, not to erase length ! return; } diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 000b5bae..b3eb62e6 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.cxx,v $ Language: C++ - Date: $Date: 2004/09/09 17:49:25 $ - Version: $Revision: 1.123 $ + Date: $Date: 2004/09/10 18:54:38 $ + Version: $Revision: 1.124 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -38,26 +38,12 @@ typedef std::pair IterHT; * user sets an a posteriori shadow dictionary (efficiency can be * seen as a side effect). * @param header already built gdcmHeader - * @return */ gdcmFile::gdcmFile(gdcmHeader *header) { Header = header; SelfHeader = false; - - PixelRead = -1; // no ImageData read yet. - LastAllocatedPixelDataLength = 0; - PixelData = NULL; - - InitialSpp = ""; - InitialPhotInt = ""; - InitialPlanConfig = ""; - InitialBitsAllocated = ""; - - if (Header->IsReadable()) - { - SetPixelDataSizeFromHeader(); - } + SetInitialValues(); } /** @@ -79,19 +65,65 @@ gdcmFile::gdcmFile(std::string const & filename ) { Header = new gdcmHeader( filename ); SelfHeader = true; - + SetInitialValues(); +} + +/** + * \ingroup gdcmFile + * \brief Sets some initial for the Constructor + */ +void gdcmFile::SetInitialValues() +{ PixelRead = -1; // no ImageData read yet. LastAllocatedPixelDataLength = 0; - PixelData = NULL; + Pixel_Data = 0; InitialSpp = ""; InitialPhotInt = ""; InitialPlanConfig = ""; InitialBitsAllocated = ""; - + + InitialRedLUTDescr = 0; + InitialGreenLUTDescr = 0; + InitialBlueLUTDescr = 0; + InitialRedLUTData = 0; + InitialGreenLUTData = 0; + InitialBlueLUTData = 0; + if ( Header->IsReadable() ) { SetPixelDataSizeFromHeader(); + + // the following values *may* be modified + // by gdcmFile::GetImageDataIntoVectorRaw + // we save their initial value. + 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. + + // we SHALL save them ! + // (some troubles, now) + /* + 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 <GetXSize() * Header->GetYSize() + ImageDataSize = + ImageDataSizeRaw = Header->GetXSize() * Header->GetYSize() * Header->GetZSize() * (nb/8) * Header->GetSamplesPerPixel(); std::string str_PhotometricInterpretation = Header->GetEntryByNumber(0x0028,0x0004); @@ -181,21 +236,6 @@ void gdcmFile::SetPixelDataSizeFromHeader() } } - -/** - * \ingroup gdcmFile - * \brief Returns the size (in bytes) of required memory to hold - * the pixel data represented in this file, if user DOESN'T want - * to get RGB pixels image when it's stored as a PALETTE COLOR image - * -the (vtk) user is supposed to know how to deal with LUTs- - * \warning to be used with GetImagePixelsRaw() - * @return The size of pixel data in bytes. - */ -size_t gdcmFile::GetImageDataSizeRaw() -{ - return ImageDataSizeRaw; -} - /** * \ingroup gdcmFile * \brief - Allocates necessary memory, @@ -210,27 +250,32 @@ size_t gdcmFile::GetImageDataSizeRaw() void *gdcmFile::GetImageData() { // FIXME (Mathieu) - // I need to deallocate PixelData before doing any allocation: + // I need to deallocate Pixel_Data before doing any allocation: - if ( PixelData ) - if ( LastAllocatedPixelDataLength != ImageDataSize) - free (PixelData); - PixelData = new uint8_t[ImageDataSize]; - if ( PixelData ) + if ( Pixel_Data ) + if ( LastAllocatedPixelDataLength != ImageDataSize ) + free(Pixel_Data); + if ( !Pixel_Data ) + Pixel_Data = new uint8_t[ImageDataSize]; + + if ( Pixel_Data ) { LastAllocatedPixelDataLength = ImageDataSize; - - GetImageDataIntoVector(PixelData, ImageDataSize); - // Will be 7fe0, 0010 in standard case - GetHeader()->SetEntryVoidAreaByNumber( PixelData, - GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); - // Now, the value is loaded. + + // we load the pixels (and transform grey level + LUT into RGB) + GetImageDataIntoVector(Pixel_Data, ImageDataSize); + + // We say the value *is* loaded. GetHeader()->SetEntryByNumber( GDCM_BINLOADED, GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); + + // Will be 7fe0, 0010 in standard case + GetHeader()->SetEntryVoidAreaByNumber( Pixel_Data, + GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); } PixelRead = 0; // no PixelRaw - return PixelData; + return Pixel_Data; } /** @@ -337,27 +382,32 @@ void * gdcmFile::GetImageDataRaw () imgDataSize = ImageDataSize; // FIXME (Mathieu) - // I need to deallocate PixelData before doing any allocation: + // I need to deallocate Pixel_Data before doing any allocation: - if ( PixelData ) - if ( LastAllocatedPixelDataLength != imgDataSize) - free (PixelData); - PixelData = new uint8_t[imgDataSize]; - if ( PixelData ) + if ( Pixel_Data ) + if ( LastAllocatedPixelDataLength != imgDataSize ) + free(Pixel_Data); + if ( !Pixel_Data ) + Pixel_Data = new uint8_t[imgDataSize]; + + if ( Pixel_Data ) { LastAllocatedPixelDataLength = imgDataSize; - GetImageDataIntoVectorRaw(PixelData, imgDataSize); - // will be 7fe0, 0010 in standard cases - GetHeader()->SetEntryVoidAreaByNumber(PixelData, - GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); - // Now, the value is loaded. + // we load the pixels ( grey level or RGB, but NO transformation) + GetImageDataIntoVectorRaw(Pixel_Data, imgDataSize); + + // We say the value *is* loaded. GetHeader()->SetEntryByNumber( GDCM_BINLOADED, GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); + + // will be 7fe0, 0010 in standard cases + GetHeader()->SetEntryVoidAreaByNumber(Pixel_Data, + GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); } PixelRead = 1; // PixelRaw - return PixelData; + return Pixel_Data; } /** @@ -679,7 +729,7 @@ bool gdcmFile::SetImageData(void *inData, size_t expectedSize) { Header->SetImageDataSize( expectedSize ); // FIXME : if already allocated, memory leak ! - PixelData = inData; + Pixel_Data = inData; ImageDataSize = ImageDataSizeRaw = expectedSize; PixelRead = 1; // FIXME : 7fe0, 0010 IS NOT set ... @@ -704,7 +754,7 @@ bool gdcmFile::WriteRawData(std::string const & fileName) printf("Fail to open (write) file [%s] \n", fileName.c_str()); return false; } - fwrite (PixelData, ImageDataSize, 1, fp1); + fwrite (Pixel_Data, ImageDataSize, 1, fp1); fclose (fp1); return true; @@ -848,7 +898,7 @@ bool gdcmFile::WriteBase (std::string const & fileName, FileType type) } // ----------------- End of Special Patch ---------------- - // fwrite(PixelData, ImageDataSize, 1, fp1); // should be useless, now + // fwrite(Pixel_Data, ImageDataSize, 1, fp1); // should be useless, now fclose (fp1); return true; diff --git a/src/gdcmFile.h b/src/gdcmFile.h index 90837096..a78434c2 100644 --- a/src/gdcmFile.h +++ b/src/gdcmFile.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.h,v $ Language: C++ - Date: $Date: 2004/09/03 07:57:10 $ - Version: $Revision: 1.44 $ + Date: $Date: 2004/09/10 18:54:39 $ + Version: $Revision: 1.45 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -46,7 +46,12 @@ public: /// the pixel data represented in this file. size_t GetImageDataSize(){ return ImageDataSize; }; - size_t GetImageDataSizeRaw(); + +/// \brief Returns the size (in bytes) of required memory to hold +/// the pixel data represented in this file, if user DOESN'T want +/// to get RGB pixels image when it's stored as a PALETTE COLOR image +/// -the (vtk) user is supposed to know how to deal with LUTs- + size_t GetImageDataSizeRaw(){ return ImageDataSizeRaw; }; void * GetImageData(); size_t GetImageDataIntoVector(void* destination, size_t maxSize); @@ -89,7 +94,7 @@ protected: private: void SwapZone(void* im, int swap, int lgr, int nb); - + void gdcmFile::SetInitialValues(); bool ReadPixelData(void * destination); // For JPEG 8 Bits, body in file gdcmJpeg.cxx @@ -117,7 +122,7 @@ private: bool SelfHeader; /// \brief to hold the Pixels (when read) - void* PixelData; + void* Pixel_Data; // (was PixelData; should be removed) /// \brief Area length to receive the pixels size_t ImageDataSizeRaw; @@ -137,7 +142,10 @@ private: /// \brief length of the last allocated area devoided to receive Pixels /// ( to allow us not to (free + new) if un necessary ) size_t LastAllocatedPixelDataLength; - + + // Initial values of some fields that can be modified during reading process + // if user asked to transform gray level + LUT image into RGB image + /// \brief Samples Per Pixel (0x0028,0x0002), as found on disk std::string InitialSpp; /// \brief Photometric Interpretation (0x0028,0x0004), as found on disk @@ -147,6 +155,22 @@ private: /// \brief Bits Allocated (0x0028,0x0100), as found on disk std::string InitialBitsAllocated; + // some DocEntry that can be moved ou of the H table during reading process + // if user asked to transform gray level + LUT image into RGB image + + /// \brief Red Palette Color Lookup Table Descriptor 0028 1101 as read + gdcmDocEntry* InitialRedLUTDescr; + /// \brief Green Palette Color Lookup Table Descriptor 0028 1102 as read + gdcmDocEntry* InitialGreenLUTDescr; + /// \brief Blue Palette Color Lookup Table Descriptor 0028 1103 as read + gdcmDocEntry* InitialBlueLUTDescr; + + /// \brief Red Palette Color Lookup Table Data 0028 1201 as read + gdcmDocEntry* InitialRedLUTData; + /// \brief Green Palette Color Lookup Table Data 0028 1202 as read + gdcmDocEntry* InitialGreenLUTData; + /// \brief Blue Palette Color Lookup Table Data 0028 1203 as read + gdcmDocEntry* InitialBlueLUTData; }; diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index 654a1b08..6eb2f39b 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmHeader.cxx,v $ Language: C++ - Date: $Date: 2004/09/09 17:49:25 $ - Version: $Revision: 1.184 $ + Date: $Date: 2004/09/10 18:54:39 $ + Version: $Revision: 1.185 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -108,10 +108,7 @@ void gdcmHeader::Write(FILE* fp,FileType filetype) SetEntryByNumber("16", 0x0028,0x0100); } - // correct Pixel group Length if necessary - - // TODO : create a gdcmHeader::Write method and move this part. - // (only gdcmHeader knows GrPixel, NumPixel) + // TODO : correct 'Pixel group' Length if necessary int i_lgPix = GetEntryLengthByNumber(GrPixel, NumPixel); if (i_lgPix != -2) diff --git a/src/gdcmVR.cxx b/src/gdcmVR.cxx index 3fcb456c..c400af14 100644 --- a/src/gdcmVR.cxx +++ b/src/gdcmVR.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmVR.cxx,v $ Language: C++ - Date: $Date: 2004/07/02 13:55:28 $ - Version: $Revision: 1.15 $ + Date: $Date: 2004/09/10 18:54:39 $ + Version: $Revision: 1.16 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -99,10 +99,16 @@ int gdcmVR::Count(gdcmVRKey key) * corresponds to the Value Representation of a \ref gdcmBinEntry . * This predicate is the negation of * \ref gdcmVR::IsVROfGdcmStringRepresentable . - * @param tested value represenation to check for. + * @param tested value representation to check for. */ bool gdcmVR::IsVROfGdcmBinaryRepresentable(gdcmVRKey tested) { + //std::cout << "gdcmVR::IsVROfGdcmBinaryRepresentable====================" + // << tested << std::endl; + + if ( tested == "unkn") + return true; + if ( ! Count(tested) ) { dbg.Verbose(0, "gdcmVR::IsVROfGdcmBinaryRepresentable: tested not a VR!"); @@ -122,10 +128,11 @@ bool gdcmVR::IsVROfGdcmBinaryRepresentable(gdcmVRKey tested) * \brief Simple predicate that checks wether the given argument * corresponds to the Value Representation of a \ref gdcmValEntry * but NOT a \ref gdcmBinEntry. - * @param tested value represenation to check for. + * @param tested value representation to check for. */ bool gdcmVR::IsVROfGdcmStringRepresentable(gdcmVRKey tested) { + if ( ! Count(tested) ) { dbg.Verbose(0, "gdcmVR::IsVROfGdcmStringRepresentable: tested not a VR!"); diff --git a/src/gdcmValEntry.cxx b/src/gdcmValEntry.cxx index ebf6947f..c1018fca 100644 --- a/src/gdcmValEntry.cxx +++ b/src/gdcmValEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmValEntry.cxx,v $ Language: C++ - Date: $Date: 2004/09/09 17:49:25 $ - Version: $Revision: 1.23 $ + Date: $Date: 2004/09/10 18:54:39 $ + Version: $Revision: 1.24 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -182,6 +182,8 @@ void gdcmValEntry::Print(std::ostream & os) void gdcmValEntry::Write(FILE *fp, FileType filetype) { gdcmDocEntry::Write(fp, filetype); + + //std::cout << "=====================================" << GetVR() << std::endl; if ( GetGroup() == 0xfffe ) {