]> Creatis software - gdcm.git/blobdiff - src/gdcmDocument.cxx
ENH: minor cleanup patch, use TagName instead of std:string for clarification. Don...
[gdcm.git] / src / gdcmDocument.cxx
index eff4ffdc89a25269be33c07b408a2dca384fe4ce..25fac9debfc836e27845097f265d1d54794410b3 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/24 03:33:40 $
+  Version:   $Revision: 1.111 $
                                                                                 
   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()
@@ -84,8 +84,7 @@ const unsigned int Document::MAX_SIZE_PRINT_ELEMENT_VALUE = 0x7fffffff;
  * \brief   constructor  
  * @param   filename file to be opened for parsing
  */
-Document::Document( std::string const & filename ) 
-              : ElementSet(-1)
+Document::Document( std::string const & filename ) : ElementSet(-1)
 {
    SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE); 
    Filename = filename;
@@ -180,8 +179,7 @@ Document::Document( std::string const & filename )
  * \brief This default constructor doesn't parse the file. You should
  *        then invoke \ref Document::SetFileName and then the parsing.
  */
-Document::Document() 
-             :ElementSet(-1)
+Document::Document() : ElementSet(-1)
 {
    SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE);
    Initialise();
@@ -299,12 +297,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 +314,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);
+   return UnknownTS;
 }
 
-/**
- * \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);
-}
-
-/**
- * \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 +350,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 +359,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 +476,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 +489,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
@@ -627,7 +530,7 @@ ValEntry* Document::ReplaceOrCreateByNumber(
                                          std::string const & value, 
                                          uint16_t group, 
                                          uint16_t elem,
-                                         std::string const & VR )
+                                         TagName const & vr )
 {
    ValEntry* valEntry = 0;
    DocEntry* currentEntry = GetDocEntryByNumber( group, elem);
@@ -643,7 +546,7 @@ ValEntry* Document::ReplaceOrCreateByNumber(
       DictEntry* dictEntry = pubDict->GetDictEntryByNumber(group, elem);
       if (!dictEntry)
       {
-         currentEntry = NewDocEntryByNumber(group, elem,VR);
+         currentEntry = NewDocEntryByNumber(group, elem, vr);
       }
       else
       {
@@ -706,7 +609,7 @@ BinEntry* Document::ReplaceOrCreateByNumber(
                                          int lgth, 
                                          uint16_t group, 
                                          uint16_t elem,
-                                         std::string const& VR )
+                                         TagName const & vr )
 {
    BinEntry* binEntry = 0;
    DocEntry* currentEntry = GetDocEntryByNumber( group, elem);
@@ -723,7 +626,7 @@ BinEntry* Document::ReplaceOrCreateByNumber(
 
       if (!dictEntry)
       {
-         currentEntry = NewDocEntryByNumber(group, elem, VR);
+         currentEntry = NewDocEntryByNumber(group, elem, vr);
       }
       else
       {
@@ -780,9 +683,7 @@ BinEntry* Document::ReplaceOrCreateByNumber(
  * \return  pointer to the modified/created SeqEntry (NULL when creation
  *          failed).
  */
-SeqEntry* Document::ReplaceOrCreateByNumber(
-                                         uint16_t group, 
-                                         uint16_t elem)
+SeqEntry* Document::ReplaceOrCreateByNumber( uint16_t group, uint16_t elem)
 {
    SeqEntry* b = 0;
    DocEntry* a = GetDocEntryByNumber( group, elem);
@@ -809,7 +710,7 @@ SeqEntry* Document::ReplaceOrCreateByNumber(
  * \return  boolean 
  */
 bool Document::ReplaceIfExistByNumber(std::string const & value, 
-                                          uint16_t group, uint16_t elem ) 
+                                      uint16_t group, uint16_t elem ) 
 {
    SetEntryByNumber(value, group, elem);
 
@@ -840,7 +741,7 @@ bool Document::CheckIfEntryExistByNumber(uint16_t group, uint16_t element )
  * @return  Corresponding element value when it exists,
  *          and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
  */
-std::string Document::GetEntryByName(TagName const& tagName)
+std::string Document::GetEntryByName(TagName const & tagName)
 {
    DictEntry* dictEntry = RefPubDict->GetDictEntryByName(tagName); 
    if( !dictEntry )
@@ -873,7 +774,7 @@ std::string Document::GetEntryVRByName(TagName const& tagName)
    }
 
    DocEntry* elem = GetDocEntryByNumber(dictEntry->GetGroup(),
-                                            dictEntry->GetElement());
+                                        dictEntry->GetElement());
    return elem->GetVR();
 }
 
@@ -945,7 +846,8 @@ int Document::GetEntryLengthByNumber(uint16_t group, uint16_t element)
  * @param   tagName name of the searched Dicom Element.
  * @return  true when found
  */
-bool Document::SetEntryByName(std::string const & content,std::string const & tagName)
+bool Document::SetEntryByName(std::string const & content,
+                              TagName const & tagName)
 {
    DictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName); 
    if( !dictEntry )
