]> Creatis software - gdcm.git/blobdiff - src/gdcmFile.cxx
*FIX : gdcmHeader::LoadElements is now based
[gdcm.git] / src / gdcmFile.cxx
index 96eb54783ef78da3b5f25da8d379862d910c504c..4b22d148d7ec4823f52bdf2e5f1ae1fbc130241a 100644 (file)
@@ -96,6 +96,21 @@ void gdcmFile::SetPixelDataSizeFromHeader(void) {
   // 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);
+}
+
 /////////////////////////////////////////////////////////////////
 /**
  * \ingroup   gdcmFile
@@ -356,12 +371,10 @@ 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;
+      int l = lgrTotaleRaw;
       memmove(newDest, destination, l);// move Gray pixels to temp area            
       int j;    
       for (int i=0;i<l; i++) {         // Build RGB Pixels
@@ -371,6 +384,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,22 +410,13 @@ 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? 
-            
+        
+   // TODO : Drop Palette Color out of the Header?          
    return lgrTotale; 
 }
 
@@ -561,10 +578,15 @@ size_t gdcmFile::GetImageDataIntoVectorRaw (void* destination, size_t MaxSize) {
          if (str_PhotometricInterpretation == "YBR_FULL") { 
         
         // Warning : YBR_FULL_422 acts as RGB
-         //       need to make RGB Pixels from Planes Y,cB,cR
+         //         : we need to make RGB Pixels from Planes Y,cB,cR
          // see http://lestourtereaux.free.fr/papers/data/yuvrgb.pdf
          // for code optimisation
-
+        
+        // to see the tricks about YBR_FULL, YBR_FULL_422, 
+         // YBR_PARTIAL_422, YBR_ICT, YBR_RCT have a look at :
+        //   ftp://medical.nema.org/medical/dicom/final/sup61_ft.pdf
+        // and be *very* affraid
+        //
             int l = GetXSize()*GetYSize();
             int nbFrames = GetZSize();