]> Creatis software - gdcm.git/commitdiff
ENH: Initial work in gathering all transfer syntax accessors. clearly IsDecompressed...
authormalaterre <malaterre>
Fri, 22 Oct 2004 04:13:24 +0000 (04:13 +0000)
committermalaterre <malaterre>
Fri, 22 Oct 2004 04:13:24 +0000 (04:13 +0000)
ChangeLog
src/gdcmDocument.cxx
src/gdcmDocument.h
src/gdcmPixelConvert.cxx

index a02571b43c9622ec6f25989d335ee92d33c856c4..121d8eab170804ab5174d6d9a927418ca32e26b5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2004-10-21 Mathieu Malaterre  <Mathieu.Malaterre@creatis.insa-lyon.fr>
+  * Initial work in gathering all transfer syntax accessors. clearly 
+   IsDecompressed/IsJPEG2000/IsJPEGLossless/IsRLELossless shouldn't be all 
+   ivars, but only one transfersyntax (class) ivar with equivalent method on 
+   the class.
+  
 2004-10-21 Mathieu Malaterre  <Mathieu.Malaterre@creatis.insa-lyon.fr>
   * Removed all FILE* ref and replace by ifstream/ofstream. For now I use a temp 
     solution with the two files jdatadst.cxx and jdatasrc.cxx, this need to be 
