]> Creatis software - gdcm.git/commitdiff
-->File gdcmParse.cxx added
authorjpr <jpr>
Thu, 25 Sep 2003 18:06:49 +0000 (18:06 +0000)
committerjpr <jpr>
Thu, 25 Sep 2003 18:06:49 +0000 (18:06 +0000)
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
src/config.h
src/config.h.in
src/gdcmFile.cxx
src/gdcmParse.cxx [new file with mode: 0644]
src/gdcmRLE.cxx

index 6d0052016b1d8be02040c1050fa000973612f7fa..6c1881ad974a1f22f005580238f3ec7685f189dd 100644 (file)
@@ -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
index aec099d768cbbf15c2ced89d88af5be575cbd2dd..5235387619dd8b995b2eaa9741cb74cff800c99a 100644 (file)
@@ -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 <dlfcn.h> header file. */
-#define HAVE_DLFCN_H 1
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-/* #undef HAVE_INTTYPES_H */
-
-/* Define to 1 if you have the <memory.h> header file. */
-/* #undef HAVE_MEMORY_H */
-
-/* Define to 1 if you have the <stdint.h> header file. */
-/* #undef HAVE_STDINT_H */
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-/* #undef HAVE_STDLIB_H */
-
-/* Define to 1 if you have the <strings.h> header file. */
-/* #undef HAVE_STRINGS_H */
-
-/* Define to 1 if you have the <string.h> header file. */
-/* #undef HAVE_STRING_H */
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-/* #undef HAVE_SYS_STAT_H */
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-/* #undef HAVE_SYS_TYPES_H */
-
-/* Define to 1 if you have the <unistd.h> 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 <sys/types.h> 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 <sys/time.h> 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 <dlfcn.h> header file.  */
+#define HAVE_DLFCN_H 1
 
-/* Define to 1 if your <sys/time.h> 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 <sys/types.h> does not define. */
-/* #undef size_t */
index 5a0d619bd4b7cb87fa7d1b4003ed368d8c18b5b5..552bf6bca1ef57a43305a20a6569e0d1ac15a39e 100644 (file)
@@ -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 <dlfcn.h> header file. */
-#undef HAVE_DLFCN_H
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#undef HAVE_INTTYPES_H
-
-/* Define to 1 if you have the <memory.h> header file. */
-#undef HAVE_MEMORY_H
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#undef HAVE_STDINT_H
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#undef HAVE_STDLIB_H
-
-/* Define to 1 if you have the <strings.h> header file. */
-#undef HAVE_STRINGS_H
-
-/* Define to 1 if you have the <string.h> header file. */
-#undef HAVE_STRING_H
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#undef HAVE_SYS_STAT_H
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#undef HAVE_SYS_TYPES_H
-
-/* Define to 1 if you have the <unistd.h> 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 <sys/types.h> 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 <sys/time.h> 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 <dlfcn.h> header file.  */
+#undef HAVE_DLFCN_H
 
