From 31c63a6cb25b49a119e0132201c051ade2e17704 Mon Sep 17 00:00:00 2001 From: malaterre Date: Tue, 11 Jan 2005 16:44:42 +0000 Subject: [PATCH] ENH: Untangle the transfer syntax from the Document. The Document can only read a string and can only ask gdcm::TS what are the property of the transfer syntax --- Testing/TestTS.cxx | 17 +++- src/gdcmDocument.cxx | 124 ++++----------------------- src/gdcmDocument.h | 32 +------ src/gdcmFile.cxx | 10 ++- src/gdcmPixelReadConvert.cxx | 24 +++--- src/gdcmTS.cxx | 159 +++++++++++++++++++++++++++++++++-- src/gdcmTS.h | 34 +++++++- 7 files changed, 237 insertions(+), 163 deletions(-) diff --git a/Testing/TestTS.cxx b/Testing/TestTS.cxx index ec79fa6b..b2f57f82 100644 --- a/Testing/TestTS.cxx +++ b/Testing/TestTS.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestTS.cxx,v $ Language: C++ - Date: $Date: 2005/01/11 14:39:03 $ - Version: $Revision: 1.5 $ + Date: $Date: 2005/01/11 16:44:42 $ + Version: $Revision: 1.6 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -56,5 +56,18 @@ int TestTS(int , char *[]) // Unknown std::cout << ts.IsTransferSyntax( "Unknown Transfer Syntax" ) << std::endl; + // Test JPEG test: + std::cout << "Test TS:" << std::endl; + std::cout << ts.IsJPEGLossless( "1.2.840.10008.1.2.4.55") << std::endl; +//if ( key == "1.2.840.10008.1.2.4.55" +// || key == "1.2.840.10008.1.2.4.57" +// || key == "1.2.840.10008.1.2.4.70" ) + std::cout << ts.IsRLELossless( "1.2.840.10008.1.2.5") << std::endl; + std::cout << ts.IsJPEGLossless( "1.2.840.10008.1.2.5") << std::endl; + std::cout << ts.IsJPEG2000( "1.2.840.10008.1.2.5") << std::endl; + std::cout << ts.IsJPEG( "1.2.840.10008.1.2.5") << std::endl; + std::cout << ts.IsEncapsulate( "1.2.840.10008.1.2.5") << std::endl; + std::cout << ts.GetSpecialTransferSyntax( ts.GetSpecialTransferSyntax( "1.2.840.10008.1.2.5")) << std::endl; + return ts.GetValue( "" ) != gdcm::GDCM_UNFOUND; } diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 2bb417ca..f4b47a1e 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2005/01/11 11:37:13 $ - Version: $Revision: 1.173 $ + Date: $Date: 2005/01/11 16:44:43 $ + Version: $Revision: 1.174 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -43,41 +43,6 @@ namespace gdcm { -//----------------------------------------------------------------------------- -static const char *TransferSyntaxStrings[] = { - // Implicit VR Little Endian - "1.2.840.10008.1.2", - // Implicit VR Big Endian DLX (G.E Private) - "1.2.840.113619.5.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() @@ -304,12 +269,12 @@ bool Document::IsReadable() * value from disk when only parsing occured). * @return The encountered Transfer Syntax of the current document. */ -TransferSyntaxType Document::GetTransferSyntax() +std::string Document::GetTransferSyntax() { DocEntry *entry = GetDocEntry(0x0002, 0x0010); if ( !entry ) { - return UnknownTS; + return GDCM_UNKNOWN; } // The entry might be present but not loaded (parsing and loading @@ -324,68 +289,15 @@ TransferSyntaxType Document::GetTransferSyntax() if ( transfer.length() == 0 ) { // for brain damaged headers - return UnknownTS; + return GDCM_UNKNOWN; } while ( !isdigit((unsigned char)transfer[transfer.length()-1]) ) { transfer.erase(transfer.length()-1, 1); } - for (int i = 0; TransferSyntaxStrings[i] != NULL; i++) - { - if ( TransferSyntaxStrings[i] == transfer ) - { - return TransferSyntaxType(i); - } - } + return transfer; } - return UnknownTS; -} - -bool Document::IsJPEGLossless() -{ - TransferSyntaxType r = GetTransferSyntax(); - return r == JPEGFullProgressionProcess10_12 - || r == JPEGLosslessProcess14 - || r == JPEGLosslessProcess14_1; -} - -/** - * \brief Determines if the Transfer Syntax was already encountered - * and if it corresponds to a JPEG2000 one - * @return True when JPEG2000 (Lossly or LossLess) found. False in all - * other cases. - */ -bool Document::IsJPEG2000() -{ - TransferSyntaxType r = GetTransferSyntax(); - return r == JPEG2000Lossless || r == JPEG2000; -} - -/** - * \brief Determines if the Transfer Syntax corresponds to any form - * of Jpeg encoded Pixel data. - * @return True when any form of JPEG found. False otherwise. - */ -bool Document::IsJPEG() -{ - 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::IsEncapsulate() -{ - TransferSyntaxType r = GetTransferSyntax(); - return IsJPEG() || r == RLELossless; + return GDCM_UNKNOWN; } /** @@ -739,11 +651,6 @@ bool Document::ReplaceIfExist(std::string const &value, return true; } -std::string Document::GetTransferSyntaxValue(TransferSyntaxType type) -{ - return TransferSyntaxStrings[type]; -} - //----------------------------------------------------------------------------- // Protected @@ -1273,15 +1180,15 @@ void Document::ParseDES(DocEntrySet *set, long offset, if ( ( newDocEntry->GetGroup() == 0x7fe0 ) && ( newDocEntry->GetElement() == 0x0010 ) ) { - TransferSyntaxType ts = GetTransferSyntax(); - if ( ts == RLELossless ) + std::string ts = GetTransferSyntax(); + if ( Global::GetTS()->IsRLELossless(ts) ) { long positionOnEntry = Fp->tellg(); Fp->seekg( newDocEntry->GetOffset(), std::ios::beg ); ComputeRLEInfo(); Fp->seekg( positionOnEntry, std::ios::beg ); } - else if ( IsJPEG() ) + else if ( Global::GetTS()->IsJPEG(ts) ) { long positionOnEntry = Fp->tellg(); Fp->seekg( newDocEntry->GetOffset(), std::ios::beg ); @@ -1669,8 +1576,8 @@ void Document::FindDocEntryLength( DocEntry *entry ) // big endian and proceed... if ( element == 0x0000 && length16 == 0x0400 ) { - TransferSyntaxType ts = GetTransferSyntax(); - if ( ts != ExplicitVRBigEndian ) + std::string ts = GetTransferSyntax(); + if ( Global::GetTS()->GetSpecialTransferSyntax(ts) != TS::ExplicitVRBigEndian ) { throw FormatError( "Document::FindDocEntryLength()", " not explicit VR." ); @@ -2714,8 +2621,8 @@ void Document::ReadAndSkipEncapsulatedBasicOffsetTable() */ void Document::ComputeRLEInfo() { - TransferSyntaxType ts = GetTransferSyntax(); - if ( ts != RLELossless ) + std::string ts = GetTransferSyntax(); + if ( Global::GetTS()->IsRLELossless(ts) ) { return; } @@ -2812,7 +2719,8 @@ void Document::ComputeRLEInfo() void Document::ComputeJPEGFragmentInfo() { // If you need to, look for comments of ComputeRLEInfo(). - if ( ! IsJPEG() ) + std::string ts = GetTransferSyntax(); + if ( ! Global::GetTS()->IsJPEG(ts) ) { return; } diff --git a/src/gdcmDocument.h b/src/gdcmDocument.h index d237d0d2..aee3aaa1 100644 --- a/src/gdcmDocument.h +++ b/src/gdcmDocument.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.h,v $ Language: C++ - Date: $Date: 2005/01/11 11:37:13 $ - Version: $Revision: 1.79 $ + Date: $Date: 2005/01/11 16:44:43 $ + Version: $Revision: 1.80 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -36,25 +36,6 @@ class Dict; class RLEFramesInfo; class JPEGFragmentsInfo; -enum TransferSyntaxType { - ImplicitVRLittleEndian = 0, - ImplicitVRLittleEndianDLXGE, - 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 @@ -66,12 +47,8 @@ public: virtual bool IsReadable(); FileType GetFileType(); - TransferSyntaxType GetTransferSyntax(); + std::string GetTransferSyntax(); - bool IsJPEGLossless(); - bool IsJPEG2000(); - bool IsJPEG(); - bool IsEncapsulate(); bool IsDicomV3(); RLEFramesInfo *GetRLEInfo() { return RLEInfo; } @@ -145,9 +122,6 @@ public: void LoadDocEntrySafe(DocEntry *entry); TagDocEntryHT *BuildFlatHashTable(); -// Divers - static std::string GetTransferSyntaxValue(TransferSyntaxType type); - protected: // Methods // Constructor and destructor are protected to forbid end user diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index c6638963..11ec7fe6 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.cxx,v $ Language: C++ - Date: $Date: 2005/01/11 11:37:13 $ - Version: $Revision: 1.189 $ + Date: $Date: 2005/01/11 16:44:43 $ + Version: $Revision: 1.190 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,6 +17,8 @@ =========================================================================*/ #include "gdcmFile.h" +#include "gdcmGlobal.h" +#include "gdcmTS.h" #include "gdcmDocument.h" #include "gdcmDebug.h" #include "gdcmUtil.h" @@ -777,7 +779,7 @@ void File::SetWriteFileTypeToACR() void File::SetWriteFileTypeToExplicitVR() { std::string ts = Util::DicomString( - Document::GetTransferSyntaxValue(ExplicitVRLittleEndian).c_str() ); + Global::GetTS()->GetSpecialTransferSyntax(TS::ExplicitVRLittleEndian) ); ValEntry *tss = CopyValEntry(0x0002,0x0010); tss->SetValue(ts); @@ -788,7 +790,7 @@ void File::SetWriteFileTypeToExplicitVR() void File::SetWriteFileTypeToImplicitVR() { std::string ts = Util::DicomString( - Document::GetTransferSyntaxValue(ImplicitVRLittleEndian).c_str() ); + Global::GetTS()->GetSpecialTransferSyntax(TS::ImplicitVRLittleEndian) ); ValEntry *tss = CopyValEntry(0x0002,0x0010); tss->SetValue(ts); diff --git a/src/gdcmPixelReadConvert.cxx b/src/gdcmPixelReadConvert.cxx index 31ebbc47..17c28603 100644 --- a/src/gdcmPixelReadConvert.cxx +++ b/src/gdcmPixelReadConvert.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmPixelReadConvert.cxx,v $ Language: C++ - Date: $Date: 2005/01/08 15:03:59 $ - Version: $Revision: 1.20 $ + Date: $Date: 2005/01/11 16:44:43 $ + Version: $Revision: 1.21 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -24,6 +24,8 @@ #include "gdcmDebug.h" #include "gdcmHeader.h" +#include "gdcmGlobal.h" +#include "gdcmTS.h" #include "gdcmPixelReadConvert.h" #include "gdcmDocEntry.h" #include "gdcmRLEFramesInfo.h" @@ -1035,17 +1037,17 @@ void PixelReadConvert::GrabInformationsFromHeader( Header *header ) PixelSize = header->GetPixelSize(); PixelSign = header->IsSignedPixelData(); SwapCode = header->GetSwapCode(); - TransferSyntaxType ts = header->GetTransferSyntax(); + std::string ts = header->GetTransferSyntax(); IsRaw = ( ! header->IsDicomV3() ) - || ts == ImplicitVRLittleEndian - || ts == ImplicitVRLittleEndianDLXGE - || ts == ExplicitVRLittleEndian - || ts == ExplicitVRBigEndian - || ts == DeflatedExplicitVRLittleEndian; - IsJPEG2000 = header->IsJPEG2000(); - IsJPEGLossless = header->IsJPEGLossless(); - IsRLELossless = ( ts == RLELossless ); + || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ImplicitVRLittleEndian + || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ImplicitVRLittleEndianDLXGE + || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRLittleEndian + || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRBigEndian + || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::DeflatedExplicitVRLittleEndian; + IsJPEG2000 = Global::GetTS()->IsJPEG2000(ts); + IsJPEGLossless = Global::GetTS()->IsJPEGLossless(ts); + IsRLELossless = Global::GetTS()->IsRLELossless(ts); PixelOffset = header->GetPixelOffset(); PixelDataLength = header->GetPixelAreaLength(); RLEInfo = header->GetRLEInfo(); diff --git a/src/gdcmTS.cxx b/src/gdcmTS.cxx index af3bf7b0..f0f2049c 100644 --- a/src/gdcmTS.cxx +++ b/src/gdcmTS.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmTS.cxx,v $ Language: C++ - Date: $Date: 2005/01/11 00:37:41 $ - Version: $Revision: 1.34 $ + Date: $Date: 2005/01/11 16:44:43 $ + Version: $Revision: 1.35 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -33,6 +33,42 @@ namespace gdcm { +//----------------------------------------------------------------------------- +static const char *SpecialStrings[] = { + // Implicit VR Little Endian + "1.2.840.10008.1.2", + // Implicit VR Big Endian DLX (G.E Private) + "1.2.840.113619.5.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" +}; + void FillDefaultTSDict(TSHT &ts); //----------------------------------------------------------------------------- // Constructor / Destructor @@ -49,13 +85,13 @@ TS::TS() { TSKey key; TSAtr name; - + while (!from.eof()) { from >> key; from >> std::ws; std::getline(from, name); - + if(key != "") { TsMap[key] = name; @@ -108,12 +144,121 @@ TSAtr const & TS::GetValue(TSKey const &key) bool TS::IsTransferSyntax(TSKey const &key) { - for (TSHT::const_iterator it = TsMap.begin(); it != TsMap.end(); ++it) + TSHT::const_iterator it = TsMap.find(key); + return it != TsMap.end(); +} + +bool TS::IsRLELossless(TSKey const &key) +{ + bool r = false; + // First check this is an actual transfer syntax + if( IsTransferSyntax(key) ) + { + if ( key == SpecialStrings[RLELossless] ) + { + r = true; + } + } + return r; +} + +bool TS::IsJPEGLossless(TSKey const &key) +{ + bool r = false; + // First check this is an actual transfer syntax + if( IsTransferSyntax(key) ) + { + if ( key == SpecialStrings[JPEGFullProgressionProcess10_12] + || key == SpecialStrings[JPEGLosslessProcess14] + || key == SpecialStrings[JPEGLosslessProcess14_1] ) + { + r = true; + } + } + return r; +} + +/** + * \brief Determines if the Transfer Syntax was already encountered + * and if it corresponds to a JPEG2000 one + * @return True when JPEG2000 (Lossly or LossLess) found. False in all + * other cases. + */ +bool TS::IsJPEG2000(TSKey const &key) +{ + bool r = false; + // First check this is an actual transfer syntax + if( IsTransferSyntax(key) ) { - if( it->first == key ) return true; + if ( key == SpecialStrings[JPEG2000Lossless] + || key == SpecialStrings[JPEG2000] ) + { + r = true; + } } + return r; +} - return false; +/** + * \brief Determines if the Transfer Syntax corresponds to any form + * of Jpeg encoded Pixel data. + * @return True when any form of JPEG found. False otherwise. + */ +bool TS::IsJPEG(TSKey const &key) +{ + bool r = false; + // First check this is an actual transfer syntax + if( IsTransferSyntax(key) ) + { + if ( key == SpecialStrings[JPEGBaselineProcess1] + || key == SpecialStrings[JPEGExtendedProcess2_4] + || key == SpecialStrings[JPEGExtendedProcess3_5] + || key == SpecialStrings[JPEGSpectralSelectionProcess6_8] + || IsJPEGLossless( key ) + || IsJPEG2000( key ) ) + { + r = true; + } + } + return r; +} + +/** + * \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 TS::IsEncapsulate(TSKey const &key) +{ + bool r = false; + // First check this is an actual transfer syntax + if( IsTransferSyntax(key) ) + { + if ( key == SpecialStrings[RLELossless] + || IsJPEG(key) ) + { + r = true; + } + } + return r; +} + +TS::SpecialType TS::GetSpecialTransferSyntax(TSKey const &key) +{ + for (int i = 0; SpecialStrings[i] != NULL; i++) + { + if ( SpecialStrings[i] == key ) + { + return SpecialType(i); + } + } + + return UnknownTS; +} + +const char* TS::GetSpecialTransferSyntax(SpecialType t) +{ + return SpecialStrings[t]; } //----------------------------------------------------------------------------- diff --git a/src/gdcmTS.h b/src/gdcmTS.h index e1fa5502..4b6ddc50 100644 --- a/src/gdcmTS.h +++ b/src/gdcmTS.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmTS.h,v $ Language: C++ - Date: $Date: 2005/01/11 15:15:38 $ - Version: $Revision: 1.16 $ + Date: $Date: 2005/01/11 16:44:43 $ + Version: $Revision: 1.17 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -32,6 +32,7 @@ typedef std::string TSKey; typedef std::string TSAtr; typedef std::map TSHT; // Transfer Syntax Hash Table + //----------------------------------------------------------------------------- /** * \brief Container for dicom 'Transfer Syntax' Hash Table @@ -39,6 +40,26 @@ typedef std::map TSHT; // Transfer Syntax Hash Table */ class GDCM_EXPORT TS { +public: +enum SpecialType { + ImplicitVRLittleEndian = 0, + ImplicitVRLittleEndianDLXGE, + ExplicitVRLittleEndian, + DeflatedExplicitVRLittleEndian, + ExplicitVRBigEndian, + JPEGBaselineProcess1, + JPEGExtendedProcess2_4, + JPEGExtendedProcess3_5, + JPEGSpectralSelectionProcess6_8, + JPEGFullProgressionProcess10_12, + JPEGLosslessProcess14, + JPEGLosslessProcess14_1, + JPEG2000Lossless, + JPEG2000, + RLELossless, + UnknownTS +}; + public: TS(); ~TS(); @@ -48,6 +69,15 @@ public: int Count(TSKey const &key); TSAtr const &GetValue(TSKey const &key); bool IsTransferSyntax(TSKey const &key); + bool IsRLELossless(TSKey const &key); + bool IsJPEGLossless(TSKey const&key); + bool IsJPEG2000(TSKey const &key); + bool IsJPEG(TSKey const &key); + bool IsEncapsulate(TSKey const &key); + + // This should be deprecated very soon + SpecialType GetSpecialTransferSyntax(TSKey const &key); + const char* GetSpecialTransferSyntax(SpecialType t); private: TSHT TsMap; -- 2.45.1