]> Creatis software - gdcm.git/blobdiff - src/gdcmFile.cxx
2004-19-02 Jean-Pierre Roux
[gdcm.git] / src / gdcmFile.cxx
index feca29338c587a829360f4c154357b524403a6ff..7b46a51a54377b27084643ee151a40769deee28c 100644 (file)
@@ -1,7 +1,7 @@
 // gdcmFile.cxx
 //-----------------------------------------------------------------------------
 #include "gdcmFile.h"
-#include "gdcmUtil.h"
+#include "gdcmDebug.h"
 #include "jpeg/ljpg/jpegless.h"
 
 typedef std::pair<TagHeaderEntryHT::iterator,TagHeaderEntryHT::iterator> IterHT;
@@ -22,7 +22,6 @@ typedef std::pair<TagHeaderEntryHT::iterator,TagHeaderEntryHT::iterator> IterHT;
  * @param header file to be opened for reading datas
  * @return     
  */
 gdcmFile::gdcmFile(gdcmHeader *header) {
    Header=header;
    SelfHeader=false;
@@ -45,8 +44,14 @@ gdcmFile::gdcmFile(gdcmHeader *header) {
  *        seen as a side effect).   
  * @param filename file to be opened for parsing
  */
-gdcmFile::gdcmFile(std::string & filename) {
-   Header=new gdcmHeader(filename.c_str());
+gdcmFile::gdcmFile(std::string & filename, 
+                   bool exception_on_error,
+                   bool enable_sequences, 
+                   bool ignore_shadow) {
+   Header=new gdcmHeader(filename.c_str(),
+                         exception_on_error,
+                         enable_sequences,
+                         ignore_shadow);
    SelfHeader=true;
    PixelRead=-1; // no ImageData read yet.
 
@@ -67,8 +72,14 @@ gdcmFile::gdcmFile(std::string & filename) {
  *        seen as a side effect).   
  * @param filename file to be opened for parsing
  */
- gdcmFile::gdcmFile(const char * filename) {
-   Header=new gdcmHeader(filename);
+ gdcmFile::gdcmFile(const char * filename, 
+                   bool exception_on_error,
+                   bool enable_sequences, 
+                   bool ignore_shadow) {
+   Header=new gdcmHeader(filename,
+                         exception_on_error,
+                         enable_sequences,
+                         ignore_shadow);
    SelfHeader=true;
    PixelRead=-1; // no ImageData read yet.
 
@@ -79,7 +90,7 @@ gdcmFile::gdcmFile(std::string & filename) {
 /**
  * \ingroup   gdcmFile
  * \brief canonical destructor
- * \Note  If the gdcmHeader is created by the gdcmFile, it is destroyed
+ * \note  If the gdcmHeader is created by the gdcmFile, it is destroyed
  *        by the gdcmFile
  */
 gdcmFile::~gdcmFile(void) {
@@ -95,7 +106,7 @@ gdcmFile::~gdcmFile(void) {
 // Public
 /**
  * \ingroup   gdcmFile
- * \brief     
+ * \brief returns the gdcmHeader *Header   
  * @return     
  */
 gdcmHeader *gdcmFile::GetHeader(void) {
@@ -196,6 +207,7 @@ void * gdcmFile::GetImageData (void) {
    PixelData = (void *) malloc(lgrTotale);
    if (PixelData)
       GetImageDataIntoVector(PixelData, lgrTotale);
+      
    PixelRead=0; // no PixelRaw
    return(PixelData);
 }
@@ -332,7 +344,7 @@ size_t gdcmFile::GetImageDataIntoVectorRaw (void* destination, size_t MaxSize) {
    }
        
    (void)ReadPixelData(destination);
-       
+       
        // Number of Bits Allocated for storing a Pixel
    str_nb = Header->GetEntryByNumber(0x0028,0x0100);
    if (str_nb == GDCM_UNFOUND ) {
@@ -378,7 +390,6 @@ size_t gdcmFile::GetImageDataIntoVectorRaw (void* destination, size_t MaxSize) {
           deb++;   
          }
     }
-
    // re arange bits inside the bytes
    if (nbu != nb){
       int l = (int)lgrTotale / (nb/8);
@@ -403,7 +414,7 @@ size_t gdcmFile::GetImageDataIntoVectorRaw (void* destination, size_t MaxSize) {
          return (size_t)0; 
       }
    } 
-// DO NOT remove this code commented out.
+// DO NOT remove this commented out code .
 // Nobody knows what's expecting you ...
 // Just to 'see' what was actually read on disk :-(
 
@@ -628,7 +639,7 @@ bool gdcmFile::WriteDcmExplVR (std::string fileName) {
  *        (a l'attention des logiciels cliniques 
  *        qui ne prennent en entrĂ©e QUE des images ACR ...
  * \warning if a DICOM_V3 header is supplied,
- *         groups < 0x0008 and shadow groups are ignored)
+ *         groups < 0x0008 and shadow groups are ignored
  * \warning NO TEST is performed on processor "Endiannity".
  * @param fileName name of the file to be created
  *                 (any already existing file is overwritten)
@@ -647,16 +658,14 @@ bool gdcmFile::WriteAcr (std::string fileName) {
  *        (used by WriteDcmExplVR, WriteDcmImplVR, WriteAcr, etc)
  * @param fileName name of the file to be created
  *                 (any already existing file is overwritten)
- * @param  type file type (ExplicitVR, ImplicitVR, DICOMDIR, ...)
+ * @param  type file type (ExplicitVR, ImplicitVR, ...)
  * @return false if write fails                
  */
 bool gdcmFile::WriteBase (std::string fileName, FileType type) {
 
    FILE * fp1;
    
-   if (PixelRead==-1 && type != DICOMDIR) {
-/*      std::cout << "U never Read the pixels; U cannot write the file" 
-                << std::endl;*/
+   if (PixelRead==-1 && type != ExplicitVR) {
       return false;               
    }
 
@@ -724,7 +733,6 @@ bool gdcmFile::WriteBase (std::string fileName, FileType type) {
    
    //PixelElement->SetPrintLevel(2);
    //PixelElement->Print();    
    Header->Write(fp1, type);
 
    // --------------------------------------------------------------
@@ -772,9 +780,10 @@ if(nb == 16)
       case 2143:
       case 4321:
 
-         for(i=0;i<lgr;i++)
+         for(i=0;i<lgr/2;i++) {
             ((unsigned short int*)im)[i]= ((((unsigned short int*)im)[i])>>8)
                                         | ((((unsigned short int*)im)[i])<<8);
+       }
          break;
                        
       default:
@@ -788,7 +797,7 @@ if( nb == 32 )
          break;
 
       case 4321:
-         for(i=0;i<lgr;i++) {
+         for(i=0;i<lgr/4;i++) {
             faible=  ((unsigned long int*)im)[i]&0x0000ffff;    /* 4321 */
             fort  =((unsigned long int*)im)[i]>>16;
             fort=  (fort>>8)   | (fort<<8);
@@ -799,7 +808,7 @@ if( nb == 32 )
          break;
 
       case 2143:
-         for(i=0;i<lgr;i++) {
+         for(i=0;i<lgr/4;i++) {
             faible=  ((unsigned long int*)im)[i]&0x0000ffff;    /* 2143 */
             fort=((unsigned long int*)im)[i]>>16;
             fort=  (fort>>8)   | (fort<<8);
@@ -810,7 +819,7 @@ if( nb == 32 )
          break;
   
       case 3412:
-         for(i=0;i<lgr;i++) {
+         for(i=0;i<lgr/4;i++) {
             faible=  ((unsigned long int*)im)[i]&0x0000ffff;    /* 3412 */
             fort=((unsigned long int*)im)[i]>>16;                  
             s32=faible;