index eff4ffdc89a25269be33c07b408a2dca384fe4ce..2f0f843a333b40a1007b8c9fc55a6e2184d2a187 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/22 03:05:41 $
-  Version:   $Revision: 1.108 $
+  Date:      $Date: 2004/10/22 04:13:25 $
+  Version:   $Revision: 1.109 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 
 namespace gdcm 
 {
-
-// Implicit VR Little Endian
-#define UI1_2_840_10008_1_2      "1.2.840.10008.1.2"
-// Explicit VR Little Endian
-#define UI1_2_840_10008_1_2_1    "1.2.840.10008.1.2.1"
-// Deflated Explicit VR Little Endian
-#define UI1_2_840_10008_1_2_1_99 "1.2.840.10008.1.2.1.99"
-// Explicit VR Big Endian
-#define UI1_2_840_10008_1_2_2    "1.2.840.10008.1.2.2"
-// JPEG Baseline (Process 1)
-#define UI1_2_840_10008_1_2_4_50 "1.2.840.10008.1.2.4.50"
-// JPEG Extended (Process 2 & 4)
-#define UI1_2_840_10008_1_2_4_51 "1.2.840.10008.1.2.4.51"
-// JPEG Extended (Process 3 & 5)
-#define UI1_2_840_10008_1_2_4_52 "1.2.840.10008.1.2.4.52"
-// JPEG Spectral Selection, Non-Hierarchical (Process 6 & 8)
-#define UI1_2_840_10008_1_2_4_53 "1.2.840.10008.1.2.4.53"
-// JPEG Full Progression, Non-Hierarchical (Process 10 & 12)
-#define UI1_2_840_10008_1_2_4_55 "1.2.840.10008.1.2.4.55"
-// JPEG Lossless, Non-Hierarchical (Process 14)
-#define UI1_2_840_10008_1_2_4_57 "1.2.840.10008.1.2.4.57"
-// JPEG Lossless, Hierarchical, First-Order Prediction (Process 14,
-// [Selection Value 1])
-#define UI1_2_840_10008_1_2_4_70 "1.2.840.10008.1.2.4.70"
-// JPEG 2000 Lossless
-#define UI1_2_840_10008_1_2_4_90 "1.2.840.10008.1.2.4.90"
-// JPEG 2000
-#define UI1_2_840_10008_1_2_4_91 "1.2.840.10008.1.2.4.91"
-// RLE Lossless
-#define UI1_2_840_10008_1_2_5    "1.2.840.10008.1.2.5"
-// UI1_1_2_840_10008_1_2_5
-#define str2num(str, typeNum) *((typeNum *)(str))
+static const char *TransferSyntaxStrings[] =  {
+  // Implicit VR Little Endian
+  "1.2.840.10008.1.2",
+  // Explicit VR Little Endian
+  "1.2.840.10008.1.2.1",
+  // Deflated Explicit VR Little Endian
+  "1.2.840.10008.1.2.1.99",
+  // Explicit VR Big Endian
+  "1.2.840.10008.1.2.2",
+  // JPEG Baseline (Process 1)
+  "1.2.840.10008.1.2.4.50",
+  // JPEG Extended (Process 2 & 4)
+  "1.2.840.10008.1.2.4.51",
+  // JPEG Extended (Process 3 & 5)
+  "1.2.840.10008.1.2.4.52",
+  // JPEG Spectral Selection, Non-Hierarchical (Process 6 & 8)
+  "1.2.840.10008.1.2.4.53",
+  // JPEG Full Progression, Non-Hierarchical (Process 10 & 12)
+  "1.2.840.10008.1.2.4.55",
+  // JPEG Lossless, Non-Hierarchical (Process 14)
+  "1.2.840.10008.1.2.4.57",
+  // JPEG Lossless, Hierarchical, First-Order Prediction (Process 14, [Selection Value 1])
+  "1.2.840.10008.1.2.4.70",
+  // JPEG 2000 Lossless
+  "1.2.840.10008.1.2.4.90",
+  // JPEG 2000
+  "1.2.840.10008.1.2.4.91",
+  // RLE Lossless
+  "1.2.840.10008.1.2.5",
+  // Unknown
+  "Unknown Transfer Syntax"
+};
 
 //-----------------------------------------------------------------------------
 // Refer to Document::CheckSwap()
@@ -299,12 +299,12 @@ bool Document::IsReadable()
  *          the current document. False either when the document contains
  *          no Transfer Syntax, or when the Tranfer Syntaxes doesn't match.
  */
-bool Document::IsGivenTransferSyntax(std::string const & syntaxToCheck)
+TransferSyntaxType Document::GetTransferSyntax()
 {
    DocEntry *entry = GetDocEntryByNumber(0x0002, 0x0010);
    if ( !entry )
    {
-      return false;
+      return UnknownTS;
    }
 
    // The entry might be present but not loaded (parsing and loading
@@ -316,127 +316,32 @@ bool Document::IsGivenTransferSyntax(std::string const & syntaxToCheck)
       // The actual transfer (as read from disk) might be padded. We
       // first need to remove the potential padding. We can make the
       // weak assumption that padding was not executed with digits...
-      if  ( transfer.length() == 0 ) { // for brain damaged headers
-         return false;
+      if  ( transfer.length() == 0 )
+      {
+         // for brain damaged headers
+         return UnknownTS;
       }
-      while ( ! isdigit(transfer[transfer.length()-1]) )
+      while ( !isdigit(transfer[transfer.length()-1]) )
       {
          transfer.erase(transfer.length()-1, 1);
       }
-      if ( transfer == syntaxToCheck )
+      for (int i = 0; TransferSyntaxStrings[i] != NULL; i++)
       {
-         return true;
+         if ( TransferSyntaxStrings[i] == transfer )
+         {
+            return TransferSyntaxType(i);
+         }
       }
    }
-   return false;
-}
-
-/**
- * \brief   Determines if the Transfer Syntax of the present document
- *          corresponds to a Implicit Value Representation of 
- *          Little Endian.
- * \sa      \ref Document::IsGivenTransferSyntax.
- * @return  True when ImplicitVRLittleEndian found. False in all other cases.
- */
-bool Document::IsImplicitVRLittleEndianTransferSyntax()
-{
-   return IsGivenTransferSyntax(UI1_2_840_10008_1_2);
-}
-
-/**
- * \brief   Determines if the Transfer Syntax was already encountered
- *          and if it corresponds to a ExplicitVRLittleEndian one.
- * @return  True when ExplicitVRLittleEndian found. False in all other cases.
- */
-bool Document::IsExplicitVRLittleEndianTransferSyntax()
-{
-   return IsGivenTransferSyntax(UI1_2_840_10008_1_2_1);
-}
-
-/**
- * \brief   Determines if the Transfer Syntax was already encountered
- *          and if it corresponds to a DeflatedExplicitVRLittleEndian one.
- * @return  True when DeflatedExplicitVRLittleEndian found. False in all other cases.
- */
-bool Document::IsDeflatedExplicitVRLittleEndianTransferSyntax()
-{
-   return IsGivenTransferSyntax(UI1_2_840_10008_1_2_1_99);
-}
-
-/**
- * \brief   Determines if the Transfer Syntax was already encountered
- *          and if it corresponds to a Explicit VR Big Endian one.
- * @return  True when big endian found. False in all other cases.
- */
-bool Document::IsExplicitVRBigEndianTransferSyntax()
-{
-   return IsGivenTransferSyntax(UI1_2_840_10008_1_2_2);
-}
-
-/**
- * \brief   Determines if the Transfer Syntax was already encountered
- *          and if it corresponds to a JPEGBaseLineProcess1 one.
- * @return  True when JPEGBaseLineProcess1found. False in all other cases.
- */
-bool Document::IsJPEGBaseLineProcess1TransferSyntax()
-{
-   return IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_50);
-}
-                                                                                
-/**
- * \brief   Determines if the Transfer Syntax was already encountered
- *          and if it corresponds to a JPEGExtendedProcess2-4 one.
- * @return  True when JPEGExtendedProcess2-4 found. False in all other cases.
- */
-bool Document::IsJPEGExtendedProcess2_4TransferSyntax()
-{
-   return IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_51);
-}
-                                                                                
-/**
- * \brief   Determines if the Transfer Syntax was already encountered
- *          and if it corresponds to a JPEGExtendeProcess3-5 one.
- * @return  True when JPEGExtendedProcess3-5 found. False in all other cases.
- */
-bool Document::IsJPEGExtendedProcess3_5TransferSyntax()
-{
-   return IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_52);
-}
-
-/**
- * \brief   Determines if the Transfer Syntax was already encountered
- *          and if it corresponds to a JPEGSpectralSelectionProcess6-8 one.
- * @return  True when JPEGSpectralSelectionProcess6-8 found. False in all
- *          other cases.
- */
-bool Document::IsJPEGSpectralSelectionProcess6_8TransferSyntax()
-{
-   return IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_53);
+   return UnknownTS;
 }
 
