X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmFile.cxx;h=88dcdf6a04a02a7ac6ad7fac2db59db677c6674a;hb=a18a9f20d96301e1c91be637415599e5fdc1ca43;hp=ddde9fe44edd128eaf2c2157508876e15d136801;hpb=eb941e8785d3742b8a6a1aac964d43dcb4cf49f0;p=gdcm.git diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index ddde9fe4..88dcdf6a 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -1,23 +1,8 @@ // gdcmFile.cxx -//This is needed when compiling in debug mode -#ifdef _MSC_VER -// 'type' : forcing value to bool 'true' or 'false' (performance warning) -//#pragma warning ( disable : 4800 ) -// 'identifier' : class 'type' needs to have dll-interface to be used by -// clients of class 'type2' -#pragma warning ( disable : 4251 ) -// 'identifier' : identifier was truncated to 'number' characters in the -// debug information -#pragma warning ( disable : 4786 ) -#endif //_MSC_VER - #include "gdcmFile.h" #include "gdcmUtil.h" #include "iddcmjpeg.h" // for the 'LibIDO' Jpeg LossLess -using namespace std; - -#define str2num(str, typeNum) *((typeNum *)(str)) ///////////////////////////////////////////////////////////////// /** @@ -37,7 +22,7 @@ using namespace std; * @return */ -gdcmFile::gdcmFile(string & filename) +gdcmFile::gdcmFile(std::string & filename) :gdcmHeader(filename.c_str()) { SetPixelDataSizeFromHeader(); @@ -54,35 +39,60 @@ gdcmFile::gdcmFile(const char * filename) * \brief calcule la longueur (in bytes) A ALLOUER pour recevoir les * pixels de l'image * ou DES images dans le cas d'un multiframe - * ATTENTION : il ne s'agit PAS de la longueur du groupe des Pixels + * ATTENTION : il ne s'agit PAS de la longueur du groupe des Pixels * (dans le cas d'images compressees, elle n'a pas de sens). * * @return longueur a allouer */ void gdcmFile::SetPixelDataSizeFromHeader(void) { int nb; - string str_nb; + std::string str_nb; str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100); - if (str_nb == "gdcm::Unfound" ) { + if (str_nb == GDCM_UNFOUND ) { nb = 16; } else { nb = atoi(str_nb.c_str() ); if (nb == 12) nb =16; } lgrTotale = GetXSize() * GetYSize() * GetZSize() * (nb/8)* GetSamplesPerPixel(); - - string str_PhotometricInterpretation = gdcmHeader::GetPubElValByNumber(0x0028,0x0004); - if ( str_PhotometricInterpretation == "PALETTE COLOR " - || str_PhotometricInterpretation == "YBR_FULL") { // --> some more to be added !! + std::string str_PhotometricInterpretation = gdcmHeader::GetPubElValByNumber(0x0028,0x0004); + if ( str_PhotometricInterpretation == "PALETTE COLOR " ) { lgrTotale*=3; } - - // remaining to check : - // str_PhotometricInterpretation == "YBR_FULL" - // str_PhotometricInterpretation == "YBR_FULL_422" (no LUT, no Palette) - // -->and some more !! } + // see PS 3.3-2003 : C.7.6.3.2.1 + // + // MONOCHROME1 + // MONOCHROME2 + // PALETTE COLOR + // RGB + // HSV (Retired) + // ARGB (Retired) + // CMYK (Retired) + // YBR_FULL + // YBR_FULL_422 (no LUT, no Palette) + // YBR_PARTIAL_422 + // YBR_ICT + // YBR_RCT + + // LUT's + // ex : gdcm-US-ALOKA-16.dcm + // 0028|1221 [OW] [Segmented Red Palette Color Lookup Table Data] + // 0028|1222 [OW] [Segmented Green Palette Color Lookup Table Data] + // 0028|1223 [OW] [Segmented Blue Palette Color Lookup Table Data] + + // ex : US-PAL-8-10x-echo.dcm, 8BitsRunLengthColor.dcm + // 0028|1201 [OW] [Red Palette Color Lookup Table Data] + // 0028|1202 [OW] [Green Palette Color Lookup Table Data] + // 0028|1203 [OW] [Blue Palette Color Lookup Table Data] + + // ex : OT-PAL-8-face.dcm + // 0028|1201 [US] [Red Palette Color Lookup Table Data] + // 0028|1202 [US] [Green Palette Color Lookup Table Data] + // 0028|1203 [US] [Blue Palette Color Lookup Table Data] + + ///////////////////////////////////////////////////////////////// /** @@ -91,127 +101,12 @@ void gdcmFile::SetPixelDataSizeFromHeader(void) { * the pixel data represented in this file. * @return The size of pixel data in bytes. */ + size_t gdcmFile::GetImageDataSize(void) { return (lgrTotale); } -///////////////////////////////////////////////////////////////// -/** - * \ingroup gdcmFile - * \brief Parse pixel data from disk and *prints* the result - * \ For multi-fragment Jpeg files checking purpose *only* - * \ Allows to 'see' if the file *does* conform - * \ (some of them do not) - * \ with Dicom Part 3, Annex A (PS 3.5-2003, page 58) - * - */ -bool gdcmFile::ParsePixelData(void) { - if ( !OpenFile()) - return false; - - if ( fseek(fp, GetPixelOffset(), SEEK_SET) == -1 ) { - CloseFile(); - return false; - } - - if ( !IsDicomV3() || - IsImplicitVRLittleEndianTransferSyntax() || - IsExplicitVRLittleEndianTransferSyntax() || - IsExplicitVRBigEndianTransferSyntax() || - IsDeflatedExplicitVRLittleEndianTransferSyntax() ) { - - printf ("gdcmFile::ParsePixelData : non JPEG File\n"); - return 0; - } - - int nb; - string str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100); - if (str_nb == "gdcm::Unfound" ) { - nb = 16; - } else { - nb = atoi(str_nb.c_str() ); - if (nb == 12) nb =16; - } - int nBytes= nb/8; - - //int taille = GetXSize() * GetYSize() * GetZSize() * GetSamplesPerPixel(); - int taille = GetXSize() * GetYSize() * GetSamplesPerPixel(); - - printf ("Checking the Dicom-Jpeg/RLE Pixels\n"); - - // ------------------------------- for Parsing : Position on begining of Jpeg Pixels - guint16 ItemTagGr,ItemTagEl; - int ln; - long ftellRes; - char * destination = NULL; - ftellRes=ftell(fp); - fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Basic Offset Table Item Tag Gr - fread(&ItemTagEl,2,1,fp); // Reading (e000) : Basic Offset Table Item Tag El - if(GetSwapCode()) { - ItemTagGr=SwapShort(ItemTagGr); - ItemTagEl=SwapShort(ItemTagEl); - } - printf ("at %x : ItemTag (should be fffe,e000): %04x,%04x\n", - ftellRes,ItemTagGr,ItemTagEl ); - ftellRes=ftell(fp); - fread(&ln,4,1,fp); - if(GetSwapCode()) - ln=SwapLong(ln); // Basic Offset Table Item Lentgh - printf("at %x : Basic Offset Table Item Lentgh (??) %d x(%08x)\n", - ftellRes,ln,ln); - if (ln != 0) { - // What is it used for ?? - char * BasicOffsetTableItemValue= (char *)malloc(ln+1); - fread(BasicOffsetTableItemValue,ln,1,fp); - guint32 a; - for (int i=0;i MaxSize ) { dbg.Verbose(0, "gdcmFile::GetImageDataIntoVector: pixel data bigger" @@ -472,7 +368,7 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { // Nombre de Bits Alloues pour le stockage d'un Pixel str_nb = GetPubElValByNumber(0x0028,0x0100); - if (str_nb == "gdcm::Unfound" ) { + if (str_nb == GDCM_UNFOUND ) { nb = 16; } else { nb = atoi(str_nb.c_str() ); @@ -480,7 +376,7 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { // Nombre de Bits Utilises str_nbu=GetPubElValByNumber(0x0028,0x0101); - if (str_nbu == "gdcm::Unfound" ) { + if (str_nbu == GDCM_UNFOUND ) { nbu = nb; } else { nbu = atoi(str_nbu.c_str() ); @@ -488,7 +384,7 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { // Position du Bit de Poids Fort str_highBit=GetPubElValByNumber(0x0028,0x0102); - if (str_highBit == "gdcm::Unfound" ) { + if (str_highBit == GDCM_UNFOUND ) { highBit = nb - 1; } else { highBit = atoi(str_highBit.c_str() ); @@ -496,7 +392,7 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { // Signe des Pixels str_signe=GetPubElValByNumber(0x0028,0x0103); - if (str_signe == "gdcm::Unfound" ) { + if (str_signe == GDCM_UNFOUND ) { signe = 1; } else { signe = atoi(str_signe.c_str() ); @@ -529,94 +425,176 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { dbg.Verbose(0, "gdcmFile::GetImageDataIntoVector: wierd image"); return (size_t)0; } - } - - // Try to deal with the color - // -------------------------- - - string str_PhotometricInterpretation = gdcmHeader::GetPubElValByNumber(0x0028,0x0004); - - if ( (str_PhotometricInterpretation == "MONOCHROME1 ") - || (str_PhotometricInterpretation == "MONOCHROME2 ") - || (str_PhotometricInterpretation == "RGB")) { - return lgrTotale; - } - - switch ( GetPlanarConfiguration() ) { - case 0: - // Pixels are already RGB - break; + } + +// Just to 'see' was was actually read on disk :-( +// Some troubles expected + +FILE * fpSpurious; +fpSpurious=fopen("SpuriousFile.raw","w"); +fwrite(destination,lgrTotale, 1,fpSpurious); +fclose(fpSpurious); + + + // *Try* to deal with the color + // ---------------------------- + + // Planar configuration = 0 : Pixels are already RGB + // Planar configuration = 1 : 3 planes : R, G, B + // Planar configuration = 2 : 1 gray Plane + 3 LUT + + // Well ... supposed to be ! + // See US-PAL-8-10x-echo.dcm: PlanarConfiguration=0,PhotometricInterpretation=PALETTE COLOR + // and heuristic has to be found :-( + + std::string str_PhotometricInterpretation = gdcmHeader::GetPubElValByNumber(0x0028,0x0004); - case 1: - // need to make RGB Pixels from Planes R,G,B - { - 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 j=0;j255.0) R=255.0; + if (G>255.0) G=255.0; + if (B>255.0) B=255.0; + + *(x++) = (unsigned char)R; + *(x++) = (unsigned char)G; + *(x++) = (unsigned char)B; + a++; b++; c++; + } + } + memmove(destination,newDest,lgrTotale); + free(newDest); + + } else { + + // need to make RGB Pixels from Planes R,G,B + + int l = GetXSize()*GetYSize(); + int nbFrames = GetZSize(); + + char * newDest = (char*) malloc(lgrTotale); + char *x = newDest; + char * a = (char *)destination; + char * b = a + l; + char * c = b + l; + + // TODO : + // any trick not to have to allocate temporary buffer is welcome ... + + for (int i=0;i