X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmFile.cxx;h=88dcdf6a04a02a7ac6ad7fac2db59db677c6674a;hb=a18a9f20d96301e1c91be637415599e5fdc1ca43;hp=475ec04ecf74c3cc5b659bed0568a20687cb2f52;hpb=48d629b49cc690bcd26f6721f38af0ca876be417;p=gdcm.git diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 475ec04e..88dcdf6a 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -1,17 +1,5 @@ // 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 @@ -68,10 +56,8 @@ void gdcmFile::SetPixelDataSizeFromHeader(void) { if (nb == 12) nb =16; } lgrTotale = GetXSize() * GetYSize() * GetZSize() * (nb/8)* GetSamplesPerPixel(); - std::string str_PhotometricInterpretation = gdcmHeader::GetPubElValByNumber(0x0028,0x0004); - if ( str_PhotometricInterpretation == "PALETTE COLOR " - || str_PhotometricInterpretation == "YBR_FULL") { // --> some more to be added !! + if ( str_PhotometricInterpretation == "PALETTE COLOR " ) { lgrTotale*=3; } } @@ -439,98 +425,176 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { dbg.Verbose(0, "gdcmFile::GetImageDataIntoVector: wierd image"); return (size_t)0; } - } - + } + +// 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 - // -------------------------- - - std::string str_PhotometricInterpretation = gdcmHeader::GetPubElValByNumber(0x0028,0x0004); - - if ( (str_PhotometricInterpretation == "MONOCHROME1 ") - || (str_PhotometricInterpretation == "MONOCHROME2 ") - || (str_PhotometricInterpretation == "RGB")) { - return lgrTotale; - } - int planConf=GetPlanarConfiguration(); + // ---------------------------- - if( str_PhotometricInterpretation!="PALETTE COLOR" && planConf == 0) - planConf=2; // Sorry, this is an heuristic - - switch ( planConf) { - case 0: - // Pixels are already RGB - break; + // 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); + + if ( (str_PhotometricInterpretation == "MONOCHROME1 ") + || (str_PhotometricInterpretation == "MONOCHROME2 ") + || (str_PhotometricInterpretation == "RGB")) { + return lgrTotale; + } + int planConf=GetPlanarConfiguration(); + + switch (planConf) { + case 0: + // Pixels are already RGB + break; - 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