]> Creatis software - gdcm.git/commitdiff
now gdcmFile::GetImageDataIntoVector, gdcmFile::GetImageData, and so on
authorjpr <jpr>
Wed, 2 Jul 2003 16:47:22 +0000 (16:47 +0000)
committerjpr <jpr>
Wed, 2 Jul 2003 16:47:22 +0000 (16:47 +0000)
return an RGB pixel map
(they return no longer an R Plane + a G Plane + a B Plane)
see gdcmData/US-RGB-8-epicard.dcm

gdcmPython/testSuite.py
src/gdcmFile.cxx
src/gdcmHeader.cxx
src/gdcmHeader.h

index 695e671fc54f8b346a80fae4e4f3d5a4cb62df8f..7efdf672476e74b67aff006af03e71cb2d0bb349 100644 (file)
@@ -187,10 +187,14 @@ class gdcmTestCase(unittest.TestCase):
            ["Manufacturer", "Acme Products"],
          # FIXME: 92160 / (120*256) = 3 bytes per pixel NOT 1. Maybe
          # it has something to do with [Samples Per Pixel] = [3] ???
+         # You said it, puffy (tu l'as dit, bouffi, in french language)
+         # RGB is 3 bytes per pixel
+         # + Planar configuration (0028,0006) = 0 --> Pixels RGB       
            ["Pixel Data", "gdcm::NotLoaded. Address:904 Length:92160"] ] ],
       ["US-RGB-8-epicard.dcm",
          # Interest: Big endian transfert syntax
          [ ["Transfer Syntax UID", "1.2.840.10008.1.2.2"],  # Big endian
+         # But ... group 0000 is LE .
            ["Modality", "US"],
            ["Photometric Interpretation", "RGB"],
            ["Rows", "480"],
@@ -201,8 +205,7 @@ class gdcmTestCase(unittest.TestCase):
            ["Pixel Representation", "0"],
            ["Manufacturer", "G.E. Medical Systems"],
            ["Manufacturer Model Name", "LOGIQ 700"],
-         # FIXME: 921600/(480*640) = 3 bytes per pixel NOT 1. Maybe
-         # it has something to do with [Samples Per Pixel] = [3] ???
+         # + Planar configuration (0028,0006) = 1 --> Plane R, Plane G, Plane B  
            ["Implementation Version Name", "OFFIS-DCMTK-311"],
            ["Pixel Data", "gdcm::NotLoaded. Address:1012 Length:921600"] ] ],
    ]
index 7003c29a67f1a38bcc4711c114add9fab8f1bb94..70859f9dcffd1aa99cfb23a9999bec63a5c17798 100644 (file)
@@ -82,7 +82,7 @@ size_t gdcmFile::GetImageDataSize(void) {
  * \ingroup gdcmFile
  * \brief   Read pixel data from disk (optionaly decompressing) into the
  *          caller specified memory location.
- * @param   destination Where the pixel data should be stored.
+ * @param   destination where the pixel data should be stored.
  *
  */
 bool gdcmFile::ReadPixelData(void* destination) {
@@ -300,6 +300,43 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t MaxSize) {
          return (size_t)0; 
       }
    }
+   
+ // ---
+   string str_PlanarConfiguration = GetPubElValByNumber(0x0028,0x0006);
+   int PlanarConfiguration;
+   if (str_PlanarConfiguration == "gdcm::Unfound" ) {
+      PlanarConfiguration = 0;
+   } else {
+      PlanarConfiguration = atoi(str_PlanarConfiguration.c_str() );
+   }   
+ // ---
+   // TODO : replace by                         
+   // if (GetPlanarConfiguration() == 1) {
+   // after unfreeze
+   
+   if  (PlanarConfiguration == 1) { // need to make RGB Pixels
+      int l = lgrTotale/3 ;
+
+      char * a = (char *)destination;
+      char * b = a + l;
+      char * c = b + l;
+      char * newDest = (char*) malloc(lgrTotale);
+      // TODO :
+      // any trick not to have to allocate temporary buffer is welcome ...
+      char *x = newDest;
+      for (int i=0;i<l; i++) {
+         *(x++) = *(a++);
+         *(x++) = *(b++);
+         *(x++) = *(c++);  
+      }
+      a = (char *)destination;
+      x = newDest;
+      for (int i=0;i<lgrTotale; i++) {
+         *(a++) = *(x++);
+      }
+      free(newDest);
+   }
    return lgrTotale; 
 }
 
@@ -320,18 +357,18 @@ if(nb == 16)
       case 1234:
          break;
                
