1 /*=========================================================================
4 Module: $RCSfile: gdcmTS.cxx,v $
6 Date: $Date: 2005/10/26 08:04:16 $
7 Version: $Revision: 1.52 $
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", // Pretty sure we never use this case...
79 NULL // Compilers have no obligation to finish by NULL, do it ourself
82 //-----------------------------------------------------------------------------
83 /// \brief auto generated function, to fill up the Dicom Dictionnary,
84 /// if relevant file is not found on user's disk
85 void FillDefaultTSDict(TSHT &ts);
87 //-----------------------------------------------------------------------------
88 // Constructor / Destructor
91 std::string filename = DictSet::BuildDictPath() + DICT_TS;
92 std::ifstream from(filename.c_str());
95 gdcmWarningMacro("Can't open dictionary" << filename.c_str());
96 FillDefaultTSDict( TsMap );
107 std::getline(from, name);
123 //-----------------------------------------------------------------------------
126 /// \brief returns occurence number of the given key
127 int TS::Count(TSKey const &key)
129 return TsMap.count(key);
132 /// \brief returns the human readable value of a Transfer Syntax string
133 TSAtr const &TS::GetValue(TSKey const &key)
135 // First thing clean up the string
136 // (sometimes the transfer syntax is padded with spaces)
137 std::string copy = key;
138 while ( copy.size() && !isdigit((unsigned char)copy[copy.size()-1]) )
140 copy.erase(copy.size()-1, 1);
143 TSHT::const_iterator it = TsMap.find(copy);
144 if (it == TsMap.end())
151 * \brief Determines if the key passed corresponds to a 'Transfer Syntax'
152 * as defined in DICOM (and stored in gdcm::TS class)
153 * @return True when key is an actual 'Transfer Syntax'.
154 * False in all other cases.
156 bool TS::IsTransferSyntax(TSKey const &key)
158 TSHT::const_iterator it = TsMap.find(key);
159 return it != TsMap.end();
163 * \brief Determines if the Transfer Syntax was already encountered
164 * and if it corresponds to a Run Length Encoding Lossless one
165 * @return True when Run Length Encoding Lossless found.
166 * False in all other cases.
168 bool TS::IsRLELossless(TSKey const &key)
171 // First check this is an actual transfer syntax
172 if ( IsTransferSyntax(key) )
174 if ( key == SpecialStrings[RLELossless] )
183 * \brief Determines if the Transfer Syntax was already encountered
184 * and if it corresponds to a 'classical' JPEG Lossless one
185 * @return True when 'classical' Lossless found.
186 * False in all other cases.
188 bool TS::IsJPEGLossless(TSKey const &key)
191 // First check this is an actual transfer syntax
192 if ( IsTransferSyntax(key) )
194 if ( key == SpecialStrings[JPEGFullProgressionProcess10_12]
195 || key == SpecialStrings[JPEGLosslessProcess14]
196 || key == SpecialStrings[JPEGLosslessProcess14_1] )
205 * \brief Determines if the Transfer Syntax was already encountered
206 * and if it corresponds to a 'classical' JPEG Lossy one
207 * @return True when 'classical' Lossy found.
208 * False in all other cases.
210 bool TS::IsJPEGLossy(TSKey const &key)
213 // First check this is an actual transfer syntax
214 if ( IsTransferSyntax(key) )
216 if ( key == SpecialStrings[JPEGBaselineProcess1]
217 || key == SpecialStrings[JPEGExtendedProcess2_4]
218 || key == SpecialStrings[JPEGExtendedProcess3_5]
219 || key == SpecialStrings[JPEGSpectralSelectionProcess6_8] )
228 * \brief Determines if the Transfer Syntax was already encountered
229 * and if it corresponds to a JPEG2000 one
230 * @return True when JPEG2000 (Lossly or LossLess) found.
231 * False in all other cases.
233 bool TS::IsJPEG2000(TSKey const &key)
236 // First check this is an actual transfer syntax
237 if ( IsTransferSyntax(key) )
239 if ( key == SpecialStrings[JPEG2000Lossless]
240 || key == SpecialStrings[JPEG2000] )
249 * \brief Determines if the Transfer Syntax corresponds to
250 * 'classical' Jpeg Lossless or Jpeg lossy.
251 * @return True when any form of JPEG found. False otherwise.
253 bool TS::IsJPEG(TSKey const &key)
256 // First check this is an actual transfer syntax
257 if ( IsTransferSyntax(key) )
259 if ( IsJPEGLossy( key )
260 || IsJPEGLossless( key )
272 * \brief Determines if the Transfer Syntax corresponds to any form
273 * of Jpeg-LS encoded Pixel data.
274 * @return True when any form of JPEG-LS found. False otherwise.
276 bool TS::IsJPEGLS(TSKey const &key)
279 // First check this is an actual transfer syntax
280 if ( IsTransferSyntax(key) )
282 if ( key == SpecialStrings[JPEGLSLossless]
283 || key == SpecialStrings[JPEGLSNearLossless] )
292 * \brief Determines if the Transfer Syntax corresponds to any form
293 * of MPEG encoded Pixel data.
294 * @return True when any form of MPEG found. False otherwise.
296 bool TS::IsMPEG(TSKey const &key)
299 // First check this is an actual transfer syntax
300 if ( IsTransferSyntax(key) )
302 if ( key == SpecialStrings[MPEG2MainProfile] )
311 * \brief GetSpecialTransferSyntax ??
312 * @param key TSKey const &key ??
313 * @return TS::SpecialType ??.
315 TS::SpecialType TS::GetSpecialTransferSyntax(TSKey const &key)
317 for (int i = 0; SpecialStrings[i] != NULL; i++)
319 if ( SpecialStrings[i] == key )
321 return SpecialType(i);
328 * \brief GetSpecialTransferSyntax ??
329 * @param t SpecialType t ??
330 * @return char* TS : SpecialStrings[t] ??.
332 const char* TS::GetSpecialTransferSyntax(SpecialType t)
334 return SpecialStrings[t];
337 //-----------------------------------------------------------------------------
340 //-----------------------------------------------------------------------------
343 //-----------------------------------------------------------------------------
347 * @param os The output stream to be written to.
349 void TS::Print(std::ostream &os,std::string const &)
351 std::ostringstream s;
353 for (TSHT::const_iterator it = TsMap.begin(); it != TsMap.end(); ++it)
355 s << "TS : " << it->first << " = " << it->second << std::endl;
360 //-----------------------------------------------------------------------------
361 } // end namespace gdcm