]> Creatis software - gdcm.git/blobdiff - src/gdcmDocument.cxx
ENH: Since HandleOutOfGroup0002 need access to the transfer syntax move the method...
[gdcm.git] / src / gdcmDocument.cxx
index 4c85abc879cc503245e81a49c2f55aeb2f42701e..ae50bc8a2cbd31b55893e6e57c672bb5f84939d0 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/11 22:05:22 $
-  Version:   $Revision: 1.177 $
+  Date:      $Date: 2005/01/11 23:06:35 $
+  Version:   $Revision: 1.180 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -160,7 +160,7 @@ Document::Document() : ElementSet(-1)
 
    SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE);
    Initialise();
-   SwapCode = 0;
+   SwapCode = 1234;
    Filetype = ExplicitVR;
    Group0002Parsed = false;
 }
@@ -1010,7 +1010,7 @@ uint32_t Document::SwapLong(uint32_t a)
 {
    switch (SwapCode)
    {
-      case    0 :
+      case 1234 :
          break;
       case 4321 :
          a=( ((a<<24) & 0xff000000) | ((a<<8)  & 0x00ff0000) | 
@@ -2164,7 +2164,7 @@ bool Document::CheckSwap()
       }
       else 
       {
-         SwapCode = 0;
+         SwapCode = 1234;
          gdcmVerboseMacro( "HostByteOrder = NetworkByteOrder");
       }
       
@@ -2207,7 +2207,7 @@ bool Document::CheckSwap()
          Filetype = ACR;
          return true;
       case 0x00000004 :
-         SwapCode = 0;
+         SwapCode = 1234;
          Filetype = ACR;
          return true;
       default :
@@ -2238,7 +2238,7 @@ bool Document::CheckSwap()
             case 0x0006 :
             case 0x0007 :
             case 0x0008 :
-               SwapCode = 0;
+               SwapCode = 1234;
                Filetype = ACR;
                return true;
             case 0x0100 :
@@ -2259,7 +2259,7 @@ bool Document::CheckSwap()
          }
          // Then the only info we have is the net2host one.
          //if (! net2host )
-         //   SwapCode = 0;
+         //   SwapCode = 1234;
          //else
          //  SwapCode = 4321;
          //return;
@@ -2274,13 +2274,13 @@ bool Document::CheckSwap()
 void Document::SwitchByteSwapCode() 
 {
    gdcmVerboseMacro( "Switching Byte Swap code.");
-   if ( SwapCode == 0    ) 
+   if ( SwapCode == 1234 ) 
    {
       SwapCode = 4321;
    }
    else if ( SwapCode == 4321 ) 
    {
-      SwapCode = 0;
+      SwapCode = 1234;
    }
    else if ( SwapCode == 3412 ) 
    {
@@ -2339,7 +2339,7 @@ void Document::SetMaxSizePrintEntry(long newSize)
  *          apparent reason
  * @return  no return
  */
-void Document::HandleBrokenEndian(uint16_t group, uint16_t elem)
+void Document::HandleBrokenEndian(uint16_t &group, uint16_t &elem)
 {
    // Endian reversion. Some files contain groups of tags with reversed endianess.
    static int reversedEndian = 0;
@@ -2361,6 +2361,40 @@ void Document::HandleBrokenEndian(uint16_t group, uint16_t elem)
    }
 }
 
+/**
+ * \brief Accesses the info from 0002,0010 : Transfer Syntax and TS
+ *        else 1.
+ * @return The full Transfer Syntax Name (as opposed to Transfer Syntax UID)
+ */
+std::string Document::GetTransferSyntaxName()
+{
+   // use the TS (TS : Transfer Syntax)
+   std::string transferSyntax = GetEntry(0x0002,0x0010);
+
+   if ( transferSyntax == GDCM_NOTLOADED )
+   {
+      gdcmVerboseMacro( "Transfer Syntax not loaded. " << std::endl
+               << "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE" );
+      return "Uncompressed ACR-NEMA";
+   }
+   if ( transferSyntax == GDCM_UNFOUND )
+   {
+      gdcmVerboseMacro( "Unfound Transfer Syntax (0002,0010)");
+      return "Uncompressed ACR-NEMA";
+   }
+
+   while ( ! isdigit((unsigned char)transferSyntax[transferSyntax.length()-1]) )
+   {
+      transferSyntax.erase(transferSyntax.length()-1, 1);
+   }
+   // we do it only when we need it
+   TS* ts         = Global::GetTS();
+   std::string tsName = ts->GetValue( transferSyntax );
+
+   // Global::GetTS() is a global static you shall never try to delete it!
+   return tsName;
+}
+
 /**
  * \brief   Group 0002 is always coded Little Endian
  *          whatever Transfer Syntax is
@@ -2372,25 +2406,23 @@ void Document::HandleOutOfGroup0002(uint16_t group)
    if ( !Group0002Parsed && group != 0x0002)
    {
       Group0002Parsed = true;
-     // we just came out of group 0002
-     // if Transfer syntax is Big Endian we have to change CheckSwap
+      // we just came out of group 0002
+      // if Transfer syntax is Big Endian we have to change CheckSwap
 
-      TagKey key = DictEntry::TranslateToKey(0x0002, 0x0010);
-      if ( !TagHT.count(key))
+      std::string ts = GetTransferSyntaxName();
+      if ( !Global::GetTS()->IsTransferSyntax(ts) )
       {
-         gdcmVerboseMacro("True DICOM File, with NO Tansfer Syntax ?!?");
+         gdcmVerboseMacro("True DICOM File, with NO Tansfer Syntax: " << ts );
          return;
       }
 
-   // FIXME Strangely, this works with 
-   //'Implicit VR Transfer Syntax (GE Private)
-
-       if ( ((ValEntry *)TagHT.find(key)->second)->GetValue()
-               == "Explicit VR - Big Endian" )
-       {
-          gdcmVerboseMacro("Tansfer Syntax = Explicit VR - Big Endian");
-          SwitchByteSwapCode();
-        }
+      // FIXME Strangely, this works with 
+      //'Implicit VR Transfer Syntax (GE Private)
+      if ( Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRBigEndian )
+      {
+         gdcmVerboseMacro("Tansfer Syntax = Explicit VR - Big Endian");
+         SwitchByteSwapCode();
+      }
    }
 }