-/* Define to 1 if your <sys/time.h> 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 <sys/types.h> does not define. */
-#undef size_t
index 43d8c3a19f612626015becf4bf28cd2b8a86b343..475ec04ecf74c3cc5b659bed0568a20687cb2f52 100644 (file)
@@ -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;i<ln;i+=4){
-            a=str2num(&BasicOffsetTableItemValue[i],guint32);
-            printf("      x(%08x)  %d\n",a,a);
-         }              
-      }
-      
-      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 );
-      
-      while (  ( ItemTagGr == 0xfffe) && (ItemTagEl != 0xe0dd) ) { // Parse fragments
-      
-         ftellRes=ftell(fp);
-         fread(&ln,4,1,fp); 
-         if(GetSwapCode()) 
-            ln=SwapLong(ln);    // length
-         printf("      at %x : fragment length %d x(%08x)\n",
-                ftellRes, ln,ln);
-
-        // destination += taille * nBytes; // location in user's memory        
-        //printf ("      Destination will be x(%x) = %d \n",
-        //     destination,destination );
-
-         // ------------------------                                     
-         fseek(fp,ln,SEEK_CUR); // skipping (not reading) 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 );
-      } 
-
-   } else {
-
-      // RLE Image
-
-      std::cout << "RLE image" << std::endl;
-      long RleSegmentLength[15],fragmentLength;
-      guint32 nbRleSegments;
-      guint32 RleSegmentOffsetTable[15];
-      ftellRes=ftell(fp);
-      // Basic Offset Table with Item Value
-         // Item Tag
-      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 );
-         // 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",
-            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;i<ln;i+=4){
-            a=str2num(&BasicOffsetTableItemValue[i],guint32);
-            printf("      x(%08x)  %d\n",a,a);
-         }              
-      }
-
-      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 );
-
-      // while 'Sequence Delimiter Item' (fffe,e0dd) not found
-      while (  ( ItemTagGr == 0xfffe) && (ItemTagEl != 0xe0dd) ) { 
-      // Parse fragments of the current Fragment (Frame)    
-         ftellRes=ftell(fp);
-         fread(&fragmentLength,4,1,fp); 
-         if(GetSwapCode()) 
-            fragmentLength=SwapLong(fragmentLength);    // length
-         printf("      at %x : 'fragment' length %d x(%08x)\n",
-                ftellRes, fragmentLength,fragmentLength);
-
-//         destination += taille * nBytes; // location in user's memory                 
-//         printf ("      Destination will be x(%x) = %d \n",
-//               destination,destination );
-                        
-          //------------------ scanning (not reading) fragment pixels
-         fread(&nbRleSegments,4,1,fp);  // Reading : Number of RLE Segments           
-         if(GetSwapCode()) 
-            nbRleSegments=SwapLong(nbRleSegments);
-            printf("         Nb of RLE Segments : %d\n",nbRleSegments);
-         for(int k=1; k<=15; k++) { // Reading RLE Segments Offset Table
-            ftellRes=ftell(fp);
-            fread(&RleSegmentOffsetTable[k],4,1,fp);
-            if(GetSwapCode())
-               RleSegmentOffsetTable[k]=SwapLong(RleSegmentOffsetTable[k]);
-            printf("        at : %x Offset Segment %d : %d (%x)\n",
-                      ftellRes,k,RleSegmentOffsetTable[k],RleSegmentOffsetTable[k]);
-         }
-          if (nbRleSegments>1) { 
-             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 (file)
index 0000000..0682f2c
--- /dev/null
@@ -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;i<ln;i+=4){
+            a=str2num(&BasicOffsetTableItemValue[i],guint32);
+            printf("      x(%08x)  %d\n",a,a);
+         }              
+      }
+      
+      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 );
+      
+      while (  ( ItemTagGr == 0xfffe) && (ItemTagEl != 0xe0dd) ) { // Parse fragments
+      
+         ftellRes=ftell(fp);
+         fread(&ln,4,1,fp); 
+         if(GetSwapCode()) 
+            ln=SwapLong(ln);    // length
+         printf("      at %x : fragment length %d x(%08x)\n",
+                ftellRes, ln,ln);
+
+        // destination += taille * nBytes; // location in user's memory        
+        //printf ("      Destination will be x(%x) = %d \n",
+        //     destination,destination );
+
+         // ------------------------                                     
+         fseek(fp,ln,SEEK_CUR); // skipping (not reading) 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 );
+      } 
+
+   } else {
+
+      // RLE Image
+
+      std::cout << "RLE image" << std::endl;
+      long RleSegmentLength[15],fragmentLength;
+      guint32 nbRleSegments;
+      guint32 RleSegmentOffsetTable[15];
+      ftellRes=ftell(fp);
+      // Basic Offset Table with Item Value
+         // Item Tag
+      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 );
+         // 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",
+            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;i<ln;i+=4){
+            a=str2num(&BasicOffsetTableItemValue[i],guint32);
+            printf("      x(%08x)  %d\n",a,a);
+         }              
+      }
+
+      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 );
+
+      // while 'Sequence Delimiter Item' (fffe,e0dd) not found
+      while (  ( ItemTagGr == 0xfffe) && (ItemTagEl != 0xe0dd) ) { 
+      // Parse fragments of the current Fragment (Frame)    
+         ftellRes=ftell(fp);
+         fread(&fragmentLength,4,1,fp); 
+         if(GetSwapCode()) 
+            fragmentLength=SwapLong(fragmentLength);    // length
+         printf("      at %x : 'fragment' length %d x(%08x)\n",
+                ftellRes, fragmentLength,fragmentLength);
+                       
+          //------------------ scanning (not reading) fragment pixels
+         fread(&nbRleSegments,4,1,fp);  // Reading : Number of RLE Segments           
+         if(GetSwapCode()) 
+            nbRleSegments=SwapLong(nbRleSegments);
+            printf("         Nb of RLE Segments : %d\n",nbRleSegments);
+         for(int k=1; k<=15; k++) { // Reading RLE Segments Offset Table
+            ftellRes=ftell(fp);
+            fread(&RleSegmentOffsetTable[k],4,1,fp);
+            if(GetSwapCode())
+               RleSegmentOffsetTable[k]=SwapLong(RleSegmentOffsetTable[k]);
+            printf("        at : %x Offset Segment %d : %d (%x)\n",
+                    ftellRes,k,RleSegmentOffsetTable[k],RleSegmentOffsetTable[k]);
+         }
+
+          if (nbRleSegments>1) { 
+             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;            
+}
index 3a0f2ed0ab2581cd496dac496ce2ff783be8304a..7bdcee608734f544bf3e5fbb531c1c362d386602 100644 (file)
@@ -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;i<ln;i+=4){
          a=str2num(&BasicOffsetTableItemValue[i],guint32);
-         printf("      x(%08x)  %d\n",a,a);
+        if (DEBUG)printf("      x(%08x)  %d\n",a,a);
       }        
    }
 
