X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmFile.cxx;h=4b22d148d7ec4823f52bdf2e5f1ae1fbc130241a;hb=f8c25fd447e8d2502521e06baae45be835ee7c1c;hp=522e3f54f8d5b3efadc3f84485ee510017eff09e;hpb=13fd600696872f088e41161308fe4e37df1a57bd;p=gdcm.git diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 522e3f54..4b22d148 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -2,7 +2,7 @@ #include "gdcmFile.h" #include "gdcmUtil.h" -#include "iddcmjpeg.h" // for the 'LibIDO' Jpeg LossLess +#include "jpeg/ljpg/jpegless.h" ///////////////////////////////////////////////////////////////// /** @@ -25,29 +25,30 @@ gdcmFile::gdcmFile(std::string & filename) :gdcmHeader(filename.c_str()) { - SetPixelDataSizeFromHeader(); + if (IsReadable()) + SetPixelDataSizeFromHeader(); } gdcmFile::gdcmFile(const char * filename) :gdcmHeader(filename) { - SetPixelDataSizeFromHeader(); + if (IsReadable()) + SetPixelDataSizeFromHeader(); } /** * \ingroup gdcmFile * \brief calcule la longueur (in bytes) A ALLOUER pour recevoir les - * pixels de l'image - * ou DES images dans le cas d'un multiframe - * ATTENTION : il ne s'agit PAS de la longueur du groupe des Pixels - * (dans le cas d'images compressees, elle n'a pas de sens). + * pixels de l'image ou DES images dans le cas d'un multiframe + * + * ATTENTION : il ne s'agit PAS de la longueur du groupe des Pixels + * (dans le cas d'images compressees, elle n'a pas de sens). * * @return longueur a allouer */ void gdcmFile::SetPixelDataSizeFromHeader(void) { int nb; std::string str_nb; - str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100); if (str_nb == GDCM_UNFOUND ) { nb = 16; @@ -55,12 +56,19 @@ void gdcmFile::SetPixelDataSizeFromHeader(void) { nb = atoi(str_nb.c_str() ); 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 " ) { + lgrTotale = lgrTotaleRaw = GetXSize() * GetYSize() * GetZSize() + * (nb/8)* GetSamplesPerPixel(); + std::string str_PhotometricInterpretation = + gdcmHeader::GetPubElValByNumber(0x0028,0x0004); + + /*if ( str_PhotometricInterpretation == "PALETTE COLOR " )*/ + // pb when undealt Segmented Palette Color + + if (HasLUT()) { lgrTotale*=3; } } + // see PS 3.3-2003 : C.7.6.3.2.1 // // MONOCHROME1 @@ -82,17 +90,26 @@ 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] // 0028|1203 [US] [Blue Palette Color Lookup Table Data] +///////////////////////////////////////////////////////////////// +/** + * \ingroup gdcmFile + * \brief Returns the size (in bytes) of required memory to hold + * \ the pixel data represented in this file, when user DOESN'T want + * \ to get RGB pixels image when it's stored as a PALETTE COLOR image + * \ - the (vtk) user is supposed to know how deal with LUTs - + * \ warning to be used with GetImagePixelsRaw() + * @return The size of pixel data in bytes. + */ + +size_t gdcmFile::GetImageDataSizeRaw(void) { + return (lgrTotaleRaw); +} ///////////////////////////////////////////////////////////////// /** @@ -123,17 +140,45 @@ bool gdcmFile::ReadPixelData(void* destination) { if ( fseek(fp, GetPixelOffset(), SEEK_SET) == -1 ) { CloseFile(); return false; - } + } + + + // ---------------------- Compacted File (12 Bits Per Pixel) -// ------------------------- Uncompressed File + /* unpack 12 Bits pixels into 16 Bits pixels */ + /* 2 pixels 12bit = [0xABCDEF] */ + /* 2 pixels 16bit = [0x0ABD] + [0x0FCE] */ + + if (GetBitsAllocated()==12) { + 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); + /* F */ /* C */ /* E */ + + // Troubles expected on Big-Endian processors ? + } + return(true); + } + + // ---------------------- Uncompressed File if ( !IsDicomV3() || IsImplicitVRLittleEndianTransferSyntax() || IsExplicitVRLittleEndianTransferSyntax() || IsExplicitVRBigEndianTransferSyntax() || - IsDeflatedExplicitVRLittleEndianTransferSyntax() ) { - - size_t ItemRead = fread(destination, lgrTotale, 1, fp); + IsDeflatedExplicitVRLittleEndianTransferSyntax() ) { + + size_t ItemRead = fread(destination, GetPixelAreaLength(), 1, fp); + if ( ItemRead != 1 ) { CloseFile(); return false; @@ -142,8 +187,15 @@ bool gdcmFile::ReadPixelData(void* destination) { return true; } } + + // ---------------------- Run Length Encoding + + if (gdcmHeader::IsRLELossLessTransferSyntax()) { + int res = (bool)gdcm_read_RLE_file (destination); + return res; + } - // ------------------------ Compressed File . + // --------------- SingleFrame/Multiframe JPEG Lossless/Lossy/2000 int nb; std::string str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100); @@ -151,74 +203,21 @@ bool gdcmFile::ReadPixelData(void* destination) { nb = 16; } else { nb = atoi(str_nb.c_str() ); - if (nb == 12) nb =16; + if (nb == 12) nb =16; // ?? 12 should be ACR-NEMA only ? } int nBytes= nb/8; - int taille = GetXSize() * GetYSize() * GetSamplesPerPixel(); - - - // ------------------------------- JPEG LossLess : call to Jpeg Libido - - if (IsJPEGLossless() /*&& GetZSize() == 1*/) { - - int ln; // Position on begining of Jpeg Pixels - fseek(fp,4,SEEK_CUR); // skipping (fffe,e000) : Basic Offset Table Item - fread(&ln,4,1,fp); - if(GetSwapCode()) - ln=SwapLong(ln); // Item length - fseek(fp,ln,SEEK_CUR); // skipping Basic Offset Table ('ln' bytes) - fseek(fp,4,SEEK_CUR); // skipping (fffe,e000) : First fragment Item Tag - fread(&ln,4,1,fp); // First fragment length (just to know) - if(GetSwapCode()) - ln=SwapLong(ln); - - ClbJpeg* jpg = _IdDcmJpegRead(fp); // TODO : find a 'full' one. - // (We use the LibIDO one :-( - if(jpg == NULL) { - CloseFile(); - return false; - } - int * dataJpg = jpg->DataImg; - - switch (nBytes) { - case 1: - { - unsigned short *dest = (unsigned short *)destination; - for (int i=0; iDataImg; - unsigned short *dest = (unsigned short *)destination; - switch (nBytes) { - case 1: - { - for (int i=0; i