]> Creatis software - gdcm.git/blobdiff - src/gdcmDocument.cxx
Bugfixes. --- JPR (with frog)
[gdcm.git] / src / gdcmDocument.cxx
index ece8f61937dffe2e50f38e741e82340c07d68b8d..e29c08bfc24dd287b2ecbacc27528ac6955d67ea 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/06/22 14:07:05 $
-  Version:   $Revision: 1.23 $
+  Date:      $Date: 2004/06/23 15:01:57 $
+  Version:   $Revision: 1.29 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -126,6 +126,25 @@ gdcmDocument::gdcmDocument(std::string const & inFilename,
    
    long l=ParseDES( this, beg, lgt, false); // le Load sera fait a la volee
    (void)l; //is l used anywhere ?
+       
+       rewind(fp); 
+   
+   // Load 'non string' values
+      
+   std::string PhotometricInterpretation = GetEntryByNumber(0x0028,0x0004);   
+   if( PhotometricInterpretation == "PALETTE COLOR " ) {
+      LoadEntryVoidArea(0x0028,0x1200);  // gray LUT   
+      LoadEntryVoidArea(0x0028,0x1201);  // R    LUT
+      LoadEntryVoidArea(0x0028,0x1202);  // G    LUT
+      LoadEntryVoidArea(0x0028,0x1203);  // B    LUT
+      
+      LoadEntryVoidArea(0x0028,0x1221);  // Segmented Red   Palette Color LUT Data
+      LoadEntryVoidArea(0x0028,0x1222);  // Segmented Green Palette Color LUT Data
+      LoadEntryVoidArea(0x0028,0x1223);  // Segmented Blue  Palette Color LUT Data
+   } 
+   //FIXME later : how to use it?
+   LoadEntryVoidArea(0x0028,0x3006);  //LUT Data (CTX dependent) 
+               
    CloseFile(); 
   
    // --------------------------------------------------------------
@@ -390,11 +409,12 @@ bool gdcmDocument::IsRLELossLessTransferSyntax(void)
  * @return  True when RLE Lossless found. False in all
  *          other cases.
  */
 bool gdcmDocument::IsJPEGLossless(void)
 {
    return (   IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_55)
            || IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_57)
-           || IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_90) );
+           || IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_70) ); // was 90 
 }
                                                                                 
 /**
@@ -551,8 +571,8 @@ bool gdcmDocument::WriteF(FileType filetype) {
  * if ( filetype == ACR)
  *    UpdateGroupLength(true,ACR);
  */
-   Write(fp,filetype);  // the gdcmElementSet one !
+       
+       gdcmElementSet::Write(fp,filetype);
 
    /// WriteEntries(fp,type); // old stuff
    return true;
@@ -1180,7 +1200,7 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, long offset, long l_max, bool
             NewValEntry->SetDepthLevel(depth);
             set->AddEntry(NewValEntry);
             LoadDocEntry(NewValEntry);
-            if (/*!delim_mode && */NewValEntry->isItemDelimitor())
+            if (NewValEntry->isItemDelimitor())
                break;
             if ( !delim_mode && ftell(fp)-offset >= l_max)
             {
@@ -1207,9 +1227,16 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, long offset, long l_max, bool
              NewDocEntry->GetElement() == 0x0010 )
          {
              if (NewDocEntry->GetLength()==0xffffffff)
+             {
                 // Broken US.3405.1.dcm
                 Parse7FE0(); // to skip the pixels 
                              // (multipart JPEG/RLE are trouble makers)
+             }
+             else
+             {
+                SkipToNextDocEntry(NewDocEntry);
+                l = NewDocEntry->GetFullLength(); 
+             }
          }
          else
          {
@@ -1272,6 +1299,8 @@ long gdcmDocument::ParseSQ(gdcmSeqEntry *set,
 
    while (true) {
       NewDocEntry = ReadNextDocEntry();   
+      if (!NewDocEntry)
+         break;
       if(delim_mode) {   
          if (NewDocEntry->isSequenceDelimitor()) {
             set->SetSequenceDelimitationItem(NewDocEntry);
@@ -1323,9 +1352,6 @@ void gdcmDocument::LoadDocEntry(gdcmDocEntry *Entry)
    //          (fffe e0dd) tells us the current SeQuence just ended
    if( group == 0xfffe ) {
       // NO more value field for SQ !
-      //Entry->SetValue("gdcm::Skipped");
-      // appel recursif de Load Value
-      // (meme pb que pour le parsing)
       return;
    }
 
@@ -1338,21 +1364,41 @@ void gdcmDocument::LoadDocEntry(gdcmDocEntry *Entry)
    // The elements whose length is bigger than the specified upper bound
    // are not loaded. Instead we leave a short notice of the offset of
    // the element content and it's length.
+       
    if (length > MaxSizeLoadEntry) {
+      if (gdcmBinEntry* BinEntryPtr = dynamic_cast< gdcmBinEntry* >(Entry) )
+      {
+         std::ostringstream s;
+         s << "gdcm::NotLoaded (BinEntry)";
+         s << " Address:" << (long)Entry->GetOffset();
+         s << " Length:"  << Entry->GetLength();
+         s << " x(" << std::hex << Entry->GetLength() << ")";
+         BinEntryPtr->SetValue(s.str());
+      }
+      // to be sure we are at the end of the value ...
+      fseek(fp,(long)Entry->GetOffset()+(long)Entry->GetLength(),SEEK_SET);      
+      return;          
+       // Be carefull : a BinEntry IS_A ValEntry ...   
       if (gdcmValEntry* ValEntryPtr = dynamic_cast< gdcmValEntry* >(Entry) )
       {
          std::ostringstream s;
-         s << "gdcm::NotLoaded.";
+         s << "gdcm::NotLoaded. (ValEntry)";
          s << " Address:" << (long)Entry->GetOffset();
          s << " Length:"  << Entry->GetLength();
          s << " x(" << std::hex << Entry->GetLength() << ")";
          ValEntryPtr->SetValue(s.str());
-      }
+      }                
       // to be sure we are at the end of the value ...
-      fseek(fp,(long)Entry->GetOffset()+(long)Entry->GetLength(),SEEK_SET);
-      
+      fseek(fp,(long)Entry->GetOffset()+(long)Entry->GetLength(),SEEK_SET);      
       return;
    }
+
+   // When we find a BinEntry not very much can be done :
+   if (gdcmBinEntry* BinEntryPtr = dynamic_cast< gdcmBinEntry* >(Entry) ) {
+      LoadEntryVoidArea (BinEntryPtr->GetGroup(),BinEntryPtr->GetElement());
+               return; 
+       }
     
    // Any compacter code suggested (?)
    if ( IsDocEntryAnInteger(Entry) ) {   
@@ -1777,16 +1823,6 @@ void gdcmDocument::SkipToNextDocEntry(gdcmDocEntry *entry)
    (void)fseek(fp, (long)(entry->GetReadLength()), SEEK_CUR);
 }
 
-/**
- * \brief   Loads the value for a a given VLEntry 
- * \warning NOT end user intended method !
- * @param   entry 
- */
-void gdcmDocument::LoadVLEntry(gdcmDocEntry *entry) 
-{
-    //SkipBytes(entry->GetLength());
-    LoadDocEntry(entry);
-}
 /**
  * \brief   When the length of an element value is obviously wrong (because
  *          the parser went Jabberwocky) one can hope improving things by