X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=src%2FgdcmFile.cxx;h=32ef12b9af921513d04fdab8312a11780cf8b17a;hb=4b22e3b8d982d7d46d64aea9f71b2fd04b1a394d;hp=678a54940d0a676ab8676f3cb5ca6eafe2d651ab;hpb=29bdd1e88a28b6267618f633f304e1154537ce7b;p=gdcm.git diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 678a5494..32ef12b9 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,14 +56,19 @@ void gdcmFile::SetPixelDataSizeFromHeader(void) { nb = atoi(str_nb.c_str() ); if (nb == 12) nb =16; } - lgrTotale = GetXSize() * GetYSize() * GetZSize() * (nb/8)* GetSamplesPerPixel(); + 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 - std::string str_PhotometricInterpretation = gdcmHeader::GetPubElValByNumber(0x0028,0x0004); - if ( str_PhotometricInterpretation == "PALETTE COLOR " - || str_PhotometricInterpretation == "YBR_FULL") { // --> some more to be added !! + if (HasLUT()) { lgrTotale*=3; } } + // see PS 3.3-2003 : C.7.6.3.2.1 // // MONOCHROME1 @@ -84,18 +90,12 @@ 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 @@ -125,17 +125,45 @@ bool gdcmFile::ReadPixelData(void* destination) { if ( fseek(fp, GetPixelOffset(), SEEK_SET) == -1 ) { CloseFile(); return false; - } + } + + + // ---------------------- Compacted File (12 Bits Per Pixel) + + /* 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 + // ---------------------- 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; @@ -144,8 +172,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); @@ -153,74 +188,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; i255.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 { - // now, it's an RGB image - std::string spp = "3"; - gdcmHeader::SetPubElValByNumber(spp,0x0028,0x0002); - std::string rgb="RGB"; - gdcmHeader::SetPubElValByNumber(rgb,0x0028,0x0004); - - } else { // need to make RGB Pixels (?) - // from grey Pixels (?!) - // and Gray Lut (!?!) - unsigned char *lutGray =(unsigned char *)GetPubElValVoidAreaByNumber(0x0028,0x1200); - // Well . I'll wait till I find such an image - } + // need to make RGB Pixels from R,G,B Planes + // (all the Frames at a time) + + int l = GetXSize()*GetYSize()*GetZSize(); + + char * newDest = (char*) malloc(lgrTotale); + char * x = newDest; + char * a = (char *)destination; + char * b = a + l; + char * c = b + l; + + for (int j=0;j