-         case 21:
-         case 3412:
-         case 2143:
-         case 4321:
-
-            for(i=0;i<lgr;i++)
-               ((unsigned short int*)im)[i]= ((((unsigned short int*)im)[i])>>8)
-                                           | ((((unsigned short int*)im)[i])<<8);
-               break;
+      case 21:
+      case 3412:
+      case 2143:
+      case 4321:
+
+         for(i=0;i<lgr;i++)
+            ((unsigned short int*)im)[i]= ((((unsigned short int*)im)[i])>>8)
+                                        | ((((unsigned short int*)im)[i])<<8);
+         break;
                        
-         default:
-            printf("valeur de SWAP (16 bits) non autorisee : %d\n", swap);
+      default:
+         printf("valeur de SWAP (16 bits) non autorisee : %d\n", swap);
    } 
  
 if( nb == 32 )
@@ -351,28 +388,28 @@ if( nb == 32 )
          }
          break;
 
-         case 2143:
-            for(i=0;i<lgr;i++) {
-               faible=  ((unsigned long int*)im)[i]&0x0000ffff;    /* 2143 */
-               fort=((unsigned long int*)im)[i]>>16;
-               fort=  (fort>>8)   | (fort<<8);
-               faible=(faible>>8) | (faible<<8);
-               s32=fort; 
-               ((unsigned long int*)im)[i]=(s32<<16)|faible;
-            }
-            break;
+      case 2143:
+         for(i=0;i<lgr;i++) {
+            faible=  ((unsigned long int*)im)[i]&0x0000ffff;    /* 2143 */
+            fort=((unsigned long int*)im)[i]>>16;
+            fort=  (fort>>8)   | (fort<<8);
+            faible=(faible>>8) | (faible<<8);
+            s32=fort; 
+            ((unsigned long int*)im)[i]=(s32<<16)|faible;
+         }
+         break;
   
-         case 3412:
-            for(i=0;i<lgr;i++) {
-               faible=  ((unsigned long int*)im)[i]&0x0000ffff;    /* 3412 */
-               fort=((unsigned long int*)im)[i]>>16;                  
-               s32=faible; 
-               ((unsigned long int*)im)[i]=(s32<<16)|fort;
-            }                 
-            break; 
+      case 3412:
+         for(i=0;i<lgr;i++) {
+            faible=  ((unsigned long int*)im)[i]&0x0000ffff;    /* 3412 */
+            fort=((unsigned long int*)im)[i]>>16;                  
+            s32=faible; 
+            ((unsigned long int*)im)[i]=(s32<<16)|fort;
+         }                 
+         break; 
                                
-         default:
-            printf("valeur de SWAP (32 bits) non autorisee : %d\n", swap);
+      default:
+         printf("valeur de SWAP (32 bits) non autorisee : %d\n", swap);
    } 
 return;
 }
@@ -393,8 +430,6 @@ int gdcmFile::SetImageData(void * inData, size_t ExpectedSize) {
    SetImageDataSize(ExpectedSize);
    PixelData = inData;
    lgrTotale = ExpectedSize;
-   
-   
    return(1);
 }
 
index 284bbdc61e680e47d83f954710db566ae03abaab..b4681a801639d0647b849cb1a5d7b321c27b55c4 100644 (file)
@@ -1,5 +1,5 @@
 
-// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.75 2003/07/01 17:22:44 jpr Exp $
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.76 2003/07/02 16:47:22 jpr Exp $
 
 #include <stdio.h>
 #include <cerrno>
