From f87aa828eaad96473078971c4f039e73d76b2070 Mon Sep 17 00:00:00 2001 From: jpr Date: Wed, 2 Jul 2003 16:47:22 +0000 Subject: [PATCH] now gdcmFile::GetImageDataIntoVector, gdcmFile::GetImageData, and so on return an RGB pixel map (they return no longer an R Plane + a G Plane + a B Plane) see gdcmData/US-RGB-8-epicard.dcm --- gdcmPython/testSuite.py | 7 ++- src/gdcmFile.cxx | 103 +++++++++++++++++++++++++++------------- src/gdcmHeader.cxx | 56 ++++++++++++++-------- src/gdcmHeader.h | 7 ++- 4 files changed, 117 insertions(+), 56 deletions(-) diff --git a/gdcmPython/testSuite.py b/gdcmPython/testSuite.py index 695e671f..7efdf672 100644 --- a/gdcmPython/testSuite.py +++ b/gdcmPython/testSuite.py @@ -187,10 +187,14 @@ class gdcmTestCase(unittest.TestCase): ["Manufacturer", "Acme Products"], # FIXME: 92160 / (120*256) = 3 bytes per pixel NOT 1. Maybe # it has something to do with [Samples Per Pixel] = [3] ??? + # You said it, puffy (tu l'as dit, bouffi, in french language) + # RGB is 3 bytes per pixel + # + Planar configuration (0028,0006) = 0 --> Pixels RGB ["Pixel Data", "gdcm::NotLoaded. Address:904 Length:92160"] ] ], ["US-RGB-8-epicard.dcm", # Interest: Big endian transfert syntax [ ["Transfer Syntax UID", "1.2.840.10008.1.2.2"], # Big endian + # But ... group 0000 is LE . ["Modality", "US"], ["Photometric Interpretation", "RGB"], ["Rows", "480"], @@ -201,8 +205,7 @@ class gdcmTestCase(unittest.TestCase): ["Pixel Representation", "0"], ["Manufacturer", "G.E. Medical Systems"], ["Manufacturer Model Name", "LOGIQ 700"], - # FIXME: 921600/(480*640) = 3 bytes per pixel NOT 1. Maybe - # it has something to do with [Samples Per Pixel] = [3] ??? + # + Planar configuration (0028,0006) = 1 --> Plane R, Plane G, Plane B ["Implementation Version Name", "OFFIS-DCMTK-311"], ["Pixel Data", "gdcm::NotLoaded. Address:1012 Length:921600"] ] ], ] diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 7003c29a..70859f9d 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -82,7 +82,7 @@ size_t gdcmFile::GetImageDataSize(void) { * \ingroup gdcmFile * \brief Read pixel data from disk (optionaly decompressing) into the * caller specified memory location. - * @param destination Where the pixel data should be stored. + * @param destination where the pixel data should be stored. * */ bool gdcmFile::ReadPixelData(void* destination) { @@ -300,6 +300,43 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { return (size_t)0; } } + + // --- + string str_PlanarConfiguration = GetPubElValByNumber(0x0028,0x0006); + int PlanarConfiguration; + if (str_PlanarConfiguration == "gdcm::Unfound" ) { + PlanarConfiguration = 0; + } else { + PlanarConfiguration = atoi(str_PlanarConfiguration.c_str() ); + } + // --- + + // TODO : replace by + // if (GetPlanarConfiguration() == 1) { + // after unfreeze + + if (PlanarConfiguration == 1) { // need to make RGB Pixels + int l = lgrTotale/3 ; + + char * a = (char *)destination; + char * b = a + l; + char * c = b + l; + char * newDest = (char*) malloc(lgrTotale); + // TODO : + // any trick not to have to allocate temporary buffer is welcome ... + char *x = newDest; + for (int i=0;i>8) - | ((((unsigned short int*)im)[i])<<8); - break; + case 21: + case 3412: + case 2143: + case 4321: + + for(i=0;i>8) + | ((((unsigned short int*)im)[i])<<8); + break; - default: - printf("valeur de SWAP (16 bits) non autorisee : %d\n", swap); + default: + printf("valeur de SWAP (16 bits) non autorisee : %d\n", swap); } if( nb == 32 ) @@ -351,28 +388,28 @@ if( nb == 32 ) } break; - case 2143: - for(i=0;i>16; - fort= (fort>>8) | (fort<<8); - faible=(faible>>8) | (faible<<8); - s32=fort; - ((unsigned long int*)im)[i]=(s32<<16)|faible; - } - break; + case 2143: + for(i=0;i>16; + fort= (fort>>8) | (fort<<8); + faible=(faible>>8) | (faible<<8); + s32=fort; + ((unsigned long int*)im)[i]=(s32<<16)|faible; + } + break; - case 3412: - for(i=0;i>16; - s32=faible; - ((unsigned long int*)im)[i]=(s32<<16)|fort; - } - break; + case 3412: + for(i=0;i>16; + s32=faible; + ((unsigned long int*)im)[i]=(s32<<16)|fort; + } + break; - default: - printf("valeur de SWAP (32 bits) non autorisee : %d\n", swap); + default: + printf("valeur de SWAP (32 bits) non autorisee : %d\n", swap); } return; } @@ -393,8 +430,6 @@ int gdcmFile::SetImageData(void * inData, size_t ExpectedSize) { SetImageDataSize(ExpectedSize); PixelData = inData; lgrTotale = ExpectedSize; - - return(1); } diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index 284bbdc6..b4681a80 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -1,5 +1,5 @@ -// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.75 2003/07/01 17:22:44 jpr Exp $ +// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.76 2003/07/02 16:47:22 jpr Exp $ #include #include @@ -42,15 +42,15 @@ void gdcmHeader::Initialise(void) { * @param InFilename * @param exception_on_error */ - gdcmHeader::gdcmHeader(const char *InFilename, bool exception_on_error) { - SetMaxSizeLoadElementValue(_MaxSizeLoadElementValue_); - filename = InFilename; - Initialise(); - if ( !OpenFile(exception_on_error)) - return; - ParseHeader(); - LoadElements(); - CloseFile(); +gdcmHeader::gdcmHeader(const char *InFilename, bool exception_on_error) { + SetMaxSizeLoadElementValue(_MaxSizeLoadElementValue_); + filename = InFilename; + Initialise(); + if ( !OpenFile(exception_on_error)) + return; + ParseHeader(); + LoadElements(); + CloseFile(); } /** @@ -194,8 +194,8 @@ void gdcmHeader::CheckSwap() // instead of just checking for UL, OB and UI !? if( (memcmp(entCur, "UL", (size_t)2) == 0) || (memcmp(entCur, "OB", (size_t)2) == 0) || - (memcmp(entCur, "UI", (size_t)2) == 0) ) - { + (memcmp(entCur, "UI", (size_t)2) == 0) ) + { filetype = ExplicitVR; dbg.Verbose(1, "gdcmHeader::CheckSwap:", "explicit Value Representation"); @@ -204,7 +204,6 @@ void gdcmHeader::CheckSwap() dbg.Verbose(1, "gdcmHeader::CheckSwap:", "not an explicit Value Representation"); } - if (net2host) { sw = 4321; dbg.Verbose(1, "gdcmHeader::CheckSwap:", @@ -952,11 +951,11 @@ guint16 gdcmHeader::ReadInt16(void) { size_t item_read; item_read = fread (&g, (size_t)2,(size_t)1, fp); if ( item_read != 1 ) { - dbg.Verbose(1, "gdcmHeader::ReadInt16", " Failed to read :"); + dbg.Verbose(0, "gdcmHeader::ReadInt16", " Failed to read :"); if(feof(fp)) - dbg.Verbose(1, "gdcmHeader::ReadInt16", " End of File encountered"); + dbg.Verbose(0, "gdcmHeader::ReadInt16", " End of File encountered"); if(ferror(fp)) - dbg.Verbose(1, "gdcmHeader::ReadInt16", " File Error"); + dbg.Verbose(0, "gdcmHeader::ReadInt16", " File Error"); errno = 1; return 0; } @@ -977,11 +976,11 @@ guint32 gdcmHeader::ReadInt32(void) { item_read = fread (&g, (size_t)4,(size_t)1, fp); if ( item_read != 1 ) { - dbg.Verbose(1, "gdcmHeader::ReadInt32", " Failed to read :"); + dbg.Verbose(0, "gdcmHeader::ReadInt32", " Failed to read :"); if(feof(fp)) - dbg.Verbose(1, "gdcmHeader::ReadInt32", " End of File encountered"); + dbg.Verbose(0, "gdcmHeader::ReadInt32", " End of File encountered"); if(ferror(fp)) - dbg.Verbose(1, "gdcmHeader::ReadInt32", " File Error"); + dbg.Verbose(0, "gdcmHeader::ReadInt32", " File Error"); errno = 1; return 0; } @@ -1647,6 +1646,7 @@ int gdcmHeader::GetBitsStored(void) { return atoi(StrSize.c_str()); } + /** * \ingroup gdcmHeader * \brief Retrieve the number of Samples Per Pixel @@ -1661,6 +1661,24 @@ int gdcmHeader::GetSamplesPerPixel(void) { return atoi(StrSize.c_str()); } + +/* ================ COMMENT OUT after unfreeze +** + * \ingroup gdcmHeader + * \brief Retrieve the Planar Configuration for RGB images + * (0 : RGB Pixels , 1 : R Plane + G Plane + B Plane) + * + * @return The encountered Planar Configuration, 0 by default. + * +int gdcmHeader::GetPlanarConfiguration(void) { + string StrSize = GetPubElValByNumber(0x0028,0x0006); + if (StrSize == "gdcm::Unfound") + return 0; + return atoi(StrSize.c_str()); +} + + ======================================= */ + /** * \ingroup gdcmHeader * \brief Return the size (in bytes) of a single pixel of data. diff --git a/src/gdcmHeader.h b/src/gdcmHeader.h index ac2f6363..1657e70c 100644 --- a/src/gdcmHeader.h +++ b/src/gdcmHeader.h @@ -1,4 +1,4 @@ -// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.h,v 1.31 2003/07/01 15:14:36 frog Exp $ +// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.h,v 1.32 2003/07/02 16:47:22 jpr Exp $ #ifndef GDCMHEADER_H #define GDCMHEADER_H @@ -178,6 +178,11 @@ public: int GetZSize(void); int GetBitsStored(void); int GetSamplesPerPixel(void); + +/* ================ COMMENT OUT after unfreeze + int GetPlanarConfiguration(void); + ======================================= */ + int GetPixelSize(void); std::string GetPixelType(void); -- 2.48.1