1 /*=========================================================================
4 Module: $RCSfile: gdcmTS.cxx,v $
6 Date: $Date: 2005/01/11 23:16:47 $
7 Version: $Revision: 1.36 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
20 #include "gdcmDebug.h"
22 #include "gdcmDictSet.h"
29 // a lot of troubles expected with TS : 1.2.840.113619.5.2
30 // Implicit VR - Big Endian
31 // see : http://www.gemedicalsystemseurope.com/euen/it_solutions/pdf/lsqxi_rev2.pdf
36 //-----------------------------------------------------------------------------
37 static const char *SpecialStrings[] = {
38 // Implicit VR Little Endian
40 // Implicit VR Big Endian DLX (G.E Private)
42 // Explicit VR Little Endian
43 "1.2.840.10008.1.2.1",
44 // Deflated Explicit VR Little Endian
45 "1.2.840.10008.1.2.1.99",
46 // Explicit VR Big Endian
47 "1.2.840.10008.1.2.2",
48 // JPEG Baseline (Process 1)
49 "1.2.840.10008.1.2.4.50",
50 // JPEG Extended (Process 2 & 4)
51 "1.2.840.10008.1.2.4.51",
52 // JPEG Extended (Process 3 & 5)
53 "1.2.840.10008.1.2.4.52",
54 // JPEG Spectral Selection, Non-Hierarchical (Process 6 & 8)
55 "1.2.840.10008.1.2.4.53",
56 // JPEG Full Progression, Non-Hierarchical (Process 10 & 12)
57 "1.2.840.10008.1.2.4.55",
58 // JPEG Lossless, Non-Hierarchical (Process 14)
59 "1.2.840.10008.1.2.4.57",
60 // JPEG Lossless, Hierarchical, First-Order Prediction (Process 14, [Selection Value 1])
61 "1.2.840.10008.1.2.4.70",
63 "1.2.840.10008.1.2.4.90",
65 "1.2.840.10008.1.2.4.91",
67 "1.2.840.10008.1.2.5",
69 "Unknown Transfer Syntax"
72 void FillDefaultTSDict(TSHT &ts);
73 //-----------------------------------------------------------------------------
74 // Constructor / Destructor
77 std::string filename = DictSet::BuildDictPath() + DICT_TS;
78 std::ifstream from(filename.c_str());
81 gdcmVerboseMacro("Can't open dictionary" << filename.c_str());
82 FillDefaultTSDict( TsMap );
93 std::getline(from, name);
104 //-----------------------------------------------------------------------------
110 //-----------------------------------------------------------------------------
115 * @param os The output stream to be written to.
117 void TS::Print(std::ostream &os)
119 std::ostringstream s;
121 for (TSHT::const_iterator it = TsMap.begin(); it != TsMap.end(); ++it)
123 s << "TS : " << it->first << " = " << it->second << std::endl;
128 //-----------------------------------------------------------------------------
130 int TS::Count(TSKey const &key)
132 return TsMap.count(key);
135 TSAtr const & TS::GetValue(TSKey const &key)
137 // First thing clean up the string sometime the transfer syntax is padded with spaces
138 std::string copy = key;
139 while ( copy.size() && !isdigit((unsigned char)copy[copy.size()-1]) )
141 copy.erase(copy.size()-1, 1);
144 TSHT::const_iterator it = TsMap.find(copy);
145 if (it == TsMap.end())
152 bool TS::IsTransferSyntax(TSKey const &key)
154 TSHT::const_iterator it = TsMap.find(key);
155 return it != TsMap.end();
158 bool TS::IsRLELossless(TSKey const &key)
161 // First check this is an actual transfer syntax
162 if( IsTransferSyntax(key) )
164 if ( key == SpecialStrings[RLELossless] )
172 bool TS::IsJPEGLossless(TSKey const &key)
175 // First check this is an actual transfer syntax
176 if( IsTransferSyntax(key) )
178 if ( key == SpecialStrings[JPEGFullProgressionProcess10_12]
179 || key == SpecialStrings[JPEGLosslessProcess14]
180 || key == SpecialStrings[JPEGLosslessProcess14_1] )
189 * \brief Determines if the Transfer Syntax was already encountered
190 * and if it corresponds to a JPEG2000 one
191 * @return True when JPEG2000 (Lossly or LossLess) found. False in all
194 bool TS::IsJPEG2000(TSKey const &key)
197 // First check this is an actual transfer syntax
198 if( IsTransferSyntax(key) )
200 if ( key == SpecialStrings[JPEG2000Lossless]
201 || key == SpecialStrings[JPEG2000] )
210 * \brief Determines if the Transfer Syntax corresponds to any form
211 * of Jpeg encoded Pixel data.
212 * @return True when any form of JPEG found. False otherwise.
214 bool TS::IsJPEG(TSKey const &key)
217 // First check this is an actual transfer syntax
218 if( IsTransferSyntax(key) )
220 if ( key == SpecialStrings[JPEGBaselineProcess1]
221 || key == SpecialStrings[JPEGExtendedProcess2_4]
222 || key == SpecialStrings[JPEGExtendedProcess3_5]
223 || key == SpecialStrings[JPEGSpectralSelectionProcess6_8]
224 || IsJPEGLossless( key )
225 || IsJPEG2000( key ) )
234 * \brief Determines if the Transfer Syntax corresponds to encapsulated
235 * of encoded Pixel Data (as opposed to native).
236 * @return True when encapsulated. False when native.
238 bool TS::IsEncapsulate(TSKey const &key)
241 // First check this is an actual transfer syntax
242 if( IsTransferSyntax(key) )
244 if ( key == SpecialStrings[RLELossless]
253 TS::SpecialType TS::GetSpecialTransferSyntax(TSKey const &key)
255 for (int i = 0; SpecialStrings[i] != NULL; i++)
257 if ( SpecialStrings[i] == key )
259 return SpecialType(i);
266 const char* TS::GetSpecialTransferSyntax(SpecialType t)
268 return SpecialStrings[t];
271 //-----------------------------------------------------------------------------
274 //-----------------------------------------------------------------------------
277 //-----------------------------------------------------------------------------
279 } // end namespace gdcm