@@ -966,8 +868,7 @@ bool Document::SetEntryByName(std::string const & content,std::string const & ta
  * @param   element element number of the Dicom Element to modify
  */
 bool Document::SetEntryByNumber(std::string const& content, 
-                                    uint16_t group,
-                                    uint16_t element) 
+                                uint16_t group, uint16_t element) 
 {
    int c;
    int l;
@@ -1019,10 +920,8 @@ bool Document::SetEntryByNumber(std::string const& content,
  * @param   group     group number of the Dicom Element to modify
  * @param   element element number of the Dicom Element to modify
  */
-bool Document::SetEntryByNumber(uint8_t*content,
-                                int lgth, 
-                                uint16_t group,
-                                uint16_t element) 
+bool Document::SetEntryByNumber(uint8_t*content, int lgth, 
+                                uint16_t group, uint16_t element) 
 {
    (void)lgth;  //not used
    TagKey key = DictEntry::TranslateToKey(group, element);
@@ -1058,8 +957,7 @@ bool Document::SetEntryByNumber(uint8_t*content,
  * @return  true on success, false otherwise.
  */
 bool Document::SetEntryLengthByNumber(uint32_t l, 
-                                      uint16_t group, 
-                                      uint16_t element) 
+                                      uint16_t group, uint16_t element) 
 {
    /// \todo use map methods, instead of multimap JPR
    TagKey key = DictEntry::TranslateToKey(group, element);
@@ -1188,8 +1086,7 @@ void* Document::LoadEntryBinArea(BinEntry* element)
  * @return  
  */
 bool Document::SetEntryBinAreaByNumber(uint8_t* area,
-                                            uint16_t group, 
-                                            uint16_t element) 
+                                       uint16_t group, uint16_t element) 
 {
    DocEntry* currentEntry = GetDocEntryByNumber(group, element);
    if ( !currentEntry )
@@ -1259,7 +1156,7 @@ void Document::UpdateShaEntries()
  * @return  Corresponding Dicom Element when it exists, and NULL
  *          otherwise.
  */
-DocEntry* Document::GetDocEntryByName(std::string const & tagName)
+DocEntry* Document::GetDocEntryByName(TagName const & tagName)
 {
    DictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName); 
    if( !dictEntry )
@@ -1280,8 +1177,7 @@ DocEntry* Document::GetDocEntryByName(std::string const & tagName)
  * @param   element Element number of the searched Dicom Element 
  * @return  
  */
-DocEntry* Document::GetDocEntryByNumber(uint16_t group,
-                                                uint16_t element) 
+DocEntry* Document::GetDocEntryByNumber(uint16_t group, uint16_t element) 
 {
    TagKey key = DictEntry::TranslateToKey(group, element);
    if ( !TagHT.count(key))
@@ -1297,8 +1193,7 @@ DocEntry* Document::GetDocEntryByNumber(uint16_t group,
  *         ValEntry.
  * @return When present, the corresponding ValEntry. 
  */
-ValEntry* Document::GetValEntryByNumber(uint16_t group,
-                                                uint16_t element)
+ValEntry* Document::GetValEntryByNumber(uint16_t group, uint16_t element)
 {
    DocEntry* currentEntry = GetDocEntryByNumber(group, element);
    if ( !currentEntry )
@@ -1398,10 +1293,8 @@ uint16_t Document::UnswapShort(uint16_t a)
  * \brief   Parses a DocEntrySet (Zero-level DocEntries or SQ Item DocEntries)
  * @return  length of the parsed set. 
  */ 
-void Document::ParseDES(DocEntrySet *set,
-                        long offset,
-                        long l_max,
-                        bool delim_mode)
+void Document::ParseDES(DocEntrySet *set, long offset, 
+                        long l_max, bool delim_mode)
 {
    DocEntry *newDocEntry = 0;
    
@@ -1492,15 +1385,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 );
@@ -1574,7 +1467,7 @@ void Document::ParseDES(DocEntrySet *set,
  * @return  parsed length for this level
  */ 
 void Document::ParseSQ( SeqEntry* seqEntry,
-                            long offset, long l_max, bool delim_mode)
+                        long offset, long l_max, bool delim_mode)
 {
    int SQItemNumber = 0;
    bool dlm_mod;
@@ -1873,7 +1766,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." );
@@ -2204,7 +2098,7 @@ void Document::SkipToNextDocEntry(DocEntry *entry)
  * @param   foundLength fist assumption about length    
  */
 void Document::FixDocEntryFoundLength(DocEntry *entry,
-                                          uint32_t foundLength)
+                                      uint32_t foundLength)
 {
    entry->SetReadLength( foundLength ); // will be updated only if a bug is found        
    if ( foundLength == 0xffffffff)
@@ -2893,7 +2787,8 @@ void Document::ReadAndSkipEncapsulatedBasicOffsetTable()
  */
 void Document::ComputeRLEInfo()
 {
-   if ( ! IsRLELossLessTransferSyntax() )
+   TransferSyntaxType ts = GetTransferSyntax();
+   if ( ts != RLELossless )
    {
       return;
    }
@@ -2931,6 +2826,11 @@ void Document::ComputeRLEInfo()
       long frameOffset = Fp->tellg();
 
       uint32_t nbRleSegments = ReadInt32();
+      if ( nbRleSegments > 16 )
+      {
+         // There should be at most 15 segments (refer to RLEFrame class)
+         dbg.Verbose(0, "Document::ComputeRLEInfo: too many segments.");
+      }
  
       uint32_t rleSegmentOffsetTable[15];
       for( int k = 1; k <= 15; k++ )
@@ -2986,7 +2886,7 @@ void Document::ComputeRLEInfo()
 void Document::ComputeJPEGFragmentInfo()
 {
    // If you need to, look for comments of ComputeRLEInfo().
-   if ( ! IsJPEGTransferSyntax() )
+   if ( ! IsJPEG() )
    {
       return;
    }
@@ -3028,7 +2928,7 @@ void Document::ComputeJPEGFragmentInfo()
  * @param set The structure to be traversed (recursively).
  */
 void Document::BuildFlatHashTableRecurse( TagDocEntryHT& builtHT,
-                                              DocEntrySet* set )
+                                          DocEntrySet* set )
 { 
    if (ElementSet* elementSet = dynamic_cast< ElementSet* > ( set ) )
    {