X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmFile.cxx;h=32ef12b9af921513d04fdab8312a11780cf8b17a;hb=48c3e6379fcb2517d56c15d51e45c4c79543c16c;hp=da30b3d0c4663eb998e0b942ac013b8547a49393;hpb=83215515e2daebf8680f227829e16515f6441311;p=gdcm.git diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index da30b3d0..32ef12b9 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -56,11 +56,15 @@ void gdcmFile::SetPixelDataSizeFromHeader(void) { nb = atoi(str_nb.c_str() ); if (nb == 12) nb =16; } - lgrTotale = GetXSize() * GetYSize() * GetZSize() + lgrTotale = lgrTotaleRaw = GetXSize() * GetYSize() * GetZSize() * (nb/8)* GetSamplesPerPixel(); std::string str_PhotometricInterpretation = gdcmHeader::GetPubElValByNumber(0x0028,0x0004); - if ( str_PhotometricInterpretation == "PALETTE COLOR " ) { + + /*if ( str_PhotometricInterpretation == "PALETTE COLOR " )*/ + // pb when undealt Segmented Palette Color + + if (HasLUT()) { lgrTotale*=3; } } @@ -286,6 +290,9 @@ bool gdcmFile::ReadPixelData(void* destination) { * \ingroup gdcmFile * \brief Allocates necessary memory, copies the pixel data * (image[s]/volume[s]) to newly allocated zone. + * Transforms YBR pixels into RGB pixels if any + Transforms 3 planes R, G, B into a single RGB Plane + Transforms single Grey plane + 3 Palettes into a RGB Plane * @return Pointer to newly allocated pixel data. * \ NULL if alloc fails */ @@ -296,6 +303,27 @@ void * gdcmFile::GetImageData (void) { return(PixelData); } +/** + * \ingroup gdcmFile + * \brief Allocates necessary memory, copies the pixel data + * (image[s]/volume[s]) to newly allocated zone. + * Transforms YBR pixels into RGB pixels if any + Transforms 3 planes R, G, B into a single RGB Plane + DOES NOT transform Grey plane + 3 Palettes into a RGB Plane + * @return Pointer to newly allocated pixel data. + * \ NULL if alloc fails + */ +void * gdcmFile::GetImageDataRaw (void) { + if (HasLUT()) + lgrTotale /= 3; // TODO Let gdcmHeadar user a chance + // to get the right value + // Create a member lgrTotaleRaw ??? + PixelData = (void *) malloc(lgrTotale); + if (PixelData) + GetImageDataIntoVectorRaw(PixelData, lgrTotale); + return(PixelData); +} + /** * \ingroup gdcmFile * \brief Copies at most MaxSize bytes of pixel data to caller's @@ -303,11 +331,11 @@ void * gdcmFile::GetImageData (void) { * \warning This function was designed to avoid people that want to build * a volume from an image stack to need first to get the image pixels * and then move them to the volume area. - * It's absolutely useless for VTK users since vtk chooses + * It's absolutely useless for any VTK user since vtk chooses * to invert the lines of an image, that is the last line comes first * (for some axis related reasons?). Hence he will have * to load the image line by line, starting from the end. - * VTK users hace to call GetImageData + * VTK users have to call GetImageData * * @param destination Address (in caller's memory space) at which the * pixel data should be copied @@ -320,6 +348,93 @@ void * gdcmFile::GetImageData (void) { size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { + size_t l = GetImageDataIntoVectorRaw (destination, MaxSize); + + if (!HasLUT()) + return lgrTotale; + + // from Lut R + Lut G + Lut B + + unsigned char * newDest = (unsigned char *)malloc(lgrTotale); + unsigned char * a = (unsigned char *)destination; + unsigned char * lutRGBA = (unsigned char *)GetLUTRGBA(); + if (lutRGBA) { + int l = lgrTotale/3; + memmove(newDest, destination, l);// move Gray pixels to temp area + int j; + for (int i=0;i