From: jpr Date: Fri, 3 Oct 2003 07:46:06 +0000 (+0000) Subject: gdcmFile::GetImageDataIntoVector now X-Git-Tag: Version0.3.1~137 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=1ea4314b315a12c6b484cd38d23aa2bf57f544b3;p=gdcm.git gdcmFile::GetImageDataIntoVector now - deals with MultiFrames MultiFragments Run Length Encoded files - deals with YcBcR (YBR_FULL) files - deals with YBR_YBR_FULL_422 files (they work as RBG files ?!?) WARNING : nothing was checked for YBR_PARTIAL_422, YBR_ICT, YBR_RCT files. (no sample found :-( --- diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 678a5494..1051765f 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -56,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; } } @@ -427,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 tokens; + tokens.erase(tokens.begin(),tokens.end()); // clean any previous value + Tokenize ((const std::string)x, tokens, "\\"); + for (unsigned int i=0; i