From 48d629b49cc690bcd26f6721f38af0ca876be417 Mon Sep 17 00:00:00 2001 From: jpr Date: Thu, 25 Sep 2003 18:06:49 +0000 Subject: [PATCH] -->File gdcmParse.cxx added gdcmFile::ParsePixelData(void); display the result of Dicom-encapsulated JPEG or RLE files 'Pixels Element' parsing. For checking purpose only. -->modif to improve the processing of multi-Frames multi-Segments compressed files. --- src/Makefile.am | 33 +++--- src/config.h | 83 ++++--------- src/config.h.in | 83 ++++--------- src/gdcmFile.cxx | 290 +++++++--------------------------------------- src/gdcmParse.cxx | 246 +++++++++++++++++++++++++++++++++++++++ src/gdcmRLE.cxx | 76 ++++++------ 6 files changed, 390 insertions(+), 421 deletions(-) create mode 100644 src/gdcmParse.cxx diff --git a/src/Makefile.am b/src/Makefile.am index 6d005201..6c1881ad 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,25 +30,26 @@ libgdcm_la_SOURCES= \ gdcmJpeg12.cxx \ gdcmJpeg2000.cxx \ gdcmRLE.cxx \ + gdcmParse.cxx \ gdcmJpegIdo.cxx libgdcmincludedir = $(includedir) -libgdcminclude_HEADERS = \ - gdcmException.h \ - gdcmHeader.h \ - gdcmHeaderHelper.h \ - gdcmCommon.h \ - gdcm.h \ - gdcmDictSet.h \ - gdcmDict.h \ - gdcmDictEntry.h \ - gdcmElValue.h \ - gdcmElValSet.h \ - gdcmVR.h \ - gdcmTS.h \ +libgdcminclude_HEADERS = \ + gdcmException.h \ + gdcmHeader.h \ + gdcmHeaderHelper.h \ + gdcmCommon.h \ + gdcm.h \ + gdcmDictSet.h \ + gdcmDict.h \ + gdcmDictEntry.h \ + gdcmElValue.h \ + gdcmElValSet.h \ + gdcmVR.h \ + gdcmTS.h \ gdcmFile.h -EXTRA_DIST = \ - gdcmUtil.h \ - gdcmIdo.h \ +EXTRA_DIST = \ + gdcmUtil.h \ + gdcmIdo.h \ iddcmjpeg.h diff --git a/src/config.h b/src/config.h index aec099d7..52353876 100644 --- a/src/config.h +++ b/src/config.h @@ -1,84 +1,43 @@ /* src/config.h. Generated automatically by configure. */ -/* src/config.h.in. Generated from configure.in by autoheader. */ +/* src/config.h.in. Generated automatically from configure.in by autoheader. */ -/* Define to 1 if you have the header file. */ -#define HAVE_DLFCN_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_INTTYPES_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_MEMORY_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_STDINT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_STDLIB_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_STRINGS_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_STRING_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_STAT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_TYPES_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_UNISTD_H */ - -/* Name of package */ -#define PACKAGE "gdcm" - -/* Define to the address where bug reports for this package should be sent. */ -/* #undef PACKAGE_BUGREPORT */ +/* Define to empty if the keyword does not work. */ +/* #undef const */ -/* Define to the full name of this package. */ -/* #undef PACKAGE_NAME */ +/* Define to `unsigned' if doesn't define. */ +/* #undef size_t */ -/* Define to the full name and version of this package. */ -/* #undef PACKAGE_STRING */ +/* Define if you have the ANSI C header files. */ +#define STDC_HEADERS 1 -/* Define to the one symbol short name of this package. */ -/* #undef PACKAGE_TARNAME */ +/* Define if your declares struct tm. */ +/* #undef TM_IN_SYS_TIME */ -/* Define to the version of this package. */ -/* #undef PACKAGE_VERSION */ +/* Define if your processor stores words with the most significant + byte first (like Motorola and SPARC, unlike Intel and VAX). */ +/* #undef WORDS_BIGENDIAN */ -/* The size of a `char', as computed by sizeof. */ +/* The number of bytes in a char. */ #define SIZEOF_CHAR 1 -/* The size of a `int', as computed by sizeof. */ +/* The number of bytes in a int. */ #define SIZEOF_INT 4 -/* The size of a `long', as computed by sizeof. */ +/* The number of bytes in a long. */ #define SIZEOF_LONG 4 -/* The size of a `long long', as computed by sizeof. */ +/* The number of bytes in a long long. */ #define SIZEOF_LONG_LONG 8 -/* The size of a `short', as computed by sizeof. */ +/* The number of bytes in a short. */ #define SIZEOF_SHORT 2 -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 +/* Define if you have the header file. */ +#define HAVE_DLFCN_H 1 -/* Define to 1 if your declares `struct tm'. */ -/* #undef TM_IN_SYS_TIME */ +/* Name of package */ +#define PACKAGE "gdcm" /* Version number of package */ #define VERSION "0.3.0" -/* Define to 1 if your processor stores words with the most significant byte - first (like Motorola and SPARC, unlike Intel and VAX). */ -/* #undef WORDS_BIGENDIAN */ - -/* Define to empty if `const' does not conform to ANSI C. */ -/* #undef const */ - -/* Define to `unsigned' if does not define. */ -/* #undef size_t */ diff --git a/src/config.h.in b/src/config.h.in index 5a0d619b..552bf6bc 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -1,83 +1,42 @@ -/* src/config.h.in. Generated from configure.in by autoheader. */ +/* src/config.h.in. Generated automatically from configure.in by autoheader. */ -/* Define to 1 if you have the header file. */ -#undef HAVE_DLFCN_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_INTTYPES_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDINT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDLIB_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRING_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_STAT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TYPES_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_UNISTD_H - -/* Name of package */ -#undef PACKAGE - -/* Define to the address where bug reports for this package should be sent. */ -#undef PACKAGE_BUGREPORT +/* Define to empty if the keyword does not work. */ +#undef const -/* Define to the full name of this package. */ -#undef PACKAGE_NAME +/* Define to `unsigned' if doesn't define. */ +#undef size_t -/* Define to the full name and version of this package. */ -#undef PACKAGE_STRING +/* Define if you have the ANSI C header files. */ +#undef STDC_HEADERS -/* Define to the one symbol short name of this package. */ -#undef PACKAGE_TARNAME +/* Define if your declares struct tm. */ +#undef TM_IN_SYS_TIME -/* Define to the version of this package. */ -#undef PACKAGE_VERSION +/* Define if your processor stores words with the most significant + byte first (like Motorola and SPARC, unlike Intel and VAX). */ +#undef WORDS_BIGENDIAN -/* The size of a `char', as computed by sizeof. */ +/* The number of bytes in a char. */ #undef SIZEOF_CHAR -/* The size of a `int', as computed by sizeof. */ +/* The number of bytes in a int. */ #undef SIZEOF_INT -/* The size of a `long', as computed by sizeof. */ +/* The number of bytes in a long. */ #undef SIZEOF_LONG -/* The size of a `long long', as computed by sizeof. */ +/* The number of bytes in a long long. */ #undef SIZEOF_LONG_LONG -/* The size of a `short', as computed by sizeof. */ +/* The number of bytes in a short. */ #undef SIZEOF_SHORT -/* Define to 1 if you have the ANSI C header files. */ -#undef STDC_HEADERS +/* Define if you have the header file. */ +#undef HAVE_DLFCN_H -/* Define to 1 if your declares `struct tm'. */ -#undef TM_IN_SYS_TIME +/* Name of package */ +#undef PACKAGE /* Version number of package */ #undef VERSION -/* Define to 1 if your processor stores words with the most significant byte - first (like Motorola and SPARC, unlike Intel and VAX). */ -#undef WORDS_BIGENDIAN - -/* Define to empty if `const' does not conform to ANSI C. */ -#undef const - -/* Define to `unsigned' if does not define. */ -#undef size_t diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 43d8c3a1..475ec04e 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -16,8 +16,6 @@ #include "gdcmUtil.h" #include "iddcmjpeg.h" // for the 'LibIDO' Jpeg LossLess -#define str2num(str, typeNum) *((typeNum *)(str)) - ///////////////////////////////////////////////////////////////// /** * \ingroup gdcmFile @@ -53,7 +51,7 @@ gdcmFile::gdcmFile(const char * filename) * \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 + * 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 @@ -76,12 +74,39 @@ void gdcmFile::SetPixelDataSizeFromHeader(void) { || str_PhotometricInterpretation == "YBR_FULL") { // --> some more to be added !! lgrTotale*=3; } - - // remaining to check : - // str_PhotometricInterpretation == "YBR_FULL" - // str_PhotometricInterpretation == "YBR_FULL_422" (no LUT, no Palette) - // -->and some more !! } + // see PS 3.3-2003 : C.7.6.3.2.1 + // + // MONOCHROME1 + // MONOCHROME2 + // PALETTE COLOR + // RGB + // HSV (Retired) + // ARGB (Retired) + // CMYK (Retired) + // YBR_FULL + // YBR_FULL_422 (no LUT, no Palette) + // YBR_PARTIAL_422 + // YBR_ICT + // YBR_RCT + + // LUT's + // ex : gdcm-US-ALOKA-16.dcm + // 0028|1221 [OW] [Segmented Red Palette Color Lookup Table Data] + // 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] + + ///////////////////////////////////////////////////////////////// /** @@ -90,241 +115,12 @@ void gdcmFile::SetPixelDataSizeFromHeader(void) { * the pixel data represented in this file. * @return The size of pixel data in bytes. */ + size_t gdcmFile::GetImageDataSize(void) { return (lgrTotale); } -///////////////////////////////////////////////////////////////// -/** - * \ingroup gdcmFile - * \brief Parse pixel data from disk and *prints* the result - * \ For multi-fragment Jpeg/Rle files checking purpose *only* - * \ Allows to 'see' if the file *does* conform - * \ (some of them do not) - * \ with Dicom Part 3, Annex A (PS 3.5-2003, page 58, page 85) - * - */ -bool gdcmFile::ParsePixelData(void) { - - if ( !OpenFile()) - return false; - - if ( fseek(fp, GetPixelOffset(), SEEK_SET) == -1 ) { - CloseFile(); - return false; - } - - if ( !IsDicomV3() || - IsImplicitVRLittleEndianTransferSyntax() || - IsExplicitVRLittleEndianTransferSyntax() || - IsExplicitVRBigEndianTransferSyntax() || - IsDeflatedExplicitVRLittleEndianTransferSyntax() ) { - - printf ("gdcmFile::ParsePixelData : non JPEG/RLE File\n"); - return 0; - } - - int nb; - std::string str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100); - if (str_nb == GDCM_UNFOUND ) { - nb = 16; - } else { - nb = atoi(str_nb.c_str() ); - if (nb == 12) nb =16; - } - int nBytes= nb/8; - - //int taille = GetXSize() * GetYSize() * GetZSize() * GetSamplesPerPixel(); - int taille = GetXSize() * GetYSize() * GetSamplesPerPixel(); - - printf ("Checking the Dicom-Jpeg/RLE Pixels\n"); - - guint16 ItemTagGr,ItemTagEl; - int ln; - long ftellRes; - char * destination = NULL; - - // ------------------------------- for Parsing : Position on begining of Jpeg/RLE Pixels - - if( !IsRLELossLessTransferSyntax()) { - - // JPEG Image - - std::cout << "JPEG image" << std::endl; - ftellRes=ftell(fp); - fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Basic Offset Table Item Tag Gr - fread(&ItemTagEl,2,1,fp); // Reading (e000) : Basic Offset Table Item Tag El - if(GetSwapCode()) { - ItemTagGr=SwapShort(ItemTagGr); - ItemTagEl=SwapShort(ItemTagEl); - } - printf ("at %x : ItemTag (should be fffe,e000): %04x,%04x\n", - ftellRes,ItemTagGr,ItemTagEl ); - ftellRes=ftell(fp); - fread(&ln,4,1,fp); - if(GetSwapCode()) - ln=SwapLong(ln); // Basic Offset Table Item Lentgh - printf("at %x : Basic Offset Table Item Lentgh (??) %d x(%08x)\n", - ftellRes,ln,ln); - if (ln != 0) { - // What is it used for ?? - char * BasicOffsetTableItemValue= (char *)malloc(ln+1); - fread(BasicOffsetTableItemValue,ln,1,fp); - guint32 a; - for (int i=0;i1) { - for(int k=1; k<=nbRleSegments-1; k++) { // skipping (not reading) RLE Segments - RleSegmentLength[k]=RleSegmentOffsetTable[k+1]-RleSegmentOffsetTable[k]; - ftellRes=ftell(fp); - printf (" Segment %d : Length = %d Start at %x\n", - k,RleSegmentLength[k], ftellRes); - fseek(fp,RleSegmentLength[k],SEEK_CUR); - } - } - RleSegmentLength[nbRleSegments] = fragmentLength - RleSegmentOffsetTable[nbRleSegments] ; - // TODO : Check the value - ftellRes=ftell(fp); - printf (" Segment %d : Length = %d Start at %x\n", - nbRleSegments,RleSegmentLength[nbRleSegments],ftellRes); - - fseek(fp,RleSegmentLength[nbRleSegments],SEEK_CUR); - - // ------------------ end of scanning fragment pixels - - ftellRes=ftell(fp); - fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr - fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El - if(GetSwapCode()) { - ItemTagGr=SwapShort(ItemTagGr); - ItemTagEl=SwapShort(ItemTagEl); - } - printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n", - ftellRes,ItemTagGr,ItemTagEl ); - } - } - return 1; -} - ///////////////////////////////////////////////////////////////// /** * \ingroup gdcmFile @@ -373,7 +169,6 @@ bool gdcmFile::ReadPixelData(void* destination) { } int nBytes= nb/8; - //int taille = GetXSize() * GetYSize() * GetZSize() * GetSamplesPerPixel(); int taille = GetXSize() * GetYSize() * GetSamplesPerPixel(); @@ -478,10 +273,11 @@ bool gdcmFile::ReadPixelData(void* destination) { if (b) res = (bool)gdcm_read_JPEG2000_file (destination); // Reading Fragment pixels - else if (IsJPEGLossless()) { // ------------- call to LibIDO Jpeg for each Frame/fragment + else if (IsJPEGLossless()) { + // ------------- call to LibIDO Jpeg for each Frame/fragment - // Warning : Works only if there is one fragment per frame - // (Or a single fragment for the multiframe file) + // Warning : Works only if there is one fragment per frame + // (Or a single fragment for the multiframe file) ClbJpeg* jpg = _IdDcmJpegRead(fp); // TODO : find a 'full' one. // (We use the LibIDO one :-( if(jpg == NULL) { @@ -645,7 +441,7 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { } } - // Try to deal with the color + // *Try* to deal with the color // -------------------------- std::string str_PhotometricInterpretation = gdcmHeader::GetPubElValByNumber(0x0028,0x0004); @@ -655,12 +451,16 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) { || (str_PhotometricInterpretation == "RGB")) { return lgrTotale; } + int planConf=GetPlanarConfiguration(); + + if( str_PhotometricInterpretation!="PALETTE COLOR" && planConf == 0) + planConf=2; // Sorry, this is an heuristic - switch ( GetPlanarConfiguration() ) { + switch ( planConf) { case 0: // Pixels are already RGB break; - + case 1: // need to make RGB Pixels from Planes R,G,B { diff --git a/src/gdcmParse.cxx b/src/gdcmParse.cxx new file mode 100644 index 00000000..0682f2cb --- /dev/null +++ b/src/gdcmParse.cxx @@ -0,0 +1,246 @@ +// gdcmParse.cxx + +//This is needed when compiling in debug mode +#ifdef _MSC_VER +// 'type' : forcing value to bool 'true' or 'false' (performance warning) +//#pragma warning ( disable : 4800 ) +// 'identifier' : class 'type' needs to have dll-interface to be used by +// clients of class 'type2' +#pragma warning ( disable : 4251 ) +// 'identifier' : identifier was truncated to 'number' characters in the +// debug information +#pragma warning ( disable : 4786 ) +#endif //_MSC_VER + +#include "gdcmFile.h" +#include "gdcmUtil.h" +#include "iddcmjpeg.h" // for the 'LibIDO' Jpeg LossLess + +#define str2num(str, typeNum) *((typeNum *)(str)) + +///////////////////////////////////////////////////////////////// +/** + * \ingroup gdcmFile + * \brief Parse pixel data from disk and *prints* the result + * \ For multi-fragment Jpeg/Rle files checking purpose *only* + * \ Allows to 'see' if the file *does* conform + * \ (some of them do not) + * \ with Dicom Part 3, Annex A (PS 3.5-2003, page 58, page 85) + * + */ +bool gdcmFile::ParsePixelData(void) { + + if ( !OpenFile()) + return false; + + if ( fseek(fp, GetPixelOffset(), SEEK_SET) == -1 ) { + CloseFile(); + return false; + } + + if ( !IsDicomV3() || + IsImplicitVRLittleEndianTransferSyntax() || + IsExplicitVRLittleEndianTransferSyntax() || + IsExplicitVRBigEndianTransferSyntax() || + IsDeflatedExplicitVRLittleEndianTransferSyntax() ) { + + printf ("gdcmFile::ParsePixelData : non JPEG/RLE File\n"); + return 0; + } + + int nb; + std::string str_nb=gdcmHeader::GetPubElValByNumber(0x0028,0x0100); + if (str_nb == GDCM_UNFOUND ) { + nb = 16; + } else { + nb = atoi(str_nb.c_str() ); + if (nb == 12) nb =16; + } + int nBytes= nb/8; + + int taille = GetXSize() * GetYSize() * GetSamplesPerPixel(); + + printf ("Checking the Dicom-encapsulated Jpeg/RLE Pixels\n"); + + guint16 ItemTagGr,ItemTagEl; + int ln; + long ftellRes; + char * destination = NULL; + + // ------------------------------- for Parsing : Position on begining of Jpeg/RLE Pixels + + if( !IsRLELossLessTransferSyntax()) { + + // JPEG Image + + std::cout << "JPEG image" << std::endl; + ftellRes=ftell(fp); + fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Basic Offset Table Item Tag Gr + fread(&ItemTagEl,2,1,fp); // Reading (e000) : Basic Offset Table Item Tag El + if(GetSwapCode()) { + ItemTagGr=SwapShort(ItemTagGr); + ItemTagEl=SwapShort(ItemTagEl); + } + printf ("at %x : ItemTag (should be fffe,e000): %04x,%04x\n", + ftellRes,ItemTagGr,ItemTagEl ); + ftellRes=ftell(fp); + fread(&ln,4,1,fp); + if(GetSwapCode()) + ln=SwapLong(ln); // Basic Offset Table Item Lentgh + printf("at %x : Basic Offset Table Item Lentgh (??) %d x(%08x)\n", + ftellRes,ln,ln); + if (ln != 0) { + // What is it used for ?? + char * BasicOffsetTableItemValue= (char *)malloc(ln+1); + fread(BasicOffsetTableItemValue,ln,1,fp); + guint32 a; + for (int i=0;i1) { + for(int k=1; k<=nbRleSegments-1; k++) { // skipping (not reading) RLE Segments + RleSegmentLength[k]=RleSegmentOffsetTable[k+1]-RleSegmentOffsetTable[k]; + ftellRes=ftell(fp); + printf (" Segment %d : Length = %d x(%x) Start at %x\n", + k,RleSegmentLength[k],RleSegmentLength[k], ftellRes); + fseek(fp,RleSegmentLength[k],SEEK_CUR); + } + } + RleSegmentLength[nbRleSegments] = fragmentLength - RleSegmentOffsetTable[nbRleSegments] ; + // TODO : Check the value + ftellRes=ftell(fp); + printf (" Segment %d : Length = %d x(%x) Start at %x\n", + nbRleSegments,RleSegmentLength[nbRleSegments], + RleSegmentLength[nbRleSegments],ftellRes); + + fseek(fp,RleSegmentLength[nbRleSegments],SEEK_CUR); + + // ------------------ end of scanning fragment pixels + + ftellRes=ftell(fp); + fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr + fread(&ItemTagEl,2,1,fp); // Reading (e000) : Item Tag El + if(GetSwapCode()) { + ItemTagGr=SwapShort(ItemTagGr); + ItemTagEl=SwapShort(ItemTagEl); + } + printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n", + ftellRes,ItemTagGr,ItemTagEl ); + } + } + return 1; +} diff --git a/src/gdcmRLE.cxx b/src/gdcmRLE.cxx index 3a0f2ed0..7bdcee60 100644 --- a/src/gdcmRLE.cxx +++ b/src/gdcmRLE.cxx @@ -20,6 +20,9 @@ static int _gdcm_read_RLE_fragment (char ** image_buffer, FILE* fp); // static because nothing but gdcm_read_RLE_file may call it +#define DEBUG 0 +// Will be removed + // ---------------------------------------------------------------------------- /** * \ingroup gdcmFile @@ -36,8 +39,9 @@ static int _gdcm_read_RLE_fragment (char ** image_buffer, int gdcmFile::gdcm_read_RLE_file (void * image_buffer) { + long fragmentBegining; // for ftell, fseek char * im = (char *)image_buffer; - std::cout << "RLE image" << std::endl; + if (DEBUG)std::cout << "RLE image" << std::endl; long RleSegmentLength[15],fragmentLength,uncompressedSegmentSize;; long ftellRes, ln; @@ -45,7 +49,7 @@ gdcmFile::gdcm_read_RLE_file (void * image_buffer) { guint32 RleSegmentOffsetTable[15]; guint16 ItemTagGr,ItemTagEl; uncompressedSegmentSize=GetXSize()*GetYSize(); - printf("uncompressedSegmentSize %d\n",uncompressedSegmentSize); + if (DEBUG)printf("uncompressedSegmentSize %d\n",uncompressedSegmentSize); ftellRes=ftell(fp); // Basic Offset Table with Item Value // Item Tag @@ -55,14 +59,14 @@ gdcmFile::gdcm_read_RLE_file (void * image_buffer) { ItemTagGr=SwapShort(ItemTagGr); ItemTagEl=SwapShort(ItemTagEl); } - printf ("at %x : ItemTag (should be fffe,e000): %04x,%04x\n", + if (DEBUG)printf ("at %x : ItemTag (should be fffe,e000): %04x,%04x\n", ftellRes,ItemTagGr,ItemTagEl ); // Item Length ftellRes=ftell(fp); fread(&ln,4,1,fp); if(GetSwapCode()) ln=SwapLong(ln); // Basic Offset Table Item Lentgh - printf("at %x : Basic Offset Table Item Lentgh (??) %d x(%08x)\n", + if (DEBUG)printf("at %x : Basic Offset Table Item Lentgh (??) %d x(%08x)\n", ftellRes,ln,ln); if (ln != 0) { // What is it used for ?? @@ -71,7 +75,7 @@ gdcmFile::gdcm_read_RLE_file (void * image_buffer) { guint32 a; for (int i=0;i1) { - for(int k=1; k<=nbRleSegments-1; k++) { // reading RLE Segments - RleSegmentLength[k]=RleSegmentOffsetTable[k+1]-RleSegmentOffsetTable[k]; - ftellRes=ftell(fp); - printf (" Segment %d : Length = %d Start at %x\n", - k,RleSegmentLength[k], ftellRes); - _gdcm_read_RLE_fragment (&im, RleSegmentLength[k],uncompressedSegmentSize,fp); - //fseek(fp,RleSegmentLength[k],SEEK_CUR); - - } - } - RleSegmentLength[nbRleSegments] = fragmentLength - RleSegmentOffsetTable[nbRleSegments]; // + 4; - // 4 : bytes for number of RLE Segments (WHY ???); - // TODO : Check the value - ftellRes=ftell(fp); - printf (" Segment %d : Length = %d Start at %x\n", - nbRleSegments,RleSegmentLength[nbRleSegments],ftellRes); - _gdcm_read_RLE_fragment (&im, RleSegmentLength[nbRleSegments],uncompressedSegmentSize, fp); - //fseek(fp,RleSegmentLength[nbRleSegments],SEEK_CUR); - - - // end of scanning fragment pixels + if (nbRleSegments>1) { + for(int k=1; k<=nbRleSegments-1; k++) { // reading RLE Segments + RleSegmentLength[k]=RleSegmentOffsetTable[k+1]-RleSegmentOffsetTable[k]; + ftellRes=ftell(fp); + if (DEBUG)printf (" (in) Segment %d : Length = %d x(%x) Start at %x\n", + k,RleSegmentLength[k],RleSegmentLength[k], ftellRes); + fragmentBegining=ftell(fp); + _gdcm_read_RLE_fragment (&im, RleSegmentLength[k],uncompressedSegmentSize,fp); + fseek(fp,fragmentBegining,SEEK_SET); + fseek(fp,RleSegmentLength[k],SEEK_CUR); + } + } + RleSegmentLength[nbRleSegments] = fragmentLength - RleSegmentOffsetTable[nbRleSegments]; + ftellRes=ftell(fp); + if (DEBUG)printf (" (out)Segment %d : Length = %d x(%x) Start at %x\n", + nbRleSegments, + RleSegmentLength[nbRleSegments],RleSegmentLength[nbRleSegments], + ftellRes); + fragmentBegining=ftell(fp); + _gdcm_read_RLE_fragment (&im, RleSegmentLength[nbRleSegments],uncompressedSegmentSize, fp); + fseek(fp,fragmentBegining,SEEK_SET); + fseek(fp,RleSegmentLength[nbRleSegments],SEEK_CUR); + + // end of scanning fragment pixels ftellRes=ftell(fp); fread(&ItemTagGr,2,1,fp); // Reading (fffe) : Item Tag Gr @@ -141,7 +147,7 @@ gdcmFile::gdcm_read_RLE_file (void * image_buffer) { ItemTagGr=SwapShort(ItemTagGr); ItemTagEl=SwapShort(ItemTagEl); } - printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n", + if (DEBUG)printf ("at %x : ItemTag (should be fffe,e000 or e0dd): %04x,%04x\n", ftellRes,ItemTagGr,ItemTagEl ); } return (1); @@ -167,14 +173,12 @@ _gdcm_read_RLE_fragment (char ** areaToRead, long numberOfOutputBytes=0; char n, car; ftellRes =ftell(fp); - printf ("Fragment begin : %x lengthToDecode %d\n",ftellRes,lengthToDecode); while(numberOfOutputBytes= 0 && count <= 127) { fread(*areaToRead,(count+1)*sizeof(char),1,fp); *areaToRead+=count+1; -- 2.46.1