1 /*=========================================================================
4 Module: $RCSfile: gdcmTS.cxx,v $
6 Date: $Date: 2005/06/09 21:14:43 $
7 Version: $Revision: 1.47 $
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 // http://www.gemedicalsystemseurope.com/euen/it_solutions/pdf/lsqxi_rev2.pdf
36 //-----------------------------------------------------------------------------
37 /// \brief Transfer Syntaxes gdcm deals with (internal use only)
38 static const char *SpecialStrings[] = {
39 // Implicit VR Little Endian
41 // Implicit VR Big Endian DLX (G.E Private)
43 // Explicit VR Little Endian
44 "1.2.840.10008.1.2.1",
45 // Deflated Explicit VR Little Endian
46 "1.2.840.10008.1.2.1.99",
47 // Explicit VR Big Endian
48 "1.2.840.10008.1.2.2",
49 // JPEG Baseline (Process 1)
50 "1.2.840.10008.1.2.4.50",
51 // JPEG Extended (Process 2 & 4)
52 "1.2.840.10008.1.2.4.51",
53 // JPEG Extended (Process 3 & 5)
54 "1.2.840.10008.1.2.4.52",
55 // JPEG Spectral Selection, Non-Hierarchical (Process 6 & 8)
56 "1.2.840.10008.1.2.4.53",
57 // JPEG Full Progression, Non-Hierarchical (Process 10 & 12)
58 "1.2.840.10008.1.2.4.55",
59 // JPEG Lossless, Non-Hierarchical (Process 14)
60 "1.2.840.10008.1.2.4.57",
61 // JPEG Lossless, Hierarchical, First-Order Prediction (Process 14,
62 // [Selection Value 1])
63 "1.2.840.10008.1.2.4.70",
64 // JPEG-LS Lossless Image Compression
65 "1.2.840.10008.1.2.4.80",
66 // JPEG-LS Lossy (Near-Lossless) Image Compression
67 "1.2.840.10008.1.2.4.81",
69 "1.2.840.10008.1.2.4.90",
71 "1.2.840.10008.1.2.4.91",
73 "1.2.840.10008.1.2.5",
74 // MPEG2 Main Profile @ Main Level
75 "1.2.840.10008.1.2.4.100",
77 "Unknown Transfer Syntax"
80 //-----------------------------------------------------------------------------
81 /// \brief auto generated function, to fill up the Dicom Dictionnary,
82 /// if relevant file is not found on user's disk
83 void FillDefaultTSDict(TSHT &ts);
85 //-----------------------------------------------------------------------------
86 // Constructor / Destructor
89 std::string filename = DictSet::BuildDictPath() + DICT_TS;
90 std::ifstream from(filename.c_str());
93 gdcmWarningMacro("Can't open dictionary" << filename.c_str());
94 FillDefaultTSDict( TsMap );
105 std::getline(from, name);
121 //-----------------------------------------------------------------------------
124 /// \brief returns occurence number of the given key
125 int TS::Count(TSKey const &key)
127 return TsMap.count(key);
130 /// \brief returns the human reabable value of a Transfer Synatx string
131 TSAtr const &TS::GetValue(TSKey const &key)
133 // First thing clean up the string
134 // (sometime the transfer syntax is padded with spaces)
135 std::string copy = key;
136 while ( copy.size() && !isdigit((unsigned char)copy[copy.size()-1]) )
138 copy.erase(copy.size()-1, 1);
141 TSHT::const_iterator it = TsMap.find(copy);
142 if (it == TsMap.end())
149 * \brief Determines if the key passed corresponds to a 'Transfer Syntax'
150 * as defined in DICOM (and stored in gdcm::TS class)
151 * @return True when key is an actual 'Transfer Syntax'. False in all
154 bool TS::IsTransferSyntax(TSKey const &key)
156 TSHT::const_iterator it = TsMap.find(key);
157 return it != TsMap.end();
161 * \brief Determines if the Transfer Syntax was already encountered
162 * and if it corresponds to a Run Length Encoding Lossless one
163 * @return True when Run Length Encoding Lossless found. False in all
166 bool TS::IsRLELossless(TSKey const &key)
169 // First check this is an actual transfer syntax
170 if( IsTransferSyntax(key) )
172 if ( key == SpecialStrings[RLELossless] )
181 * \brief Determines if the Transfer Syntax was already encountered
182 * and if it corresponds to a 'classical' JPEG Lossless one
183 * @return True when 'classical' Lossless found. False in all
186 bool TS::IsJPEGLossless(TSKey const &key)
189 // First check this is an actual transfer syntax
190 if( IsTransferSyntax(key) )
192 if ( key == SpecialStrings[JPEGFullProgressionProcess10_12]
193 || key == SpecialStrings[JPEGLosslessProcess14]
194 || key == SpecialStrings[JPEGLosslessProcess14_1] )
203 * \brief Determines if the Transfer Syntax was already encountered
204 * and if it corresponds to a 'classical' JPEG Lossy one
205 * @return True when 'classical' Lossy found. False in all
208 bool TS::IsJPEGLossy(TSKey const &key)
211 // First check this is an actual transfer syntax
212 if( IsTransferSyntax(key) )
214 if ( key == SpecialStrings[JPEGBaselineProcess1]
215 || key == SpecialStrings[JPEGExtendedProcess2_4]
216 || key == SpecialStrings[JPEGExtendedProcess3_5]
217 || key == SpecialStrings[JPEGSpectralSelectionProcess6_8] )
226 * \brief Determines if the Transfer Syntax was already encountered
227 * and if it corresponds to a JPEG2000 one
228 * @return True when JPEG2000 (Lossly or LossLess) found. False in all
231 bool TS::IsJPEG2000(TSKey const &key)
234 // First check this is an actual transfer syntax
235 if( IsTransferSyntax(key) )
237 if ( key == SpecialStrings[JPEG2000Lossless]
238 || key == SpecialStrings[JPEG2000] )
247 * \brief Determines if the Transfer Syntax corresponds to
248 * 'classical' Jpeg Lossless or Jpeg lossy.
249 * @return True when any form of JPEG found. False otherwise.
251 bool TS::IsJPEG(TSKey const &key)
254 // First check this is an actual transfer syntax
255 if( IsTransferSyntax(key) )
257 if ( IsJPEGLossy( key )
258 || IsJPEGLossless( key )
270 * \brief Determines if the Transfer Syntax corresponds to any form
271 * of Jpeg-LS encoded Pixel data.
272 * @return True when any form of JPEG-LS found. False otherwise.
274 bool TS::IsJPEGLS(TSKey const &key)
277 // First check this is an actual transfer syntax
278 if( IsTransferSyntax(key) )
280 if ( key == SpecialStrings[JPEGLSLossless]
281 || key == SpecialStrings[JPEGLSNearLossless] )
290 * \brief Determines if the Transfer Syntax corresponds to any form
291 * of MPEG encoded Pixel data.
292 * @return True when any form of MPEG found. False otherwise.
294 bool TS::IsMPEG(TSKey const &key)
297 // First check this is an actual transfer syntax
298 if( IsTransferSyntax(key) )
300 if ( key == SpecialStrings[MPEG2MainProfile] )
309 * \brief GetSpecialTransferSyntax ??
310 * @param key TSKey const &key ??
311 * @return TS::SpecialType ??.
313 TS::SpecialType TS::GetSpecialTransferSyntax(TSKey const &key)
315 for (int i = 0; SpecialStrings[i] != NULL; i++)
317 if ( SpecialStrings[i] == key )
319 return SpecialType(i);
326 * \brief GetSpecialTransferSyntax ??
327 * @param t SpecialType t ??
328 * @return char* TS : SpecialStrings[t] ??.
330 const char* TS::GetSpecialTransferSyntax(SpecialType t)
332 return SpecialStrings[t];
335 //-----------------------------------------------------------------------------
338 //-----------------------------------------------------------------------------
341 //-----------------------------------------------------------------------------
345 * @param os The output stream to be written to.
347 void TS::Print(std::ostream &os)
349 std::ostringstream s;
351 for (TSHT::const_iterator it = TsMap.begin(); it != TsMap.end(); ++it)
353 s << "TS : " << it->first << " = " << it->second << std::endl;
358 //-----------------------------------------------------------------------------
359 } // end namespace gdcm