From 83215515e2daebf8680f227829e16515f6441311 Mon Sep 17 00:00:00 2001 From: jpr Date: Thu, 30 Oct 2003 17:04:53 +0000 Subject: [PATCH] * FIX : a VC++ intended syntax modif broke the 12/12 Bytes expanding --- src/gdcmFile.cxx | 163 ++++++++++++++++++++--------------------------- 1 file changed, 69 insertions(+), 94 deletions(-) diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index e6e12b3e..da30b3d0 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -49,7 +49,6 @@ gdcmFile::gdcmFile(const char * filename) void gdcmFile::SetPixelDataSizeFromHeader(void) { int nb; std::string str_nb; - str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100); if (str_nb == GDCM_UNFOUND ) { nb = 16; @@ -65,6 +64,7 @@ void gdcmFile::SetPixelDataSizeFromHeader(void) { lgrTotale*=3; } } + // see PS 3.3-2003 : C.7.6.3.2.1 // // MONOCHROME1 @@ -86,11 +86,6 @@ void gdcmFile::SetPixelDataSizeFromHeader(void) { // 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] @@ -127,8 +122,9 @@ bool gdcmFile::ReadPixelData(void* destination) { CloseFile(); return false; } + -// ------------------------- Compacted File (12 Bits Per Pixel) + // ---------------------- Compacted File (12 Bits Per Pixel) /* unpack 12 Bits pixels into 16 Bits pixels */ /* 2 pixels 12bit = [0xABCDEF] */ @@ -138,12 +134,12 @@ bool gdcmFile::ReadPixelData(void* destination) { int nbPixels = GetXSize()*GetYSize(); unsigned char b0, b1, b2; + unsigned short int* pdestination = (unsigned short int*)destination; for(int p=0;p> 4) << 8) + ((b0 & 0x0f) << 4) + (b1 & 0x0f); /* A */ /* B */ /* D */ *pdestination++ = ((b2 & 0x0f) << 8) + ((b1 >> 4) << 4) + (b2 >> 4); @@ -152,18 +148,18 @@ bool gdcmFile::ReadPixelData(void* destination) { // Troubles expected on Big-Endian processors ? } return(true); - } - + } -// ------------------------- Uncompressed File + // ---------------------- Uncompressed File if ( !IsDicomV3() || IsImplicitVRLittleEndianTransferSyntax() || IsExplicitVRLittleEndianTransferSyntax() || IsExplicitVRBigEndianTransferSyntax() || IsDeflatedExplicitVRLittleEndianTransferSyntax() ) { - - size_t ItemRead = fread(destination, lgrTotale, 1, fp); + + size_t ItemRead = fread(destination, GetPixelAreaLength(), 1, fp); + if ( ItemRead != 1 ) { CloseFile(); return false; @@ -173,17 +169,14 @@ bool gdcmFile::ReadPixelData(void* destination) { } } - -// ------------------------- Run Length Encoding + // ---------------------- Run Length Encoding if (gdcmHeader::IsRLELossLessTransferSyntax()) { int res = (bool)gdcm_read_RLE_file (destination); return res; } - - -// ----------------- SingleFrame/Multiframe JPEG Lossless/Lossy/2000 + // --------------- SingleFrame/Multiframe JPEG Lossless/Lossy/2000 int nb; std::string str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100); @@ -307,6 +300,15 @@ void * gdcmFile::GetImageData (void) { * \ingroup gdcmFile * \brief Copies at most MaxSize bytes of pixel data to caller's * memory space. + * \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 + * 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 + * * @param destination Address (in caller's memory space) at which the * pixel data should be copied * @param MaxSize Maximum number of bytes to be copied. When MaxSize @@ -351,9 +353,8 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { highBit = nb - 1; } else { highBit = atoi(str_highBit.c_str() ); - } - - // Signe des Pixels + } + // Pixel sign // 0 = Unsigned // 1 = Signed str_signe=GetPubElValByNumber(0x0028,0x0103); @@ -403,12 +404,15 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { } } - -// Just to 'see' was was actually read on disk :-( +// Just to 'see' what was actually read on disk :-( // Some troubles expected +// FILE * f2; +// f2 = fopen("SpuriousFile.raw","wb"); +// fwrite(destination,lgrTotale,1,f2); +// fclose(f2); - // *Try* to deal with the color - // ---------------------------- + // Deal with the color + // ------------------- std::string str_PhotometricInterpretation = gdcmHeader::GetPubElValByNumber(0x0028,0x0004); @@ -442,8 +446,9 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { case 1: { - if (str_PhotometricInterpretation == "YBR_FULL") { // Warning : YBR_FULL_422 acts as RGB (?!) - + if (str_PhotometricInterpretation == "YBR_FULL") { + + // Warning : YBR_FULL_422 acts as RGB // need to make RGB Pixels from Planes Y,cB,cR // see http://lestourtereaux.free.fr/papers/data/yuvrgb.pdf // for code optimisation @@ -486,26 +491,22 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { } else { // need to make RGB Pixels from Planes R,G,B + // (all the Frames at a time) - int l = GetXSize()*GetYSize(); - int nbFrames = GetZSize(); + int l = GetXSize()*GetYSize()*GetZSize(); char * newDest = (char*) malloc(lgrTotale); - char *x = newDest; + 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