@@ -42,15 +42,15 @@ void gdcmHeader::Initialise(void) {
  * @param   InFilename
  * @param   exception_on_error
  */
- gdcmHeader::gdcmHeader(const char *InFilename, bool exception_on_error) {
-  SetMaxSizeLoadElementValue(_MaxSizeLoadElementValue_);
-  filename = InFilename;
-  Initialise();
-  if ( !OpenFile(exception_on_error))
-     return;
-  ParseHeader();
-  LoadElements();
-  CloseFile();
+gdcmHeader::gdcmHeader(const char *InFilename, bool exception_on_error) {
+   SetMaxSizeLoadElementValue(_MaxSizeLoadElementValue_);
+   filename = InFilename;
+   Initialise();
+   if ( !OpenFile(exception_on_error))
+      return;
+   ParseHeader();
+   LoadElements();
+   CloseFile();
 }
 
 /**
@@ -194,8 +194,8 @@ void gdcmHeader::CheckSwap()
       // instead of just checking for UL, OB and UI !?
       if(  (memcmp(entCur, "UL", (size_t)2) == 0) ||
           (memcmp(entCur, "OB", (size_t)2) == 0) ||
-          (memcmp(entCur, "UI", (size_t)2) == 0) )
-       {
+          (memcmp(entCur, "UI", (size_t)2) == 0) )   
+      {
          filetype = ExplicitVR;
          dbg.Verbose(1, "gdcmHeader::CheckSwap:",
                      "explicit Value Representation");
@@ -204,7 +204,6 @@ void gdcmHeader::CheckSwap()
          dbg.Verbose(1, "gdcmHeader::CheckSwap:",
                      "not an explicit Value Representation");
       }
-
       if (net2host) {
          sw = 4321;
          dbg.Verbose(1, "gdcmHeader::CheckSwap:",
@@ -952,11 +951,11 @@ guint16 gdcmHeader::ReadInt16(void) {
    size_t item_read;
    item_read = fread (&g, (size_t)2,(size_t)1, fp);
    if ( item_read != 1 ) {
-      dbg.Verbose(1, "gdcmHeader::ReadInt16", " Failed to read :");
+      dbg.Verbose(0, "gdcmHeader::ReadInt16", " Failed to read :");
       if(feof(fp)) 
-         dbg.Verbose(1, "gdcmHeader::ReadInt16", " End of File encountered");
+         dbg.Verbose(0, "gdcmHeader::ReadInt16", " End of File encountered");
      if(ferror(fp)) 
-         dbg.Verbose(1, "gdcmHeader::ReadInt16", " File Error");
+         dbg.Verbose(0, "gdcmHeader::ReadInt16", " File Error");
       errno = 1;
       return 0;
    }
@@ -977,11 +976,11 @@ guint32 gdcmHeader::ReadInt32(void) {
    item_read = fread (&g, (size_t)4,(size_t)1, fp);
    if ( item_read != 1 ) {
    
-      dbg.Verbose(1, "gdcmHeader::ReadInt32", " Failed to read :");
+      dbg.Verbose(0, "gdcmHeader::ReadInt32", " Failed to read :");
       if(feof(fp)) 
-         dbg.Verbose(1, "gdcmHeader::ReadInt32", " End of File encountered");
+         dbg.Verbose(0, "gdcmHeader::ReadInt32", " End of File encountered");
      if(ferror(fp)) 
-         dbg.Verbose(1, "gdcmHeader::ReadInt32", " File Error");   
+         dbg.Verbose(0, "gdcmHeader::ReadInt32", " File Error");   
       errno = 1;
       return 0;
    }
@@ -1647,6 +1646,7 @@ int gdcmHeader::GetBitsStored(void) {
    return atoi(StrSize.c_str());
 }
 
+
 /**
  * \ingroup gdcmHeader
  * \brief   Retrieve the number of Samples Per Pixel
@@ -1661,6 +1661,24 @@ int gdcmHeader::GetSamplesPerPixel(void) {
    return atoi(StrSize.c_str());
 }
 
+
+/* ================ COMMENT OUT after unfreeze
+**
+ * \ingroup gdcmHeader
+ * \brief   Retrieve the Planar Configuration for RGB images
+ *          (0 : RGB Pixels , 1 : R Plane + G Plane + B Plane)
+ * 
+ * @return  The encountered Planar Configuration, 0 by default.
+ *
+int gdcmHeader::GetPlanarConfiguration(void) { 
+   string StrSize = GetPubElValByNumber(0x0028,0x0006);
+   if (StrSize == "gdcm::Unfound")
+      return 0;
+   return atoi(StrSize.c_str());
+}
+
+ ======================================= */
+
 /**
  * \ingroup gdcmHeader
  * \brief   Return the size (in bytes) of a single pixel of data.
index ac2f63633e036c5b0009ec8b2f90ac439c618104..1657e70c0c343a32ef64e957a85a83d0b560f429 100644 (file)
@@ -1,4 +1,4 @@
-// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.h,v 1.31 2003/07/01 15:14:36 frog Exp $
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.h,v 1.32 2003/07/02 16:47:22 jpr Exp $
 
 #ifndef GDCMHEADER_H
 #define GDCMHEADER_H
@@ -178,6 +178,11 @@ public:
    int GetZSize(void);
    int GetBitsStored(void);
    int GetSamplesPerPixel(void);
+   
+/* ================ COMMENT OUT after unfreeze
+   int GetPlanarConfiguration(void);
+   ======================================= */
+
    int GetPixelSize(void);       
    std::string GetPixelType(void);