]> Creatis software - gdcm.git/commitdiff
2003-11-03 Jean-Pierre Roux
authorjpr <jpr>
Mon, 3 Nov 2003 10:49:31 +0000 (10:49 +0000)
committerjpr <jpr>
Mon, 3 Nov 2003 10:49:31 +0000 (10:49 +0000)
     * add gdcmHeaderHelper::GetNumberOfScalarComponentsRaw()
           to be used by aware (vtk) users that want to manage
   LUT (and no to turn the PALETTE image into an RGB pixels one)
     * GetPixelType now returns 8U for 24 Bits images
                    (vtkGdcmReader compliant)

src/gdcmFile.cxx
src/gdcmHeader.cxx
src/gdcmHeaderHelper.cxx
src/gdcmHeaderHelper.h

index 96eb54783ef78da3b5f25da8d379862d910c504c..32ef12b9af921513d04fdab8312a11780cf8b17a 100644 (file)
@@ -356,10 +356,8 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) {
          //       from Lut R + Lut G + Lut B
          
    unsigned char * newDest = (unsigned char *)malloc(lgrTotale);
-   unsigned char * a       = (unsigned char *)destination;
-        
+   unsigned char * a       = (unsigned char *)destination;      
    unsigned char * lutRGBA = (unsigned char *)GetLUTRGBA();
-   
    if (lutRGBA) {          
       int l = lgrTotale/3;
       memmove(newDest, destination, l);// move Gray pixels to temp area            
@@ -371,6 +369,19 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) {
          *a++ = lutRGBA[j+2];
       }
       free(newDest);
+    
+   // now, it's an RGB image
+   // Lets's write it in the Header
+
+         // CreateOrReplaceIfExist ?
+        
+   std::string spp = "3";        // Samples Per Pixel
+   gdcmHeader::SetPubElValByNumber(spp,0x0028,0x0002);
+   std::string rgb= "RGB ";      // Photometric Interpretation
+   gdcmHeader::SetPubElValByNumber(rgb,0x0028,0x0004);
+   std::string planConfig = "0"; // Planar Configuration
+   gdcmHeader::SetPubElValByNumber(planConfig,0x0028,0x0006);
+       
                
    } else { 
             // need to make RGB Pixels (?)
@@ -384,20 +395,12 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) {
                    // No idea how to manage it 
                   // It seems that *no Dicom Viewer* has any idea :-(
                   // Segmented xxx Palette Color are *more* than 65535 long ?!?
+                  
+      std::string rgb= "MONOCHROME1 ";      // Photometric Interpretation
+      gdcmHeader::SetPubElValByNumber(rgb,0x0028,0x0004);                 
+                  
    }   
-    
-   // now, it's an RGB image
-   // Lets's write it in the Header
-
-         // CreateOrReplaceIfExist ?
-        
-   std::string spp = "3";        // Samples Per Pixel
-   gdcmHeader::SetPubElValByNumber(spp,0x0028,0x0002);
-   std::string rgb="RGB ";       // Photometric Interpretation
-   gdcmHeader::SetPubElValByNumber(rgb,0x0028,0x0004);
-   std::string planConfig = "0"; // Planar Configuration
-   gdcmHeader::SetPubElValByNumber(planConfig,0x0028,0x0006);
-        
+        
         // TODO : Drop Palette Color out of the Header? 
             
    return lgrTotale; 
index a398ad35926dfdb3d1d2a461c8b36a2394ae0bbc..e99e2acf4a726ee0462bb4a84f6d2bab4615b118 100644 (file)
@@ -1,4 +1,4 @@
-// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.106 2003/10/31 11:29:59 malaterre Exp $
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.107 2003/11/03 10:49:31 jpr Exp $
 
 #include "gdcmHeader.h"
 
