1 /*=========================================================================
4 Module: $RCSfile: gdcmTS.cxx,v $
6 Date: $Date: 2005/12/09 12:23:39 $
7 Version: $Revision: 1.53 $
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 // 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
33 // G.E. deliberately violated a lot of Dicom rules are
34 // (probabely to to avoid other people to read their images)
35 // Just try and error on new images :
36 // PrintFile debug filein=...
41 //-----------------------------------------------------------------------------
42 /// \brief Transfer Syntaxes gdcm deals with (internal use only)
43 static const char *SpecialStrings[] = {
44 // Implicit VR Little Endian
46 // Implicit VR Big Endian (G.E Private)
48 // Explicit VR Little Endian
49 "1.2.840.10008.1.2.1",
50 // Deflated Explicit VR Little Endian
51 "1.2.840.10008.1.2.1.99",
52 // Explicit VR Big Endian
53 "1.2.840.10008.1.2.2",
54 // JPEG Baseline (Process 1)
55 "1.2.840.10008.1.2.4.50",
56 // JPEG Extended (Process 2 & 4)
57 "1.2.840.10008.1.2.4.51",
58 // JPEG Extended (Process 3 & 5)
59 "1.2.840.10008.1.2.4.52",
60 // JPEG Spectral Selection, Non-Hierarchical (Process 6 & 8)
61 "1.2.840.10008.1.2.4.53",
62 // JPEG Full Progression, Non-Hierarchical (Process 10 & 12)
63 "1.2.840.10008.1.2.4.55",
64 // JPEG Lossless, Non-Hierarchical (Process 14)
65 "1.2.840.10008.1.2.4.57",
66 // JPEG Lossless, Hierarchical, First-Order Prediction (Process 14,
67 // [Selection Value 1])
68 "1.2.840.10008.1.2.4.70",
69 // JPEG-LS Lossless Image Compression
70 "1.2.840.10008.1.2.4.80",
71 // JPEG-LS Lossy (Near-Lossless) Image Compression
72 "1.2.840.10008.1.2.4.81",
74 "1.2.840.10008.1.2.4.90",
76 "1.2.840.10008.1.2.4.91",
78 "1.2.840.10008.1.2.5",
79 // MPEG2 Main Profile @ Main Level
80 "1.2.840.10008.1.2.4.100",
82 "Unknown Transfer Syntax", // Pretty sure we never use this case...
83 NULL // Compilers have no obligation to finish by NULL, do it ourself
86 //-----------------------------------------------------------------------------
87 /// \brief auto generated function, to fill up the Dicom Dictionnary,
88 /// if relevant file is not found on user's disk
89 void FillDefaultTSDict(TSHT &ts);
91 //-----------------------------------------------------------------------------
92 // Constructor / Destructor
95 std::string filename = DictSet::BuildDictPath() + DICT_TS;
96 std::ifstream from(filename.c_str());
99 gdcmWarningMacro("Can't open dictionary" << filename.c_str());
100 FillDefaultTSDict( TsMap );
111 std::getline(from, name);
127 //-----------------------------------------------------------------------------
130 /// \brief returns occurence number of the given key
131 int TS::Count(TSKey const &key)
133 return TsMap.count(key);
136 /// \brief returns the human readable value of a Transfer Syntax string
137 TSAtr const &TS::GetValue(TSKey const &key)
139 // First thing clean up the string
140 // (sometimes the transfer syntax is padded with spaces)
141 std::string copy = key;
142 while ( copy.size() && !isdigit((unsigned char)copy[copy.size()-1]) )
144 copy.erase(copy.size()-1, 1);
147 TSHT::const_iterator it = TsMap.find(copy);
148 if (it == TsMap.end())
155 * \brief Determines if the key passed corresponds to a 'Transfer Syntax'
156 * as defined in DICOM (and stored in gdcm::TS class)
157 * @return True when key is an actual 'Transfer Syntax'.
158 * False in all other cases.
160 bool TS::IsTransferSyntax(TSKey const &key)
162 TSHT::const_iterator it = TsMap.find(key);
163 return it != TsMap.end();
167 * \brief Determines if the Transfer Syntax was already encountered
168 * and if it corresponds to a Run Length Encoding Lossless one
169 * @return True when Run Length Encoding Lossless found.
170 * False in all other cases.
172 bool TS::IsRLELossless(TSKey const &key)
175 // First check this is an actual transfer syntax
176 if ( IsTransferSyntax(key) )
178 if ( key == SpecialStrings[RLELossless] )
187 * \brief Determines if the Transfer Syntax was already encountered
188 * and if it corresponds to a 'classical' JPEG Lossless one
189 * @return True when 'classical' Lossless found.
190 * False in all other cases.
192 bool TS::IsJPEGLossless(TSKey const &key)
195 // First check this is an actual transfer syntax
196 if ( IsTransferSyntax(key) )
198 if ( key == SpecialStrings[JPEGFullProgressionProcess10_12]
199 || key == SpecialStrings[JPEGLosslessProcess14]
200 || key == SpecialStrings[JPEGLosslessProcess14_1] )
209 * \brief Determines if the Transfer Syntax was already encountered
210 * and if it corresponds to a 'classical' JPEG Lossy one
211 * @return True when 'classical' Lossy found.
212 * False in all other cases.
214 bool TS::IsJPEGLossy(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] )
232 * \brief Determines if the Transfer Syntax was already encountered
233 * and if it corresponds to a JPEG2000 one
234 * @return True when JPEG2000 (Lossly or LossLess) found.
235 * False in all other cases.
237 bool TS::IsJPEG2000(TSKey const &key)
240 // First check this is an actual transfer syntax
241 if ( IsTransferSyntax(key) )
243 if ( key == SpecialStrings[JPEG2000Lossless]
244 || key == SpecialStrings[JPEG2000] )
253 * \brief Determines if the Transfer Syntax corresponds to
254 * 'classical' Jpeg Lossless or Jpeg lossy.
255 * @return True when any form of JPEG found. False otherwise.
257 bool TS::IsJPEG(TSKey const &key)
260 // First check this is an actual transfer syntax
261 if ( IsTransferSyntax(key) )
263 if ( IsJPEGLossy( key )
264 || IsJPEGLossless( key )
276 * \brief Determines if the Transfer Syntax corresponds to any form
277 * of Jpeg-LS encoded Pixel data.
278 * @return True when any form of JPEG-LS found. False otherwise.
280 bool TS::IsJPEGLS(TSKey const &key)
283 // First check this is an actual transfer syntax
284 if ( IsTransferSyntax(key) )
286 if ( key == SpecialStrings[JPEGLSLossless]
287 || key == SpecialStrings[JPEGLSNearLossless] )
296 * \brief Determines if the Transfer Syntax corresponds to any form
297 * of MPEG encoded Pixel data.
298 * @return True when any form of MPEG found. False otherwise.
300 bool TS::IsMPEG(TSKey const &key)
303 // First check this is an actual transfer syntax
304 if ( IsTransferSyntax(key) )
306 if ( key == SpecialStrings[MPEG2MainProfile] )
315 * \brief GetSpecialTransferSyntax ??
316 * @param key TSKey const &key ??
317 * @return TS::SpecialType ??.
319 TS::SpecialType TS::GetSpecialTransferSyntax(TSKey const &key)
321 for (int i = 0; SpecialStrings[i] != NULL; i++)
323 if ( SpecialStrings[i] == key )
325 return SpecialType(i);
332 * \brief GetSpecialTransferSyntax ??
333 * @param t SpecialType t ??
334 * @return char* TS : SpecialStrings[t] ??.
336 const char* TS::GetSpecialTransferSyntax(SpecialType t)
338 return SpecialStrings[t];
341 //-----------------------------------------------------------------------------
344 //-----------------------------------------------------------------------------
347 //-----------------------------------------------------------------------------
351 * @param os The output stream to be written to.
353 void TS::Print(std::ostream &os,std::string const &)
355 std::ostringstream s;
357 for (TSHT::const_iterator it = TsMap.begin(); it != TsMap.end(); ++it)
359 s << "TS : " << it->first << " = " << it->second << std::endl;
364 //-----------------------------------------------------------------------------
365 } // end namespace gdcm