X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmFile.cxx;h=9351047766c5a75de5e3a692d031e20527ff8682;hb=2f30dd9c340a90310871d689c0e8fbebb55af567;hp=678a54940d0a676ab8676f3cb5ca6eafe2d651ab;hpb=29bdd1e88a28b6267618f633f304e1154537ce7b;p=gdcm.git diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 678a5494..93510477 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; } } @@ -162,7 +160,7 @@ bool gdcmFile::ReadPixelData(void* destination) { // ------------------------------- JPEG LossLess : call to Jpeg Libido - if (IsJPEGLossless() && GetZSize() == 1) { + if (IsJPEGLossless() /*&& GetZSize() == 1*/) { int ln; // Position on begining of Jpeg Pixels fseek(fp,4,SEEK_CUR); // skipping (fffe,e000) : Basic Offset Table Item @@ -427,98 +425,170 @@ 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 + // *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