-/**
- * \brief   Determines if the Transfer Syntax was already encountered
- *          and if it corresponds to a RLE Lossless one.
- * @return  True when RLE Lossless found. False in all
- *          other cases.
- */
-bool Document::IsRLELossLessTransferSyntax()
-{
-   return IsGivenTransferSyntax(UI1_2_840_10008_1_2_5);
-}
-
-/**
- * \brief  Determines if Transfer Syntax was already encountered
- *          and if it corresponds to a JPEG Lossless one.
- * @return  True when RLE Lossless found. False in all
- *          other cases.
- */
 bool Document::IsJPEGLossless()
 {
-   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_70) );
+   TransferSyntaxType r = GetTransferSyntax();
+   return    r ==  JPEGFullProgressionProcess10_12
+          || r == JPEGLosslessProcess14
+          || r == JPEGLosslessProcess14_1;
 }
                                                                                 
 /**
@@ -447,8 +352,8 @@ bool Document::IsJPEGLossless()
  */
 bool Document::IsJPEG2000()
 {
-   return (   IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_90)
-           || IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_91) );
+   TransferSyntaxType r = GetTransferSyntax();
+   return r == JPEG2000Lossless || r == JPEG2000;
 }
 
 /**
@@ -456,26 +361,26 @@ bool Document::IsJPEG2000()
  *          of Jpeg encoded Pixel data.
  * @return  True when any form of JPEG found. False otherwise.
  */
-bool Document::IsJPEGTransferSyntax()
+bool Document::IsJPEG()
 {
-   return (   IsJPEGBaseLineProcess1TransferSyntax()
-           || IsJPEGExtendedProcess2_4TransferSyntax()
-           || IsJPEGExtendedProcess3_5TransferSyntax()
-           || IsJPEGSpectralSelectionProcess6_8TransferSyntax()
-           || IsJPEGLossless()
-           || IsJPEG2000() );
+   TransferSyntaxType r = GetTransferSyntax();
+   return r == JPEGBaselineProcess1 
+     || r == JPEGExtendedProcess2_4
+     || r == JPEGExtendedProcess3_5
+     || r == JPEGSpectralSelectionProcess6_8
+     ||      IsJPEGLossless()
+     ||      IsJPEG2000();
 }
 
-
 /**
  * \brief   Determines if the Transfer Syntax corresponds to encapsulated
  *          of encoded Pixel Data (as opposed to native).
  * @return  True when encapsulated. False when native.
  */
