1 /*=========================================================================
4 Module: $RCSfile: gdcmTS.cxx,v $
6 Date: $Date: 2005/09/20 09:09:43 $
7 Version: $Revision: 1.50 $
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"
27 #include <ctype.h> // for isdigit
30 // a lot of troubles expected with TS : 1.2.840.113619.5.2
31 // Implicit VR - Big Endian
32 // http://www.gemedicalsystemseurope.com/euen/it_solutions/pdf/lsqxi_rev2.pdf
37 //-----------------------------------------------------------------------------
38 /// \brief Transfer Syntaxes gdcm deals with (internal use only)
39 static const char *SpecialStrings[] = {
40 // Implicit VR Little Endian
42 // Implicit VR Big Endian DLX (G.E Private)
44 // Explicit VR Little Endian
45 "1.2.840.10008.1.2.1",
46 // Deflated Explicit VR Little Endian
47 "1.2.840.10008.1.2.1.99",
48 // Explicit VR Big Endian
49 "1.2.840.10008.1.2.2",
50 // JPEG Baseline (Process 1)
51 "1.2.840.10008.1.2.4.50",
52 // JPEG Extended (Process 2 & 4)
53 "1.2.840.10008.1.2.4.51",
54 // JPEG Extended (Process 3 & 5)
55 "1.2.840.10008.1.2.4.52",
56 // JPEG Spectral Selection, Non-Hierarchical (Process 6 & 8)
57 "1.2.840.10008.1.2.4.53",
58 // JPEG Full Progression, Non-Hierarchical (Process 10 & 12)
59 "1.2.840.10008.1.2.4.55",
60 // JPEG Lossless, Non-Hierarchical (Process 14)
61 "1.2.840.10008.1.2.4.57",
62 // JPEG Lossless, Hierarchical, First-Order Prediction (Process 14,
63 // [Selection Value 1])
64 "1.2.840.10008.1.2.4.70",
65 // JPEG-LS Lossless Image Compression
66 "1.2.840.10008.1.2.4.80",
67 // JPEG-LS Lossy (Near-Lossless) Image Compression
68 "1.2.840.10008.1.2.4.81",
70 "1.2.840.10008.1.2.4.90",
72 "1.2.840.10008.1.2.4.91",
74 "1.2.840.10008.1.2.5",
75 // MPEG2 Main Profile @ Main Level
76 "1.2.840.10008.1.2.4.100",
78 "Unknown Transfer Syntax"
81 //-----------------------------------------------------------------------------
82 /// \brief auto generated function, to fill up the Dicom Dictionnary,
83 /// if relevant file is not found on user's disk
84 void FillDefaultTSDict(TSHT &ts);
86 //-----------------------------------------------------------------------------
87 // Constructor / Destructor
90 std::string filename = DictSet::BuildDictPath() + DICT_TS;
91 std::ifstream from(filename.c_str());
94 gdcmWarningMacro("Can't open dictionary" << filename.c_str());
95 FillDefaultTSDict( TsMap );
106 std::getline(from, name);
122 //-----------------------------------------------------------------------------
125 /// \brief returns occurence number of the given key
126 int TS::Count(TSKey const &key)
128 return TsMap.count(key);
131 /// \brief returns the human readable value of a Transfer Syntax string
132 TSAtr const &TS::GetValue(TSKey const &key)
134 // First thing clean up the string
135 // (sometimes the transfer syntax is padded with spaces)
136 std::string copy = key;
137 while ( copy.size() && !isdigit((unsigned char)copy[copy.size()-1]) )
139 copy.erase(copy.size()-1, 1);
142 TSHT::const_iterator it = TsMap.find(copy);
143 if (it == TsMap.end())
150 * \brief Determines if the key passed corresponds to a 'Transfer Syntax'
151 * as defined in DICOM (and stored in gdcm::TS class)
152 * @return True when key is an actual 'Transfer Syntax'.
153 * False in all other cases.
155 bool TS::IsTransferSyntax(TSKey const &key)
157 TSHT::const_iterator it = TsMap.find(key);
158 return it != TsMap.end();
162 * \brief Determines if the Transfer Syntax was already encountered
163 * and if it corresponds to a Run Length Encoding Lossless one
164 * @return True when Run Length Encoding Lossless found.
165 * False in all other cases.
167 bool TS::IsRLELossless(TSKey const &key)
170 // First check this is an actual transfer syntax
171 if ( IsTransferSyntax(key) )
173 if ( key == SpecialStrings[RLELossless] )
182 * \brief Determines if the Transfer Syntax was already encountered
183 * and if it corresponds to a 'classical' JPEG Lossless one
184 * @return True when 'classical' Lossless found.
185 * False in all other cases.
187 bool TS::IsJPEGLossless(TSKey const &key)
190 // First check this is an actual transfer syntax
191 if ( IsTransferSyntax(key) )
193 if ( key == SpecialStrings[JPEGFullProgressionProcess10_12]
194 || key == SpecialStrings[JPEGLosslessProcess14]
195 || key == SpecialStrings[JPEGLosslessProcess14_1] )
204 * \brief Determines if the Transfer Syntax was already encountered
205 * and if it corresponds to a 'classical' JPEG Lossy one
206 * @return True when 'classical' Lossy found.
207 * False in all other cases.
209 bool TS::IsJPEGLossy(TSKey const &key)
212 // First check this is an actual transfer syntax
213 if ( IsTransferSyntax(key) )
215 if ( key == SpecialStrings[JPEGBaselineProcess1]
216 || key == SpecialStrings[JPEGExtendedProcess2_4]
217 || key == SpecialStrings[JPEGExtendedProcess3_5]
218 || key == SpecialStrings[JPEGSpectralSelectionProcess6_8] )
227 * \brief Determines if the Transfer Syntax was already encountered
228 * and if it corresponds to a JPEG2000 one
229 * @return True when JPEG2000 (Lossly or LossLess) found.
230 * False in all other cases.
232 bool TS::IsJPEG2000(TSKey const &key)
235 // First check this is an actual transfer syntax
236 if ( IsTransferSyntax(key) )
238 if ( key == SpecialStrings[JPEG2000Lossless]
239 || key == SpecialStrings[JPEG2000] )
248 * \brief Determines if the Transfer Syntax corresponds to
249 * 'classical' Jpeg Lossless or Jpeg lossy.
250 * @return True when any form of JPEG found. False otherwise.
252 bool TS::IsJPEG(TSKey const &key)
255 // First check this is an actual transfer syntax
256 if ( IsTransferSyntax(key) )
258 if ( IsJPEGLossy( key )
259 || IsJPEGLossless( key )
271 * \brief Determines if the Transfer Syntax corresponds to any form
272 * of Jpeg-LS encoded Pixel data.
273 * @return True when any form of JPEG-LS found. False otherwise.
275 bool TS::IsJPEGLS(TSKey const &key)
278 // First check this is an actual transfer syntax
279 if ( IsTransferSyntax(key) )
281 if ( key == SpecialStrings[JPEGLSLossless]
282 || key == SpecialStrings[JPEGLSNearLossless] )
291 * \brief Determines if the Transfer Syntax corresponds to any form
292 * of MPEG encoded Pixel data.
293 * @return True when any form of MPEG found. False otherwise.
295 bool TS::IsMPEG(TSKey const &key)
298 // First check this is an actual transfer syntax
299 if ( IsTransferSyntax(key) )
301 if ( key == SpecialStrings[MPEG2MainProfile] )
310 * \brief GetSpecialTransferSyntax ??
311 * @param key TSKey const &key ??
312 * @return TS::SpecialType ??.
314 TS::SpecialType TS::GetSpecialTransferSyntax(TSKey const &key)
316 for (int i = 0; SpecialStrings[i] != NULL; i++)
318 if ( SpecialStrings[i] == key )
320 return SpecialType(i);
327 * \brief GetSpecialTransferSyntax ??
328 * @param t SpecialType t ??
329 * @return char* TS : SpecialStrings[t] ??.
331 const char* TS::GetSpecialTransferSyntax(SpecialType t)
333 return SpecialStrings[t];
336 //-----------------------------------------------------------------------------
339 //-----------------------------------------------------------------------------
342 //-----------------------------------------------------------------------------
346 * @param os The output stream to be written to.
348 void TS::Print(std::ostream &os)
350 std::ostringstream s;
352 for (TSHT::const_iterator it = TsMap.begin(); it != TsMap.end(); ++it)
354 s << "TS : " << it->first << " = " << it->second << std::endl;
359 //-----------------------------------------------------------------------------
360 } // end namespace gdcm