@@ -82,7 +86,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 );
 
    // while 'Sequence Delimiter Item' (fffe,e0dd) not found
@@ -92,47 +96,49 @@ gdcmFile::gdcm_read_RLE_file (void * image_buffer) {
       fread(&fragmentLength,4,1,fp); 
       if(GetSwapCode()) 
          fragmentLength=SwapLong(fragmentLength);    // length
-      printf("      at %x : fragment length %d x(%08x)\n",
+      if (DEBUG)printf("      at %x : fragment length %d x(%08x)\n",
              ftellRes, fragmentLength,fragmentLength);
 
-       // scanning fragment pixels
+          //------------------ scanning (not reading) fragment pixels
  
       fread(&nbRleSegments,4,1,fp);  // Reading : Number of RLE Segments        
       if(GetSwapCode()) 
          nbRleSegments=SwapLong(nbRleSegments);
-         printf("         Nb of RLE Segments : %d\n",nbRleSegments);
+         if (DEBUG)printf("         Nb of RLE Segments : %d\n",nbRleSegments);
  
       for(int k=1; k<=15; k++) { // Reading RLE Segments Offset Table
          ftellRes=ftell(fp);
          fread(&RleSegmentOffsetTable[k],4,1,fp);
          if(GetSwapCode())
             RleSegmentOffsetTable[k]=SwapLong(RleSegmentOffsetTable[k]);
-         printf("        at : %x Offset Segment %d : %d (%x)\n",
-                   ftellRes,k,RleSegmentOffsetTable[k],RleSegmentOffsetTable[k]);
+         if (DEBUG)printf("        at : %x Offset Segment %d : %d (%x)\n",
+                 ftellRes,k,RleSegmentOffsetTable[k],RleSegmentOffsetTable[k]);
       }
 
-       if (nbRleSegments>1) { 
-          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<uncompressedSegmentSize) {
 
       ftellRes =ftell(fp);
       fread(&n,sizeof(char),1,fp);
       count=n;
-     //printf ("   Piece begin : %x count : %d x(%x)\n",ftellRes, count, count);
       if (count >= 0 && count <= 127) {
          fread(*areaToRead,(count+1)*sizeof(char),1,fp);
          *areaToRead+=count+1;