-bool Document::IsEncapsulateTransferSyntax()
+bool Document::IsEncapsulate()
 {
-   return (   IsJPEGTransferSyntax()
-           || IsRLELossLessTransferSyntax() );
+   TransferSyntaxType r = GetTransferSyntax();
+   return IsJPEG() || r == RLELossless;
 }
 
 /**
@@ -573,8 +478,8 @@ void Document::Write(std::ofstream* fp, FileType filetype)
 
    if (filetype == ImplicitVR) 
    {
-      std::string implicitVRTransfertSyntax = UI1_2_840_10008_1_2;
-      ReplaceOrCreateByNumber(implicitVRTransfertSyntax,0x0002, 0x0010);
+      std::string ts = TransferSyntaxStrings[ImplicitVRLittleEndian];
+      ReplaceOrCreateByNumber(ts, 0x0002, 0x0010);
       
       /// \todo Refer to standards on page 21, chapter 6.2
       ///       "Value representation": values with a VR of UI shall be
@@ -586,8 +491,8 @@ void Document::Write(std::ofstream* fp, FileType filetype)
 
    if (filetype == ExplicitVR)
    {
-      std::string explicitVRTransfertSyntax = UI1_2_840_10008_1_2_1;
-      ReplaceOrCreateByNumber(explicitVRTransfertSyntax,0x0002, 0x0010);
+      std::string ts = TransferSyntaxStrings[ExplicitVRLittleEndian];
+      ReplaceOrCreateByNumber(ts, 0x0002, 0x0010);
       
       /// \todo Refer to standards on page 21, chapter 6.2
       ///       "Value representation": values with a VR of UI shall be
@@ -1492,15 +1397,15 @@ void Document::ParseDES(DocEntrySet *set,
          if (    ( newDocEntry->GetGroup()   == 0x7fe0 )
               && ( newDocEntry->GetElement() == 0x0010 ) )
          {
-             if ( IsRLELossLessTransferSyntax() ) 
+             TransferSyntaxType ts = GetTransferSyntax();
+             if ( ts == RLELossless ) 
              {
                 long PositionOnEntry = Fp->tellg();
                 Fp->seekg( newDocEntry->GetOffset(), std::ios_base::beg );
                 ComputeRLEInfo();
                 Fp->seekg( PositionOnEntry, std::ios_base::beg );
              }
-             else 
-             if ( IsJPEGTransferSyntax() )
+             else if ( IsJPEG() )
              {
                 long PositionOnEntry = Fp->tellg();
                 Fp->seekg( newDocEntry->GetOffset(), std::ios_base::beg );
@@ -1873,7 +1778,8 @@ void Document::FindDocEntryLength( DocEntry *entry )
       // big endian and proceed...
       if ( element  == 0x0000 && length16 == 0x0400 ) 
       {
-         if ( !IsExplicitVRBigEndianTransferSyntax() ) 
+         TransferSyntaxType ts = GetTransferSyntax();
+         if ( ts != ExplicitVRBigEndian ) 
          {
             throw FormatError( "Document::FindDocEntryLength()",
                                " not explicit VR." );
@@ -2893,7 +2799,8 @@ void Document::ReadAndSkipEncapsulatedBasicOffsetTable()
  */
 void Document::ComputeRLEInfo()
 {
-   if ( ! IsRLELossLessTransferSyntax() )
+   TransferSyntaxType ts = GetTransferSyntax();
+   if ( ts != RLELossless )
    {
       return;
    }
@@ -2986,7 +2893,7 @@ void Document::ComputeRLEInfo()
 void Document::ComputeJPEGFragmentInfo()
 {
    // If you need to, look for comments of ComputeRLEInfo().
-   if ( ! IsJPEGTransferSyntax() )
+   if ( ! IsJPEG() )
    {
       return;
    }
index f7384be5e94e13418d5d79e5e5e2d95447fcdd24..31ed27ff82fbcc5b88800a2f7013fd0c2e20fece 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/22 03:05:41 $
-  Version:   $Revision: 1.53 $
+  Date:      $Date: 2004/10/22 04:13:25 $
+  Version:   $Revision: 1.54 $
  
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -41,6 +41,24 @@ class SeqEntry;
 namespace gdcm 
 {
 
+enum TransferSyntaxType {
+  ImplicitVRLittleEndian = 0,
+  ExplicitVRLittleEndian,
+  DeflatedExplicitVRLittleEndian,
+  ExplicitVRBigEndian,
+  JPEGBaselineProcess1,
+  JPEGExtendedProcess2_4,
+  JPEGExtendedProcess3_5,
+  JPEGSpectralSelectionProcess6_8,
+  JPEGFullProgressionProcess10_12,
+  JPEGLosslessProcess14,
+  JPEGLosslessProcess14_1,
+  JPEG2000Lossless,
+  JPEG2000,
+  RLELossless,
+  UnknownTS
+};
+
 //-----------------------------------------------------------------------------
 /**
  * \brief Derived by both Header and DicomDir
@@ -119,20 +137,11 @@ public:
 
 // Informations contained in the parser
    virtual bool IsReadable();
-   bool IsGivenTransferSyntax(std::string const & syntaxToCheck);
-   bool IsImplicitVRLittleEndianTransferSyntax();
-   bool IsExplicitVRLittleEndianTransferSyntax();
-   bool IsDeflatedExplicitVRLittleEndianTransferSyntax();
-   bool IsExplicitVRBigEndianTransferSyntax();
-   bool IsRLELossLessTransferSyntax();
-   bool IsJPEGBaseLineProcess1TransferSyntax();
-   bool IsJPEGExtendedProcess2_4TransferSyntax();
-   bool IsJPEGExtendedProcess3_5TransferSyntax();
-   bool IsJPEGSpectralSelectionProcess6_8TransferSyntax();
+   TransferSyntaxType GetTransferSyntax();
    bool IsJPEGLossless();
    bool IsJPEG2000();
-   bool IsJPEGTransferSyntax();
-   bool IsEncapsulateTransferSyntax();
+   bool IsJPEG();
+   bool IsEncapsulate();
    bool IsDicomV3();
 
    FileType GetFileType();
@@ -143,12 +152,12 @@ public:
    void Write( std::ofstream* fp, FileType type );
 
    ValEntry* ReplaceOrCreateByNumber(std::string const & value,
-                                         uint16_t group, uint16_t elem,
-                                         std::string const & VR ="unkn");
+                                     uint16_t group, uint16_t elem,
+                                     std::string const & VR ="unkn");
    
    BinEntry* ReplaceOrCreateByNumber(uint8_t* binArea, int lgth,
-                                         uint16_t group, uint16_t elem,
-                                         std::string const & VR="unkn");
+                                     uint16_t group, uint16_t elem,
+                                     std::string const & VR="unkn");
 
    SeqEntry* ReplaceOrCreateByNumber(uint16_t group, uint16_t elem);
 
index e345dceaf92c0c3c539d807a0177ae548b13faf0..59febdc49d70d5a21d93795bf3eea1c2b82e374b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmPixelConvert.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/22 03:05:42 $
-  Version:   $Revision: 1.18 $
+  Date:      $Date: 2004/10/22 04:13:26 $
+  Version:   $Revision: 1.19 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -613,7 +613,7 @@ bool PixelConvert::ReadAndDecompressPixelData( std::ifstream* fp )
    else if ( IsDecompressed )
    {
       fp->read( (char*)Decompressed, PixelDataLength);
-      if ( fp->fail() | |fp->eof())//Fp->gcount() == 1
+      if ( fp->fail() |fp->eof())//Fp->gcount() == 1
       {
          dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: "
                          "reading of decompressed pixel data failed." );
@@ -783,15 +783,16 @@ void PixelConvert::GrabInformationsFromHeader( Header* header )
    PixelSize = header->GetPixelSize();
    PixelSign = header->IsSignedPixelData();
    SwapCode  = header->GetSwapCode();
+   TransferSyntaxType ts = header->GetTransferSyntax();
    IsDecompressed =
         ( ! header->IsDicomV3() )
-     || header->IsImplicitVRLittleEndianTransferSyntax()
-     || header->IsExplicitVRLittleEndianTransferSyntax()
-     || header->IsExplicitVRBigEndianTransferSyntax()
-     || header->IsDeflatedExplicitVRLittleEndianTransferSyntax();
+     || ts == ImplicitVRLittleEndian
+     || ts == ExplicitVRLittleEndian
+     || ts == ExplicitVRBigEndian
+     || ts == DeflatedExplicitVRLittleEndian;
    IsJPEG2000     = header->IsJPEG2000();
    IsJPEGLossless = header->IsJPEGLossless();
-   IsRLELossless  = header->IsRLELossLessTransferSyntax();
+   IsRLELossless  =  ( ts == RLELossless );
    PixelOffset     = header->GetPixelOffset();
    PixelDataLength = header->GetPixelAreaLength();
    RLEInfo  = header->GetRLEInfo();