@@ -2011,7 +2011,7 @@ int gdcmHeader::GetBitsAllocated(void) {
 /**
  * \ingroup gdcmHeader
  * \brief   Retrieve the number of Samples Per Pixel
- *          (1 : gray level, 3 : RGB)
+ *          (1 : gray level, 3 : RGB -1 or 3 Planes-)
  * 
  * @return  The encountered number of Samples Per Pixel, 1 by default.
  */
@@ -2065,6 +2065,7 @@ int gdcmHeader::GetPixelSize(void) {
  *          - 32U unsigned 32 bit,
  *          - 32S   signed 32 bit,
  * \warning 12 bit images appear as 16 bit.
+ * \        24 bit images appear as 8 bit
  * @return  
  */
 std::string gdcmHeader::GetPixelType(void) {
@@ -2074,9 +2075,11 @@ std::string gdcmHeader::GetPixelType(void) {
       dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Bits Allocated");
       BitsAlloc = std::string("16");
    }
-   if (BitsAlloc == "12")
+   if (BitsAlloc == "12")            // It will be unpacked
       BitsAlloc = std::string("16");
-
+   else if (BitsAlloc == "24")       // (in order no to be messed up
+      BitsAlloc = std::string("8");  // by old RGB images)
+     
    std::string Signed;
    Signed = GetElValByName("Pixel Representation");
    if (Signed == GDCM_UNFOUND) {
@@ -2086,6 +2089,8 @@ std::string gdcmHeader::GetPixelType(void) {
    if (Signed == "0")
       Signed = std::string("U");
    else
+
+std::cout << "GetPixelType : " << BitsAlloc + Signed << std::endl;
       Signed = std::string("S");
 
    return( BitsAlloc + Signed);
@@ -2115,12 +2120,15 @@ std::string gdcmHeader::GetTransferSyntaxName(void) {
 /**
   * \ingroup gdcmHeader
   * \brief tells us if LUT are used
+  * \warning Right now, Segmented xxx Palette Color Lookup Table Data
+  * \        are NOT considered as LUT, since nobody knows
+  *\         how to deal with them
   * @return int acts as a Boolean 
   */
   
 int gdcmHeader::HasLUT(void) {
 
-   // Just hope checking the presence of the LUT Descriptors is enough 
+   // Check the presence of the LUT Descriptors 
    if (GetPubElValByNumber(0x0028,0x1101) == GDCM_UNFOUND)
       return 0;
    // LutDescriptorGreen 
@@ -2128,7 +2136,15 @@ int gdcmHeader::HasLUT(void) {
       return 0;
    // LutDescriptorBlue 
    if (GetPubElValByNumber(0x0028,0x1103) == GDCM_UNFOUND)
+      return 0;
+   //  It is not enough
+   // we check also 
+   if (GetPubElValByNumber(0x0028,0x1201) == GDCM_UNFOUND)
       return 0;  
+   if (GetPubElValByNumber(0x0028,0x1202) == GDCM_UNFOUND)
+      return 0;
+   if (GetPubElValByNumber(0x0028,0x1203) == GDCM_UNFOUND)
+      return 0;   
    return 1;
 }
 
@@ -2269,7 +2285,8 @@ void * gdcmHeader::GetLUTRGBA(void) {
             // if it works, we shall have to check the 3 Palettes
             // to see which byte is ==0 (first one, or second one)
            // and fix the code
-           // We give up the checking to avoid some overhead    
+           // We give up the checking to avoid some overhead 
+           
   char *a;      
   int i;
   a= LUTRGBA+0;
@@ -2292,9 +2309,10 @@ void * gdcmHeader::GetLUTRGBA(void) {
      *a = 1; // Alpha component
      a+=4; 
   } 
-    
-// WHY does it seg fault ?!?
-//free(LutR); free(LutB); free(LutG); printf ("libere\n");
+      
+//How to free the now useless LUTs?
+//
+//free(LutR); free(LutB); free(LutG);
 
   return(LUTRGBA);   
 } 
index a5f78136d3eb6dcac4bb06e8be5420330c254f6c..25d2d80c55d1e0dde855a0ebae8ff24f7e3fc5d2 100644 (file)
@@ -1,4 +1,4 @@
-// $Header: /cvs/public/gdcm/src/Attic/gdcmHeaderHelper.cxx,v 1.14 2003/10/27 14:01:12 jpr Exp $
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeaderHelper.cxx,v 1.15 2003/11/03 10:49:31 jpr Exp $
 
 #include "gdcmHeaderHelper.h"
 
@@ -79,6 +79,12 @@ gdcmHeaderHelper::gdcmHeaderHelper(const char *InFilename,
  *
  */
 int gdcmHeaderHelper::GetPixelSize() {
+
+     // 0028 0100 US IMG Bits Allocated
+     // (in order no to be messed up by old RGB images)
+   if (gdcmHeader::GetPubElValByNumber(0x0028,0x0100) == "24")
+      return 3;
+        
    std::string PixelType = GetPixelType();
    if (PixelType == "8U"  || PixelType == "8S")
       return 1;
@@ -93,29 +99,65 @@ int gdcmHeaderHelper::GetPixelSize() {
 //----------------------------------------------------------------------------
 /**
   * \ingroup gdcmHeaderHelper
-  * \brief gets the info from 0028,0004 : Photometric Interp
-  * \           else 1.
-  * @return 1 if Gray level, 3 if Color
+  * \brief This function is intended to user who doesn't whan 
+  * \ to have to manage a LUT and expects to get an RBG Pixel image
+  * \ (or a monochrome one ...) 
+  * \warning to be used with GetImagePixels()
+  * @return 1 if Gray level, 3 if Color (RGB, YBR or PALETTE COLOR)
   */
 int gdcmHeaderHelper::GetNumberOfScalarComponents() {
-      std::string PhotometricInterpretation = 
-                  gdcmHeader::GetPubElValByNumber(0x0028,0x0004);
-
-
-// The compiler will optimze, if it feels like !
 
-      //beware of trailing space at end of string
-      if (PhotometricInterpretation.find(GDCM_UNFOUND) < PhotometricInterpretation.length() || 
-          PhotometricInterpretation.find("MONOCHROME1") < PhotometricInterpretation.length() || 
-          PhotometricInterpretation.find("MONOCHROME2") < PhotometricInterpretation.length() ) return 1;
+   if (GetSamplesPerPixel() ==3)
+      return 3;
+      
+     // 0028 0100 US IMG Bits Allocated
+     // (in order no to be messed up by old RGB images)
+   if (gdcmHeader::GetPubElValByNumber(0x0028,0x0100) == "24")
+      return 3;
+       
+   std::string PhotometricInterpretation = 
+                  gdcmHeader::GetPubElValByNumber(0x0028,0x0004);
 
-            // WARNING : quick and dirty trick to produce a single plane Grey image
-           // See also  gdcmFile::GetImageDataIntoVector()
-           // if(GetPubElValVoidAreaByNumber(0x0028,0x1201)==NULL) return 1; // Lut Red
-            // end of dirty trick
+   if ( ( PhotometricInterpretation == "PALETTE COLOR ") ) {
+      if (HasLUT())   // PALETTE COLOR is NOT enough
+         return 3;
+      else
+         return 1;      
+   }   
+                 
+      //beware of trailing space at end of string                                              
+   if (PhotometricInterpretation.find(GDCM_UNFOUND) < 
+                           PhotometricInterpretation.length() || 
+       PhotometricInterpretation.find("MONOCHROME1") < 
+                           PhotometricInterpretation.length() || 
+       PhotometricInterpretation.find("MONOCHROME2") < 
+                           PhotometricInterpretation.length() ) 
+       return 1;
+    else
+    // we assume that *all* kinds of YBR are dealt with
+      return 3;
+}
 
+//----------------------------------------------------------------------------
+/**
+  * \ingroup gdcmHeaderHelper
+  * \brief This function is intended to user that 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 1 if Gray level, 3 if Color (RGB or YBR - NOT 'PALETTE COLOR' -)
+  */
+int gdcmHeaderHelper::GetNumberOfScalarComponentsRaw() {
+      
+     // 0028 0100 US IMG Bits Allocated
+     // (in order no to be messed up by old RGB images)
+   if (gdcmHeader::GetPubElValByNumber(0x0028,0x0100) == "24")
       return 3;
+
+    // we assume that *all* kinds of YBR are dealt with
+      return GetSamplesPerPixel();
 }
+
 //----------------------------------------------------------------------------
 /**
  * \ingroup gdcmHeaderHelper
@@ -128,6 +170,7 @@ int gdcmHeaderHelper::GetNumberOfScalarComponents() {
  *          - 32U unsigned 32 bit,
  *          - 32S   signed 32 bit,
  * \warning 12 bit images appear as 16 bit.
+ * \        24 bit images appear as 8 bit
  * @return  
  */
 std::string gdcmHeaderHelper::GetPixelType() {
@@ -137,9 +180,11 @@ std::string gdcmHeaderHelper::GetPixelType() {
       dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Bits Allocated");
       BitsAlloc = std::string("16");
    }
-   if (BitsAlloc == "12")
+   if (BitsAlloc == "12")           // It will be unpacked
       BitsAlloc = std::string("16");
-
+   else if (BitsAlloc == "24")      // (in order no to be messed up
+      BitsAlloc = std::string("8"); // by old RGB images)
+      
    std::string Signed;
    Signed = GetElValByName("Pixel Representation");
    if (Signed == GDCM_UNFOUND) {
index 06455a49d9cd88856c1c20c5c878a67acd1ebe1b..c09bbbb79c0f59a6dfc91c2a39ada17ecda5dfb5 100644 (file)
@@ -1,4 +1,4 @@
-// $Header: /cvs/public/gdcm/src/Attic/gdcmHeaderHelper.h,v 1.4 2003/10/03 14:26:11 jpr Exp $
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeaderHelper.h,v 1.5 2003/11/03 10:49:31 jpr Exp $
 
 #ifndef GDCMHEADERHELPER_H
 #define GDCMHEADERHELPER_H
@@ -78,6 +78,7 @@ public:
    float GetZSpacing();
 
    int GetNumberOfScalarComponents();
+   int GetNumberOfScalarComponentsRaw();
 
    std::string GetStudyUID();
    std::string GetSeriesUID();